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,1356 +0,0 @@
1
- /*eslint no-unused-expressions: 0, prefer-arrow-callback: 0 */
2
-
3
- 'use strict';
4
-
5
- const parseQueryTerms = require('../lib/commands/search').parseQueryTerms;
6
- const matchSearchQuery = require('../lib/search').matchSearchQuery;
7
- const Indexer = require('../lib/indexer/indexer');
8
- const indexer = new Indexer();
9
-
10
- const chai = require('chai');
11
- const expect = chai.expect;
12
- chai.config.includeStack = true;
13
-
14
- describe('#parseQueryTerms', function() {
15
- let uidList = [39, 40, 44, 52, 53, 54, 59, 72];
16
-
17
- describe('<sequence set>', function() {
18
- it('should detect sequence as first argument', function() {
19
- expect(parseQueryTerms('1,2,4:6'.split(' '), uidList).query).to.deep.equal([
20
- {
21
- key: 'uid',
22
- value: [39, 40, 52, 53, 54]
23
- }
24
- ]);
25
- });
26
-
27
- it('should detect sequence as subargument', function() {
28
- expect(parseQueryTerms('NOT 1,2,4:6'.split(' '), uidList).query).to.deep.equal([
29
- {
30
- key: 'not',
31
- value: {
32
- key: 'uid',
33
- value: [39, 40, 52, 53, 54]
34
- }
35
- }
36
- ]);
37
- });
38
- });
39
-
40
- it('should handle ALL', function() {
41
- expect(parseQueryTerms('ALL'.split(' '), uidList).query).to.deep.equal([
42
- {
43
- key: 'all',
44
- value: true
45
- }
46
- ]);
47
- });
48
-
49
- it('should handle ANSWERED', function() {
50
- expect(parseQueryTerms('ANSWERED'.split(' '), uidList).query).to.deep.equal([
51
- {
52
- key: 'flag',
53
- value: '\\Answered',
54
- exists: true
55
- }
56
- ]);
57
- });
58
-
59
- it('should handle BCC', function() {
60
- expect(parseQueryTerms('BCC query'.split(' '), uidList).query).to.deep.equal([
61
- {
62
- key: 'header',
63
- header: 'bcc',
64
- value: 'query'
65
- }
66
- ]);
67
- });
68
-
69
- it('should handle BEFORE', function() {
70
- expect(parseQueryTerms('BEFORE 1-Feb-1994'.split(' '), uidList).query).to.deep.equal([
71
- {
72
- key: 'internaldate',
73
- operator: '<',
74
- value: '1-Feb-1994'
75
- }
76
- ]);
77
- });
78
-
79
- it('should handle BODY', function() {
80
- expect(parseQueryTerms('BODY query'.split(' '), uidList).query).to.deep.equal([
81
- {
82
- key: 'body',
83
- value: 'query'
84
- }
85
- ]);
86
- });
87
-
88
- it('should handle CC', function() {
89
- expect(parseQueryTerms('CC query'.split(' '), uidList).query).to.deep.equal([
90
- {
91
- key: 'header',
92
- header: 'cc',
93
- value: 'query'
94
- }
95
- ]);
96
- });
97
-
98
- it('should handle DELETED', function() {
99
- expect(parseQueryTerms('DELETED'.split(' '), uidList).query).to.deep.equal([
100
- {
101
- key: 'flag',
102
- value: '\\Deleted',
103
- exists: true
104
- }
105
- ]);
106
- });
107
-
108
- it('should handle DRAFT', function() {
109
- expect(parseQueryTerms('DRAFT'.split(' '), uidList).query).to.deep.equal([
110
- {
111
- key: 'flag',
112
- value: '\\Draft',
113
- exists: true
114
- }
115
- ]);
116
- });
117
-
118
- it('should handle FLAGGED', function() {
119
- expect(parseQueryTerms('FLAGGED'.split(' '), uidList).query).to.deep.equal([
120
- {
121
- key: 'flag',
122
- value: '\\Flagged',
123
- exists: true
124
- }
125
- ]);
126
- });
127
-
128
- it('should handle FROM', function() {
129
- expect(parseQueryTerms('FROM query'.split(' '), uidList).query).to.deep.equal([
130
- {
131
- key: 'header',
132
- header: 'from',
133
- value: 'query'
134
- }
135
- ]);
136
- });
137
-
138
- it('should handle HEADER', function() {
139
- expect(parseQueryTerms('HEADER X-FOO query'.split(' '), uidList).query).to.deep.equal([
140
- {
141
- key: 'header',
142
- header: 'x-foo',
143
- value: 'query'
144
- }
145
- ]);
146
-
147
- expect(parseQueryTerms(['HEADER', 'X-FOO', null], uidList).query).to.deep.equal([
148
- {
149
- key: 'header',
150
- header: 'x-foo',
151
- value: ''
152
- }
153
- ]);
154
- });
155
-
156
- it('should handle KEYWORD', function() {
157
- expect(parseQueryTerms('KEYWORD $MyFlag'.split(' '), uidList).query).to.deep.equal([
158
- {
159
- key: 'flag',
160
- value: '$MyFlag',
161
- exists: true
162
- }
163
- ]);
164
- });
165
-
166
- it('should handle LARGER', function() {
167
- expect(parseQueryTerms('LARGER 123'.split(' '), uidList).query).to.deep.equal([
168
- {
169
- key: 'size',
170
- value: 123,
171
- operator: '>'
172
- }
173
- ]);
174
- });
175
-
176
- describe('MODSEQ', function() {
177
- it('should handle only required param', function() {
178
- expect(parseQueryTerms('MODSEQ 123'.split(' '), uidList).query).to.deep.equal([
179
- {
180
- key: 'modseq',
181
- value: 123
182
- }
183
- ]);
184
- });
185
-
186
- it('should handle optional params', function() {
187
- expect(parseQueryTerms('MODSEQ "/flags/\\\\draft" all 123'.split(' '), uidList).query).to.deep.equal([
188
- {
189
- key: 'modseq',
190
- value: 123
191
- }
192
- ]);
193
- });
194
- });
195
-
196
- it('should handle NEW', function() {
197
- expect(parseQueryTerms('NEW'.split(' '), uidList).query).to.deep.equal([
198
- {
199
- key: 'flag',
200
- value: '\\Recent',
201
- exists: true
202
- },
203
- {
204
- key: 'flag',
205
- value: '\\Seen',
206
- exists: false
207
- }
208
- ]);
209
- });
210
-
211
- it('should handle NOT', function() {
212
- expect(parseQueryTerms('NOT ALL'.split(' '), uidList).query).to.deep.equal([
213
- {
214
- key: 'not',
215
- value: {
216
- key: 'all',
217
- value: true
218
- }
219
- }
220
- ]);
221
-
222
- expect(parseQueryTerms('NOT NOT ALL'.split(' '), uidList).query).to.deep.equal([
223
- {
224
- key: 'not',
225
- value: {
226
- key: 'not',
227
- value: {
228
- key: 'all',
229
- value: true
230
- }
231
- }
232
- }
233
- ]);
234
- });
235
-
236
- it('should handle OLD', function() {
237
- expect(parseQueryTerms('OLD'.split(' '), uidList).query).to.deep.equal([
238
- {
239
- key: 'flag',
240
- value: '\\Recent',
241
- exists: false
242
- }
243
- ]);
244
- });
245
-
246
- it('should handle ON', function() {
247
- expect(parseQueryTerms('ON 1-Feb-1994'.split(' '), uidList).query).to.deep.equal([
248
- {
249
- key: 'internaldate',
250
- operator: '=',
251
- value: '1-Feb-1994'
252
- }
253
- ]);
254
- });
255
-
256
- it('should handle OR', function() {
257
- expect(parseQueryTerms('OR ALL NOT ALL'.split(' '), uidList).query).to.deep.equal([
258
- {
259
- key: 'or',
260
- value: [
261
- {
262
- key: 'all',
263
- value: true
264
- },
265
- {
266
- key: 'not',
267
- value: {
268
- key: 'all',
269
- value: true
270
- }
271
- }
272
- ]
273
- }
274
- ]);
275
- });
276
-
277
- it('should handle RECENT', function() {
278
- expect(parseQueryTerms('RECENT'.split(' '), uidList).query).to.deep.equal([
279
- {
280
- key: 'flag',
281
- value: '\\Recent',
282
- exists: true
283
- }
284
- ]);
285
- });
286
-
287
- it('should handle SEEN', function() {
288
- expect(parseQueryTerms('SEEN'.split(' '), uidList).query).to.deep.equal([
289
- {
290
- key: 'flag',
291
- value: '\\Seen',
292
- exists: true
293
- }
294
- ]);
295
- });
296
-
297
- it('should handle SENTBEFORE', function() {
298
- expect(parseQueryTerms('SENTBEFORE 1-Feb-1994'.split(' '), uidList).query).to.deep.equal([
299
- {
300
- key: 'date',
301
- operator: '<',
302
- value: '1-Feb-1994'
303
- }
304
- ]);
305
- });
306
-
307
- it('should handle SENTON', function() {
308
- expect(parseQueryTerms('SENTON 1-Feb-1994'.split(' '), uidList).query).to.deep.equal([
309
- {
310
- key: 'date',
311
- operator: '=',
312
- value: '1-Feb-1994'
313
- }
314
- ]);
315
- });
316
-
317
- it('should handle SENTSINCE', function() {
318
- expect(parseQueryTerms('SENTSINCE 1-Feb-1994'.split(' '), uidList).query).to.deep.equal([
319
- {
320
- key: 'date',
321
- operator: '>=',
322
- value: '1-Feb-1994'
323
- }
324
- ]);
325
- });
326
-
327
- it('should handle SINCE', function() {
328
- expect(parseQueryTerms('SINCE 1-Feb-1994'.split(' '), uidList).query).to.deep.equal([
329
- {
330
- key: 'internaldate',
331
- operator: '>=',
332
- value: '1-Feb-1994'
333
- }
334
- ]);
335
-
336
- let fn = parseQueryTerms.bind(null, 'SINCE XX-ZZZ-YYY'.split(' '), uidList);
337
- expect(fn).to.throw(Error);
338
- });
339
-
340
- it('should handle SMALLER', function() {
341
- expect(parseQueryTerms('SMALLER 123'.split(' '), uidList).query).to.deep.equal([
342
- {
343
- key: 'size',
344
- value: 123,
345
- operator: '<'
346
- }
347
- ]);
348
- });
349
-
350
- it('should handle SUBJECT', function() {
351
- expect(parseQueryTerms('SUBJECT query'.split(' '), uidList).query).to.deep.equal([
352
- {
353
- key: 'header',
354
- header: 'subject',
355
- value: 'query'
356
- }
357
- ]);
358
- });
359
-
360
- it('should handle TEXT', function() {
361
- expect(parseQueryTerms('TEXT query'.split(' '), uidList).query).to.deep.equal([
362
- {
363
- key: 'text',
364
- value: 'query'
365
- }
366
- ]);
367
- });
368
-
369
- it('should handle TO', function() {
370
- expect(parseQueryTerms('TO query'.split(' '), uidList).query).to.deep.equal([
371
- {
372
- key: 'header',
373
- header: 'to',
374
- value: 'query'
375
- }
376
- ]);
377
- });
378
-
379
- it('should handle UID', function() {
380
- expect(parseQueryTerms('UID 44,54:*'.split(' '), uidList).query).to.deep.equal([
381
- {
382
- key: 'uid',
383
- value: [44, 54, 59, 72]
384
- }
385
- ]);
386
- });
387
-
388
- it('should handle UNANSWERED', function() {
389
- expect(parseQueryTerms('UNANSWERED'.split(' '), uidList).query).to.deep.equal([
390
- {
391
- key: 'flag',
392
- value: '\\Answered',
393
- exists: false
394
- }
395
- ]);
396
- });
397
-
398
- it('should handle UNDELETED', function() {
399
- expect(parseQueryTerms('UNDELETED'.split(' '), uidList).query).to.deep.equal([
400
- {
401
- key: 'flag',
402
- value: '\\Deleted',
403
- exists: false
404
- }
405
- ]);
406
- });
407
-
408
- it('should handle UNDRAFT', function() {
409
- expect(parseQueryTerms('UNDRAFT'.split(' '), uidList).query).to.deep.equal([
410
- {
411
- key: 'flag',
412
- value: '\\Draft',
413
- exists: false
414
- }
415
- ]);
416
- });
417
-
418
- it('should handle UNFLAGGED', function() {
419
- expect(parseQueryTerms('UNFLAGGED'.split(' '), uidList).query).to.deep.equal([
420
- {
421
- key: 'flag',
422
- value: '\\Flagged',
423
- exists: false
424
- }
425
- ]);
426
- });
427
-
428
- it('should handle UNKEYWORD', function() {
429
- expect(parseQueryTerms('UNKEYWORD $MyFlag'.split(' '), uidList).query).to.deep.equal([
430
- {
431
- key: 'flag',
432
- value: '$MyFlag',
433
- exists: false
434
- }
435
- ]);
436
- });
437
-
438
- it('should handle UNSEEN', function() {
439
- expect(parseQueryTerms('UNSEEN'.split(' '), uidList).query).to.deep.equal([
440
- {
441
- key: 'flag',
442
- value: '\\Seen',
443
- exists: false
444
- }
445
- ]);
446
- });
447
-
448
- it('should handle complex query', function() {
449
- // this is a query by iOS Mail app
450
- // UID SEARCH (OR FROM "Time" (OR SUBJECT "Time" (OR TO "Time" (OR CC "Time" BODY "Time")))) NOT DELETED
451
- expect(parseQueryTerms('OR FROM Time OR SUBJECT Time OR TO Time OR CC Time BODY Time NOT DELETED'.split(' '), uidList).query).to.deep.equal([
452
- {
453
- key: 'or',
454
- value: [
455
- {
456
- key: 'header',
457
- header: 'from',
458
- value: 'Time'
459
- },
460
- {
461
- key: 'or',
462
- value: [
463
- {
464
- key: 'header',
465
- header: 'subject',
466
- value: 'Time'
467
- },
468
- {
469
- key: 'or',
470
- value: [
471
- {
472
- key: 'header',
473
- header: 'to',
474
- value: 'Time'
475
- },
476
- {
477
- key: 'or',
478
- value: [
479
- {
480
- key: 'header',
481
- header: 'cc',
482
- value: 'Time'
483
- },
484
- {
485
- key: 'body',
486
- value: 'Time'
487
- }
488
- ]
489
- }
490
- ]
491
- }
492
- ]
493
- }
494
- ]
495
- },
496
- {
497
- key: 'not',
498
- value: {
499
- key: 'flag',
500
- value: '\\Deleted',
501
- exists: true
502
- }
503
- }
504
- ]);
505
- });
506
- });
507
-
508
- describe('Search term match tests', function() {
509
- describe('AND', function() {
510
- it('should find all matches', function(done) {
511
- matchSearchQuery(
512
- {},
513
- [
514
- {
515
- key: 'all',
516
- value: true
517
- },
518
- {
519
- key: 'all',
520
- value: true
521
- },
522
- {
523
- key: 'all',
524
- value: true
525
- },
526
- {
527
- key: 'all',
528
- value: true
529
- }
530
- ],
531
- (err, match) => {
532
- expect(err).to.not.exist;
533
- expect(match).to.be.true;
534
- done();
535
- }
536
- );
537
- });
538
-
539
- it('should fail on single error', function(done) {
540
- matchSearchQuery(
541
- {},
542
- [
543
- {
544
- key: 'all',
545
- value: true
546
- },
547
- {
548
- key: 'all',
549
- value: true
550
- },
551
- {
552
- key: 'all',
553
- value: true
554
- },
555
- {
556
- key: 'flag',
557
- value: 'zzzzzzz',
558
- exists: true
559
- }
560
- ],
561
- (err, match) => {
562
- expect(err).to.not.exist;
563
- expect(match).to.be.false;
564
- done();
565
- }
566
- );
567
- });
568
- });
569
-
570
- describe('OR', function() {
571
- it('should succeed with at least one match', function(done) {
572
- matchSearchQuery(
573
- {},
574
- {
575
- key: 'or',
576
- value: [
577
- {
578
- key: 'flag',
579
- value: 'zzzzzzz',
580
- exists: true
581
- },
582
- {
583
- key: 'all',
584
- value: true
585
- },
586
- {
587
- key: 'flag',
588
- value: 'zzzzzzz',
589
- exists: true
590
- }
591
- ]
592
- },
593
- (err, match) => {
594
- expect(err).to.not.exist;
595
- expect(match).to.be.true;
596
- done();
597
- }
598
- );
599
- });
600
-
601
- it('should fail with no matches', function(done) {
602
- matchSearchQuery(
603
- {},
604
- {
605
- key: 'or',
606
- value: [
607
- {
608
- key: 'flag',
609
- value: 'zzzzzzz',
610
- exists: true
611
- },
612
- {
613
- key: 'flag',
614
- value: 'zzzzzzz',
615
- exists: true
616
- }
617
- ]
618
- },
619
- (err, match) => {
620
- expect(err).to.not.exist;
621
- expect(match).to.be.false;
622
- done();
623
- }
624
- );
625
- });
626
- });
627
-
628
- describe('NOT', function() {
629
- it('should succeed with false value', function(done) {
630
- matchSearchQuery(
631
- {},
632
- {
633
- key: 'not',
634
- value: {
635
- key: 'flag',
636
- value: 'zzzzzzz',
637
- exists: true
638
- }
639
- },
640
- (err, match) => {
641
- expect(err).to.not.exist;
642
- expect(match).to.be.true;
643
- done();
644
- }
645
- );
646
- });
647
-
648
- it('should fail with thruthy value', function(done) {
649
- matchSearchQuery(
650
- {},
651
- {
652
- key: 'not',
653
- value: {
654
- key: 'all',
655
- value: true
656
- }
657
- },
658
- (err, match) => {
659
- expect(err).to.not.exist;
660
- expect(match).to.be.false;
661
- done();
662
- }
663
- );
664
- });
665
- });
666
-
667
- describe('ALL', function() {
668
- it('should match ALL', function(done) {
669
- matchSearchQuery(
670
- {},
671
- {
672
- key: 'all',
673
- value: true
674
- },
675
- (err, match) => {
676
- expect(err).to.not.exist;
677
- expect(match).to.be.true;
678
- done();
679
- }
680
- );
681
- });
682
- });
683
-
684
- describe('FLAG', function() {
685
- it('should match existing flag', function(done) {
686
- matchSearchQuery(
687
- {
688
- flags: ['abc', 'def', 'ghi']
689
- },
690
- {
691
- key: 'flag',
692
- value: 'def',
693
- exists: true
694
- },
695
- (err, match) => {
696
- expect(err).to.not.exist;
697
- expect(match).to.be.true;
698
- done();
699
- }
700
- );
701
- });
702
-
703
- it('should match non-existing flag', function(done) {
704
- matchSearchQuery(
705
- {
706
- flags: ['abc', 'def', 'ghi']
707
- },
708
- {
709
- key: 'flag',
710
- value: 'zzzzz',
711
- exists: false
712
- },
713
- (err, match) => {
714
- expect(err).to.not.exist;
715
- expect(match).to.be.true;
716
- done();
717
- }
718
- );
719
- });
720
-
721
- it('should fail non-existing flag', function(done) {
722
- matchSearchQuery(
723
- {
724
- flags: ['abc', 'def', 'ghi']
725
- },
726
- {
727
- key: 'flag',
728
- value: 'zzzzz',
729
- exists: true
730
- },
731
- (err, match) => {
732
- expect(err).to.not.exist;
733
- expect(match).to.be.false;
734
- done();
735
- }
736
- );
737
- });
738
-
739
- it('should fail existing flag', function(done) {
740
- matchSearchQuery(
741
- {
742
- flags: ['abc', 'def', 'ghi']
743
- },
744
- {
745
- key: 'flag',
746
- value: 'abc',
747
- exists: false
748
- },
749
- (err, match) => {
750
- expect(err).to.not.exist;
751
- expect(match).to.be.false;
752
- done();
753
- }
754
- );
755
- });
756
- });
757
-
758
- describe('INTERNALDATE', function() {
759
- it('should match <', function(done) {
760
- matchSearchQuery(
761
- {
762
- idate: new Date('1999-01-01')
763
- },
764
- {
765
- key: 'internaldate',
766
- value: '2001-01-01',
767
- operator: '<'
768
- },
769
- (err, match) => {
770
- expect(err).to.not.exist;
771
- expect(match).to.be.true;
772
- done();
773
- }
774
- );
775
- });
776
-
777
- it('should not match <', function(done) {
778
- matchSearchQuery(
779
- {
780
- idate: new Date('1999-01-01')
781
- },
782
- {
783
- key: 'internaldate',
784
- value: '1998-01-01',
785
- operator: '<'
786
- },
787
- (err, match) => {
788
- expect(err).to.not.exist;
789
- expect(match).to.be.false;
790
- done();
791
- }
792
- );
793
- });
794
-
795
- it('should match =', function(done) {
796
- matchSearchQuery(
797
- {
798
- idate: new Date('1999-01-01')
799
- },
800
- {
801
- key: 'internaldate',
802
- value: '1999-01-01',
803
- operator: '='
804
- },
805
- (err, match) => {
806
- expect(err).to.not.exist;
807
- expect(match).to.be.true;
808
- done();
809
- }
810
- );
811
- });
812
-
813
- it('should not match <', function(done) {
814
- matchSearchQuery(
815
- {
816
- idate: new Date('1999-01-01')
817
- },
818
- {
819
- key: 'internaldate',
820
- value: '1999-01-02',
821
- operator: '='
822
- },
823
- (err, match) => {
824
- expect(err).to.not.exist;
825
- expect(match).to.be.false;
826
- done();
827
- }
828
- );
829
- });
830
-
831
- it('should match >=', function(done) {
832
- matchSearchQuery(
833
- {
834
- idate: new Date('1999-01-01')
835
- },
836
- {
837
- key: 'internaldate',
838
- value: '1999-01-01',
839
- operator: '>='
840
- },
841
- (err, match) => {
842
- expect(err).to.not.exist;
843
- expect(match).to.be.true;
844
-
845
- matchSearchQuery(
846
- {
847
- internaldate: new Date('1999-01-02')
848
- },
849
- {
850
- key: 'internaldate',
851
- value: '1999-01-01',
852
- operator: '>='
853
- },
854
- (err, match) => {
855
- expect(err).to.not.exist;
856
- expect(match).to.be.true;
857
- done();
858
- }
859
- );
860
- }
861
- );
862
- });
863
-
864
- it('should not match >=', function(done) {
865
- matchSearchQuery(
866
- {
867
- idate: new Date('1999-01-01')
868
- },
869
- {
870
- key: 'internaldate',
871
- value: '1999-01-02',
872
- operator: '>='
873
- },
874
- (err, match) => {
875
- expect(err).to.not.exist;
876
- expect(match).to.be.false;
877
- done();
878
- }
879
- );
880
- });
881
- });
882
-
883
- describe('DATE', function() {
884
- let raw = 'Subject: test\r\nDate: 1999-01-01\r\n\r\nHello world!';
885
-
886
- it('should match <', function(done) {
887
- matchSearchQuery(
888
- {
889
- mimeTree: indexer.parseMimeTree(raw)
890
- },
891
- {
892
- key: 'date',
893
- value: '2001-01-01',
894
- operator: '<'
895
- },
896
- (err, match) => {
897
- expect(err).to.not.exist;
898
- expect(match).to.be.true;
899
- done();
900
- }
901
- );
902
- });
903
-
904
- it('should not match <', function(done) {
905
- matchSearchQuery(
906
- {
907
- mimeTree: indexer.parseMimeTree(raw)
908
- },
909
- {
910
- key: 'date',
911
- value: '1998-01-01',
912
- operator: '<'
913
- },
914
- (err, match) => {
915
- expect(err).to.not.exist;
916
- expect(match).to.be.false;
917
- done();
918
- }
919
- );
920
- });
921
-
922
- it('should match =', function(done) {
923
- matchSearchQuery(
924
- {
925
- mimeTree: indexer.parseMimeTree(raw)
926
- },
927
- {
928
- key: 'date',
929
- value: '1999-01-01',
930
- operator: '='
931
- },
932
- (err, match) => {
933
- expect(err).to.not.exist;
934
- expect(match).to.be.true;
935
- done();
936
- }
937
- );
938
- });
939
-
940
- it('should not match <', function(done) {
941
- matchSearchQuery(
942
- {
943
- mimeTree: indexer.parseMimeTree(raw)
944
- },
945
- {
946
- key: 'date',
947
- value: '1999-01-02',
948
- operator: '='
949
- },
950
- (err, match) => {
951
- expect(err).to.not.exist;
952
- expect(match).to.be.false;
953
- done();
954
- }
955
- );
956
- });
957
-
958
- it('should match >=', function(done) {
959
- matchSearchQuery(
960
- {
961
- mimeTree: indexer.parseMimeTree(raw)
962
- },
963
- {
964
- key: 'date',
965
- value: '1999-01-01',
966
- operator: '>='
967
- },
968
- (err, match) => {
969
- expect(err).to.not.exist;
970
- expect(match).to.be.true;
971
-
972
- matchSearchQuery(
973
- {
974
- mimeTree: indexer.parseMimeTree(raw)
975
- },
976
- {
977
- key: 'date',
978
- value: '1998-01-01',
979
- operator: '>='
980
- },
981
- (err, match) => {
982
- expect(err).to.not.exist;
983
- expect(match).to.be.true;
984
- done();
985
- }
986
- );
987
- }
988
- );
989
- });
990
-
991
- it('should not match >=', function(done) {
992
- matchSearchQuery(
993
- {
994
- mimeTree: indexer.parseMimeTree(raw)
995
- },
996
- {
997
- key: 'date',
998
- value: '1999-01-02',
999
- operator: '>='
1000
- },
1001
- (err, match) => {
1002
- expect(err).to.not.exist;
1003
- expect(match).to.be.false;
1004
- done();
1005
- }
1006
- );
1007
- });
1008
- });
1009
-
1010
- describe('BODY', function() {
1011
- let raw = 'Subject: test\r\n\r\nHello world!';
1012
-
1013
- it('should match a string', function(done) {
1014
- matchSearchQuery(
1015
- {
1016
- mimeTree: indexer.parseMimeTree(raw)
1017
- },
1018
- {
1019
- key: 'body',
1020
- value: 'hello'
1021
- },
1022
- (err, match) => {
1023
- expect(err).to.not.exist;
1024
- expect(match).to.be.true;
1025
- done();
1026
- }
1027
- );
1028
- });
1029
-
1030
- it('should not match a string', function(done) {
1031
- matchSearchQuery(
1032
- {
1033
- mimeTree: indexer.parseMimeTree(raw)
1034
- },
1035
- {
1036
- key: 'body',
1037
- value: 'test'
1038
- },
1039
- (err, match) => {
1040
- expect(err).to.not.exist;
1041
- expect(match).to.be.false;
1042
- done();
1043
- }
1044
- );
1045
- });
1046
- });
1047
-
1048
- describe('TEXT', function() {
1049
- let raw = 'Subject: test\r\n\r\nHello world!';
1050
-
1051
- it('should match a string', function(done) {
1052
- matchSearchQuery(
1053
- {
1054
- mimeTree: indexer.parseMimeTree(raw)
1055
- },
1056
- {
1057
- key: 'text',
1058
- value: 'hello'
1059
- },
1060
- (err, match) => {
1061
- expect(err).to.not.exist;
1062
- expect(match).to.be.true;
1063
-
1064
- matchSearchQuery(
1065
- {
1066
- mimeTree: indexer.parseMimeTree(raw)
1067
- },
1068
- {
1069
- key: 'text',
1070
- value: 'test'
1071
- },
1072
- (err, match) => {
1073
- expect(err).to.not.exist;
1074
- expect(match).to.be.true;
1075
- done();
1076
- }
1077
- );
1078
- }
1079
- );
1080
- });
1081
-
1082
- it('should not match a string', function(done) {
1083
- matchSearchQuery(
1084
- {
1085
- mimeTree: indexer.parseMimeTree(raw)
1086
- },
1087
- {
1088
- key: 'text',
1089
- value: 'zzzzz'
1090
- },
1091
- (err, match) => {
1092
- expect(err).to.not.exist;
1093
- expect(match).to.be.false;
1094
- done();
1095
- }
1096
- );
1097
- });
1098
- });
1099
-
1100
- describe('UID', function() {
1101
- it('should match message uid', function(done) {
1102
- matchSearchQuery(
1103
- {
1104
- uid: 123
1105
- },
1106
- {
1107
- key: 'uid',
1108
- value: [11, 123, 134]
1109
- },
1110
- (err, match) => {
1111
- expect(err).to.not.exist;
1112
- expect(match).to.be.true;
1113
- done();
1114
- }
1115
- );
1116
- });
1117
-
1118
- it('should not match message uid', function(done) {
1119
- matchSearchQuery(
1120
- {
1121
- uid: 124
1122
- },
1123
- {
1124
- key: 'uid',
1125
- value: [11, 123, 134]
1126
- },
1127
- (err, match) => {
1128
- expect(err).to.not.exist;
1129
- expect(match).to.be.false;
1130
- done();
1131
- }
1132
- );
1133
- });
1134
- });
1135
-
1136
- describe('SIZE', function() {
1137
- it('should match <', function(done) {
1138
- matchSearchQuery(
1139
- {
1140
- size: 10
1141
- },
1142
- {
1143
- key: 'size',
1144
- value: 11,
1145
- operator: '<'
1146
- },
1147
- (err, match) => {
1148
- expect(err).to.not.exist;
1149
- expect(match).to.be.true;
1150
- done();
1151
- }
1152
- );
1153
- });
1154
-
1155
- it('should not match <', function(done) {
1156
- matchSearchQuery(
1157
- {
1158
- size: 10
1159
- },
1160
- {
1161
- key: 'size',
1162
- value: 9,
1163
- operator: '<'
1164
- },
1165
- (err, match) => {
1166
- expect(err).to.not.exist;
1167
- expect(match).to.be.false;
1168
- done();
1169
- }
1170
- );
1171
- });
1172
-
1173
- it('should match =', function(done) {
1174
- matchSearchQuery(
1175
- {
1176
- size: 10
1177
- },
1178
- {
1179
- key: 'size',
1180
- value: 10,
1181
- operator: '='
1182
- },
1183
- (err, match) => {
1184
- expect(err).to.not.exist;
1185
- expect(match).to.be.true;
1186
- done();
1187
- }
1188
- );
1189
- });
1190
-
1191
- it('should not match =', function(done) {
1192
- matchSearchQuery(
1193
- {
1194
- size: 10
1195
- },
1196
- {
1197
- key: 'size',
1198
- value: 11,
1199
- operator: '='
1200
- },
1201
- (err, match) => {
1202
- expect(err).to.not.exist;
1203
- expect(match).to.be.false;
1204
- done();
1205
- }
1206
- );
1207
- });
1208
-
1209
- it('should match >', function(done) {
1210
- matchSearchQuery(
1211
- {
1212
- size: 10
1213
- },
1214
- {
1215
- key: 'size',
1216
- value: 9,
1217
- operator: '>'
1218
- },
1219
- (err, match) => {
1220
- expect(err).to.not.exist;
1221
- expect(match).to.be.true;
1222
- done();
1223
- }
1224
- );
1225
- });
1226
-
1227
- it('should not match <', function(done) {
1228
- matchSearchQuery(
1229
- {
1230
- size: 10
1231
- },
1232
- {
1233
- key: 'size',
1234
- value: 11,
1235
- operator: '>'
1236
- },
1237
- (err, match) => {
1238
- expect(err).to.not.exist;
1239
- expect(match).to.be.false;
1240
- done();
1241
- }
1242
- );
1243
- });
1244
- });
1245
-
1246
- describe('header', function() {
1247
- let raw = 'Subject: test\r\n\r\nHello world!';
1248
-
1249
- it('should match header value', function(done) {
1250
- matchSearchQuery(
1251
- {
1252
- mimeTree: indexer.parseMimeTree(raw)
1253
- },
1254
- {
1255
- key: 'header',
1256
- value: 'test',
1257
- header: 'subject'
1258
- },
1259
- (err, match) => {
1260
- expect(err).to.not.exist;
1261
- expect(match).to.be.true;
1262
- done();
1263
- }
1264
- );
1265
- });
1266
-
1267
- it('should match empty header value', function(done) {
1268
- matchSearchQuery(
1269
- {
1270
- mimeTree: indexer.parseMimeTree(raw)
1271
- },
1272
- {
1273
- key: 'header',
1274
- value: '',
1275
- header: 'subject'
1276
- },
1277
- (err, match) => {
1278
- expect(err).to.not.exist;
1279
- expect(match).to.be.true;
1280
- done();
1281
- }
1282
- );
1283
- });
1284
-
1285
- it('should not match header value', function(done) {
1286
- matchSearchQuery(
1287
- {
1288
- mimeTree: indexer.parseMimeTree(raw)
1289
- },
1290
- {
1291
- key: 'header',
1292
- value: 'tests',
1293
- header: 'subject'
1294
- },
1295
- (err, match) => {
1296
- expect(err).to.not.exist;
1297
- expect(match).to.be.false;
1298
- done();
1299
- }
1300
- );
1301
- });
1302
- });
1303
-
1304
- describe('MODSEQ', function() {
1305
- it('should match equal modseq', function(done) {
1306
- matchSearchQuery(
1307
- {
1308
- modseq: 500
1309
- },
1310
- {
1311
- key: 'modseq',
1312
- value: [500]
1313
- },
1314
- (err, match) => {
1315
- expect(err).to.not.exist;
1316
- expect(match).to.be.true;
1317
- done();
1318
- }
1319
- );
1320
- });
1321
-
1322
- it('should match greater modseq', function(done) {
1323
- matchSearchQuery(
1324
- {
1325
- modseq: 1000
1326
- },
1327
- {
1328
- key: 'modseq',
1329
- value: [500]
1330
- },
1331
- (err, match) => {
1332
- expect(err).to.not.exist;
1333
- expect(match).to.be.true;
1334
- done();
1335
- }
1336
- );
1337
- });
1338
-
1339
- it('should not match lesser modseq', function(done) {
1340
- matchSearchQuery(
1341
- {
1342
- modseq: 500
1343
- },
1344
- {
1345
- key: 'modseq',
1346
- value: [100]
1347
- },
1348
- (err, match) => {
1349
- expect(err).to.not.exist;
1350
- expect(match).to.be.true;
1351
- done();
1352
- }
1353
- );
1354
- });
1355
- });
1356
- });