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>
7 use PublicInbox::Hval qw(ascii_html);
8 use PublicInbox::InboxWritable;
9 use_ok('PublicInbox::MsgIter');
12 my $parts = [ Email::MIME->create(body => "a\n"),
13 Email::MIME->create(body => "b\n") ];
14 my $mime = Email::MIME->create(parts => $parts,
15 header_str => [ From => 'root@localhost' ]);
18 my ($part, $level, @ex) = @{$_[0]};
19 my $s = $part->body_str;
21 push @parts, [ $s, $level, @ex ];
23 is_deeply(\@parts, [ [ qw(a 1 1) ], [ qw(b 1 2) ] ], 'order is fine');
27 my $parts = [ Email::MIME->create(body => 'a'),
28 Email::MIME->create(body => 'b') ];
29 $parts = [ Email::MIME->create(parts => $parts,
30 header_str => [ From => 'sub@localhost' ]),
31 Email::MIME->create(body => 'sig') ];
32 my $mime = Email::MIME->create(parts => $parts,
33 header_str => [ From => 'root@localhost' ]);
36 my ($part, $level, @ex) = @{$_[0]};
37 my $s = $part->body_str;
39 push @parts, [ $s, $level, @ex ];
41 is_deeply(\@parts, [ [qw(a 2 1 1)], [qw(b 2 1 2)], [qw(sig 1 2)] ],
42 'nested part shows up properly');
46 my $f = 't/iso-2202-jp.eml';
47 my $mime = PublicInbox::InboxWritable::mime_from_path($f) or
51 my ($part, $level, @ex) = @{$_[0]};
52 my ($s, $err) = msg_part_text($part, 'text/plain');
53 ok(!$err, 'no error');
56 ok(length($raw) > 0, 'got non-empty message');
57 is(index($raw, '$$$'), -1, 'no unescaped $$$');
61 my $f = 't/x-unknown-alpine.eml';
62 my $mime = PublicInbox::InboxWritable::mime_from_path($f) or
66 my ($part, $level, @ex) = @{$_[0]};
67 my ($s, $err) = msg_part_text($part, 'text/plain');
70 like($raw, qr!^\thttps://!ms, 'tab expanded with X-UNKNOWN');
71 like(ascii_html($raw), qr/• bullet point/s,
72 'got bullet point when X-UNKNOWN assumes UTF-8');
77 local $SIG{__WARN__} = sub { push @warn, [ @_ ] };
78 my $attr = "So and so wrote:\n";
79 my $q = "> hello world\n" x 10;
80 my $nq = "hello world\n" x 10;
81 my @sections = PublicInbox::MsgIter::split_quotes($attr . $q . $nq);
82 is($sections[0], $attr, 'attribution matches');
83 is($sections[1], $q, 'quoted section matches');
84 is($sections[2], $nq, 'non-quoted section matches');
85 is(scalar(@sections), 3, 'only three sections for short message');
86 is_deeply(\@warn, [], 'no warnings');
90 @sections = PublicInbox::MsgIter::split_quotes($attr . $q . $nq);
91 is_deeply(\@warn, [], 'no warnings on giant message');
92 is(join('', @sections), $attr . $q . $nq, 'result matches expected');
93 is(shift(@sections), $attr, 'attribution is first section');
95 while (defined(my $l = shift @sections)) {
97 like($l, qr/\n\z/s, 'section ends with newline');
98 my $idx = ($l =~ /\A>/) ? 0 : 1;
101 is($check[0], $q, 'long quoted section matches');
102 is($check[1], $nq, 'long quoted section matches');