]> Sergey Matveev's repositories - public-inbox.git/blob - t/content_id.t
v2: improve deduplication checks
[public-inbox.git] / t / content_id.t
1 # Copyright (C) 2018 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 warnings;
5 use Test::More;
6 use PublicInbox::ContentId qw(content_id);
7 use Email::MIME;
8
9 my $mime = Email::MIME->create(
10         header => [
11                 From => 'a@example.com',
12                 To => 'b@example.com',
13                 'Content-Type' => 'text/plain',
14                 Subject => 'this is a subject',
15                 'Message-ID' => '<a@example.com>',
16                 Date => 'Fri, 02 Oct 1993 00:00:00 +0000',
17         ],
18         body => "hello world\n",
19 );
20
21 my $orig = content_id($mime);
22 my $reload = content_id(Email::MIME->new($mime->as_string));
23 is($orig, $reload, 'content_id matches after serialization');
24
25 foreach my $h (qw(From To Cc)) {
26         my $n = '"Quoted N\'Ame" <foo@EXAMPLE.com>';
27         $mime->header_str_set($h, "$n");
28         my $q = content_id($mime);
29         is($n, $mime->header($h), "content_id does not mutate $h:");
30         $mime->header_str_set($h, 'Quoted N\'Ame <foo@example.com>');
31         my $nq = content_id($mime);
32         is($nq, $q, "quotes ignored in $h:");
33 }
34
35 done_testing();