1 USING: smtp tools.test io.streams.string io.sockets threads
2 smtp.server kernel sequences namespaces logging accessors
3 assocs sorting smtp.private ;
6 { 0 0 } [ [ ] with-smtp-connection ] must-infer-as
8 [ "hello\nworld" validate-address ] must-fail
10 [ "slava@factorcode.org" ]
11 [ "slava@factorcode.org" validate-address ] unit-test
13 [ { "hello" "." "world" } validate-message ] must-fail
15 [ "hello\r\nworld\r\n.\r\n" ] [
16 "hello\nworld" [ send-body ] with-string-writer
19 [ "500 syntax error" check-response ] must-fail
21 [ ] [ "220 success" check-response ] unit-test
24 "220 success" [ receive-response ] with-string-reader
28 "220-a multiline response\r\n250-another line\r\n220 the end"
29 [ receive-response ] with-string-reader
33 "220-a multiline response\r\n250-another line\r\n220 the end"
34 [ get-ok ] with-string-reader
38 "Subject:\r\nsecurity hole" validate-header
43 { "From" "Doug <erg@factorcode.org>" }
44 { "Subject" "Factor rules" }
45 { "To" "Slava <slava@factorcode.org>, Ed <dharmatech@factorcode.org>" }
47 { "slava@factorcode.org" "dharmatech@factorcode.org" }
51 "Factor rules" >>subject
53 "Slava <slava@factorcode.org>"
54 "Ed <dharmatech@factorcode.org>"
56 "Doug <erg@factorcode.org>" >>from
58 email>headers sort-keys [
59 drop { "Date" "Message-Id" } member? not
62 [ to>> [ extract-email ] map ]
63 [ from>> extract-email ] tri
66 [ ] [ [ 4321 mock-smtp-server ] "SMTP server" spawn drop ] unit-test
68 [ ] [ yield ] unit-test
72 "localhost" 4321 <inet> smtp-server set
75 "Hi guys\nBye guys" >>body
76 "Factor rules" >>subject
78 "Slava <slava@factorcode.org>"
79 "Ed <dharmatech@factorcode.org>"
81 "Doug <erg@factorcode.org>" >>from
86 [ ] [ yield ] unit-test