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 [ { "hello" "." "world" } validate-message ] must-fail
16 [ "aGVsbG8Kd29ybGQ=\r\n.\r\n" ] [
17 T{ email { body "hello\nworld" } } [ send-body ] with-string-writer
20 [ { "500 syntax error" } <response> check-response ]
21 [ smtp-error? ] must-fail-with
23 [ ] [ { "220 success" } <response> check-response ] unit-test
25 [ T{ response f 220 { "220 success" } } ] [
26 "220 success" [ receive-response ] with-string-reader
31 "220-a multiline response"
36 "220-a multiline response\r\n250-another line\r\n220 the end"
37 [ receive-response ] with-string-reader
41 "220-a multiline response\r\n250-another line\r\n220 the end"
42 [ get-ok ] with-string-reader
46 "Subject:\r\nsecurity hole" validate-header
51 { "Content-Transfer-Encoding" "base64" }
52 { "Content-Type" "text/plain; charset=UTF-8" }
53 { "From" "Doug <erg@factorcode.org>" }
54 { "MIME-Version" "1.0" }
55 { "Subject" "Factor rules" }
56 { "To" "Slava <slava@factorcode.org>, Ed <dharmatech@factorcode.org>" }
58 { "slava@factorcode.org" "dharmatech@factorcode.org" }
62 "Factor rules" >>subject
64 "Slava <slava@factorcode.org>"
65 "Ed <dharmatech@factorcode.org>"
67 "Doug <erg@factorcode.org>" >>from
69 email>headers sort-keys [
70 drop { "Date" "Message-Id" } member? not
73 [ to>> [ extract-email ] map ]
74 [ from>> extract-email ] tri
79 [ ] [ "p" get mock-smtp-server ] unit-test
82 <secure-config> f >>verify [
83 "localhost" "p" get ?promise <inet> smtp-server set
85 os unix? [ smtp-tls? on ] when
88 "Hi guys\nBye guys" >>body
89 "Factor rules" >>subject
91 "Slava <slava@factorcode.org>"
92 "Ed <dharmatech@factorcode.org>"
94 "Doug <erg@factorcode.org>" >>from