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';
15 my ($part, $level, @ex) = @{$_[0]};
16 my $s = $part->body_str;
18 push @parts, [ $s, $level, @ex ];
20 is_deeply(\@parts, [ [ qw(a 1 1) ], [ qw(b 1 2) ] ], 'order is fine');
24 my $mime = mime_load 't/msg_iter-nested.eml';
27 my ($part, $level, @ex) = @{$_[0]};
28 my $s = $part->body_str;
30 push @parts, [ $s, $level, @ex ];
32 is_deeply(\@parts, [ [qw(a 2 1 1)], [qw(b 2 1 2)], [qw(sig 1 2)] ],
33 'nested part shows up properly');
37 my $f = 't/iso-2202-jp.eml';
38 my $mime = PublicInbox::InboxWritable::mime_from_path($f) or
42 my ($part, $level, @ex) = @{$_[0]};
43 my ($s, $err) = msg_part_text($part, 'text/plain');
44 ok(!$err, 'no error');
47 ok(length($raw) > 0, 'got non-empty message');
48 is(index($raw, '$$$'), -1, 'no unescaped $$$');
52 my $f = 't/x-unknown-alpine.eml';
53 my $mime = PublicInbox::InboxWritable::mime_from_path($f) or
57 my ($part, $level, @ex) = @{$_[0]};
58 my ($s, $err) = msg_part_text($part, 'text/plain');
61 like($raw, qr!^\thttps://!ms, 'tab expanded with X-UNKNOWN');
62 like(ascii_html($raw), qr/• bullet point/s,
63 'got bullet point when X-UNKNOWN assumes UTF-8');
68 local $SIG{__WARN__} = sub { push @warn, [ @_ ] };
69 my $attr = "So and so wrote:\n";
70 my $q = "> hello world\n" x 10;
71 my $nq = "hello world\n" x 10;
72 my @sections = PublicInbox::MsgIter::split_quotes($attr . $q . $nq);
73 is($sections[0], $attr, 'attribution matches');
74 is($sections[1], $q, 'quoted section matches');
75 is($sections[2], $nq, 'non-quoted section matches');
76 is(scalar(@sections), 3, 'only three sections for short message');
77 is_deeply(\@warn, [], 'no warnings');
81 @sections = PublicInbox::MsgIter::split_quotes($attr . $q . $nq);
82 is_deeply(\@warn, [], 'no warnings on giant message');
83 is(join('', @sections), $attr . $q . $nq, 'result matches expected');
84 is(shift(@sections), $attr, 'attribution is first section');
86 while (defined(my $l = shift @sections)) {
88 like($l, qr/\n\z/s, 'section ends with newline');
89 my $idx = ($l =~ /\A>/) ? 0 : 1;
92 is($check[0], $q, 'long quoted section matches');
93 is($check[1], $nq, 'long quoted section matches');