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 [ "hello\r\nworld\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 { "From" "Doug <erg@factorcode.org>" }
54 { "Subject" "Factor rules" }
55 { "To" "Slava <slava@factorcode.org>, Ed <dharmatech@factorcode.org>" }
57 { "slava@factorcode.org" "dharmatech@factorcode.org" }
61 "Factor rules" >>subject
63 "Slava <slava@factorcode.org>"
64 "Ed <dharmatech@factorcode.org>"
66 "Doug <erg@factorcode.org>" >>from
68 email>headers sort-keys [
69 drop { "Date" "Message-Id" } member? not
72 [ to>> [ extract-email ] map ]
73 [ from>> extract-email ] tri
78 [ ] [ "p" get mock-smtp-server ] unit-test
81 <secure-config> f >>verify [
82 "localhost" "p" get ?promise <inet> smtp-server set
84 os unix? [ smtp-tls? on ] when
87 "Hi guys\nBye guys" >>body
88 "Factor rules" >>subject
90 "Slava <slava@factorcode.org>"
91 "Ed <dharmatech@factorcode.org>"
93 "Doug <erg@factorcode.org>" >>from