X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FFilter.pm;h=5a023cf7032b0e27573932238c6349b1464f5004;hb=f76f265a851944b5dedcc3be5f3b5224b6ebda89;hp=49ba5cb2df452ea72a8991dbfbeabf5fad997745;hpb=f66473b1a41606d8b4cda74c551aa85d12ec37ef;p=public-inbox.git diff --git a/lib/PublicInbox/Filter.pm b/lib/PublicInbox/Filter.pm index 49ba5cb2..5a023cf7 100644 --- a/lib/PublicInbox/Filter.pm +++ b/lib/PublicInbox/Filter.pm @@ -1,4 +1,4 @@ -# Copyright (C) 2013, Eric Wong and all contributors +# Copyright (C) 2013-2015 all contributors # License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt) # # This only exposes one function: run @@ -15,7 +15,7 @@ our $VERSION = '0.0.1'; use constant NO_HTML => '*** We only accept plain-text email, no HTML ***'; # start with the same defaults as mailman -our $BAD_EXT = qr/\.(?:exe|bat|cmd|com|pif|scr|vbs|cpl)\z/i; +our $BAD_EXT = qr/\.(exe|bat|cmd|com|pif|scr|vbs|cpl|zip)\s*\z/i; our $MIME_HTML = qr!\btext/html\b!i; our $MIME_TEXT_ANY = qr!\btext/[a-z0-9\+\._-]+\b!i; @@ -127,6 +127,7 @@ sub strip_multipart { # some extensions are just bad, reject them outright my $fn = $part->filename; if (defined($fn) && $fn =~ $BAD_EXT) { + $filter->reject("Bad file type: $1") if $filter; $rejected++; return; } @@ -144,16 +145,18 @@ sub strip_multipart { push @keep, $part; } elsif ($part_type eq '' || - $part_type =~ m!\Aapplication/octet-stream\z!i) { + $part_type =~ m!\bapplication/octet-stream\b!i) { # unfortunately, some mailers don't set correct types, # let messages of unknown type through but do not # change the sender-specified type if (recheck_type_ok($part)) { push @keep, $part; + } elsif ($filter) { + $filter->reject('no attachments') } else { $rejected++; } - } elsif ($part_type =~ m!\Aapplication/pgp-signature\z!i) { + } elsif ($part_type =~ m!\bapplication/pgp-signature\b!i) { # PGP signatures are not huge, we may keep them. # They can only be valid if it's the last element, # so we keep them iff the message is unmodified: @@ -161,6 +164,7 @@ sub strip_multipart { push @keep, $part; } } else { + $filter->reject('no attachments') if $filter; # reject everything else, including non-PGP signatures $rejected++; } @@ -207,7 +211,7 @@ sub collapse { $mime->header_set('Content-Type', $part->content_type); $mime->body_set($part->body_raw); my $cte = $part->header('Content-Transfer-Encoding'); - if (defined($cte) && length($cte)) { + if (defined($cte) && $cte ne '') { $mime->header_set('Content-Transfer-Encoding', $cte); } mark_changed($mime);