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.unix.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.
40 [ dup [ "HELO" head? ] [ "EHLO" head? ] bi or ]
41 [ "220 and..?\r\n" write flush t ]
46 "220 2.0.0 Ready to start TLS\r\n" write flush
47 accept-secure-handshake t
50 { [ dup "QUIT" = ] [ "220 bye\r\n" write flush f ] }
51 { [ dup "MAIL FROM:" head? ] [ "220 OK\r\n" write flush t ] }
52 { [ dup "RCPT TO:" head? ] [ "220 OK\r\n" write flush t ] }
57 "354 Enter message, ending with \".\" on a line by itself\r\n"
62 [ dup "." = data-mode get and ]
65 "220 OK\r\n" write flush t
68 { [ data-mode get ] [ dup global [ print ] bind t ] }
69 [ "500 ERROR\r\n" write flush t ]
70 } cond nip [ process ] when ;
72 :: mock-smtp-server ( promise -- )
73 #! Store the port we are running on in the promise.
76 "127.0.0.1" 0 <inet4> ascii <server> [
77 dup addr>> port>> promise fulfill
80 "220 hello\r\n" write flush