]> Sergey Matveev's repositories - public-inbox.git/blob - t/content_hash.t
www: drop --subject from "git send-email" instructions
[public-inbox.git] / t / content_hash.t
1 #!perl -w
2 # Copyright (C) 2018-2021 all contributors <meta@public-inbox.org>
3 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
4 use strict;
5 use v5.10.1;
6 use Test::More;
7 use PublicInbox::ContentHash qw(content_hash);
8 use PublicInbox::Eml;
9
10 my $mime = PublicInbox::Eml->new(<<'EOF');
11 From: a@example.com
12 To: b@example.com
13 Subject: this is a subject
14 Message-ID: <a@example.com>
15 Date: Fri, 02 Oct 1993 00:00:00 +0000
16
17 hello world
18 EOF
19
20 my $orig = content_hash($mime);
21 my $reload = content_hash(PublicInbox::Eml->new($mime->as_string));
22 is($orig, $reload, 'content_hash matches after serialization');
23 {
24         my $s1 = PublicInbox::Eml->new($mime->as_string);
25         $s1->header_set('Sender', 's@example.com');
26         is(content_hash($s1), $orig, "Sender ignored when 'From' present");
27         my $s2 = PublicInbox::Eml->new($s1->as_string);
28         $s1->header_set('Sender', 'sender@example.com');
29         is(content_hash($s2), $orig, "Sender really ignored 'From'");
30         $_->header_set('From') for ($s1, $s2);
31         isnt(content_hash($s1), content_hash($s2),
32                 'sender accounted when From missing');
33 }
34
35 foreach my $h (qw(From To Cc)) {
36         my $n = q("Quoted N'Ame" <foo@EXAMPLE.com>);
37         $mime->header_set($h, "$n");
38         my $q = content_hash($mime);
39         is($mime->header($h), $n, "content_hash does not mutate $h:");
40         $mime->header_set($h, 'Quoted N\'Ame <foo@example.com>');
41         my $nq = content_hash($mime);
42         is($nq, $q, "quotes ignored in $h:");
43 }
44
45 done_testing();