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>
5 use PublicInbox::MID qw(mid_escape mids references mids_for_index);
7 is(mid_escape('foo!@(bar)'), 'foo!@(bar)');
8 is(mid_escape('foo%!@(bar)'), 'foo%25!@(bar)');
9 is(mid_escape('foo%!@(bar)'), 'foo%25!@(bar)');
13 my $mime = Email::MIME->create;
14 $mime->header_set('X-Alt-Message-ID', '<alt-id-for-nntp>');
15 $mime->header_set('Message-Id', '<mid-1@a>');
16 is_deeply(['mid-1@a'], mids($mime->header_obj), 'mids in common case');
17 $mime->header_set('Message-Id', '<mid-1@a>', '<mid-2@b>');
18 is_deeply(['mid-1@a', 'mid-2@b'], mids($mime->header_obj), '2 mids');
19 $mime->header_set('Message-Id', '<mid-1@a>', '<mid-1@a>');
20 is_deeply(['mid-1@a'], mids($mime->header_obj), 'dup mids');
21 $mime->header_set('Message-Id', '<mid-1@a> comment');
22 is_deeply(['mid-1@a'], mids($mime->header_obj), 'comment ignored');
23 $mime->header_set('Message-Id', 'bare-mid');
24 is_deeply(['bare-mid'], mids($mime->header_obj), 'bare mid OK');
26 $mime->header_set('References', '<hello> <world>');
27 $mime->header_set('In-Reply-To', '<weld>');
28 is_deeply(['hello', 'world', 'weld'], references($mime->header_obj),
29 'references combines with In-Reply-To');
31 $mime->header_set('References', "<hello>\n\t<world>");
32 $mime->header_set('In-Reply-To');
33 is_deeply(references($mime->header_obj), ['hello', 'world'],
34 'multiline References OK');
35 $mime->header_set('References', "<hello\tworld>");
36 is_deeply(references($mime->header_obj), ['helloworld'],
37 'drop \t in References <656C30A1EFC89F6B2082D9B6@localhost>');
38 $mime->header_set('Message-ID', "<hello\tworld>");
39 is_deeply(mids($mime->header_obj), ['helloworld'],
40 'drop \t in Message-ID');
42 $mime->header_set('To', 'u@example.com');
43 $mime->header_set('References', '<hello> <world> <n> <u@example.com>');
44 is_deeply(references($mime->header_obj), [qw(hello world)]);
46 is_deeply([qw(helloworld alt-id-for-nntp)],
47 mids_for_index($mime->header_obj),
48 'X-Alt-Message-ID can be indexed');