1 USING: accessors assocs combinators concurrency.promises
2 continuations fry io.sockets io.sockets.secure io.streams.string
3 kernel namespaces sequences smtp smtp.private smtp.server
4 sorting system tools.test ;
7 : with-test-smtp-config ( quot -- )
10 "p" get mock-smtp-server
13 "localhost" "p" get ?promise <inet> >>server
15 os unix? [ t >>tls? ] when
17 ] dip with-variable ; inline
19 { 0 0 } [ [ ] with-smtp-connection ] must-infer-as
21 [ "hello\nworld" validate-address ] must-fail
23 { "slava@factorcode.org" }
24 [ "slava@factorcode.org" validate-address ] unit-test
26 { "aGVsbG8Kd29ybGQ=\r\n.\r\n" } [
27 T{ email { body "hello\nworld" } } [ send-body ] with-string-writer
30 [ { "500 syntax error" } <response> check-response ]
31 [ smtp-error? ] must-fail-with
33 { } [ { "220 success" } <response> check-response ] unit-test
35 { T{ response f 220 { "220 success" } } } [
36 "220 success" [ receive-response ] with-string-reader
41 "220-a multiline response"
46 "220-a multiline response\r\n250-another line\r\n220 the end"
47 [ receive-response ] with-string-reader
51 "220-a multiline response\r\n250-another line\r\n220 the end"
52 [ get-ok ] with-string-reader
56 "Subject:\r\nsecurity hole" validate-header
61 { "Content-Transfer-Encoding" "base64" }
62 { "Content-Type" "text/plain; charset=UTF-8" }
63 { "From" "Doug <erg@factorcode.org>" }
64 { "MIME-Version" "1.0" }
65 { "Subject" "Factor rules" }
66 { "To" "Slava <slava@factorcode.org>, Ed <dharmatech@factorcode.org>" }
68 { "slava@factorcode.org" "dharmatech@factorcode.org" }
73 "Factor rules" >>subject
75 "Slava <slava@factorcode.org>"
76 "Ed <dharmatech@factorcode.org>"
78 "Doug <erg@factorcode.org>" >>from
81 email>headers sort-keys [
82 drop { "Date" "Message-Id" } member? not
85 [ to>> [ extract-email ] map ]
86 [ from>> extract-email ]
87 ! To get the smtp server to clean up itself
88 [ '[ _ send-email ] ignore-errors ]
90 ] with-test-smtp-config
94 <secure-config> f >>verify [
97 "Hi guys\nBye guys" >>body
98 "Factor rules" >>subject
100 "Slava <slava@factorcode.org>"
101 "Ed <dharmatech@factorcode.org>"
103 "Doug <erg@factorcode.org>" >>from
105 ] with-test-smtp-config
106 ] with-secure-context