1 ! Copyright (C) 2009 Elie Chaftari.
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: accessors calendar combinators concurrency.promises
4 destructors fry io io.crlf io.encodings.utf8 io.sockets
5 io.sockets.secure.debug io.streams.duplex io.timeouts
6 kernel locals math.parser namespaces prettyprint sequences
10 ! Mock POP3 server for testing purposes.
12 ! $ telnet 127.0.0.1 (start-pop3-server outputs listening port)
14 ! Connected to localhost.
15 ! Escape character is '^]'.
16 ! +OK POP3 server ready
17 ! USER username@host.com
18 ! +OK Password required
29 ! +OK 1 000000d547ac2fc2
32 ! Return-Path: <from.first@mail.com>
33 ! Delivered-To: username@host.com
34 ! Received: from User.local ([66.249.71.201])
35 ! by mail.isp.com with ESMTP id n95BgmJg012655
36 ! for <username@host.com>; Mon, 5 Oct 2009 14:42:59 +0300
37 ! Date: Mon, 5 Oct 2009 14:42:31 +0300
38 ! Message-Id: <4273644000823950677-1254742951070701@User.local>
40 ! Content-Transfer-Encoding: base64
41 ! From: from.first@mail.com
42 ! To: username@host.com
43 ! Subject: First test with mock POP3 server
44 ! Content-Type: text/plain; charset=UTF-8
48 ! +OK Marked for deletion
50 ! +OK POP3 server closing connection
51 ! Connection closed by foreign host.
59 "+OK Password required\r\n"
73 "+OK\r\nCAPA\r\nTOP\r\nUIDL\r\n.\r\n"
87 "+OK 2 messages:\r\n1 1006\r\n2 747\r\n.\r\n"
98 "+OK 1 000000d547ac2fc2\r\n"
105 "+OK 2 000000d647ac2fc2\r\n"
110 "+OK\r\n1 000000d547ac2fc2\r\n2 000000d647ac2fc2\r\n.\r\n"
124 Return-Path: <from.first@mail.com>
125 Delivered-To: username@host.com
126 Received: from User.local ([66.249.71.201])
127 by mail.isp.com with ESMTP id n95BgmJg012655
128 for <username@host.com>; Mon, 5 Oct 2009 14:42:59 +0300
129 Date: Mon, 5 Oct 2009 14:42:31 +0300
130 Message-Id: <4273644000823950677-1254742951070701@User.local>
132 Content-Transfer-Encoding: base64
133 From: from.first@mail.com
134 To: username@host.com
135 Subject: First test with mock POP3 server
136 Content-Type: text/plain; charset=UTF-8
147 Return-Path: <from.second@mail.com>
148 Delivered-To: username@host.com
149 Received: from User.local ([66.249.71.201])
150 by mail.isp.com with ESMTP id n95BgmJg012655
151 for <username@host.com>; Mon, 5 Oct 2009 14:44:09 +0300
152 Date: Mon, 5 Oct 2009 14:43:11 +0300
153 Message-Id: <9783644000823934577-4563442951070856@User.local>
155 Content-Transfer-Encoding: base64
156 From: from.second@mail.com
157 To: username@host.com
158 Subject: Second test with mock POP3 server
159 Content-Type: text/plain; charset=UTF-8
177 Return-Path: <from.first@mail.com>
178 Delivered-To: username@host.com
179 Received: from User.local ([66.249.71.201])
180 by mail.isp.com with ESMTP id n95BgmJg012655
181 for <username@host.com>; Mon, 5 Oct 2009 14:42:59 +0300
182 Date: Mon, 5 Oct 2009 14:42:31 +0300
183 Message-Id: <4273644000823950677-1254742951070701@User.local>
185 Content-Transfer-Encoding: base64
186 From: from.first@mail.com
187 To: username@host.com
188 Subject: First test with mock POP3 server
189 Content-Type: text/plain; charset=UTF-8
191 This is the body of the first test.
201 Return-Path: <from.second@mail.com>
202 Delivered-To: username@host.com
203 Received: from User.local ([66.249.71.201])
204 by mail.isp.com with ESMTP id n95BgmJg012655
205 for <username@host.com>; Mon, 5 Oct 2009 14:44:09 +0300
206 Date: Mon, 5 Oct 2009 14:43:11 +0300
207 Message-Id: <9783644000823934577-4563442951070856@User.local>
209 Content-Transfer-Encoding: base64
210 From: from.second@mail.com
211 To: username@host.com
212 Subject: Second test with mock POP3 server
213 Content-Type: text/plain; charset=UTF-8
215 This is the body of the second test.
227 "+OK Marked for deletion\r\n"
241 "+OK POP3 server closing connection\r\n"
245 } cond nip [ process ] when ;
247 :: mock-pop3-server ( promise -- )
248 #! Store the port we are running on in the promise.
251 "127.0.0.1" 0 <inet4> utf8 <server> [
252 dup addr>> port>> promise fulfill
255 "+OK POP3 server ready\r\n" write flush
257 [ flush ] with-global
263 : start-pop3-server ( -- )
264 <promise> [ mock-pop3-server ] keep ?promise
265 number>string "POP3 server started on port "