1 ! Copyright (C) 2007 Elie CHAFTARI
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: combinators kernel prettyprint io io.timeouts sequences
4 namespaces io.sockets io.sockets.secure continuations calendar
5 io.encodings.ascii io.streams.duplex destructors locals
6 concurrency.promises threads accessors smtp.private
7 io.sockets.secure.debug io.crlf ;
10 ! Mock SMTP server for testing purposes.
12 ! $ telnet 127.0.0.1 4321
14 ! Connected to localhost.
15 ! Escape character is '^]'.
19 ! MAIL FROM: <here@mail.com>
21 ! RCPT TO: <there@mail.com>
26 ! 354 Enter message, ending with "." on a line by itself
27 ! Hello I am still waiting for your call
33 ! Connection closed by foreign host.
41 [ dup [ "HELO" head? ] [ "EHLO" head? ] bi or ]
42 [ "220 and..?\r\n" write flush t ]
47 "220 2.0.0 Ready to start TLS\r\n" write flush
48 accept-secure-handshake t
51 { [ dup "QUIT" = ] [ "220 bye\r\n" write flush f ] }
52 { [ dup "MAIL FROM:" head? ] [ "220 OK\r\n" write flush t ] }
53 { [ dup "RCPT TO:" head? ] [ "220 OK\r\n" write flush t ] }
58 "354 Enter message, ending with \".\" on a line by itself\r\n"
63 [ dup "." = data-mode get and ]
66 "220 OK\r\n" write flush t
69 { [ data-mode get ] [ dup [ print ] with-global t ] }
70 [ "500 ERROR\r\n" write flush t ]
71 } cond nip [ process ] when ;
73 :: mock-smtp-server ( promise -- )
74 #! Store the port we are running on in the promise.
77 "127.0.0.1" 0 <inet4> ascii <server> [
78 dup addr>> port>> promise fulfill
81 "220 hello\r\n" write flush