]> Sergey Matveev's repositories - public-inbox.git/blob - t/mid.t
t/httpd-unix.t: avoid race in between bind() and listen()
[public-inbox.git] / t / mid.t
1 # Copyright (C) 2016-2018 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);
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('Message-Id', '<mid-1@a>');
14         is_deeply(['mid-1@a'], mids($mime->header_obj), 'mids in common case');
15         $mime->header_set('Message-Id', '<mid-1@a>', '<mid-2@b>');
16         is_deeply(['mid-1@a', 'mid-2@b'], mids($mime->header_obj), '2 mids');
17         $mime->header_set('Message-Id', '<mid-1@a>', '<mid-1@a>');
18         is_deeply(['mid-1@a'], mids($mime->header_obj), 'dup mids');
19         $mime->header_set('Message-Id', '<mid-1@a> comment');
20         is_deeply(['mid-1@a'], mids($mime->header_obj), 'comment ignored');
21         $mime->header_set('Message-Id', 'bare-mid');
22         is_deeply(['bare-mid'], mids($mime->header_obj), 'bare mid OK');
23
24         $mime->header_set('References', '<hello> <world>');
25         $mime->header_set('In-Reply-To', '<weld>');
26         is_deeply(['hello', 'world', 'weld'], references($mime->header_obj),
27                 'references combines with In-Reply-To');
28
29         $mime->header_set('References', "<hello>\n\t<world>");
30         $mime->header_set('In-Reply-To');
31         is_deeply(references($mime->header_obj), ['hello', 'world'],
32                 'multiline References OK');
33         $mime->header_set('References', "<hello\tworld>");
34         is_deeply(references($mime->header_obj), ['helloworld'],
35                 'drop \t in References <656C30A1EFC89F6B2082D9B6@localhost>');
36         $mime->header_set('Message-ID', "<hello\tworld>");
37         is_deeply(mids($mime->header_obj), ['helloworld'],
38                 'drop \t in Message-ID');
39
40         $mime->header_set('To', 'u@example.com');
41         $mime->header_set('References', '<hello> <world> <n> <u@example.com>');
42         is_deeply(references($mime->header_obj), [qw(hello world)]);
43 }
44
45 done_testing();
46 1;