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_ok('PublicInbox::MsgIter');
11 my $mime = eml_load 't/msg_iter-order.eml';
14 my ($part, $level, @ex) = @{$_[0]};
15 my $s = $part->body_str;
17 push @parts, [ $s, $level, @ex ];
19 is_deeply(\@parts, [ [ qw(a 1 1) ], [ qw(b 1 2) ] ], 'order is fine');
23 my $mime = eml_load 't/msg_iter-nested.eml';
26 my ($part, $level, @ex) = @{$_[0]};
27 my $s = $part->body_str;
29 push @parts, [ $s, $level, @ex ];
31 is_deeply(\@parts, [ [qw(a 2 1.1)], [qw(b 2 1.2)], [qw(sig 1 2)] ],
32 'nested part shows up properly');
36 my $mime = eml_load 't/iso-2202-jp.eml';
39 my ($part, $level, @ex) = @{$_[0]};
40 my ($s, $err) = msg_part_text($part, 'text/plain');
41 ok(!$err, 'no error');
44 ok(length($raw) > 0, 'got non-empty message');
45 is(index($raw, '$$$'), -1, 'no unescaped $$$');
49 my $mime = eml_load 't/x-unknown-alpine.eml';
52 my ($part, $level, @ex) = @{$_[0]};
53 my ($s, $err) = msg_part_text($part, 'text/plain');
56 like($raw, qr!^\thttps://!ms, 'tab expanded with X-UNKNOWN');
57 like(ascii_html($raw), qr/• bullet point/s,
58 'got bullet point when X-UNKNOWN assumes UTF-8');
63 local $SIG{__WARN__} = sub { push @warn, [ @_ ] };
64 my $attr = "So and so wrote:\n";
65 my $q = "> hello world\n" x 10;
66 my $nq = "hello world\n" x 10;
67 my @sections = PublicInbox::MsgIter::split_quotes($attr . $q . $nq);
68 is($sections[0], $attr, 'attribution matches');
69 is($sections[1], $q, 'quoted section matches');
70 is($sections[2], $nq, 'non-quoted section matches');
71 is(scalar(@sections), 3, 'only three sections for short message');
72 is_deeply(\@warn, [], 'no warnings');
76 @sections = PublicInbox::MsgIter::split_quotes($attr . $q . $nq);
77 is_deeply(\@warn, [], 'no warnings on giant message');
78 is(join('', @sections), $attr . $q . $nq, 'result matches expected');
79 is(shift(@sections), $attr, 'attribution is first section');
81 while (defined(my $l = shift @sections)) {
83 like($l, qr/\n\z/s, 'section ends with newline');
84 my $idx = ($l =~ /\A>/) ? 0 : 1;
87 is($check[0], $q, 'long quoted section matches');
88 is($check[1], $nq, 'long quoted section matches');