]> Sergey Matveev's repositories - public-inbox.git/blob - t/mid.t
t/httpd: use run_script for -init
[public-inbox.git] / t / mid.t
1 # Copyright (C) 2016-2019 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3 use Test::More;
4 use PublicInbox::MID qw(mid_escape mids references mids_for_index);
5
6 is(mid_escape('foo!@(bar)'), 'foo!@(bar)');
7 is(mid_escape('foo%!@(bar)'), 'foo%25!@(bar)');
8 is(mid_escape('foo%!@(bar)'), 'foo%25!@(bar)');
9
10 {
11         use Email::MIME;
12         my $mime = Email::MIME->create;
13         $mime->header_set('X-Alt-Message-ID', '<alt-id-for-nntp>');
14         $mime->header_set('Message-Id', '<mid-1@a>');
15         is_deeply(['mid-1@a'], mids($mime->header_obj), 'mids in common case');
16         $mime->header_set('Message-Id', '<mid-1@a>', '<mid-2@b>');
17         is_deeply(['mid-1@a', 'mid-2@b'], mids($mime->header_obj), '2 mids');
18         $mime->header_set('Message-Id', '<mid-1@a>', '<mid-1@a>');
19         is_deeply(['mid-1@a'], mids($mime->header_obj), 'dup mids');
20         $mime->header_set('Message-Id', '<mid-1@a> comment');
21         is_deeply(['mid-1@a'], mids($mime->header_obj), 'comment ignored');
22         $mime->header_set('Message-Id', 'bare-mid');
23         is_deeply(['bare-mid'], mids($mime->header_obj), 'bare mid OK');
24
25         $mime->header_set('References', '<hello> <world>');
26         $mime->header_set('In-Reply-To', '<weld>');
27         is_deeply(['hello', 'world', 'weld'], references($mime->header_obj),
28                 'references combines with In-Reply-To');
29
30         $mime->header_set('References', "<hello>\n\t<world>");
31         $mime->header_set('In-Reply-To');
32         is_deeply(references($mime->header_obj), ['hello', 'world'],
33                 'multiline References OK');
34         $mime->header_set('References', "<hello\tworld>");
35         is_deeply(references($mime->header_obj), ['helloworld'],
36                 'drop \t in References <656C30A1EFC89F6B2082D9B6@localhost>');
37         $mime->header_set('Message-ID', "<hello\tworld>");
38         is_deeply(mids($mime->header_obj), ['helloworld'],
39                 'drop \t in Message-ID');
40
41         $mime->header_set('To', 'u@example.com');
42         $mime->header_set('References', '<hello> <world> <n> <u@example.com>');
43         is_deeply(references($mime->header_obj), [qw(hello world)]);
44
45         is_deeply([qw(helloworld alt-id-for-nntp)],
46                 mids_for_index($mime->header_obj),
47                 'X-Alt-Message-ID can be indexed');
48 }
49
50 done_testing();
51 1;