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>
4 use PublicInbox::MID qw(mid_escape mids references);
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)');
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');
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');
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');
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)]);