1 # Copyright (C) 2016-2020 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
6 use PublicInbox::TestCommon;
7 use PublicInbox::Hval qw(ascii_html);
8 use PublicInbox::InboxWritable;
9 use_ok('PublicInbox::MsgIter');
12 my $mime = mime_load 't/msg_iter-order.eml', sub {
13 my $parts = [ Email::MIME->create(body => "a\n"),
14 Email::MIME->create(body => "b\n") ];
15 Email::MIME->create(parts => $parts,
16 header_str => [ From => 'root@localhost' ]);
20 my ($part, $level, @ex) = @{$_[0]};
21 my $s = $part->body_str;
23 push @parts, [ $s, $level, @ex ];
25 is_deeply(\@parts, [ [ qw(a 1 1) ], [ qw(b 1 2) ] ], 'order is fine');
29 my $mime = mime_load 't/msg_iter-nested.eml', sub {
30 my $parts = [ Email::MIME->create(body => 'a'),
31 Email::MIME->create(body => 'b') ];
32 $parts = [ Email::MIME->create(parts => $parts,
33 header_str => [ From => 'sub@localhost' ]),
34 Email::MIME->create(body => 'sig') ];
35 Email::MIME->create(parts => $parts,
36 header_str => [ From => 'root@localhost' ]);
40 my ($part, $level, @ex) = @{$_[0]};
41 my $s = $part->body_str;
43 push @parts, [ $s, $level, @ex ];
45 is_deeply(\@parts, [ [qw(a 2 1 1)], [qw(b 2 1 2)], [qw(sig 1 2)] ],
46 'nested part shows up properly');
50 my $f = 't/iso-2202-jp.eml';
51 my $mime = PublicInbox::InboxWritable::mime_from_path($f) or
55 my ($part, $level, @ex) = @{$_[0]};
56 my ($s, $err) = msg_part_text($part, 'text/plain');
57 ok(!$err, 'no error');
60 ok(length($raw) > 0, 'got non-empty message');
61 is(index($raw, '$$$'), -1, 'no unescaped $$$');
65 my $f = 't/x-unknown-alpine.eml';
66 my $mime = PublicInbox::InboxWritable::mime_from_path($f) or
70 my ($part, $level, @ex) = @{$_[0]};
71 my ($s, $err) = msg_part_text($part, 'text/plain');
74 like($raw, qr!^\thttps://!ms, 'tab expanded with X-UNKNOWN');
75 like(ascii_html($raw), qr/• bullet point/s,
76 'got bullet point when X-UNKNOWN assumes UTF-8');
81 local $SIG{__WARN__} = sub { push @warn, [ @_ ] };
82 my $attr = "So and so wrote:\n";
83 my $q = "> hello world\n" x 10;
84 my $nq = "hello world\n" x 10;
85 my @sections = PublicInbox::MsgIter::split_quotes($attr . $q . $nq);
86 is($sections[0], $attr, 'attribution matches');
87 is($sections[1], $q, 'quoted section matches');
88 is($sections[2], $nq, 'non-quoted section matches');
89 is(scalar(@sections), 3, 'only three sections for short message');
90 is_deeply(\@warn, [], 'no warnings');
94 @sections = PublicInbox::MsgIter::split_quotes($attr . $q . $nq);
95 is_deeply(\@warn, [], 'no warnings on giant message');
96 is(join('', @sections), $attr . $q . $nq, 'result matches expected');
97 is(shift(@sections), $attr, 'attribution is first section');
99 while (defined(my $l = shift @sections)) {
101 like($l, qr/\n\z/s, 'section ends with newline');
102 my $idx = ($l =~ /\A>/) ? 0 : 1;
105 is($check[0], $q, 'long quoted section matches');
106 is($check[1], $nq, 'long quoted section matches');