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 { 0 0 } [ [ ] with-smtp-connection ] must-infer-as
9 [ "hello\nworld" validate-address ] must-fail
11 [ "slava@factorcode.org" ]
12 [ "slava@factorcode.org" validate-address ] unit-test
14 [ "aGVsbG8Kd29ybGQ=\r\n.\r\n" ] [
15 T{ email { body "hello\nworld" } } [ send-body ] with-string-writer
18 [ { "500 syntax error" } <response> check-response ]
19 [ smtp-error? ] must-fail-with
21 [ ] [ { "220 success" } <response> check-response ] unit-test
23 [ T{ response f 220 { "220 success" } } ] [
24 "220 success" [ receive-response ] with-string-reader
29 "220-a multiline response"
34 "220-a multiline response\r\n250-another line\r\n220 the end"
35 [ receive-response ] with-string-reader
39 "220-a multiline response\r\n250-another line\r\n220 the end"
40 [ get-ok ] with-string-reader
44 "Subject:\r\nsecurity hole" validate-header
49 { "Content-Transfer-Encoding" "base64" }
50 { "Content-Type" "text/plain; charset=UTF-8" }
51 { "From" "Doug <erg@factorcode.org>" }
52 { "MIME-Version" "1.0" }
53 { "Subject" "Factor rules" }
54 { "To" "Slava <slava@factorcode.org>, Ed <dharmatech@factorcode.org>" }
56 { "slava@factorcode.org" "dharmatech@factorcode.org" }
60 "Factor rules" >>subject
62 "Slava <slava@factorcode.org>"
63 "Ed <dharmatech@factorcode.org>"
65 "Doug <erg@factorcode.org>" >>from
67 email>headers sort-keys [
68 drop { "Date" "Message-Id" } member? not
71 [ to>> [ extract-email ] map ]
72 [ from>> extract-email ] tri
77 [ ] [ "p" get mock-smtp-server ] unit-test
80 <secure-config> f >>verify [
81 "localhost" "p" get ?promise <inet> smtp-server set
83 os unix? [ smtp-tls? on ] when
86 "Hi guys\nBye guys" >>body
87 "Factor rules" >>subject
89 "Slava <slava@factorcode.org>"
90 "Ed <dharmatech@factorcode.org>"
92 "Doug <erg@factorcode.org>" >>from