]> Sergey Matveev's repositories - public-inbox.git/blob - t/mid.t
doc: txt2pre: auto-linkify manpage references
[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 strict;
4 use Test::More;
5 use PublicInbox::MID qw(mid_escape mids references mids_for_index id_compress);
6
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)');
10
11 # n.b: this is probably invalid since we dropped CGI for PSGI:
12 like(id_compress('foo%bar@wtf'), qr/\A[a-f0-9]{40}\z/,
13         "percent always converted to sha1 to workaround buggy httpds");
14
15 is(id_compress('foobar-wtf'), 'foobar-wtf', 'regular ID not compressed');
16
17 {
18         use Email::MIME;
19         my $mime = Email::MIME->create;
20         $mime->header_set('X-Alt-Message-ID', '<alt-id-for-nntp>');
21         $mime->header_set('Message-Id', '<mid-1@a>');
22         is_deeply(['mid-1@a'], mids($mime->header_obj), 'mids in common case');
23         $mime->header_set('Message-Id', '<mid-1@a>', '<mid-2@b>');
24         is_deeply(['mid-1@a', 'mid-2@b'], mids($mime->header_obj), '2 mids');
25         $mime->header_set('Message-Id', '<mid-1@a>', '<mid-1@a>');
26         is_deeply(['mid-1@a'], mids($mime->header_obj), 'dup mids');
27         $mime->header_set('Message-Id', '<mid-1@a> comment');
28         is_deeply(['mid-1@a'], mids($mime->header_obj), 'comment ignored');
29         $mime->header_set('Message-Id', 'bare-mid');
30         is_deeply(['bare-mid'], mids($mime->header_obj), 'bare mid OK');
31
32         $mime->header_set('References', '<hello> <world>');
33         $mime->header_set('In-Reply-To', '<weld>');
34         is_deeply(['hello', 'world', 'weld'], references($mime->header_obj),
35                 'references combines with In-Reply-To');
36
37         $mime->header_set('References', "<hello>\n\t<world>");
38         $mime->header_set('In-Reply-To');
39         is_deeply(references($mime->header_obj), ['hello', 'world'],
40                 'multiline References OK');
41         $mime->header_set('References', "<hello\tworld>");
42         is_deeply(references($mime->header_obj), ['helloworld'],
43                 'drop \t in References <656C30A1EFC89F6B2082D9B6@localhost>');
44         $mime->header_set('Message-ID', "<hello\tworld>");
45         is_deeply(mids($mime->header_obj), ['helloworld'],
46                 'drop \t in Message-ID');
47
48         $mime->header_set('To', 'u@example.com');
49         $mime->header_set('References', '<hello> <world> <n> <u@example.com>');
50         is_deeply(references($mime->header_obj), [qw(hello world)]);
51
52         is_deeply([qw(helloworld alt-id-for-nntp)],
53                 mids_for_index($mime->header_obj),
54                 'X-Alt-Message-ID can be indexed');
55 }
56
57 done_testing();
58 1;