emailengine-app 2.61.1 → 2.61.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/data/google-crawlers.json +1 -1
  3. package/lib/account/account-state.js +248 -0
  4. package/lib/account.js +45 -193
  5. package/lib/api-routes/account-routes.js +1023 -0
  6. package/lib/api-routes/message-routes.js +1377 -0
  7. package/lib/consts.js +12 -2
  8. package/lib/email-client/base-client.js +282 -771
  9. package/lib/email-client/gmail/gmail-api.js +243 -0
  10. package/lib/email-client/gmail-client.js +145 -53
  11. package/lib/email-client/imap/mailbox.js +24 -698
  12. package/lib/email-client/imap/sync-operations.js +812 -0
  13. package/lib/email-client/imap-client.js +1 -1
  14. package/lib/email-client/message-builder.js +566 -0
  15. package/lib/email-client/notification-handler.js +314 -0
  16. package/lib/email-client/outlook/graph-api.js +326 -0
  17. package/lib/email-client/outlook-client.js +159 -113
  18. package/lib/email-client/smtp-pool-manager.js +196 -0
  19. package/lib/imapproxy/imap-server.js +3 -12
  20. package/lib/oauth/gmail.js +4 -4
  21. package/lib/oauth/mail-ru.js +30 -5
  22. package/lib/oauth/outlook.js +57 -3
  23. package/lib/oauth/pubsub/google.js +30 -11
  24. package/lib/oauth/scope-checker.js +202 -0
  25. package/lib/oauth2-apps.js +8 -4
  26. package/lib/redis-operations.js +484 -0
  27. package/lib/routes-ui.js +283 -2582
  28. package/lib/tools.js +4 -196
  29. package/lib/ui-routes/account-routes.js +1931 -0
  30. package/lib/ui-routes/admin-config-routes.js +1233 -0
  31. package/lib/ui-routes/admin-entities-routes.js +2367 -0
  32. package/lib/ui-routes/oauth-routes.js +992 -0
  33. package/lib/utils/network.js +237 -0
  34. package/package.json +10 -10
  35. package/sbom.json +1 -1
  36. package/static/js/app.js +5 -5
  37. package/static/licenses.html +79 -19
  38. package/translations/de.mo +0 -0
  39. package/translations/de.po +97 -86
  40. package/translations/en.mo +0 -0
  41. package/translations/en.po +80 -75
  42. package/translations/et.mo +0 -0
  43. package/translations/et.po +96 -86
  44. package/translations/fr.mo +0 -0
  45. package/translations/fr.po +97 -86
  46. package/translations/ja.mo +0 -0
  47. package/translations/ja.po +96 -86
  48. package/translations/messages.pot +105 -91
  49. package/translations/nl.mo +0 -0
  50. package/translations/nl.po +98 -86
  51. package/translations/pl.mo +0 -0
  52. package/translations/pl.po +96 -86
  53. package/views/account/security.hbs +4 -4
  54. package/views/accounts/account.hbs +13 -13
  55. package/views/accounts/register/imap-server.hbs +12 -12
  56. package/views/config/document-store/pre-processing/index.hbs +4 -2
  57. package/views/config/oauth/app.hbs +6 -7
  58. package/views/config/oauth/index.hbs +2 -2
  59. package/views/config/service.hbs +3 -4
  60. package/views/dashboard.hbs +5 -7
  61. package/views/error.hbs +22 -7
  62. package/views/gateways/gateway.hbs +2 -2
  63. package/views/partials/add_account_modal.hbs +7 -10
  64. package/views/partials/document_store_header.hbs +1 -1
  65. package/views/partials/editor_scope_info.hbs +0 -1
  66. package/views/partials/oauth_config_header.hbs +1 -1
  67. package/views/partials/side_menu.hbs +3 -3
  68. package/views/partials/webhook_form.hbs +2 -2
  69. package/views/templates/index.hbs +1 -1
  70. package/views/templates/template.hbs +8 -8
  71. package/views/tokens/index.hbs +6 -6
  72. package/views/tokens/new.hbs +1 -1
  73. package/views/webhooks/index.hbs +4 -4
  74. package/views/webhooks/webhook.hbs +7 -7
  75. package/workers/api.js +148 -2436
  76. package/workers/smtp.js +2 -1
  77. package/lib/imapproxy/imap-core/test/client.js +0 -46
  78. package/lib/imapproxy/imap-core/test/fixtures/append.eml +0 -1196
  79. package/lib/imapproxy/imap-core/test/fixtures/chunks.js +0 -44
  80. package/lib/imapproxy/imap-core/test/fixtures/fix1.eml +0 -6
  81. package/lib/imapproxy/imap-core/test/fixtures/fix2.eml +0 -599
  82. package/lib/imapproxy/imap-core/test/fixtures/fix3.eml +0 -32
  83. package/lib/imapproxy/imap-core/test/fixtures/fix4.eml +0 -6
  84. package/lib/imapproxy/imap-core/test/fixtures/mimetorture.eml +0 -599
  85. package/lib/imapproxy/imap-core/test/fixtures/mimetorture.js +0 -2740
  86. package/lib/imapproxy/imap-core/test/fixtures/mimetorture.json +0 -1411
  87. package/lib/imapproxy/imap-core/test/fixtures/mimetree.js +0 -85
  88. package/lib/imapproxy/imap-core/test/fixtures/nodemailer.eml +0 -582
  89. package/lib/imapproxy/imap-core/test/fixtures/ryan_finnie_mime_torture.eml +0 -599
  90. package/lib/imapproxy/imap-core/test/fixtures/simple.eml +0 -42
  91. package/lib/imapproxy/imap-core/test/fixtures/simple.json +0 -164
  92. package/lib/imapproxy/imap-core/test/imap-compile-stream-test.js +0 -671
  93. package/lib/imapproxy/imap-core/test/imap-compiler-test.js +0 -272
  94. package/lib/imapproxy/imap-core/test/imap-indexer-test.js +0 -236
  95. package/lib/imapproxy/imap-core/test/imap-parser-test.js +0 -922
  96. package/lib/imapproxy/imap-core/test/memory-notifier.js +0 -129
  97. package/lib/imapproxy/imap-core/test/prepare.sh +0 -74
  98. package/lib/imapproxy/imap-core/test/protocol-test.js +0 -1756
  99. package/lib/imapproxy/imap-core/test/search-test.js +0 -1356
  100. package/lib/imapproxy/imap-core/test/test-client.js +0 -152
  101. package/lib/imapproxy/imap-core/test/test-server.js +0 -623
  102. package/lib/imapproxy/imap-core/test/tools-test.js +0 -22
  103. package/test/api-test.js +0 -899
  104. package/test/autoreply-test.js +0 -327
  105. package/test/bounce-test.js +0 -151
  106. package/test/complaint-test.js +0 -256
  107. package/test/fixtures/autoreply/LICENSE +0 -27
  108. package/test/fixtures/autoreply/rfc3834-01.eml +0 -23
  109. package/test/fixtures/autoreply/rfc3834-02.eml +0 -24
  110. package/test/fixtures/autoreply/rfc3834-03.eml +0 -26
  111. package/test/fixtures/autoreply/rfc3834-04.eml +0 -48
  112. package/test/fixtures/autoreply/rfc3834-05.eml +0 -19
  113. package/test/fixtures/autoreply/rfc3834-06.eml +0 -59
  114. package/test/fixtures/bounces/163.eml +0 -2521
  115. package/test/fixtures/bounces/fastmail.eml +0 -242
  116. package/test/fixtures/bounces/gmail.eml +0 -252
  117. package/test/fixtures/bounces/hotmail.eml +0 -655
  118. package/test/fixtures/bounces/mailru.eml +0 -121
  119. package/test/fixtures/bounces/outlook.eml +0 -1107
  120. package/test/fixtures/bounces/postfix.eml +0 -101
  121. package/test/fixtures/bounces/rambler.eml +0 -116
  122. package/test/fixtures/bounces/workmail.eml +0 -142
  123. package/test/fixtures/bounces/yahoo.eml +0 -139
  124. package/test/fixtures/bounces/zoho.eml +0 -83
  125. package/test/fixtures/bounces/zonemta.eml +0 -100
  126. package/test/fixtures/complaints/LICENSE +0 -27
  127. package/test/fixtures/complaints/amazonses.eml +0 -72
  128. package/test/fixtures/complaints/dmarc.eml +0 -59
  129. package/test/fixtures/complaints/hotmail.eml +0 -49
  130. package/test/fixtures/complaints/optout.eml +0 -40
  131. package/test/fixtures/complaints/standard-arf.eml +0 -68
  132. package/test/fixtures/complaints/yahoo.eml +0 -68
  133. package/test/oauth2-apps-test.js +0 -301
  134. package/test/sendonly-test.js +0 -160
  135. package/test/test-config.js +0 -34
  136. package/test/webhooks-server.js +0 -39
