diff options
author | Eric Wong <e@yhbt.net> | 2020-05-16 10:03:22 +0000 |
---|---|---|
committer | Eric Wong <e@yhbt.net> | 2020-05-17 06:56:40 +0000 |
commit | e60231148eb604a379033c69e8c4494eb1753783 (patch) | |
tree | c49950605f50bc46082e20ee7fe679c6cf76989e /t | |
parent | 77aa1a9eae83fa60eb8208710a714aa4f39d9b34 (diff) | |
download | public-inbox-e60231148eb604a379033c69e8c4494eb1753783.tar.gz |
Email::MIME never supported this properly, but there's real instances of forwarded messages as message/rfc822 attachments. message/news is legacy thing which we'll see in archives, and message/global appears to be the new thing. gmime also supports message/rfc2822, so we'll support it anyways despite lacking other evidence of its existence. Existing attachments remain downloadable as a whole message, but individual attachments of subparts are now downloadable and can be displayed in HTML, too. Furthermore, ensure Xapian can now search for common headers inside those messages as well as the message bodies.
Diffstat (limited to 't')
-rw-r--r-- | t/eml.t | 28 | ||||
-rw-r--r-- | t/psgi_attach.t | 9 | ||||
-rw-r--r-- | t/search.t | 25 |
3 files changed, 62 insertions, 0 deletions
@@ -117,6 +117,34 @@ EOF '', '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; diff --git a/t/psgi_attach.t b/t/psgi_attach.t index 12f9e6ee..c6f8072f 100644 --- a/t/psgi_attach.t +++ b/t/psgi_attach.t @@ -75,6 +75,9 @@ $im->init_bare; $res = $cb->(GET("/test/$mid/")); like($res->content, qr/\bhref="2-embed2x\.eml"/s, 'href to message/rfc822 attachment visible'); + like($res->content, qr/\bhref="2\.1\.2-test\.eml"/s, + 'href to nested message/rfc822 attachment visible'); + $res = $cb->(GET("/test/$mid/2-embed2x.eml")); my $eml = PublicInbox::Eml->new(\($res->content)); is_deeply([ $eml->header_raw('Message-ID') ], [ "<$irt>" ], @@ -85,6 +88,12 @@ $im->init_bare; '1st attachment is as expected'); is($subs[1]->header('Content-Type'), 'message/rfc822', '2nd attachment is as expected'); + + $res = $cb->(GET("/test/$mid/2.1.2-test.eml")); + $eml = PublicInbox::Eml->new(\($res->content)); + is_deeply([ $eml->header_raw('Message-ID') ], + [ '<20200418214114.7575-1-e@yhbt.net>' ], + 'nested eml retrieved'); }); } done_testing(); @@ -479,6 +479,31 @@ EOF is_deeply($found, [], 'matched on phrase with l:'); } +$ibx->with_umask(sub { + $rw_commit->(); + my $doc_id = $rw->add_message(eml_load('t/data/message_embed.eml')); + ok($doc_id > 0, 'messages within messages'); + $rw->commit_txn_lazy; + $ro->reopen; + my $n_test_eml = $ro->query('n:test.eml'); + is(scalar(@$n_test_eml), 1, 'got a result'); + my $n_embed2x_eml = $ro->query('n:embed2x.eml'); + is_deeply($n_test_eml, $n_embed2x_eml, '.eml filenames searchable'); + for my $m (qw(20200418222508.GA13918@dcvr 20200418222020.GA2745@dcvr + 20200418214114.7575-1-e@yhbt.net)) { + is($ro->query("m:$m")->[0]->{mid}, + '20200418222508.GA13918@dcvr', 'probabilistic m:'.$m); + is($ro->query("mid:$m")->[0]->{mid}, + '20200418222508.GA13918@dcvr', 'boolean mid:'.$m); + } + is($ro->query('dfpost:4dc62c50')->[0]->{mid}, + '20200418222508.GA13918@dcvr', + 'diff search reaches inside message/rfc822'); + is($ro->query('s:"mail header experiments"')->[0]->{mid}, + '20200418222508.GA13918@dcvr', + 'Subject search reaches inside message/rfc822'); +}); + done_testing(); 1; |