user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
* [PATCH] filter: fix handling of bad attachments
@ 2015-10-15 18:32 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2015-10-15 18:32 UTC (permalink / raw)
  To: meta

Improve error messages and use a better regexp for detecting
printable characters in attachments.
---
 lib/PublicInbox/Filter.pm | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/lib/PublicInbox/Filter.pm b/lib/PublicInbox/Filter.pm
index 01052d0..82baa9b 100644
--- a/lib/PublicInbox/Filter.pm
+++ b/lib/PublicInbox/Filter.pm
@@ -151,7 +151,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 +163,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 +235,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;
-- 
EW


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2015-10-15 18:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-15 18:32 [PATCH] filter: fix handling of bad attachments Eric Wong

Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).