1 USING: smtp tools.test io.streams.string io.sockets
2 io.sockets.secure threads smtp.server kernel sequences
3 namespaces logging accessors assocs sorting smtp.private
4 concurrency.promises system ;
7 \ send-email must-infer
9 { 0 0 } [ [ ] with-smtp-connection ] must-infer-as
11 [ "hello\nworld" validate-address ] must-fail
13 [ "slava@factorcode.org" ]
14 [ "slava@factorcode.org" validate-address ] unit-test
16 [ { "hello" "." "world" } validate-message ] must-fail
18 [ "aGVsbG8Kd29ybGQ=\r\n.\r\n" ] [
19 "hello\nworld" [ send-body ] with-string-writer
22 [ { "500 syntax error" } <response> check-response ]
23 [ smtp-error? ] must-fail-with
25 [ ] [ { "220 success" } <response> check-response ] unit-test
27 [ T{ response f 220 { "220 success" } } ] [
28 "220 success" [ receive-response ] with-string-reader
33 "220-a multiline response"
38 "220-a multiline response\r\n250-another line\r\n220 the end"
39 [ receive-response ] with-string-reader
43 "220-a multiline response\r\n250-another line\r\n220 the end"
44 [ get-ok ] with-string-reader
48 "Subject:\r\nsecurity hole" validate-header
53 { "Content-Transfer-Encoding" "base64" }
54 { "Content-Type" "Text/plain; charset=utf-8" }
55 { "From" "Doug <erg@factorcode.org>" }
56 { "MIME-Version" "1.0" }
57 { "Subject" "Factor rules" }
58 { "To" "Slava <slava@factorcode.org>, Ed <dharmatech@factorcode.org>" }
60 { "slava@factorcode.org" "dharmatech@factorcode.org" }
64 "Factor rules" >>subject
66 "Slava <slava@factorcode.org>"
67 "Ed <dharmatech@factorcode.org>"
69 "Doug <erg@factorcode.org>" >>from
71 email>headers sort-keys [
72 drop { "Date" "Message-Id" } member? not
75 [ to>> [ extract-email ] map ]
76 [ from>> extract-email ] tri
81 [ ] [ "p" get mock-smtp-server ] unit-test
84 <secure-config> f >>verify [
85 "localhost" "p" get ?promise <inet> smtp-server set
87 os unix? [ smtp-tls? on ] when
90 "Hi guys\nBye guys" >>body
91 "Factor rules" >>subject
93 "Slava <slava@factorcode.org>"
94 "Ed <dharmatech@factorcode.org>"
96 "Doug <erg@factorcode.org>" >>from