forked from postalsys/imapflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimap-parser-test.js
877 lines (815 loc) · 28.5 KB
/
imap-parser-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
/*eslint no-unused-expressions: 0, prefer-arrow-callback: 0 */
'use strict';
const { parser } = require('../lib/handler/imap-handler');
const mimetorture = require('./fixtures/serialized-mimetorture');
let asyncWrapper = (test, handler) => {
handler(test)
.then(() => test.done())
.catch(err => {
test.ifError(err);
test.done();
});
};
let asyncWrapperFail = (test, handler) => {
handler(test)
.then(() => {
test.ok(false);
test.done();
})
.catch(err => {
test.ok(err);
test.done();
});
};
module.exports['IMAP Parser: Tags: get TAG'] = test => asyncWrapper(test, async test => test.equal((await parser('TAG1 CMD')).tag, 'TAG1'));
module.exports['IMAP Parser: Tags: space before TAG'] = test => asyncWrapperFail(test, async test => test.ok(await parser(' TAG CMD')));
module.exports['IMAP Parser: Tags: fail empty TAG'] = test => asyncWrapperFail(test, async test => test.ok(await parser('')));
module.exports['IMAP Parser: Tags: * TAG'] = test => asyncWrapper(test, async test => test.equal((await parser('* CMD')).tag, '*'));
module.exports['IMAP Parser: Tags: + TAG'] = test => asyncWrapper(test, async test => test.equal((await parser('+ CMD')).tag, '+'));
module.exports['IMAP Parser: Tags: fail TAG only'] = test => asyncWrapperFail(test, async test => test.ok(await parser('TAG1')));
module.exports['IMAP Parser: Tags: fail invalid char in TAG'] = test => asyncWrapperFail(test, async test => test.ok(await parser('TAG"1 CMD')));
module.exports['IMAP Parser: Command: single'] = test => asyncWrapper(test, async test => test.equal((await parser('TAG1 CMD')).command, 'CMD'));
module.exports['IMAP Parser: Command: multi word'] = test =>
asyncWrapper(test, async test => test.equal((await parser('TAG1 UID FETCH')).command, 'UID FETCH'));
module.exports['IMAP Parser: Command: fail extra ws'] = test => asyncWrapperFail(test, async test => test.ok(await parser('TAG1 CMD')));
module.exports['IMAP Parser: Command: fail empty command'] = test => asyncWrapperFail(test, async test => test.ok(await parser('TAG1 ')));
module.exports['IMAP Parser: Command: fail invalid char in command'] = test => asyncWrapperFail(test, async test => test.ok(await parser('TAG1 CM=D')));
module.exports['IMAP Parser: Args: allow trailing whitespace and empty arguments'] = test =>
asyncWrapper(test, async test => test.deepEqual(await parser('* SEARCH '), { tag: '*', command: 'SEARCH' }));
module.exports['IMAP Parser: Attributes: single atom'] = test =>
asyncWrapper(test, async test =>
test.deepEqual((await parser('TAG1 CMD FED')).attributes, [
{
type: 'ATOM',
value: 'FED'
}
])
);
module.exports['IMAP Parser: Attributes: multiple atoms'] = test =>
asyncWrapper(test, async test =>
test.deepEqual((await parser('TAG1 CMD FED TED')).attributes, [
{
type: 'ATOM',
value: 'FED'
},
{
type: 'ATOM',
value: 'TED'
}
])
);
module.exports['IMAP Parser: Attributes: special char in atom'] = test =>
asyncWrapper(test, async test =>
test.deepEqual((await parser('TAG1 CMD %')).attributes, [
{
type: 'ATOM',
value: '%'
}
])
);
module.exports['IMAP Parser: Attributes: escaped char in atom'] = test =>
asyncWrapper(test, async test =>
test.deepEqual((await parser('TAG1 CMD \\*')).attributes, [
{
type: 'ATOM',
value: '\\*'
}
])
);
module.exports['IMAP Parser: Attributes: sub list'] = test =>
asyncWrapper(test, async test =>
test.deepEqual((await parser('12.82 STATUS [Gmail].Trash (UIDNEXT UNSEEN HIGHESTMODSEQ)')).attributes, [
{
type: 'ATOM',
value: '[Gmail].Trash'
},
[
{
type: 'ATOM',
value: 'UIDNEXT'
},
{
type: 'ATOM',
value: 'UNSEEN'
},
{
type: 'ATOM',
value: 'HIGHESTMODSEQ'
}
]
])
);
module.exports['IMAP Parser: Attributes: single string'] = test =>
asyncWrapper(test, async test =>
test.deepEqual((await parser('TAG1 CMD "ABCDE"')).attributes, [
{
type: 'STRING',
value: 'ABCDE'
}
])
);
module.exports['IMAP Parser: Attributes: multiple strings'] = test =>
asyncWrapper(test, async test =>
test.deepEqual((await parser('TAG1 CMD "ABCDE" "DEFGH"')).attributes, [
{
type: 'STRING',
value: 'ABCDE'
},
{
type: 'STRING',
value: 'DEFGH'
}
])
);
module.exports['IMAP Parser: Attributes: invalid char in string'] = test =>
asyncWrapper(test, async test =>
test.deepEqual((await parser('* 1 FETCH (BODY[] "\xc2")')).attributes, [
{
type: 'ATOM',
value: 'FETCH'
},
[
{
type: 'ATOM',
value: 'BODY',
section: []
},
{
type: 'STRING',
value: '\xc2'
}
]
])
);
module.exports['IMAP Parser: Lists: single atom'] = test =>
asyncWrapper(test, async test =>
test.deepEqual((await parser('TAG1 CMD (1234)')).attributes, [
[
{
type: 'ATOM',
value: '1234'
}
]
])
);
module.exports['IMAP Parser: Lists: multiple atoms'] = test =>
asyncWrapper(test, async test =>
test.deepEqual((await parser('TAG1 CMD (1234 TERE)')).attributes, [
[
{
type: 'ATOM',
value: '1234'
},
{
type: 'ATOM',
value: 'TERE'
}
]
])
);
module.exports['IMAP Parser: Lists: multiple lists'] = test =>
asyncWrapper(test, async test =>
test.deepEqual((await parser('TAG1 CMD (1234)(TERE)')).attributes, [
[
{
type: 'ATOM',
value: '1234'
}
],
[
{
type: 'ATOM',
value: 'TERE'
}
]
])
);
module.exports['IMAP Parser: Lists: extra whitespace in start of list'] = test =>
asyncWrapper(test, async test =>
test.deepEqual((await parser('TAG1 CMD ( 1234)')).attributes, [
[
{
type: 'ATOM',
value: '1234'
}
]
])
);
module.exports['IMAP Parser: Lists: extra whitespace in end of list'] = test =>
asyncWrapper(test, async test =>
test.deepEqual((await parser('TAG1 CMD (1234 )')).attributes, [
[
{
type: 'ATOM',
value: '1234'
}
]
])
);
module.exports['IMAP Parser: Lists: extra whitespace after list'] = test =>
asyncWrapper(test, async test =>
test.deepEqual((await parser('TAG1 CMD (1234) ')).attributes, [
[
{
type: 'ATOM',
value: '1234'
}
]
])
);
module.exports['IMAP Parser: Lists: nested list 1'] = test =>
asyncWrapper(test, async test =>
test.deepEqual((await parser('TAG1 CMD (((TERE)) VANA)')).attributes, [
[
[
[
{
type: 'ATOM',
value: 'TERE'
}
]
],
{
type: 'ATOM',
value: 'VANA'
}
]
])
);
module.exports['IMAP Parser: Lists: nested list 2'] = test =>
asyncWrapper(test, async test =>
test.deepEqual((await parser('TAG1 CMD (( (TERE)) VANA)')).attributes, [
[
[
[
{
type: 'ATOM',
value: 'TERE'
}
]
],
{
type: 'ATOM',
value: 'VANA'
}
]
])
);
module.exports['IMAP Parser: Lists: nested list 3'] = test =>
asyncWrapper(test, async test =>
test.deepEqual((await parser('TAG1 CMD (((TERE) ) VANA)')).attributes, [
[
[
[
{
type: 'ATOM',
value: 'TERE'
}
]
],
{
type: 'ATOM',
value: 'VANA'
}
]
])
);
module.exports['IMAP Parser: Literals: single literal'] = test =>
asyncWrapper(test, async test =>
test.deepEqual((await parser('TAG1 CMD {4}\r\n', { literals: [Buffer.from('abcd')] })).attributes, [
{
type: 'LITERAL',
value: Buffer.from('abcd')
}
])
);
module.exports['IMAP Parser: Literals: multiple literals'] = test =>
asyncWrapper(test, async test =>
test.deepEqual((await parser('TAG1 CMD {4}\r\n {4}\r\n', { literals: [Buffer.from('abcd'), Buffer.from('kere')] })).attributes, [
{
type: 'LITERAL',
value: Buffer.from('abcd')
},
{
type: 'LITERAL',
value: Buffer.from('kere')
}
])
);
module.exports['IMAP Parser: Literals: list'] = test =>
asyncWrapper(test, async test =>
test.deepEqual((await parser('TAG1 CMD ({4}\r\n {4}\r\n)', { literals: [Buffer.from('abcd'), Buffer.from('kere')] })).attributes, [
[
{
type: 'LITERAL',
value: Buffer.from('abcd')
},
{
type: 'LITERAL',
value: Buffer.from('kere')
}
]
])
);
module.exports['IMAP Parser: Tags: fail extra ws after literal'] = test =>
asyncWrapperFail(test, async test => test.ok(await parser('TAG1 CMD {4}\r\n{4} \r\n', { literals: [Buffer.from('abcd'), Buffer.from('kere')] })));
module.exports['IMAP Parser: Literals: allow zero length literal in the end of a list'] = test =>
asyncWrapper(test, async test =>
test.deepEqual((await parser('TAG1 CMD ({0}\r\n)')).attributes, [
[
{
type: 'LITERAL',
value: Buffer.from('')
}
]
])
);
module.exports['IMAP Parser: Section: empty'] = test =>
asyncWrapper(test, async test =>
test.deepEqual((await parser('TAG1 CMD BODY[]')).attributes, [
{
type: 'ATOM',
value: 'BODY',
section: []
}
])
);
module.exports['IMAP Parser: Section: list'] = test =>
asyncWrapper(test, async test =>
test.deepEqual((await parser('TAG1 CMD BODY[(KERE)]')).attributes, [
{
type: 'ATOM',
value: 'BODY',
section: [
[
{
type: 'ATOM',
value: 'KERE'
}
]
]
}
])
);
module.exports['IMAP Parser: Section: allow trailing ws'] = test =>
asyncWrapper(test, async test =>
test.deepEqual((await parser('TAG1 CMD BODY[HEADER.FIELDS (Subject From) ]')).attributes, [
{
type: 'ATOM',
value: 'BODY',
section: [
{
type: 'ATOM',
value: 'HEADER.FIELDS'
},
[
{
type: 'ATOM',
value: 'Subject'
},
{
type: 'ATOM',
value: 'From'
}
]
]
}
])
);
module.exports['IMAP Parser: Tags: fail unknown section'] = test => asyncWrapperFail(test, async test => test.ok(await parser('TAG1 CMD KODY[]')));
module.exports['IMAP Parser: Readable: simple'] = test =>
asyncWrapper(test, async test =>
test.deepEqual(await parser('* OK Hello world!'), {
command: 'OK',
tag: '*',
attributes: [
{
type: 'TEXT',
value: 'Hello world!'
}
]
})
);
module.exports['IMAP Parser: Readable: section'] = test =>
asyncWrapper(test, async test =>
test.deepEqual(await parser('* OK [CAPABILITY IDLE] Hello world!'), {
command: 'OK',
tag: '*',
attributes: [
{
section: [
{
type: 'ATOM',
value: 'CAPABILITY'
},
{
type: 'ATOM',
value: 'IDLE'
}
],
type: 'ATOM',
value: ''
},
{
type: 'TEXT',
value: 'Hello world!'
}
]
})
);
// USEATTR is from RFC6154; we are testing that just an ATOM
// on its own will parse successfully here. (All of the
// RFC5530 codes are also single atoms.)
module.exports['IMAP Parser: Section: USEATTR'] = test =>
asyncWrapper(test, async test =>
test.deepEqual(await parser('TAG1 OK [USEATTR] \\All not supported'), {
tag: 'TAG1',
command: 'OK',
attributes: [
{
type: 'ATOM',
value: '',
section: [
{
type: 'ATOM',
value: 'USEATTR'
}
]
},
{
type: 'TEXT',
value: '\\All not supported'
}
]
})
);
// RFC5267 defines the NOUPDATE error. Including for quote /
// string coverage.
module.exports['IMAP Parser: Section: NOUPDATE'] = test =>
asyncWrapper(test, async test =>
test.deepEqual(await parser('* NO [NOUPDATE "B02"] Too many contexts'), {
tag: '*',
command: 'NO',
attributes: [
{
type: 'ATOM',
value: '',
section: [
{
type: 'ATOM',
value: 'NOUPDATE'
},
{
type: 'STRING',
value: 'B02'
}
]
},
{
type: 'TEXT',
value: 'Too many contexts'
}
]
})
);
// RFC5464 defines the METADATA response code; adding this to
// ensure the transition for when '2199' hits ']' is handled
// safely.
module.exports['IMAP Parser: Section: METADATA'] = test =>
asyncWrapper(test, async test =>
test.deepEqual(await parser('TAG1 OK [METADATA LONGENTRIES 2199] GETMETADATA complete'), {
tag: 'TAG1',
command: 'OK',
attributes: [
{
type: 'ATOM',
value: '',
section: [
{
type: 'ATOM',
value: 'METADATA'
},
{
type: 'ATOM',
value: 'LONGENTRIES'
},
{
type: 'ATOM',
value: '2199'
}
]
},
{
type: 'TEXT',
value: 'GETMETADATA complete'
}
]
})
);
// RFC4467 defines URLMECH. Included because of the example
// third atom involves base64-encoding which is somewhat unusual
module.exports['IMAP Parser: Section: URLMECH'] = test =>
asyncWrapper(test, async test =>
test.deepEqual(await parser('TAG1 OK [URLMECH INTERNAL XSAMPLE=P34OKhO7VEkCbsiYY8rGEg==] done'), {
tag: 'TAG1',
command: 'OK',
attributes: [
{
type: 'ATOM',
value: '',
section: [
{
type: 'ATOM',
value: 'URLMECH'
},
{
type: 'ATOM',
value: 'INTERNAL'
},
{
type: 'ATOM',
value: 'XSAMPLE=P34OKhO7VEkCbsiYY8rGEg=='
}
]
},
{
type: 'TEXT',
value: 'done'
}
]
})
);
// RFC2221 defines REFERRAL where the argument is an imapurl
// (defined by RFC2192 which is obsoleted by RFC5092) which
// is significantly more complicated than the rest of the IMAP
// grammar and which was based on the RFC2060 grammar where
// resp_text_code included:
// atom [SPACE 1*<any TEXT_CHAR except ']'>]
// So this is just a test case of our explicit special-casing
// of REFERRAL.
module.exports['IMAP Parser: Section: REFERRAL'] = test =>
asyncWrapper(test, async test =>
test.deepEqual(await parser('TAG1 NO [REFERRAL IMAP://user;AUTH=*@SERVER2/] Remote Server'), {
tag: 'TAG1',
command: 'NO',
attributes: [
{
type: 'ATOM',
value: '',
section: [
{
type: 'ATOM',
value: 'REFERRAL'
},
{
type: 'ATOM',
value: 'IMAP://user;AUTH=*@SERVER2/'
}
]
},
{
type: 'TEXT',
value: 'Remote Server'
}
]
})
);
// PERMANENTFLAGS is from RFC3501. Its syntax is also very
// similar to BADCHARSET, except BADCHARSET has astrings
// inside the list.
module.exports['IMAP Parser: Section: PERMANENTFLAGS'] = test =>
asyncWrapper(test, async test =>
test.deepEqual(await parser('* OK [PERMANENTFLAGS (de:hacking $label kt-evalution [css3-page] \\*)] Flags permitted.'), {
tag: '*',
command: 'OK',
attributes: [
{
type: 'ATOM',
value: '',
section: [
{
type: 'ATOM',
value: 'PERMANENTFLAGS'
},
[
{
type: 'ATOM',
value: 'de:hacking'
},
{
type: 'ATOM',
value: '$label'
},
{
type: 'ATOM',
value: 'kt-evalution'
},
{
type: 'ATOM',
value: '[css3-page]'
},
{
type: 'ATOM',
value: '\\*'
}
]
]
},
{
type: 'TEXT',
value: 'Flags permitted.'
}
]
})
);
// COPYUID is from RFC4315 and included the previously failing
// parsing situation of a sequence terminated by ']' rather than
// whitespace.
module.exports['IMAP Parser: Section: COPYUID'] = test =>
asyncWrapper(test, async test =>
test.deepEqual(await parser('TAG1 OK [COPYUID 4 1417051618:1417051620 1421730687:1421730689] COPY completed'), {
tag: 'TAG1',
command: 'OK',
attributes: [
{
type: 'ATOM',
value: '',
section: [
{
type: 'ATOM',
value: 'COPYUID'
},
{
type: 'ATOM',
value: '4'
},
{
type: 'SEQUENCE',
value: '1417051618:1417051620'
},
{
type: 'SEQUENCE',
value: '1421730687:1421730689'
}
]
},
{
type: 'TEXT',
value: 'COPY completed'
}
]
})
);
// MODIFIED is from RFC4551 and is basically the same situation
// as the COPYUID case, but in this case our example sequences
// have commas in them. (Note that if there was no comma, the
// '7,9' payload would end up an ATOM.)
module.exports['IMAP Parser: Section: MODIFIED'] = test =>
asyncWrapper(test, async test =>
test.deepEqual(await parser('TAG1 OK [MODIFIED 7,9] Conditional STORE failed'), {
tag: 'TAG1',
command: 'OK',
attributes: [
{
type: 'ATOM',
value: '',
section: [
{
type: 'ATOM',
value: 'MODIFIED'
},
{
type: 'SEQUENCE',
value: '7,9'
}
]
},
{
type: 'TEXT',
value: 'Conditional STORE failed'
}
]
})
);
module.exports['IMAP Parser: Partial: Start'] = test =>
asyncWrapper(test, async test =>
test.deepEqual((await parser('TAG1 CMD BODY[]<0>')).attributes, [
{
type: 'ATOM',
value: 'BODY',
section: [],
partial: [0]
}
])
);
module.exports['IMAP Parser: Partial: Start.End'] = test =>
asyncWrapper(test, async test =>
test.deepEqual((await parser('TAG1 CMD BODY[]<12.45>')).attributes, [
{
type: 'ATOM',
value: 'BODY',
section: [],
partial: [12, 45]
}
])
);
module.exports['IMAP Parser: Partial: Section'] = test =>
asyncWrapper(test, async test =>
test.deepEqual((await parser('TAG1 CMD BODY[HEADER.FIELDS (Subject From)]<12.45>')).attributes, [
{
type: 'ATOM',
value: 'BODY',
section: [
// keep indentation
{
type: 'ATOM',
value: 'HEADER.FIELDS'
},
[
{
type: 'ATOM',
value: 'Subject'
},
{
type: 'ATOM',
value: 'From'
}
]
],
partial: [12, 45]
}
])
);
module.exports['IMAP Parser: Partial: fail unknown section'] = test => asyncWrapperFail(test, async test => test.ok(await parser('TAG1 CMD KODY<0.123>')));
module.exports['IMAP Parser: Partial: fail zero prefix for start'] = test => asyncWrapperFail(test, async test => test.ok(await parser('TAG1 CMD BODY[]<01>')));
module.exports['IMAP Parser: Partial: fail zero prefix for end'] = test => asyncWrapperFail(test, async test => test.ok(await parser('TAG1 CMD BODY[]<0.01>')));
module.exports['IMAP Parser: Partial: fail extra separator'] = test => asyncWrapperFail(test, async test => test.ok(await parser('TAG1 CMD BODY[]<0.1.>')));
module.exports['IMAP Parser: Sequence: mixed'] = test =>
asyncWrapper(test, async test =>
test.deepEqual((await parser('TAG1 CMD *:4,5:7 TEST')).attributes, [
{
type: 'SEQUENCE',
value: '*:4,5:7'
},
{
type: 'ATOM',
value: 'TEST'
}
])
);
module.exports['IMAP Parser: Sequence: range'] = test =>
asyncWrapper(test, async test =>
test.deepEqual((await parser('TAG1 CMD 1:* TEST')).attributes, [
{
type: 'SEQUENCE',
value: '1:*'
},
{
type: 'ATOM',
value: 'TEST'
}
])
);
module.exports['IMAP Parser: Sequence: limited range'] = test =>
asyncWrapper(test, async test =>
test.deepEqual((await parser('TAG1 CMD *:4 TEST')).attributes, [
{
type: 'SEQUENCE',
value: '*:4'
},
{
type: 'ATOM',
value: 'TEST'
}
])
);
module.exports['IMAP Parser: Sequence: fail partial range'] = test => asyncWrapperFail(test, async test => test.ok(await parser('TAG1 CMD *:4,5:')));
module.exports['IMAP Parser: Sequence: fail invalid chars'] = test => asyncWrapperFail(test, async test => test.ok(await parser('TAG1 CMD *:4,5:TEST TEST')));
module.exports['IMAP Parser: Sequence: fail partial range w/ args'] = test =>
asyncWrapperFail(test, async test => test.ok(await parser('TAG1 CMD *:4,5: TEST')));
module.exports['IMAP Parser: Sequence: fail missing colon'] = test => asyncWrapperFail(test, async test => test.ok(await parser('TAG1 CMD *4,5 TEST')));
module.exports['IMAP Parser: Sequence: fail non-range wildchar 1'] = test => asyncWrapperFail(test, async test => test.ok(await parser('TAG1 CMD *,5 TEST')));
module.exports['IMAP Parser: Sequence: fail non-range wildchar 2'] = test => asyncWrapperFail(test, async test => test.ok(await parser('TAG1 CMD 5,* TEST')));
module.exports['IMAP Parser: Sequence: failextra comma'] = test => asyncWrapperFail(test, async test => test.ok(await parser('TAG1 CMD 5, TEST')));
module.exports['IMAP Parser: escaped quotes'] = test =>
asyncWrapper(test, async test =>
test.deepEqual((await parser('* 331 FETCH (ENVELOPE ("=?ISO-8859-1?Q?\\"G=FCnter__Hammerl\\"?="))')).attributes, [
{
type: 'ATOM',
value: 'FETCH'
},
[
{
type: 'ATOM',
value: 'ENVELOPE'
},
[
{
type: 'STRING',
value: '=?ISO-8859-1?Q?"G=FCnter__Hammerl"?='
}
]
]
])
);
module.exports['IMAP Parser: mimetorture'] = test => asyncWrapper(test, async test => test.deepEqual(await parser(mimetorture.input), mimetorture.output));