};
use_ok $_ for @classes;
+sub mime_load ($) {
+ my ($path) = @_;
+ open(my $fh, '<', $path) or die "open $path: $!";
+ PublicInbox::MIME->new(\(do { local $/; <$fh> }));
+}
+
{
my $eml = PublicInbox::Eml->new(\(my $str = "a: b\n\nhi\n"));
is($str, "hi\n", '->new modified body like Email::Simple');
$eml->header_str_set('Subject', "\x{100}");
like($eml->header_raw('Subject'), qr/utf-8\?B\?/i,
'MIME-B encoded UTF-8 Subject');
- is_deeply([$eml->header_str('Subject')], [ "\x{100}" ],
+ is_deeply([$eml->header('Subject')], [ "\x{100}" ],
'got wide character back');
}
'', 'each_part can clobber body');
}
+if ('descend into message/rfc822') {
+ my $eml = eml_load 't/data/message_embed.eml';
+ my @parts;
+ $eml->each_part(sub {
+ my ($part, $level, @ex) = @{$_[0]};
+ push @parts, [ $part, $level, @ex ];
+ });
+ is(scalar(@parts), 6, 'got all parts');
+ like($parts[0]->[0]->body, qr/^testing embedded message harder\n/sm,
+ 'first part found');
+ is_deeply([ @{$parts[0]}[1..2] ], [ 1, '1' ],
+ 'got expected depth and level for part #0');
+ is($parts[1]->[0]->filename, 'embed2x.eml',
+ 'attachment filename found');
+ is_deeply([ @{$parts[1]}[1..2] ], [ 1, '2' ],
+ 'got expected depth and level for part #1');
+ is_deeply([ @{$parts[2]}[1..2] ], [ 2, '2.1' ],
+ 'got expected depth and level for part #2');
+ is_deeply([ @{$parts[3]}[1..2] ], [ 3, '2.1.1' ],
+ 'got expected depth and level for part #3');
+ is_deeply([ @{$parts[4]}[1..2] ], [ 3, '2.1.2' ],
+ 'got expected depth and level for part #4');
+ is($parts[4]->[0]->filename, 'test.eml',
+ 'another attachment filename found');
+ is_deeply([ @{$parts[5]}[1..2] ], [ 4, '2.1.2.1' ],
+ 'got expected depth and level for part #5');
+}
+
# body-less, boundary-less
for my $cls (@classes) {
my $call = 0;
is(scalar(@tmp), 1, 'got one part even w/o boundary');
is($tmp[0]->[0]->[0]->body, "hello world\n", 'body preserved');
is($tmp[0]->[0]->[1], 0, '$depth is zero');
- is($tmp[0]->[0]->[2], 0, '@idx is zero');
+ is($tmp[0]->[0]->[2], 1, '@idx is one');
}
# I guess the following only worked in PI::M because of a happy accident
'final "\n" preserved on missing epilogue');
}
+if ('header_size_limit stolen from postfix') {
+ local $PublicInbox::Eml::header_size_limit = 4;
+ my @w;
+ local $SIG{__WARN__} = sub { push @w, @_ };
+ my $eml = PublicInbox::Eml->new("a:b\na:d\n\nzz");
+ is_deeply([$eml->header('a')], ['b'], 'no overrun header');
+ is($eml->body_raw, 'zz', 'body not damaged');
+ is($eml->header_obj->as_string, "a:b\n", 'header truncated');
+ is(grep(/truncated/, @w), 1, 'truncation warned');
+
+ $eml = PublicInbox::Eml->new("a:b\na:d\n");
+ is_deeply([$eml->header('a')], ['b'], 'no overrun header w/o body');
+
+ local $PublicInbox::Eml::header_size_limit = 5;
+ $eml = PublicInbox::Eml->new("a:b\r\na:d\r\n\nzz");
+ is_deeply([$eml->header('a')], ['b'], 'no overrun header on CRLF');
+ is($eml->body_raw, 'zz', 'body not damaged');
+
+ @w = ();
+ $eml = PublicInbox::Eml->new("too:long\n");
+ $eml = PublicInbox::Eml->new("too:long\n\n");
+ $eml = PublicInbox::Eml->new("too:long\r\n\r\n");
+ is(grep(/ignored/, @w), 3, 'ignored header warned');
+}
+
if ('maxparts is a feature unique to us') {
my $eml = eml_load 't/psgi_attach.eml';
my @orig;
$eml->each_part(sub { push @orig, $_[0]->[0] });
- local $PublicInbox::Eml::MAXPARTS = scalar(@orig);
+ local $PublicInbox::Eml::mime_parts_limit = scalar(@orig);
my $i = 0;
$eml->each_part(sub {
my $cur = $_[0]->[0];
is($cur->body_raw, $prv->body_raw, "part #$i matches");
});
is($i, scalar(@orig), 'maxparts honored');
- $PublicInbox::Eml::MAXPARTS--;
+ $PublicInbox::Eml::mime_parts_limit--;
my @ltd;
$eml->each_part(sub { push @ltd, $_[0]->[0] });
for ($i = 0; $i <= $#ltd; $i++) {