@@ -1,1756 +0,0 @@
1
- /* eslint no-unused-expressions: 0, prefer-arrow-callback: 0, no-console: 0 */
2
-
3
- 'use strict';
4
-
5
- let config = require('@zone-eu/wild-config');
6
- //let testServer = require('./test-server.js');
7
- let testClient = require('./test-client.js');
8
- let exec = require('child_process').exec;
9
-
10
- let chai = require('chai');
11
- let chunks = require('./fixtures/chunks');
12
- let expect = chai.expect;
13
- chai.config.includeStack = true;
14
-
15
- describe('IMAP Protocol integration tests', function () {
16
- this.timeout(10000);
17
- let port = 9993;
18
-
19
- beforeEach(function (done) {
20
- exec(__dirname + '/prepare.sh ' + config.dbs.dbname, { cwd: __dirname }, (err, stdout, stderr) => {
21
- if (process.env.DEBUG_CONSOLE) {
22
- console.log(stdout.toString());
23
- console.log(stderr.toString());
24
- }
25
- if (err) {
26
- return done(err);
27
- }
28
- done();
29
- });
30
- });
31
-
32
- afterEach(function (done) {
33
- done();
34
- });
35
-
36
- after(function (done) {
37
- //mongo "$DBNAME" --eval "db.getCollectionNames().forEach(function(key){db[key].deleteMany({});})" > /dev/null
38
- exec('mongo ' + config.dbs.dbname + ' --eval "db.getCollectionNames().forEach(function(key){db[key].deleteMany({});})"', err => {
39
- if (err) {
40
- return done(err);
41
- }
42
- done();
43
- });
44
- });
45
-
46
- describe('CAPABILITY', function () {
47
- it('should list capabilities', function (done) {
48
- let cmds = ['T1 CAPABILITY', 'T2 LOGOUT'];
49
-
50
- testClient(
51
- {
52
- commands: cmds,
53
- secure: true,
54
- port
55
- },
56
- function (resp) {
57
- expect(/^\* CAPABILITY IMAP4rev1 /m.test(resp.toString())).to.be.true;
58
- expect(/^T1 OK/m.test(resp.toString())).to.be.true;
59
- done();
60
- }
61
- );
62
- });
63
- });
64
-
65
- describe('LOGIN', function () {
66
- /*
67
- let stlsServer;
68
- let stlsPort;
69
- let txtServer;
70
- let txtPort;
71
- */
72
-
73
- beforeEach(function (done) {
74
- /*
75
- stlsServer = testServer({
76
- secure: false,
77
- logger: false // remove to print IMAP traffic to console
78
- });
79
-
80
- txtServer = testServer({
81
- secure: false,
82
- ignoreSTARTTLS: true,
83
- logger: false // remove to print IMAP traffic to console
84
- });
85
-
86
- stlsServer.listen(function() {
87
- stlsPort = stlsServer.server.address().port;
88
- txtServer.listen(function() {
89
- txtPort = txtServer.server.address().port;
90
- done();
91
- });
92
- });
93
- */
94
- done();
95
- });
96
-
97
- afterEach(function (done) {
98
- /*
99
- stlsServer.close(function() {
100
- txtServer.close(done);
101
- });
102
- */
103
- done();
104
- });
105
-
106
- it('should authenticate', function (done) {
107
- let cmds = ['T1 LOGIN testuser pass', 'T2 LOGOUT'];
108
-
109
- testClient(
110
- {
111
- commands: cmds,
112
- secure: true,
113
- port
114
- },
115
- function (resp) {
116
- expect(/^T1 OK/m.test(resp.toString())).to.be.true;
117
- done();
118
- }
119
- );
120
- });
121
- /*
122
- it('should authenticate using STARTTLS', function(done) {
123
- let cmds = ['T1 STARTTLS', 'T2 LOGIN testuser pass', 'T3 LOGOUT'];
124
-
125
- testClient(
126
- {
127
- port: stlsPort,
128
- commands: cmds,
129
- secure: false
130
- },
131
- function(resp) {
132
- expect(/^T2 OK/m.test(resp.toString())).to.be.true;
133
- done();
134
- }
135
- );
136
- });
137
-
138
- it('should fail auth without STARTTLS', function(done) {
139
- let cmds = ['T1 LOGIN testuser pass', 'T2 LOGOUT'];
140
-
141
- testClient(
142
- {
143
- port: stlsPort,
144
- commands: cmds,
145
- secure: false
146
- },
147
- function(resp) {
148
- expect(/^T1 BAD/m.test(resp.toString())).to.be.true;
149
- done();
150
- }
151
- );
152
- });
153
-
154
- it('should authenticate without using STARTTLS', function(done) {
155
- let cmds = ['T1 LOGIN testuser pass', 'T2 LOGOUT'];
156
-
157
- testClient(
158
- {
159
- port: txtPort,
160
- commands: cmds,
161
- secure: false
162
- },
163
- function(resp) {
164
- expect(/^T1 OK/m.test(resp.toString())).to.be.true;
165
- done();
166
- }
167
- );
168
- });
169
- */
170
- it('should fail authentication', function (done) {
171
- let cmds = ['T1 LOGIN testuser wrongpass', 'T2 LOGOUT'];
172
-
173
- testClient(
174
- {
175
- commands: cmds,
176
- secure: true,
177
- port
178
- },
179
- function (resp) {
180
- expect(/^T1 NO/m.test(resp.toString())).to.be.true;
181
- done();
182
- }
183
- );
184
- });
185
- });
186
-
187
- describe('AUTHENTICATE PLAIN', function () {
188
- it('should authenticate', function (done) {
189
- let cmds = ['T1 AUTHENTICATE PLAIN', Buffer.from('\x00testuser\x00pass', 'utf-8').toString('base64'), 'T2 LOGOUT'];
190
-
191
- testClient(
192
- {
193
- commands: cmds,
194
- secure: true,
195
- port
196
- },
197
- function (resp) {
198
- expect(/^T1 OK/m.test(resp.toString())).to.be.true;
199
- done();
200
- }
201
- );
202
- });
203
-
204
- it('should authenticate using SASL-IR', function (done) {
205
- let cmds = ['T1 AUTHENTICATE PLAIN ' + Buffer.from('\x00testuser\x00pass', 'utf-8').toString('base64'), 'T2 LOGOUT'];
206
-
207
- testClient(
208
- {
209
- commands: cmds,
210
- secure: true,
211
- port
212
- },
213
- function (resp) {
214
- expect(/^T1 OK/m.test(resp.toString())).to.be.true;
215
- done();
216
- }
217
- );
218
- });
219
-
220
- it('should fail authentication', function (done) {
221
- let cmds = ['T1 AUTHENTICATE PLAIN', Buffer.from('\x00testuser\x00wrongpass', 'utf-8').toString('base64'), 'T2 LOGOUT'];
222
-
223
- testClient(
224
- {
225
- commands: cmds,
226
- secure: true,
227
- port
228
- },
229
- function (resp) {
230
- expect(/^T1 NO/m.test(resp.toString())).to.be.true;
231
- done();
232
- }
233
- );
234
- });
235
-
236
- it('should reject client token', function (done) {
237
- let cmds = ['T1 AUTHENTICATE PLAIN', Buffer.from('\x00testuser\x00pass\x00token', 'utf-8').toString('base64'), 'T2 LOGOUT'];
238
-
239
- testClient(
240
- {
241
- commands: cmds,
242
- secure: true,
243
- port
244
- },
245
- function (resp) {
246
- expect(/^T1 BAD/m.test(resp.toString())).to.be.true;
247
- done();
248
- }
249
- );
250
- });
251
-
252
- it('should authenticate with client token', function (done) {
253
- let cmds = ['T1 AUTHENTICATE PLAIN-CLIENTTOKEN', Buffer.from('\x00testuser\x00pass\x00token', 'utf-8').toString('base64'), 'T2 LOGOUT'];
254
-
255
- testClient(
256
- {
257
- commands: cmds,
258
- secure: true,
259
- port
260
- },
261
- function (resp) {
262
- expect(/^T1 OK/m.test(resp.toString())).to.be.true;
263
- done();
264
- }
265
- );
266
- });
267
- });
268
-
269
- describe('NAMESPACE', function () {
270
- it('should list namespaces', function (done) {
271
- let cmds = ['T1 LOGIN testuser pass', 'T2 NAMESPACE', 'T3 LOGOUT'];
272
-
273
- testClient(
274
- {
275
- commands: cmds,
276
- secure: true,
277
- port
278
- },
279
- function (resp) {
280
- expect(/^\* NAMESPACE \(\("" "\/"\)\) NIL NIL$/m.test(resp.toString())).to.be.true;
281
- expect(/^T2 OK/m.test(resp.toString())).to.be.true;
282
- done();
283
- }
284
- );
285
- });
286
- });
287
-
288
- describe('LIST', function () {
289
- it('should list delimiter', function (done) {
290
- let cmds = ['T1 LOGIN testuser pass', 'T2 LIST "" ""', 'T3 LOGOUT'];
291
-
292
- testClient(
293
- {
294
- commands: cmds,
295
- secure: true,
296
- port
297
- },
298
- function (resp) {
299
- resp = resp.toString();
300
- expect(resp.match(/^\* LIST /gm).length).to.equal(1);
301
- expect(resp.indexOf('\r\n* LIST (\\Noselect) "/" "/"\r\n') >= 0).to.be.true;
302
- expect(/^T2 OK/m.test(resp)).to.be.true;
303
- done();
304
- }
305
- );
306
- });
307
-
308
- it('should list all mailboxes', function (done) {
309
- let cmds = ['T1 LOGIN testuser pass', 'T2 LIST "" "*"', 'T3 LOGOUT'];
310
-
311
- testClient(
312
- {
313
- commands: cmds,
314
- secure: true,
315
- port
316
- },
317
- function (resp) {
318
- resp = resp.toString();
319
- expect(resp.match(/^\* LIST /gm).length).to.equal(6);
320
- expect(resp.indexOf('\r\n* LIST (\\HasNoChildren) "/" "INBOX"\r\n') >= 0).to.be.true;
321
- expect(resp.indexOf('\r\n* LIST (\\Noselect \\HasChildren) "/" "[Gmail]"\r\n') >= 0).to.be.true;
322
- expect(resp.indexOf('\r\n* LIST (\\HasNoChildren \\Sent) "/" "[Gmail]/Sent Mail"\r\n') >= 0).to.be.true;
323
- expect(/^T2 OK/m.test(resp)).to.be.true;
324
- done();
325
- }
326
- );
327
- });
328
-
329
- it('should list all mailboxes using XLIST', function (done) {
330
- let cmds = ['T1 LOGIN testuser pass', 'T2 XLIST "" "*"', 'T3 LOGOUT'];
331
-
332
- testClient(
333
- {
334
- commands: cmds,
335
- secure: true,
336
- port
337
- },
338
- function (resp) {
339
- resp = resp.toString();
340
- expect(resp.match(/^\* XLIST /gm).length).to.equal(6);
341
- expect(resp.indexOf('\r\n* XLIST (\\HasNoChildren \\Inbox) "/" "Inbox"\r\n') >= 0).to.be.true;
342
- expect(resp.indexOf('\r\n* XLIST (\\Noselect \\HasChildren) "/" "[Gmail]"\r\n') >= 0).to.be.true;
343
- expect(resp.indexOf('\r\n* XLIST (\\HasNoChildren \\Sent) "/" "[Gmail]/Sent Mail"\r\n') >= 0).to.be.true;
344
- expect(/^T2 OK/m.test(resp)).to.be.true;
345
- done();
346
- }
347
- );
348
- });
349
-
350
- it('should list first level mailboxes', function (done) {
351
- let cmds = ['T1 LOGIN testuser pass', 'T2 LIST "" "%"', 'T3 LOGOUT'];
352
-
353
- testClient(
354
- {
355
- commands: cmds,
356
- secure: true,
357
- port
358
- },
359
- function (resp) {
360
- resp = resp.toString();
361
- expect(resp.match(/^\* LIST /gm).length).to.equal(5);
362
- expect(resp.indexOf('\r\n* LIST (\\HasNoChildren) "/" "INBOX"\r\n') >= 0).to.be.true;
363
- expect(resp.indexOf('\r\n* LIST (\\Noselect \\HasChildren) "/" "[Gmail]"\r\n') >= 0).to.be.true;
364
- expect(resp.indexOf('\r\n* LIST (\\HasNoChildren \\Sent) "/" "[Gmail]/Sent Mail"\r\n') >= 0).to.be.false;
365
- expect(/^T2 OK/m.test(resp)).to.be.true;
366
- done();
367
- }
368
- );
369
- });
370
-
371
- it('should list second level mailboxes', function (done) {
372
- let cmds = ['T1 LOGIN testuser pass', 'T2 LIST "" "[Gmail]/%"', 'T3 LOGOUT'];
373
-
374
- testClient(
375
- {
376
- commands: cmds,
377
- secure: true,
378
- port
379
- },
380
- function (resp) {
381
- resp = resp.toString();
382
- expect(resp.match(/^\* LIST /gm).length).to.equal(1);
383
- expect(resp.indexOf('\r\n* LIST (\\HasNoChildren \\Sent) "/" "[Gmail]/Sent Mail"\r\n') >= 0).to.be.true;
384
- expect(/^T2 OK/m.test(resp)).to.be.true;
385
- done();
386
- }
387
- );
388
- });
389
- });
390
-
391
- describe('LSUB', function () {
392
- it('should list all mailboxes', function (done) {
393
- let cmds = ['T1 LOGIN testuser pass', 'T2 LSUB "" "*"', 'T3 LOGOUT'];
394
-
395
- testClient(
396
- {
397
- commands: cmds,
398
- secure: true,
399
- port
400
- },
401
- function (resp) {
402
- resp = resp.toString();
403
- expect(resp.match(/^\* LSUB /gm).length).to.equal(5);
404
- expect(resp.indexOf('\r\n* LSUB (\\HasNoChildren) "/" "INBOX"\r\n') >= 0).to.be.true;
405
- expect(resp.indexOf('\r\n* LSUB (\\HasNoChildren) "/" "[Gmail]/Sent Mail"\r\n') >= 0).to.be.true;
406
- expect(/^T2 OK/m.test(resp)).to.be.true;
407
- done();
408
- }
409
- );
410
- });
411
-
412
- it('should list first level mailboxes', function (done) {
413
- let cmds = ['T1 LOGIN testuser pass', 'T2 LSUB "" "%"', 'T3 LOGOUT'];
414
-
415
- testClient(
416
- {
417
- commands: cmds,
418
- secure: true,
419
- port
420
- },
421
- function (resp) {
422
- resp = resp.toString();
423
- expect(resp.match(/^\* LSUB /gm).length).to.equal(4);
424
- expect(resp.indexOf('\r\n* LSUB (\\HasNoChildren) "/" "INBOX"\r\n') >= 0).to.be.true;
425
- expect(resp.indexOf('\r\n* LSUB (\\HasNoChildren) "/" "[Gmail]/Sent Mail"\r\n') >= 0).to.be.false;
426
- expect(/^T2 OK/m.test(resp)).to.be.true;
427
- done();
428
- }
429
- );
430
- });
431
-
432
- it('should list second level mailboxes', function (done) {
433
- let cmds = ['T1 LOGIN testuser pass', 'T2 LSUB "" "[Gmail]/%"', 'T3 LOGOUT'];
434
-
435
- testClient(
436
- {
437
- commands: cmds,
438
- secure: true,
439
- port
440
- },
441
- function (resp) {
442
- resp = resp.toString();
443
- expect(resp.match(/^\* LSUB /gm).length).to.equal(1);
444
- expect(resp.indexOf('\r\n* LSUB (\\HasNoChildren) "/" "[Gmail]/Sent Mail"\r\n') >= 0).to.be.true;
445
- expect(/^T2 OK/m.test(resp)).to.be.true;
446
- done();
447
- }
448
- );
449
- });
450
- });
451
-
452
- describe('CREATE', function () {
453
- it('should create new mailbox', function (done) {
454
- let cmds = ['T1 LOGIN testuser pass', 'T2 CREATE testfolder', 'T3 CREATE parent/child', 'T4 CREATE testfolder', 'T5 LIST "" "*"', 'T6 LOGOUT'];
455
-
456
- testClient(
457
- {
458
- commands: cmds,
459
- secure: true,
460
- port
461
- },
462
- function (resp) {
463
- resp = resp.toString();
464
- expect(/^T2 OK/m.test(resp)).to.be.true;
465
- expect(/^T3 OK/m.test(resp)).to.be.true;
466
- expect(/^T4 NO \[ALREADYEXISTS\]/m.test(resp)).to.be.true;
467
- expect(resp.indexOf('\r\n* LIST (\\HasNoChildren) "/" "testfolder"\r\n') >= 0).to.be.true;
468
- expect(resp.indexOf('\r\n* LIST (\\Noselect \\HasChildren) "/" "parent"\r\n') >= 0).to.be.true;
469
- expect(resp.indexOf('\r\n* LIST (\\HasNoChildren) "/" "parent/child"\r\n') >= 0).to.be.true;
470
- done();
471
- }
472
- );
473
- });
474
- });
475
-
476
- describe('RENAME', function () {
477
- it('should rename existing mailbox', function (done) {
478
- let cmds = [
479
- 'T1 LOGIN testuser pass',
480
- 'T2 CREATE testfolder',
481
- 'T3 RENAME testfolder parent/child',
482
- 'T4 RENAME testfolder other',
483
- 'T5 LIST "" "*"',
484
- 'T6 LOGOUT'
485
- ];
486
-
487
- testClient(
488
- {
489
- commands: cmds,
490
- secure: true,
491
- port
492
- },
493
- function (resp) {
494
- resp = resp.toString();
495
- expect(/^T3 OK/m.test(resp)).to.be.true;
496
- expect(/^T4 NO \[NONEXISTENT\]/m.test(resp)).to.be.true;
497
- expect(resp.indexOf('\r\n* LIST (\\HasNoChildren) "/" "testfolder"\r\n') >= 0).to.be.false;
498
- expect(resp.indexOf('\r\n* LIST (\\Noselect \\HasChildren) "/" "parent"\r\n') >= 0).to.be.true;
499
- expect(resp.indexOf('\r\n* LIST (\\HasNoChildren) "/" "parent/child"\r\n') >= 0).to.be.true;
500
- done();
501
- }
502
- );
503
- });
504
- });
505
-
506
- describe('DELETE', function () {
507
- it('should delete existing mailbox', function (done) {
508
- let cmds = ['T1 LOGIN testuser pass', 'T2 CREATE testfolder', 'T3 DELETE testfolder', 'T4 DELETE testfolder', 'T5 LIST "" "*"', 'T6 LOGOUT'];
509
-
510
- testClient(
511
- {
512
- commands: cmds,
513
- secure: true,
514
- port
515
- },
516
- function (resp) {
517
- resp = resp.toString();
518
- expect(/^T3 OK/m.test(resp)).to.be.true;
519
- expect(/^T4 NO \[NONEXISTENT\]/m.test(resp)).to.be.true;
520
- expect(resp.indexOf('\r\n* LIST (\\HasNoChildren) "/" "testfolder"\r\n') >= 0).to.be.false;
521
- done();
522
- }
523
- );
524
- });
525
-
526
- it('should disconnect deleted mailbox clients', function (done) {
527
- let cmds = ['T1 LOGIN testuser pass', 'T2 CREATE testfolder', 'T3 SELECT testfolder', 'T4 DELETE testfolder'];
528
-
529
- testClient(
530
- {
531
- commands: cmds,
532
- secure: true,
533
- port
534
- },
535
- function (resp) {
536
- resp = resp.toString();
537
- expect(/^T3 OK/m.test(resp)).to.be.true;
538
- expect(resp.indexOf('\r\n* BYE') >= 0).to.be.true;
539
- done();
540
- }
541
- );
542
- });
543
- });
544
-
545
- describe('APPEND', function () {
546
- this.timeout(60000);
547
-
548
- it('should fail appending to nonexistent mailbox', function (done) {
549
- let message = Buffer.from('From: sender <sender@example.com>\r\nTo: receiver@example.com\r\nSubject: HELLO!\r\n\r\nWORLD!');
550
- let cmds = ['T1 LOGIN testuser pass', 'T2 APPEND zzz {' + message.length + '}\r\n' + message.toString('binary'), 'T3 LOGOUT'];
551
-
552
- testClient(
553
- {
554
- commands: cmds,
555
- secure: true,
556
- port
557
- },
558
- function (resp) {
559
- resp = resp.toString();
560
- expect(/^T2 NO/m.test(resp)).to.be.true;
561
- expect(resp.indexOf('\r\n* LIST (\\HasNoChildren) "/" "testfolder"\r\n') >= 0).to.be.false;
562
- done();
563
- }
564
- );
565
- });
566
-
567
- it('should append to mailbox', function (done) {
568
- let message = Buffer.from('From: sender <sender@example.com>\r\nTo: receiver@example.com\r\nSubject: HELLO!\r\n\r\nWORLD!');
569
- let cmds = ['T1 LOGIN testuser pass', 'T2 APPEND INBOX {' + message.length + '}\r\n' + message.toString('binary'), 'T3 LOGOUT'];
570
-
571
- testClient(
572
- {
573
- commands: cmds,
574
- secure: true,
575
- port
576
- },
577
- function (resp) {
578
- resp = resp.toString();
579
- expect(/^T2 OK/m.test(resp)).to.be.true;
580
- expect(resp.indexOf('\r\n* LIST (\\HasNoChildren) "/" "testfolder"\r\n') >= 0).to.be.false;
581
- done();
582
- }
583
- );
584
- });
585
-
586
- it('should append to mailbox with optional arguments', function (done) {
587
- let message = Buffer.from('From: sender <sender@example.com>\r\nTo: receiver@example.com\r\nSubject: HELLO!\r\n\r\nWORLD!');
588
- let cmds = [
589
- 'T1 LOGIN testuser pass',
590
- 'T2 APPEND INBOX (MyFlag) "14-Sep-2013 21:22:28 -0300" {' + message.length + '}\r\n' + message.toString('binary'),
591
- 'T3 LOGOUT'
592
- ];
593
-
594
- testClient(
595
- {
596
- commands: cmds,
597
- secure: true,
598
- port
599
- },
600
- function (resp) {
601
- resp = resp.toString();
602
- expect(/^T2 OK/m.test(resp)).to.be.true;
603
- expect(resp.indexOf('\r\n* LIST (\\HasNoChildren) "/" "testfolder"\r\n') >= 0).to.be.false;
604
- expect(/^[^\s]+ BAD/m.test(resp)).to.be.false;
605
- done();
606
- }
607
- );
608
- });
609
-
610
- it('should append large file in chunks', function (done) {
611
- let lchunks = [].concat(chunks);
612
- let message = lchunks.join('');
613
-
614
- let cmds = [
615
- 'T1 LOGIN testuser pass',
616
- 'T2 APPEND INBOX (Seen $NotJunk NotJunk) "20-Oct-2015 09:57:08 +0300" {' + message.length + '}',
617
- lchunks,
618
- 'T3 LOGOUT'
619
- ];
620
-
621
- testClient(
622
- {
623
- commands: cmds,
624
- secure: true,
625
- //debug: true,
626
- port
627
- },
628
- function (resp) {
629
- resp = resp.toString();
630
- expect(/^T2 OK/m.test(resp)).to.be.true;
631
- expect(resp.indexOf('\r\n* LIST (\\HasNoChildren) "/" "testfolder"\r\n') >= 0).to.be.false;
632
- expect(/^[^\s]+ BAD/m.test(resp)).to.be.false;
633
- done();
634
- }
635
- );
636
- });
637
- });
638
-
639
- describe('SELECT', function () {
640
- it('should not select nonexistent mailbox', function (done) {
641
- let cmds = ['T1 LOGIN testuser pass', 'T2 SELECT zzz', 'T3 LOGOUT'];
642
-
643
- testClient(
644
- {
645
- commands: cmds,
646
- secure: true,
647
- port
648
- },
649
- function (resp) {
650
- resp = resp.toString();
651
- expect(/^T2 NO/m.test(resp)).to.be.true;
652
- done();
653
- }
654
- );
655
- });
656
-
657
- it('should not select existing mailbox', function (done) {
658
- let cmds = ['T1 LOGIN testuser pass', 'T2 SELECT INBOX', 'T3 LOGOUT'];
659
-
660
- testClient(
661
- {
662
- commands: cmds,
663
- secure: true,
664
- port
665
- },
666
- function (resp) {
667
- resp = resp.toString();
668
- expect(/^\* FLAGS /m.test(resp)).to.be.true;
669
- expect(/^\* OK \[PERMANENTFLAGS /m.test(resp)).to.be.true;
670
- expect(/^\* OK \[UIDVALIDITY \d+\]/m.test(resp)).to.be.true;
671
- expect(/^\* \d+ EXISTS$/m.test(resp)).to.be.true;
672
- expect(/^\* \d+ RECENT$/m.test(resp)).to.be.true;
673
- expect(/^\* OK \[UIDNEXT \d+\]/m.test(resp)).to.be.true;
674
- expect(/^T2 OK \[READ-WRITE\]/m.test(resp)).to.be.true;
675
- done();
676
- }
677
- );
678
- });
679
- });
680
-
681
- describe('COPY', function () {
682
- it('should not copy to nonexistent mailbox', function (done) {
683
- let cmds = ['T1 LOGIN testuser pass', 'T2 SELECT INBOX', 'T3 COPY 1:* zzz', 'T4 LOGOUT'];
684
-
685
- testClient(
686
- {
687
- commands: cmds,
688
- secure: true,
689
- port
690
- },
691
- function (resp) {
692
- resp = resp.toString();
693
- expect(/^T3 NO/m.test(resp)).to.be.true;
694
- done();
695
- }
696
- );
697
- });
698
-
699
- it('should copy to selected mailbox', function (done) {
700
- let cmds = ['T1 LOGIN testuser pass', 'T2 SELECT INBOX', 'T3 COPY 1:* "[Gmail]/Sent Mail"', 'T4 LOGOUT'];
701
-
702
- testClient(
703
- {
704
- commands: cmds,
705
- secure: true,
706
- port
707
- },
708
- function (resp) {
709
- resp = resp.toString();
710
- expect(/^T3 OK/m.test(resp)).to.be.true;
711
- done();
712
- }
713
- );
714
- });
715
- });
716
-
717
- describe('STATUS', function () {
718
- it('should error on nonexistent mailbox', function (done) {
719
- let cmds = ['T1 LOGIN testuser pass', 'T2 STATUS zzz (UIDNEXT MESSAGES)', 'T3 LOGOUT'];
720
-
721
- testClient(
722
- {
723
- commands: cmds,
724
- secure: true,
725
- port
726
- },
727
- function (resp) {
728
- resp = resp.toString();
729
- expect(/^T2 NO/m.test(resp)).to.be.true;
730
- done();
731
- }
732
- );
733
- });
734
-
735
- it('should return status response', function (done) {
736
- let cmds = ['T1 LOGIN testuser pass', 'T2 STATUS INBOX (UIDNEXT MESSAGES HIGHESTMODSEQ)', 'T3 LOGOUT'];
737
-
738
- testClient(
739
- {
740
- commands: cmds,
741
- secure: true,
742
- port
743
- },
744
- function (resp) {
745
- resp = resp.toString();
746
- expect(/^\* STATUS INBOX \(UIDNEXT \d+ MESSAGES \d+ HIGHESTMODSEQ \d+\)$/m.test(resp)).to.be.true;
747
- expect(/^T2 OK/m.test(resp)).to.be.true;
748
- done();
749
- }
750
- );
751
- });
752
- });
753
-
754
- describe('ENABLE', function () {
755
- it('should not enable anything', function (done) {
756
- let cmds = ['T1 LOGIN testuser pass', 'T2 ENABLE X-TEST', 'T3 LOGOUT'];
757
-
758
- testClient(
759
- {
760
- commands: cmds,
761
- secure: true,
762
- port
763
- },
764
- function (resp) {
765
- resp = resp.toString();
766
- expect(/^\* ENABLED$/m.test(resp)).to.be.true;
767
- expect(/^T2 OK/m.test(resp)).to.be.true;
768
- done();
769
- }
770
- );
771
- });
772
-
773
- it('should enable CONDSTORE', function (done) {
774
- let cmds = ['T1 LOGIN testuser pass', 'T2 ENABLE CONDSTORE', 'T3 LOGOUT'];
775
-
776
- testClient(
777
- {
778
- commands: cmds,
779
- secure: true,
780
- port
781
- },
782
- function (resp) {
783
- resp = resp.toString();
784
- expect(/^\* ENABLED CONDSTORE$/m.test(resp)).to.be.true;
785
- expect(/^T2 OK/m.test(resp)).to.be.true;
786
- done();
787
- }
788
- );
789
- });
790
- });
791
-
792
- describe('CLOSE', function () {
793
- it('should error if not in selected state', function (done) {
794
- let cmds = ['T1 LOGIN testuser pass', 'T2 CLOSE', 'T3 LOGOUT'];
795
-
796
- testClient(
797
- {
798
- commands: cmds,
799
- secure: true,
800
- port
801
- },
802
- function (resp) {
803
- resp = resp.toString();
804
- expect(/^T2 BAD/m.test(resp)).to.be.true;
805
- done();
806
- }
807
- );
808
- });
809
-
810
- it('should close mailbox', function (done) {
811
- let cmds = ['T1 LOGIN testuser pass', 'T2 SELECT INBOX', 'T3 CLOSE', 'T4 LOGOUT'];
812
-
813
- testClient(
814
- {
815
- commands: cmds,
816
- secure: true,
817
- port
818
- },
819
- function (resp) {
820
- resp = resp.toString();
821
- expect(/^T3 OK/m.test(resp)).to.be.true;
822
- done();
823
- }
824
- );
825
- });
826
- });
827
-
828
- describe('UNSELECT', function () {
829
- it('should close mailbox', function (done) {
830
- let cmds = ['T1 LOGIN testuser pass', 'T2 SELECT INBOX', 'T3 UNSELECT', 'T4 LOGOUT'];
831
-
832
- testClient(
833
- {
834
- commands: cmds,
835
- secure: true,
836
- port
837
- },
838
- function (resp) {
839
- resp = resp.toString();
840
- expect(/^T3 OK/m.test(resp)).to.be.true;
841
- done();
842
- }
843
- );
844
- });
845
- });
846
-
847
- describe('ID', function () {
848
- it('should return ID info', function (done) {
849
- let cmds = ['T1 ID NIL', 'T2 LOGOUT'];
850
-
851
- testClient(
852
- {
853
- commands: cmds,
854
- secure: true,
855
- port
856
- },
857
- function (resp) {
858
- resp = resp.toString();
859
- expect(/^\* ID \("name"/m.test(resp)).to.be.true;
860
- expect(/^T1 OK/m.test(resp)).to.be.true;
861
- done();
862
- }
863
- );
864
- });
865
- });
866
-
867
- describe('STORE', function () {
868
- it('should set flags', function (done) {
869
- let cmds = ['T1 LOGIN testuser pass', 'T2 SELECT INBOX', 'T3 STORE 1:* FLAGS (MyFlag1 MyFlag2)', 'T4 LOGOUT'];
870
-
871
- testClient(
872
- {
873
- commands: cmds,
874
- secure: true,
875
- port
876
- },
877
- function (resp) {
878
- resp = resp.toString();
879
- expect(resp.match(/^\* \d+ FETCH \(FLAGS \(MyFlag1 MyFlag2\)\)$/gm).length).to.equal(6);
880
- expect(/^T3 OK/m.test(resp)).to.be.true;
881
- done();
882
- }
883
- );
884
- });
885
-
886
- it('should add flags', function (done) {
887
- let cmds = ['T1 LOGIN testuser pass', 'T2 SELECT INBOX', 'T3 STORE 1:* +FLAGS (MyFlag1 MyFlag2)', 'T4 LOGOUT'];
888
-
889
- testClient(
890
- {
891
- commands: cmds,
892
- secure: true,
893
- port
894
- },
895
- function (resp) {
896
- resp = resp.toString();
897
- expect(resp.match(/^\* \d+ FETCH \(FLAGS \(MyFlag1 MyFlag2\)\)$/gm).length).to.equal(4);
898
- expect(resp.match(/^\* \d+ FETCH \(FLAGS \(\\Seen MyFlag1 MyFlag2\)\)$/gm).length).to.equal(2);
899
- expect(/^T3 OK/m.test(resp)).to.be.true;
900
- done();
901
- }
902
- );
903
- });
904
-
905
- it('should remove flags', function (done) {
906
- let cmds = ['T1 LOGIN testuser pass', 'T2 SELECT INBOX', 'T3 STORE 1:* -FLAGS (\\Seen MyFlag2)', 'T4 LOGOUT'];
907
-
908
- testClient(
909
- {
910
- commands: cmds,
911
- secure: true,
912
- port
913
- },
914
- function (resp) {
915
- resp = resp.toString();
916
- expect(resp.match(/^\* \d+ FETCH \(FLAGS \(\)\)$/gm).length).to.equal(2);
917
- expect(/^T3 OK/m.test(resp)).to.be.true;
918
- done();
919
- }
920
- );
921
- });
922
-
923
- it('should set some flags with modifier', function (done) {
924
- let cmds = ['T1 LOGIN testuser pass', 'T2 SELECT INBOX', 'T3 STORE 1:* (UNCHANGEDSINCE 99) FLAGS (MyFlag1 MyFlag2)', 'T4 LOGOUT'];
925
-
926
- testClient(
927
- {
928
- commands: cmds,
929
- secure: true,
930
- port
931
- },
932
- function (resp) {
933
- resp = resp.toString();
934
- expect(resp.match(/^\* \d+ FETCH \(FLAGS \(MyFlag1 MyFlag2\) MODSEQ \(\d+\)\)$/gm).length).to.equal(4);
935
- expect(/\[MODIFIED [\d,:]+\]/.test(resp)).to.be.true;
936
- expect(/^T3 OK/m.test(resp)).to.be.true;
937
- done();
938
- }
939
- );
940
- });
941
-
942
- it('should set flags with modifier', function (done) {
943
- let cmds = ['T1 LOGIN testuser pass', 'T2 SELECT INBOX', 'T3 STORE 1:* (UNCHANGEDSINCE 100000) FLAGS (MyFlag1 MyFlag2)', 'T4 LOGOUT'];
944
-
945
- testClient(
946
- {
947
- commands: cmds,
948
- secure: true,
949
- port
950
- },
951
- function (resp) {
952
- resp = resp.toString();
953
- expect(resp.match(/^\* \d+ FETCH \(FLAGS \(MyFlag1 MyFlag2\) MODSEQ \(\d+\)\)$/gm).length).to.equal(6);
954
- expect(/MODIFIED/.test(resp)).to.be.false;
955
- expect(/^T3 OK/m.test(resp)).to.be.true;
956
- done();
957
- }
958
- );
959
- });
960
- });
961
-
962
- describe('UID STORE', function () {
963
- it('should set flags', function (done) {
964
- let cmds = ['T1 LOGIN testuser pass', 'T2 SELECT INBOX', 'T3 UID STORE 1:* FLAGS (MyFlag1 MyFlag2)', 'T4 LOGOUT'];
965
-
966
- testClient(
967
- {
968
- commands: cmds,
969
- secure: true,
970
- port
971
- },
972
- function (resp) {
973
- resp = resp.toString();
974
- expect(resp.match(/^\* \d+ FETCH \(UID \d+ FLAGS \(MyFlag1 MyFlag2\)\)$/gm).length).to.equal(6);
975
- expect(/^T3 OK/m.test(resp)).to.be.true;
976
- done();
977
- }
978
- );
979
- });
980
-
981
- it('should add flags', function (done) {
982
- let cmds = ['T1 LOGIN testuser pass', 'T2 SELECT INBOX', 'T3 UID STORE 1:* +FLAGS (MyFlag1 MyFlag2)', 'T4 LOGOUT'];
983
-
984
- testClient(
985
- {
986
- commands: cmds,
987
- secure: true,
988
- port
989
- },
990
- function (resp) {
991
- resp = resp.toString();
992
- expect(resp.match(/^\* \d+ FETCH \(UID \d+ FLAGS \(MyFlag1 MyFlag2\)\)$/gm).length).to.equal(4);
993
- expect(resp.match(/^\* \d+ FETCH \(UID \d+ FLAGS \(\\Seen MyFlag1 MyFlag2\)\)$/gm).length).to.equal(2);
994
- expect(/^T3 OK/m.test(resp)).to.be.true;
995
- done();
996
- }
997
- );
998
- });
999
-
1000
- it('should remove flags', function (done) {
1001
- let cmds = ['T1 LOGIN testuser pass', 'T2 SELECT INBOX', 'T3 UID STORE 1:* -FLAGS (\\Seen MyFlag2)', 'T4 LOGOUT'];
1002
-
1003
- testClient(
1004
- {
1005
- commands: cmds,
1006
- secure: true,
1007
- port
1008
- },
1009
- function (resp) {
1010
- resp = resp.toString();
1011
- expect(resp.match(/^\* \d+ FETCH \(UID \d+ FLAGS \(\)\)$/gm).length).to.equal(2);
1012
- expect(/^T3 OK/m.test(resp)).to.be.true;
1013
- done();
1014
- }
1015
- );
1016
- });
1017
-
1018
- it('should set some flags with modifier', function (done) {
1019
- let cmds = ['T1 LOGIN testuser pass', 'T2 SELECT INBOX', 'T3 UID STORE 1:* (UNCHANGEDSINCE 99) FLAGS (MyFlag1 MyFlag2)', 'T4 LOGOUT'];
1020
-
1021
- testClient(
1022
- {
1023
- commands: cmds,
1024
- secure: true,
1025
- port
1026
- },
1027
- function (resp) {
1028
- resp = resp.toString();
1029
- expect(resp.match(/^\* \d+ FETCH \(UID \d+ FLAGS \(MyFlag1 MyFlag2\) MODSEQ \(\d+\)\)$/gm).length).to.equal(4);
1030
- expect(/\[MODIFIED [\d,:]+\]/.test(resp)).to.be.true;
1031
- expect(/^T3 OK/m.test(resp)).to.be.true;
1032
- done();
1033
- }
1034
- );
1035
- });
1036
-
1037
- it('should set some flags with modifier', function (done) {
1038
- let cmds = ['T1 LOGIN testuser pass', 'T2 SELECT INBOX', 'T3 UID STORE 1:* (UNCHANGEDSINCE 10000) FLAGS (MyFlag1 MyFlag2)', 'T4 LOGOUT'];
1039
-
1040
- testClient(
1041
- {
1042
- commands: cmds,
1043
- secure: true,
1044
- port
1045
- },
1046
- function (resp) {
1047
- resp = resp.toString();
1048
- expect(resp.match(/^\* \d+ FETCH \(UID \d+ FLAGS \(MyFlag1 MyFlag2\) MODSEQ \(\d+\)\)$/gm).length).to.equal(6);
1049
- expect(/MODIFIED/.test(resp)).to.be.false;
1050
- expect(/^T3 OK/m.test(resp)).to.be.true;
1051
- done();
1052
- }
1053
- );
1054
- });
1055
- });
1056
-
1057
- describe('SUBSCRIBE', function () {
1058
- it('should subscribe to mailbox', function (done) {
1059
- let cmds = [
1060
- 'T1 LOGIN testuser pass',
1061
- 'T2 CREATE testfolder',
1062
- 'T3 UNSUBSCRIBE testfolder',
1063
- 'T4 SUBSCRIBE testfolder',
1064
- 'T5 LSUB "" "*"',
1065
- 'T6 LOGOUT'
1066
- ];
1067
-
1068
- testClient(
1069
- {
1070
- commands: cmds,
1071
- secure: true,
1072
- port
1073
- },
1074
- function (resp) {
1075
- resp = resp.toString();
1076
- expect(resp.match(/^\* LSUB /gm).length).to.equal(6);
1077
- expect(resp.indexOf('\r\n* LSUB (\\HasNoChildren) "/" "INBOX"\r\n') >= 0).to.be.true;
1078
- expect(resp.indexOf('\r\n* LSUB (\\HasNoChildren) "/" "[Gmail]/Sent Mail"\r\n') >= 0).to.be.true;
1079
- expect(resp.indexOf('\r\n* LSUB (\\HasNoChildren) "/" "testfolder"\r\n') >= 0).to.be.true;
1080
- expect(/^T4 OK/m.test(resp)).to.be.true;
1081
- done();
1082
- }
1083
- );
1084
- });
1085
- });
1086
-
1087
- describe('UNSUBSCRIBE', function () {
1088
- it('should unsubscribe from mailbox', function (done) {
1089
- let cmds = [
1090
- 'T1 LOGIN testuser pass',
1091
- 'T2 CREATE testfolder',
1092
- 'T3 SUBSCRIBE testfolder',
1093
- 'T4 UNSUBSCRIBE testfolder',
1094
- 'T5 LSUB "" "*"',
1095
- 'T6 LOGOUT'
1096
- ];
1097
-
1098
- testClient(
1099
- {
1100
- commands: cmds,
1101
- secure: true,
1102
- port
1103
- },
1104
- function (resp) {
1105
- resp = resp.toString();
1106
- expect(resp.match(/^\* LSUB /gm).length).to.equal(5);
1107
- expect(resp.indexOf('\r\n* LSUB (\\HasNoChildren) "/" "INBOX"\r\n') >= 0).to.be.true;
1108
- expect(resp.indexOf('\r\n* LSUB (\\HasNoChildren) "/" "[Gmail]/Sent Mail"\r\n') >= 0).to.be.true;
1109
- expect(resp.indexOf('\r\n* LSUB (\\HasNoChildren) "/" "testfolder"\r\n') >= 0).to.be.false;
1110
- expect(/^T4 OK/m.test(resp)).to.be.true;
1111
- done();
1112
- }
1113
- );
1114
- });
1115
- });
1116
-
1117
- describe('EXPUNGE', function () {
1118
- // EXPUNGE is a NO OP with autoexpunge
1119
- it('should expunge all deleted messages', function (done) {
1120
- let cmds = ['T1 LOGIN testuser pass', 'T2 SELECT INBOX', 'T3 STORE 2:* +FLAGS (\\Deleted)', 'T4 EXPUNGE', 'T6 LOGOUT'];
1121
-
1122
- testClient(
1123
- {
1124
- commands: cmds,
1125
- secure: true,
1126
- port
1127
- },
1128
- function (resp) {
1129
- resp = resp.toString();
1130
- expect(resp.match(/^\* \d+ EXPUNGE/gm).length).to.equal(5);
1131
- expect(/^T4 OK/m.test(resp)).to.be.true;
1132
- done();
1133
- }
1134
- );
1135
- });
1136
- });
1137
-
1138
- describe('UID EXPUNGE', function () {
1139
- // UID EXPUNGE is a NO OP with autoexpunge
1140
- it('should expunge specific messages', function (done) {
1141
- let cmds = ['T1 LOGIN testuser pass', 'T2 SELECT INBOX', 'T3 STORE 1:* +FLAGS (\\Deleted)', 'T4 UID EXPUNGE 103,105', 'T5 LOGOUT'];
1142
-
1143
- testClient(
1144
- {
1145
- commands: cmds,
1146
- secure: true,
1147
- port
1148
- },
1149
- function (resp) {
1150
- resp = resp.toString();
1151
- expect(resp.match(/^\* \d+ EXPUNGE/gm).length).to.equal(2);
1152
- expect(resp.match(/^\* 3 EXPUNGE/gm).length).to.equal(1);
1153
- expect(resp.match(/^\* 4 EXPUNGE/gm).length).to.equal(1);
1154
- expect(/^T4 OK/m.test(resp)).to.be.true;
1155
- done();
1156
- }
1157
- );
1158
- });
1159
- });
1160
-
1161
- describe('FETCH command', function () {
1162
- it('should list by UID', function (done) {
1163
- let cmds = ['T1 LOGIN testuser pass', 'T2 SELECT INBOX', 'T3 UID FETCH 103 (FLAGS)', 'T4 FETCH 3 (FLAGS)', 'T4 LOGOUT'];
1164
-
1165
- testClient(
1166
- {
1167
- commands: cmds,
1168
- secure: true,
1169
- port
1170
- },
1171
- function (resp) {
1172
- resp = resp.toString();
1173
- expect(resp.slice(/\n/).indexOf('* 3 FETCH (FLAGS (\\Seen) UID 103)') >= 0).to.be.true; // UID FETCH FLAGS
1174
- expect(resp.slice(/\n/).indexOf('* 3 FETCH (FLAGS (\\Seen))') >= 0).to.be.true; // FETCH FLAGS
1175
- expect(/^T3 OK/m.test(resp)).to.be.true;
1176
- done();
1177
- }
1178
- );
1179
- });
1180
-
1181
- it('should list with MODSEQ', function (done) {
1182
- let cmds = [
1183
- 'T1 LOGIN testuser pass',
1184
- 'T2 SELECT INBOX',
1185
- 'T3 UID FETCH 103 (FLAGS) (CHANGEDSINCE 1)',
1186
- 'T4 FETCH 3 (FLAGS) (CHANGEDSINCE 1)',
1187
- 'T5 UID FETCH 103 (FLAGS) (CHANGEDSINCE 10000)',
1188
- 'T6 FETCH 3 (FLAGS) (CHANGEDSINCE 10000)',
1189
- 'T7 LOGOUT'
1190
- ];
1191
-
1192
- testClient(
1193
- {
1194
- commands: cmds,
1195
- secure: true,
1196
- port
1197
- },
1198
- function (resp) {
1199
- resp = resp.toString();
1200
- expect(resp.slice(/\n/).indexOf('* 3 FETCH (FLAGS (\\Seen) UID 103 MODSEQ (3))') >= 0).to.be.true; // UID FETCH FLAGS
1201
- expect(resp.slice(/\n/).indexOf('* 3 FETCH (FLAGS (\\Seen) MODSEQ (3))') >= 0).to.be.true; // FETCH FLAGS
1202
- expect(resp.match(/^\* \d+ FETCH/gm).length).to.equal(2);
1203
- expect(/^T3 OK/m.test(resp)).to.be.true;
1204
- expect(/^T4 OK/m.test(resp)).to.be.true;
1205
- expect(/^T5 OK/m.test(resp)).to.be.true;
1206
- expect(/^T6 OK/m.test(resp)).to.be.true;
1207
- done();
1208
- }
1209
- );
1210
- });
1211
-
1212
- describe('Multiple values', function () {
1213
- it('should list mixed data', function (done) {
1214
- let cmds = ['T1 LOGIN testuser pass', 'T2 SELECT INBOX', 'T3 FETCH 1:* (UID BODYSTRUCTURE ENVELOPE)', 'T4 LOGOUT'];
1215
- testClient(
1216
- {
1217
- commands: cmds,
1218
- secure: true,
1219
- port
1220
- },
1221
- function (resp) {
1222
- resp = resp.toString();
1223
- expect(
1224
- resp
1225
- .slice(/\n/)
1226
- .indexOf(
1227
- '* 1 FETCH (UID 101 BODYSTRUCTURE ("TEXT" "PLAIN" NIL NIL NIL "7BIT" 6 1 NIL NIL NIL NIL) ENVELOPE (NIL "test" ((NIL NIL "sender" "example.com")) ((NIL NIL "sender" "example.com")) ((NIL NIL "sender" "example.com")) ((NIL NIL "to" "example.com")) ((NIL NIL "cc" "example.com")) NIL NIL NIL))'
1228
- ) >= 0
1229
- ).to.be.true;
1230
- expect(/^T3 OK/m.test(resp)).to.be.true;
1231
- done();
1232
- }
1233
- );
1234
- });
1235
- });
1236
-
1237
- describe('BODY[] marks message as seen', function () {
1238
- it('should list raw message', function (done) {
1239
- let cmds = ['T1 LOGIN testuser pass', 'T2 SELECT INBOX', 'T3 FETCH 3 BODY[2.HEADER]', 'T4 LOGOUT'];
1240
-
1241
- testClient(
1242
- {
1243
- commands: cmds,
1244
- secure: true,
1245
- port
1246
- },
1247
- function (resp) {
1248
- resp = resp.toString();
1249
-
1250
- expect(
1251
- resp.indexOf(
1252
- '\n* 3 FETCH (BODY[2.HEADER] {71}\r\n' +
1253
- 'MIME-Version: 1.0\r\n' +
1254
- 'From: andris@kreata.ee\r\n' +
1255
- 'To: andris@pangalink.net\r\n' +
1256
- '\r\n' +
1257
- ' FLAGS (\\Seen))\r\n'
1258
- ) >= 0
1259
- ).to.be.true;
1260
-
1261
- expect(/^T3 OK/m.test(resp)).to.be.true;
1262
- done();
1263
- }
1264
- );
1265
- });
1266
- });
1267
-
1268
- describe('UID', function () {
1269
- it('should return correct UID', function (done) {
1270
- let cmds = ['T1 LOGIN testuser pass', 'T2 SELECT INBOX', 'T3 FETCH 3 UID', 'T4 LOGOUT'];
1271
-
1272
- testClient(
1273
- {
1274
- commands: cmds,
1275
- secure: true,
1276
- port
1277
- },
1278
- function (resp) {
1279
- resp = resp.toString();
1280
-
1281
- expect(resp.indexOf('\n* 3 FETCH (UID 103)\r\n') >= 0).to.be.true;
1282
- expect(/^T3 OK/m.test(resp)).to.be.true;
1283
-
1284
- done();
1285
- }
1286
- );
1287
- });
1288
- });
1289
-
1290
- describe('FLAGS', function () {
1291
- it('should return corretc FLAGS', function (done) {
1292
- let cmds = ['T1 LOGIN testuser pass', 'T2 SELECT INBOX', 'T3 FETCH 3 FLAGS', 'T4 LOGOUT'];
1293
-
1294
- testClient(
1295
- {
1296
- commands: cmds,
1297
- secure: true,
1298
- port
1299
- },
1300
- function (resp) {
1301
- resp = resp.toString();
1302
-
1303
- expect(resp.indexOf('\n* 3 FETCH (FLAGS (\\Seen))\r\n') >= 0).to.be.true;
1304
- expect(/^T3 OK/m.test(resp)).to.be.true;
1305
-
1306
- done();
1307
- }
1308
- );
1309
- });
1310
- });
1311
-
1312
- describe('BODYSTRUCTURE', function () {
1313
- it('should list bodystructure object', function (done) {
1314
- let cmds = ['T1 LOGIN testuser pass', 'T2 SELECT INBOX', 'T3 FETCH 3 BODYSTRUCTURE', 'T4 LOGOUT'];
1315
-
1316
- testClient(
1317
- {
1318
- commands: cmds,
1319
- secure: true,
1320
- port
1321
- },
1322
- function (resp) {
1323
- resp = resp.toString();
1324
- expect(
1325
- resp.indexOf(
1326
- '\n* 3 FETCH (BODYSTRUCTURE (("MESSAGE" "RFC822" NIL NIL NIL "7BIT" 107 (NIL "" ((NIL NIL "andris" "kreata.ee")) ((NIL NIL "andris" "kreata.ee")) ((NIL NIL "andris" "kreata.ee")) ((NIL NIL "andris" "pangalink.net")) NIL NIL "<test1>" NIL) ("TEXT" "PLAIN" NIL NIL NIL "7BIT" 14 0 NIL NIL NIL NIL) 5 NIL NIL NIL NIL)("MESSAGE" "RFC822" NIL NIL NIL "7BIT" 85 (NIL "" ((NIL NIL "andris" "kreata.ee")) ((NIL NIL "andris" "kreata.ee")) ((NIL NIL "andris" "kreata.ee")) ((NIL NIL "andris" "pangalink.net")) NIL NIL NIL NIL) ("TEXT" "PLAIN" NIL NIL NIL "7BIT" 14 0 NIL NIL NIL NIL) 4 NIL NIL NIL NIL)("TEXT" "HTML" ("CHARSET" "utf-8") NIL NIL "QUOTED-PRINTABLE" 21 0 NIL NIL NIL NIL) "MIXED" ("BOUNDARY" "----mailcomposer-?=_1-1328088797399") NIL NIL NIL))\r\n'
1327
- ) >= 0
1328
- ).to.be.true;
1329
- expect(/^T3 OK/m.test(resp)).to.be.true;
1330
- done();
1331
- }
1332
- );
1333
- });
1334
- });
1335
-
1336
- describe('ENVELOPE', function () {
1337
- it('should list envelope object', function (done) {
1338
- let cmds = ['T1 LOGIN testuser pass', 'T2 SELECT INBOX', 'T3 FETCH 1:* ENVELOPE', 'T4 LOGOUT'];
1339
-
1340
- testClient(
1341
- {
1342
- commands: cmds,
1343
- secure: true,
1344
- port
1345
- },
1346
- function (resp) {
1347
- resp = resp.toString();
1348
- expect(
1349
- resp.indexOf(
1350
- '\n* 3 FETCH (ENVELOPE (NIL "" ((NIL NIL "andris" "kreata.ee")) ((NIL NIL "andris" "kreata.ee")) ((NIL NIL "andris" "kreata.ee")) ((NIL NIL "andris" "tr.ee")) NIL NIL NIL "<testmessage-for-bug>;"))\r\n'
1351
- ) >= 0
1352
- ).to.be.true;
1353
- expect(/^T3 OK/m.test(resp)).to.be.true;
1354
- done();
1355
- }
1356
- );
1357
- });
1358
- });
1359
-
1360
- describe('BODY', function () {
1361
- it('should return BODY', function (done) {
1362
- let cmds = ['T1 LOGIN testuser pass', 'T2 SELECT INBOX', 'T3 FETCH 1 BODY', 'T4 LOGOUT'];
1363
-
1364
- testClient(
1365
- {
1366
- commands: cmds,
1367
- secure: true,
1368
- port
1369
- },
1370
- function (resp) {
1371
- resp = resp.toString();
1372
- expect(resp.indexOf('\n* 1 FETCH (BODY ("TEXT" "PLAIN" NIL NIL NIL "7BIT" 6 1))\r\n') >= 0).to.be.true;
1373
- expect(/^T3 OK/m.test(resp)).to.be.true;
1374
- done();
1375
- }
1376
- );
1377
- });
1378
-
1379
- it('should return BODY[]', function (done) {
1380
- let cmds = ['T1 LOGIN testuser pass', 'T2 SELECT INBOX', 'T3 FETCH 4 BODY.PEEK[]', 'T4 LOGOUT'];
1381
-
1382
- testClient(
1383
- {
1384
- commands: cmds,
1385
- secure: true,
1386
- port
1387
- },
1388
- function (resp) {
1389
- resp = resp.toString();
1390
- expect(
1391
- resp.indexOf(
1392
- '\r\n* 4 FETCH (BODY[] {97}\r\nfrom: sender@example.com\r\nto: to@example.com\r\ncc: cc@example.com\r\nsubject: test\r\n\r\nHello World!\r\n)\r\n'
1393
- ) >= 0
1394
- ).to.be.true;
1395
- expect(/^T3 OK/m.test(resp)).to.be.true;
1396
- done();
1397
- }
1398
- );
1399
- });
1400
-
1401
- it('should return partial BODY[]', function (done) {
1402
- let cmds = ['T1 LOGIN testuser pass', 'T2 SELECT INBOX', 'T3 FETCH 4 BODY.PEEK[]<4.5>', 'T4 FETCH 4 BODY.PEEK[]<4.10000>', 'T5 LOGOUT'];
1403
-
1404
- testClient(
1405
- {
1406
- commands: cmds,
1407
- secure: true,
1408
- port
1409
- },
1410
- function (resp) {
1411
- resp = resp.toString();
1412
- expect(resp.indexOf('\n* 4 FETCH (BODY[]<4> {5}\r\n: sen)\r\n') >= 0).to.be.true;
1413
- expect(
1414
- resp.indexOf(
1415
- '\n* 4 FETCH (BODY[]<4> {93}\r\n: sender@example.com\r\nto: to@example.com\r\ncc: cc@example.com\r\nsubject: test\r\n\r\nHello World!\r\n)\r\n'
1416
- ) >= 0
1417
- ).to.be.true;
1418
- expect(/^T3 OK/m.test(resp)).to.be.true;
1419
- expect(/^T4 OK/m.test(resp)).to.be.true;
1420
- done();
1421
- }
1422
- );
1423
- });
1424
-
1425
- it('should return partial BODY[1]', function (done) {
1426
- let cmds = ['T1 LOGIN testuser pass', 'T2 SELECT INBOX', 'T3 FETCH 3 BODY.PEEK[1]', 'T4 LOGOUT'];
1427
-
1428
- testClient(
1429
- {
1430
- commands: cmds,
1431
- secure: true,
1432
- port
1433
- },
1434
- function (resp) {
1435
- resp = resp.toString();
1436
- expect(
1437
- resp.indexOf(
1438
- '\r\n* 3 FETCH (BODY[1] {107}\r\nMIME-Version: 1.0\r\nFrom: andris@kreata.ee\r\nTo: andris@pangalink.net\r\nIn-Reply-To: <test1>\r\n\r\nHello world 1!)\r\n'
1439
- ) >= 0
1440
- ).to.be.true;
1441
-
1442
- expect(/^T3 OK/m.test(resp)).to.be.true;
1443
- done();
1444
- }
1445
- );
1446
- });
1447
-
1448
- it('should return BODY[HEADER]', function (done) {
1449
- let cmds = ['T1 LOGIN testuser pass', 'T2 SELECT INBOX', 'T3 FETCH 4 BODY.PEEK[HEADER]', 'T4 LOGOUT'];
1450
-
1451
- testClient(
1452
- {
1453
- commands: cmds,
1454
- secure: true,
1455
- port
1456
- },
1457
- function (resp) {
1458
- resp = resp.toString();
1459
- expect(
1460
- resp.indexOf(
1461
- '\r\n* 4 FETCH (BODY[HEADER] {83}\r\nfrom: sender@example.com\r\nto: to@example.com\r\ncc: cc@example.com\r\nsubject: test\r\n\r\n)\r\n'
1462
- ) >= 0
1463
- ).to.be.true;
1464
- expect(/^T3 OK/m.test(resp)).to.be.true;
1465
- done();
1466
- }
1467
- );
1468
- });
1469
-
1470
- it('should return BODY[HEADER.FIELDS]', function (done) {
1471
- let cmds = ['T1 LOGIN testuser pass', 'T2 SELECT INBOX', 'T3 FETCH 4 BODY.PEEK[HEADER.FIELDS (From Cc)]', 'T4 LOGOUT'];
1472
-
1473
- testClient(
1474
- {
1475
- commands: cmds,
1476
- secure: true,
1477
- port
1478
- },
1479
- function (resp) {
1480
- resp = resp.toString();
1481
- expect(
1482
- resp.indexOf('\r\n* 4 FETCH (BODY[HEADER.FIELDS (From Cc)] {48}\r\nfrom: sender@example.com\r\ncc: cc@example.com\r\n\r\n)\r\n') >=
1483
- 0
1484
- ).to.be.true;
1485
- expect(/^T3 OK/m.test(resp)).to.be.true;
1486
- done();
1487
- }
1488
- );
1489
- });
1490
-
1491
- it('should return BODY[HEADER.FIELDS.NOT]', function (done) {
1492
- let cmds = ['T1 LOGIN testuser pass', 'T2 SELECT INBOX', 'T3 FETCH 4 BODY.PEEK[HEADER.FIELDS.NOT (From Cc)]', 'T4 LOGOUT'];
1493
-
1494
- testClient(
1495
- {
1496
- commands: cmds,
1497
- secure: true,
1498
- port
1499
- },
1500
- function (resp) {
1501
- resp = resp.toString();
1502
- expect(resp.indexOf('\r\n* 4 FETCH (BODY[HEADER.FIELDS.NOT (From Cc)] {37}\r\nto: to@example.com\r\nsubject: test\r\n\r\n)\r\n') >= 0)
1503
- .to.be.true;
1504
- expect(/^T3 OK/m.test(resp)).to.be.true;
1505
- done();
1506
- }
1507
- );
1508
- });
1509
-
1510
- it('should return BODY[TEXT]', function (done) {
1511
- let cmds = ['T1 LOGIN testuser pass', 'T2 SELECT INBOX', 'T3 FETCH 4 BODY.PEEK[TEXT]', 'T4 LOGOUT'];
1512
-
1513
- testClient(
1514
- {
1515
- commands: cmds,
1516
- secure: true,
1517
- port
1518
- },
1519
- function (resp) {
1520
- resp = resp.toString();
1521
- expect(resp.indexOf('\r\n* 4 FETCH (BODY[TEXT] {14}\r\nHello World!\r\n)\r\n') >= 0).to.be.true;
1522
- expect(/^T3 OK/m.test(resp)).to.be.true;
1523
- done();
1524
- }
1525
- );
1526
- });
1527
-
1528
- it('should return BODY[x.HEADER]', function (done) {
1529
- let cmds = ['T1 LOGIN testuser pass', 'T2 SELECT INBOX', 'T3 FETCH 3 BODY.PEEK[1.HEADER]', 'T4 FETCH 3 BODY.PEEK[2.HEADER]', 'T5 LOGOUT'];
1530
-
1531
- testClient(
1532
- {
1533
- commands: cmds,
1534
- secure: true,
1535
- port
1536
- },
1537
- function (resp) {
1538
- resp = resp.toString();
1539
-
1540
- expect(
1541
- resp.indexOf(
1542
- '\n* 3 FETCH (BODY[1.HEADER] {93}\r\n' +
1543
- 'MIME-Version: 1.0\r\n' +
1544
- 'From: andris@kreata.ee\r\n' +
1545
- 'To: andris@pangalink.net\r\n' +
1546
- 'In-Reply-To: <test1>\r\n' +
1547
- '\r\n' +
1548
- ')\r\n'
1549
- ) >= 0
1550
- ).to.be.true;
1551
-
1552
- expect(
1553
- resp.indexOf(
1554
- '\n* 3 FETCH (BODY[2.HEADER] {71}\r\n' +
1555
- 'MIME-Version: 1.0\r\n' +
1556
- 'From: andris@kreata.ee\r\n' +
1557
- 'To: andris@pangalink.net\r\n' +
1558
- '\r\n' +
1559
- ')\r\n'
1560
- ) >= 0
1561
- ).to.be.true;
1562
-
1563
- expect(/^T3 OK/m.test(resp)).to.be.true;
1564
- expect(/^T4 OK/m.test(resp)).to.be.true;
1565
- done();
1566
- }
1567
- );
1568
- });
1569
-
1570
- it('should return BODY[1.MIME]', function (done) {
1571
- let cmds = ['T1 LOGIN testuser pass', 'T2 SELECT INBOX', 'T3 FETCH 3 BODY.PEEK[1.MIME]', 'T4 LOGOUT'];
1572
-
1573
- testClient(
1574
- {
1575
- commands: cmds,
1576
- secure: true,
1577
- port
1578
- },
1579
- function (resp) {
1580
- resp = resp.toString();
1581
- expect(
1582
- resp.indexOf('\r\n* 3 FETCH (BODY[1.MIME] {65}\r\nContent-Type: message/rfc822\r\nContent-Transfer-Encoding: 7bit\r\n\r\n)\r\n') >=
1583
- 0
1584
- ).to.be.true;
1585
- expect(/^T3 OK/m.test(resp)).to.be.true;
1586
- done();
1587
- }
1588
- );
1589
- });
1590
- });
1591
-
1592
- describe('RFC822', function () {
1593
- it('should return RFC822', function (done) {
1594
- let cmds = ['T1 LOGIN testuser pass', 'T2 SELECT INBOX', 'T3 FETCH 4 RFC822', 'T4 LOGOUT'];
1595
-
1596
- testClient(
1597
- {
1598
- commands: cmds,
1599
- secure: true,
1600
- port
1601
- },
1602
- function (resp) {
1603
- resp = resp.toString();
1604
- expect(
1605
- resp.indexOf(
1606
- '\r\n* 4 FETCH (RFC822 {97}\r\nfrom: sender@example.com\r\nto: to@example.com\r\ncc: cc@example.com\r\nsubject: test\r\n\r\nHello World!\r\n FLAGS (\\Seen))\r\n'
1607
- ) >= 0
1608
- ).to.be.true;
1609
- expect(/^T3 OK/m.test(resp)).to.be.true;
1610
- done();
1611
- }
1612
- );
1613
- });
1614
-
1615
- it('should return RFC822.SIZE', function (done) {
1616
- let cmds = ['T1 LOGIN testuser pass', 'T2 SELECT INBOX', 'T3 FETCH 4 RFC822.SIZE', 'T4 LOGOUT'];
1617
-
1618
- testClient(
1619
- {
1620
- commands: cmds,
1621
- secure: true,
1622
- port
1623
- },
1624
- function (resp) {
1625
- resp = resp.toString();
1626
- expect(resp.indexOf('\r\n* 4 FETCH (RFC822.SIZE 97)\r\n') >= 0).to.be.true;
1627
- expect(/^T3 OK/m.test(resp)).to.be.true;
1628
- done();
1629
- }
1630
- );
1631
- });
1632
-
1633
- it('should return RFC822.HEADER', function (done) {
1634
- let cmds = ['T1 LOGIN testuser pass', 'T2 SELECT INBOX', 'T3 FETCH 4 RFC822.HEADER', 'T4 LOGOUT'];
1635
-
1636
- testClient(
1637
- {
1638
- commands: cmds,
1639
- secure: true,
1640
- port
1641
- },
1642
- function (resp) {
1643
- resp = resp.toString();
1644
- expect(
1645
- resp.indexOf(
1646
- '\r\n* 4 FETCH (RFC822.HEADER {83}\r\nfrom: sender@example.com\r\nto: to@example.com\r\ncc: cc@example.com\r\nsubject: test\r\n\r\n)\r\n'
1647
- ) >= 0
1648
- ).to.be.true;
1649
- expect(/^T3 OK/m.test(resp)).to.be.true;
1650
- done();
1651
- }
1652
- );
1653
- });
1654
-
1655
- it('should return RFC822.TEXT', function (done) {
1656
- let cmds = ['T1 LOGIN testuser pass', 'T2 SELECT INBOX', 'T3 FETCH 4 RFC822.TEXT', 'T4 LOGOUT'];
1657
-
1658
- testClient(
1659
- {
1660
- commands: cmds,
1661
- secure: true,
1662
- port
1663
- },
1664
- function (resp) {
1665
- resp = resp.toString();
1666
-
1667
- expect(resp.indexOf('\r\n* 4 FETCH (RFC822.TEXT {14}\r\nHello World!\r\n)\r\n') >= 0).to.be.true;
1668
- expect(/^T3 OK/m.test(resp)).to.be.true;
1669
- done();
1670
- }
1671
- );
1672
- });
1673
- });
1674
-
1675
- describe('INTERNALDATE', function () {
1676
- it('should return message internaldate', function (done) {
1677
- let cmds = ['T1 LOGIN testuser pass', 'T2 SELECT INBOX', 'T3 FETCH 1 INTERNALDATE', 'T4 LOGOUT'];
1678
-
1679
- testClient(
1680
- {
1681
- commands: cmds,
1682
- secure: true,
1683
- port
1684
- },
1685
- function (resp) {
1686
- resp = resp.toString();
1687
- expect(resp.indexOf('\r\n* 1 FETCH (INTERNALDATE "15-Sep-2013 00:22:28 +0000")\r\n') >= 0).to.be.true;
1688
- expect(/^T3 OK/m.test(resp)).to.be.true;
1689
- done();
1690
- }
1691
- );
1692
- });
1693
- });
1694
- });
1695
-
1696
- describe('SEARCH command', function () {
1697
- it('should succeed', function (done) {
1698
- let cmds = ['T1 LOGIN testuser pass', 'T2 SELECT INBOX', 'T3 SEARCH ALL', 'T4 UID SEARCH ALL', 'T7 LOGOUT'];
1699
-
1700
- testClient(
1701
- {
1702
- commands: cmds,
1703
- secure: true,
1704
- port
1705
- },
1706
- function (resp) {
1707
- resp = resp.toString();
1708
- expect(resp.match(/^\* SEARCH /gm).length).to.equal(2);
1709
- expect(/^T3 OK/m.test(resp)).to.be.true;
1710
- expect(/^T4 OK/m.test(resp)).to.be.true;
1711
- done();
1712
- }
1713
- );
1714
- });
1715
-
1716
- it('should find with FLAGS', function (done) {
1717
- let cmds = ['T1 LOGIN testuser pass', 'T2 SELECT INBOX', 'T3 SEARCH (UNSEEN)', 'T4 UID SEARCH UNSEEN', 'T7 LOGOUT'];
1718
-
1719
- testClient(
1720
- {
1721
- commands: cmds,
1722
- secure: true,
1723
- port
1724
- },
1725
- function (resp) {
1726
- resp = resp.toString();
1727
- expect(resp.match(/^\* SEARCH /gm).length).to.equal(2);
1728
- expect(/^\* SEARCH 1 4 5 6$/m.test(resp)).to.be.true;
1729
- expect(/^\* SEARCH 101 104 105 106$/m.test(resp)).to.be.true;
1730
- expect(/^T3 OK/m.test(resp)).to.be.true;
1731
- expect(/^T4 OK/m.test(resp)).to.be.true;
1732
- done();
1733
- }
1734
- );
1735
- });
1736
-
1737
- it('should find with MODSEQ', function (done) {
1738
- let cmds = ['T1 LOGIN testuser pass', 'T2 SELECT INBOX', 'T3 SEARCH MODSEQ 1000', 'T4 LOGOUT'];
1739
-
1740
- testClient(
1741
- {
1742
- commands: cmds,
1743
- secure: true,
1744
- port
1745
- },
1746
- function (resp) {
1747
- resp = resp.toString();
1748
- expect(resp.match(/^\* SEARCH /gm).length).to.equal(1);
1749
- expect(/^\* SEARCH 2 \(MODSEQ 5000\)$/m.test(resp)).to.be.true;
1750
- expect(/^T3 OK/m.test(resp)).to.be.true;
1751
- done();
1752
- }
1753
- );
1754
- });
1755
- });
1756
- });