1 USING: smtp tools.test io.streams.string io.sockets threads
2 smtp.server kernel sequences namespaces logging accessors
3 assocs sorting smtp.private concurrency.promises ;
6 \ send-email must-infer
8 { 0 0 } [ [ ] with-smtp-connection ] must-infer-as
10 [ "hello\nworld" validate-address ] must-fail
12 [ "slava@factorcode.org" ]
13 [ "slava@factorcode.org" validate-address ] unit-test
15 [ { "hello" "." "world" } validate-message ] must-fail
17 [ "hello\r\nworld\r\n.\r\n" ] [
18 "hello\nworld" [ send-body ] with-string-writer
21 [ "500 syntax error" check-response ] must-fail
23 [ ] [ "220 success" check-response ] unit-test
26 "220 success" [ receive-response ] with-string-reader
30 "220-a multiline response\r\n250-another line\r\n220 the end"
31 [ receive-response ] with-string-reader
35 "220-a multiline response\r\n250-another line\r\n220 the end"
36 [ get-ok ] with-string-reader
40 "Subject:\r\nsecurity hole" validate-header
45 { "From" "Doug <erg@factorcode.org>" }
46 { "Subject" "Factor rules" }
47 { "To" "Slava <slava@factorcode.org>, Ed <dharmatech@factorcode.org>" }
49 { "slava@factorcode.org" "dharmatech@factorcode.org" }
53 "Factor rules" >>subject
55 "Slava <slava@factorcode.org>"
56 "Ed <dharmatech@factorcode.org>"
58 "Doug <erg@factorcode.org>" >>from
60 email>headers sort-keys [
61 drop { "Date" "Message-Id" } member? not
64 [ to>> [ extract-email ] map ]
65 [ from>> extract-email ] tri
70 [ ] [ "p" get mock-smtp-server ] unit-test
74 "localhost" "p" get ?promise <inet> smtp-server set
77 "Hi guys\nBye guys" >>body
78 "Factor rules" >>subject
80 "Slava <slava@factorcode.org>"
81 "Ed <dharmatech@factorcode.org>"
83 "Doug <erg@factorcode.org>" >>from