1 ! Copyright (C) 2009 Elie Chaftari.
2 ! See https://factorcode.org/license.txt for BSD license.
3 USING: accessors calendar combinators concurrency.promises
4 destructors io io.crlf io.encodings.utf8 io.sockets
5 io.sockets.secure.debug io.streams.duplex io.timeouts kernel
6 math.parser namespaces sequences threads ;
9 ! Mock POP3 server for testing purposes.
11 ! $ telnet 127.0.0.1 (start-pop3-server outputs listening port)
13 ! Connected to localhost.
14 ! Escape character is '^]'.
15 ! +OK POP3 server ready
16 ! USER username@host.com
17 ! +OK Password required
28 ! +OK 1 000000d547ac2fc2
31 ! Return-Path: <from.first@mail.com>
32 ! Delivered-To: username@host.com
33 ! Received: from User.local ([66.249.71.201])
34 ! by mail.isp.com with ESMTP id n95BgmJg012655
35 ! for <username@host.com>; Mon, 5 Oct 2009 14:42:59 +0300
36 ! Date: Mon, 5 Oct 2009 14:42:31 +0300
37 ! Message-Id: <4273644000823950677-1254742951070701@User.local>
39 ! Content-Transfer-Encoding: base64
40 ! From: from.first@mail.com
41 ! To: username@host.com
42 ! Subject: First test with mock POP3 server
43 ! Content-Type: text/plain; charset=UTF-8
47 ! +OK Marked for deletion
49 ! +OK POP3 server closing connection
50 ! Connection closed by foreign host.
58 "+OK Password required\r\n"
72 "+OK\r\nCAPA\r\nTOP\r\nUIDL\r\n.\r\n"
86 "+OK 2 messages:\r\n1 1006\r\n2 747\r\n.\r\n"
97 "+OK 1 000000d547ac2fc2\r\n"
104 "+OK 2 000000d647ac2fc2\r\n"
109 "+OK\r\n1 000000d547ac2fc2\r\n2 000000d647ac2fc2\r\n.\r\n"
123 Return-Path: <from.first@mail.com>
124 Delivered-To: username@host.com
125 Received: from User.local ([66.249.71.201])
126 by mail.isp.com with ESMTP id n95BgmJg012655
127 for <username@host.com>; Mon, 5 Oct 2009 14:42:59 +0300
128 Date: Mon, 5 Oct 2009 14:42:31 +0300
129 Message-Id: <4273644000823950677-1254742951070701@User.local>
131 Content-Transfer-Encoding: base64
132 From: from.first@mail.com
133 To: username@host.com
134 Subject: First test with mock POP3 server
135 Content-Type: text/plain; charset=UTF-8
146 Return-Path: <from.second@mail.com>
147 Delivered-To: username@host.com
148 Received: from User.local ([66.249.71.201])
149 by mail.isp.com with ESMTP id n95BgmJg012655
150 for <username@host.com>; Mon, 5 Oct 2009 14:44:09 +0300
151 Date: Mon, 5 Oct 2009 14:43:11 +0300
152 Message-Id: <9783644000823934577-4563442951070856@User.local>
154 Content-Transfer-Encoding: base64
155 From: from.second@mail.com
156 To: username@host.com
157 Subject: Second test with mock POP3 server
158 Content-Type: text/plain; charset=UTF-8
176 Return-Path: <from.first@mail.com>
177 Delivered-To: username@host.com
178 Received: from User.local ([66.249.71.201])
179 by mail.isp.com with ESMTP id n95BgmJg012655
180 for <username@host.com>; Mon, 5 Oct 2009 14:42:59 +0300
181 Date: Mon, 5 Oct 2009 14:42:31 +0300
182 Message-Id: <4273644000823950677-1254742951070701@User.local>
184 Content-Transfer-Encoding: base64
185 From: from.first@mail.com
186 To: username@host.com
187 Subject: First test with mock POP3 server
188 Content-Type: text/plain; charset=UTF-8
190 This is the body of the first test.
200 Return-Path: <from.second@mail.com>
201 Delivered-To: username@host.com
202 Received: from User.local ([66.249.71.201])
203 by mail.isp.com with ESMTP id n95BgmJg012655
204 for <username@host.com>; Mon, 5 Oct 2009 14:44:09 +0300
205 Date: Mon, 5 Oct 2009 14:43:11 +0300
206 Message-Id: <9783644000823934577-4563442951070856@User.local>
208 Content-Transfer-Encoding: base64
209 From: from.second@mail.com
210 To: username@host.com
211 Subject: Second test with mock POP3 server
212 Content-Type: text/plain; charset=UTF-8
214 This is the body of the second test.
226 "+OK Marked for deletion\r\n"
240 "+OK POP3 server closing connection\r\n"
244 } cond nip [ process ] when ;
246 :: mock-pop3-server ( promise -- )
247 ! Store the port we are running on in the promise.
250 "127.0.0.1" 0 <inet4> utf8 <server> [
251 dup addr>> port>> promise fulfill
254 "+OK POP3 server ready\r\n" write flush
256 [ flush ] with-global
262 : start-pop3-server ( -- )
263 <promise> [ mock-pop3-server ] keep ?promise
264 number>string "POP3 server started on port "