From 0b4b51e8ba8cf62c8da9312666d4866ff2403d6e Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 28 Mar 2014 08:22:45 +0000 Subject: filter: use file(1) to detect mime type if octet-stream Some mailers do not correctly detect/set the Content-Type header; so attempt to keep messages based on our server-detected MIME type if application/octet-stream was specified. --- t/filter.t | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 't') diff --git a/t/filter.t b/t/filter.t index 12f4ed6f..0aa26a5f 100644 --- a/t/filter.t +++ b/t/filter.t @@ -278,5 +278,40 @@ sub count_body_parts { is(undef, $f->simple->header("Mail-Followup-To"), "mft stripped"); } +# multi-part with application/octet-stream +{ + my $os = 'application/octet-stream'; + my $parts = [ + Email::MIME->create( + attributes => { content_type => $os }, + body => < +int main(void) +{ + printf("Hello world\\n"); + return 0; +} +EOF + ), + Email::MIME->create( + attributes => { + filename => 'zero.data', + encoding => 'base64', + content_type => $os, + }, + body => ("\0" x 4096), + ) + ]; + my $email = Email::MIME->create( + header_str => [ From => 'a@example.com', Subject => 'blah' ], + parts => $parts, + ); + my $f = Email::Filter->new(data => $email->as_string); + is(1, PublicInbox::Filter->run($f->simple), "run was a success"); + my $parsed = Email::MIME->new($f->simple->as_string); + is(scalar $parsed->parts, 1, "only one remaining part"); + like($f->simple->header("X-Content-Filtered-By"), + qr/PublicInbox::Filter/, "XCFB header added"); +} done_testing(); -- cgit v1.2.3-24-ge0c7