]> Sergey Matveev's repositories - public-inbox.git/blob - t/imap.t
c435d365543c66a49c224469f8c74c70f110aab3
[public-inbox.git] / t / imap.t
1 #!perl -w
2 # Copyright (C) 2020 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 use strict;
5 use Test::More;
6 use PublicInbox::IMAP;
7 {
8         my $partial_prepare = \&PublicInbox::IMAP::partial_prepare;
9         my $x = {};
10         my $r = $partial_prepare->($x, [], my $p = 'BODY.PEEK[9]');
11         ok($r, $p);
12         $r = $partial_prepare->($x, [], $p = 'BODY.PEEK[9]<5>');
13         ok($r, $p);
14         $r = $partial_prepare->($x, [], $p = 'BODY.PEEK[9]<5.1>');
15         ok($r, $p);
16         $r = $partial_prepare->($x, [], $p = 'BODY[1.1]');
17         ok($r, $p);
18         $r = $partial_prepare->($x, [], $p = 'BODY[HEADER.FIELDS (DATE FROM)]');
19         ok($r, $p);
20         $r = $partial_prepare->($x, [], $p = 'BODY[HEADER.FIELDS.NOT (TO)]');
21         ok($r, $p);
22         $r = $partial_prepare->($x, [], $p = 'BODY[HEDDER.FIELDS.NOT (TO)]');
23         ok(!$r, "rejected misspelling $p");
24         $r = $partial_prepare->($x, [], $p = 'BODY[1.1.HEADER.FIELDS (TO)]');
25         ok($r, $p);
26         my $partial_body = \&PublicInbox::IMAP::partial_body;
27         my $partial_hdr_get = \&PublicInbox::IMAP::partial_hdr_get;
28         my $partial_hdr_not = \&PublicInbox::IMAP::partial_hdr_not;
29         is_deeply($x, {
30                 'BODY.PEEK[9]' => [ $partial_body, 9, undef, undef, undef ],
31                 'BODY.PEEK[9]<5>' => [ $partial_body, 9, undef, 5, undef ],
32                 'BODY.PEEK[9]<5.1>' => [ $partial_body, 9, undef, 5, 1 ],
33                 'BODY[1.1]' => [ $partial_body, '1.1', undef, undef, undef ],
34                 'BODY[HEADER.FIELDS (DATE FROM)]' => [ $partial_hdr_get,
35                                         undef, 'DATE FROM', undef, undef ],
36                 'BODY[HEADER.FIELDS.NOT (TO)]' => [ $partial_hdr_not,
37                                                 undef, 'TO', undef, undef ],
38                 'BODY[1.1.HEADER.FIELDS (TO)]' => [ $partial_hdr_get,
39                                                 '1.1', 'TO', undef, undef ],
40         }, 'structure matches expected');
41 }
42
43 done_testing;