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