1 | var assert = require('assert'),
|
2 | net = require('net'),
|
3 | Imap = require('../lib/Connection'),
|
4 | result;
|
5 |
|
6 | var CRLF = '\r\n';
|
7 |
|
8 | var RESPONSES = [
|
9 | ['* CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA CHILDREN',
|
10 | 'A0 OK Thats all she wrote!',
|
11 | ''
|
12 | ].join(CRLF),
|
13 | ['* CAPABILITY IMAP4rev1 UNSELECT IDLE NAMESPACE QUOTA CHILDREN UIDPLUS MOVE',
|
14 | 'A1 OK authenticated (Success)',
|
15 | ''
|
16 | ].join(CRLF),
|
17 | ['* NAMESPACE (("" "/")) NIL NIL',
|
18 | 'A2 OK Success',
|
19 | ''
|
20 | ].join(CRLF),
|
21 | ['* LIST (\\Noselect) "/" "/"',
|
22 | 'A3 OK Success',
|
23 | ''
|
24 | ].join(CRLF),
|
25 | ['* FLAGS (\\Answered \\Flagged \\Draft \\Deleted \\Seen)',
|
26 | '* OK [PERMANENTFLAGS ()] Flags permitted.',
|
27 | '* OK [UIDVALIDITY 2] UIDs valid.',
|
28 | '* 685 EXISTS',
|
29 | '* 0 RECENT',
|
30 | '* OK [UIDNEXT 4422] Predicted next UID.',
|
31 | 'A4 OK [READ-ONLY] INBOX selected. (Success)',
|
32 | ''
|
33 | ].join(CRLF),
|
34 | ['* 1 FETCH (UID 1)',
|
35 | '* 1 FETCH (INTERNALDATE "05-Sep-2004 00:38:03 +0000" UID 1000)',
|
36 | '* 1 FETCH (FLAGS (\\Seen))',
|
37 | 'A5 OK Success',
|
38 | ''
|
39 | ].join(CRLF),
|
40 | ['* BYE LOGOUT Requested',
|
41 | 'A6 OK good day (Success)',
|
42 | ''
|
43 | ].join(CRLF)
|
44 | ];
|
45 |
|
46 | var srv = net.createServer(function(sock) {
|
47 | sock.write('* OK asdf\r\n');
|
48 | var buf = '', lines;
|
49 | sock.on('data', function(data) {
|
50 | buf += data.toString('utf8');
|
51 | if (buf.indexOf(CRLF) > -1) {
|
52 | lines = buf.split(CRLF);
|
53 | buf = lines.pop();
|
54 | lines.forEach(function() {
|
55 | sock.write(RESPONSES.shift());
|
56 | });
|
57 | }
|
58 | });
|
59 | });
|
60 | srv.listen(0, '127.0.0.1', function() {
|
61 | var port = srv.address().port;
|
62 | var imap = new Imap({
|
63 | user: 'foo',
|
64 | password: 'bar',
|
65 | host: '127.0.0.1',
|
66 | port: port,
|
67 | keepalive: false
|
68 | });
|
69 | imap.on('ready', function() {
|
70 | imap.openBox('INBOX', true, function() {
|
71 | var f = imap.seq.fetch(1);
|
72 | f.on('message', function(m) {
|
73 | m.once('attributes', function(attrs) {
|
74 | result = attrs;
|
75 | });
|
76 | });
|
77 | f.on('end', function() {
|
78 | srv.close();
|
79 | imap.end();
|
80 | });
|
81 | });
|
82 | });
|
83 | imap.connect();
|
84 | });
|
85 |
|
86 | process.once('exit', function() {
|
87 | assert.deepEqual(result, {
|
88 | uid: 1,
|
89 | date: new Date('05-Sep-2004 00:38:03 +0000'),
|
90 | flags: [ '\\Seen' ]
|
91 | });
|
92 | }); |
\ | No newline at end of file |