]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/Filter.pm
emergency: implement new emergency Maildir delivery
[public-inbox.git] / lib / PublicInbox / Filter.pm
index 01052d02e3a6de06a07cd65a76988874fee5c3d4..8b78a44163743dcd4a235a1bc661471e29f091e6 100644 (file)
@@ -1,6 +1,7 @@
 # Copyright (C) 2013-2015 all contributors <meta@public-inbox.org>
 # License: AGPLv3 or later (https://www.gnu.org/licenses/agpl-3.0.txt)
 #
+# Used to filter incoming mail for -mda and importers
 # This only exposes one function: run
 # Note: the settings here are highly opinionated.  Obviously, this is
 # Free Software (AGPLv3), so you may change it if you host yourself.
@@ -27,16 +28,6 @@ sub run {
 
        my $content_type = $mime->header('Content-Type') || 'text/plain';
 
-       # kill potentially bad/confusing headers
-       # Note: ssoma already does this, but since we mangle the message,
-       # we should do this before it gets to ssoma.
-       # We also kill Mail-{Followup,Reply}-To headers due to
-       # the nature of public-inbox having no real subscribers.
-       foreach my $d (qw(status lines content-length
-                       mail-followup-to mail-reply-to)) {
-               $mime->header_set($d);
-       }
-
        if ($content_type =~ m!\btext/plain\b!i) {
                return 1; # yay, nothing to do
        } elsif ($content_type =~ $MIME_HTML) {
@@ -151,7 +142,8 @@ sub strip_multipart {
                        if (recheck_type_ok($part)) {
                                push @keep, $part;
                        } elsif ($filter) {
-                               $filter->reject(TEXT_ONLY);
+                               $filter->reject("Bad attachment: $part_type ".
+                                               TEXT_ONLY);
                        } else {
                                $rejected++;
                        }
@@ -162,8 +154,10 @@ sub strip_multipart {
                        if ($rejected == 0 && !@html) {
                                push @keep, $part;
                        }
+               } elsif ($filter) {
+                       $filter->reject("unacceptable mime-type: $part_type ".
+                                       TEXT_ONLY);
                } else {
-                       $filter->reject(TEXT_ONLY) if $filter;
                        # reject everything else, including non-PGP signatures
                        $rejected++;
                }
@@ -232,8 +226,7 @@ sub replace_body {
 sub recheck_type_ok {
        my ($part) = @_;
        my $s = $part->body;
-       ((length($s) < 0x10000) &&
-               ($s =~ /\A([\P{XPosixPrint}\f\n\r\t]+)\z/))
+       ((length($s) < 0x10000) && ($s =~ /\A([[:print:]\s]+)\z/s));
 }
 
 1;