You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by jm...@apache.org on 2007/04/03 20:08:45 UTC

svn commit: r525224 - in /spamassassin/trunk: MANIFEST lib/Mail/SpamAssassin/Util.pm t/text_bad_ctype.t

Author: jm
Date: Tue Apr  3 11:08:44 2007
New Revision: 525224

URL: http://svn.apache.org/viewvc?view=rev&rev=525224
Log:
bug 5399: if the content-type starts with /^text\b/i, and isn't in a list of already-dealt-with types, treat it as text/plain to emulate silly MUA behaviour

Added:
    spamassassin/trunk/t/text_bad_ctype.t   (with props)
Modified:
    spamassassin/trunk/MANIFEST
    spamassassin/trunk/lib/Mail/SpamAssassin/Util.pm

Modified: spamassassin/trunk/MANIFEST
URL: http://svn.apache.org/viewvc/spamassassin/trunk/MANIFEST?view=diff&rev=525224&r1=525223&r2=525224
==============================================================================
--- spamassassin/trunk/MANIFEST (original)
+++ spamassassin/trunk/MANIFEST Tue Apr  3 11:08:44 2007
@@ -488,3 +488,4 @@
 t/zz_cleanup.t
 lib/Mail/SpamAssassin/Plugin/ImageInfo.pm
 rules/20_imageinfo.cf
+t/text_bad_ctype.t

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Util.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Util.pm?view=diff&rev=525224&r1=525223&r2=525224
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Util.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Util.pm Tue Apr  3 11:08:44 2007
@@ -850,15 +850,19 @@
   $ct =~ s/^\s+//;				# strip leading whitespace
   $ct =~ s/;.*$//s;				# strip everything after first ';'
   $ct =~ s@^([^/]+(?:/[^/\s]*)?).*$@$1@s;	# only something/something ...
-  # strip inappropriate chars
-  $ct =~ tr/\000-\040\177-\377\042\050\051\054\056\072-\077\100\133-\135//d;
   $ct = lc $ct;
 
-  # bug 4298: If at this point we don't have a content-type, assume text/plain
-  # also, if the content-type is simply "text" or "text/", assume text/plain
-  if (!$ct || $ct =~ /^text\/?$/) {
+  # bug 4298: If at this point we don't have a content-type, assume text/plain;
+  # also, bug 5399: if the content-type *starts* with "text", and isn't in a 
+  # list of known bad/non-plain formats, do likewise.
+  if (!$ct ||
+        ($ct =~ /^text\b/ && $ct !~ /^text\/(?:x-vcard|calendar|html)$/))
+  {
     $ct = "text/plain";
   }
+
+  # strip inappropriate chars (bug 5399: after the text/plain fixup)
+  $ct =~ tr/\000-\040\177-\377\042\050\051\054\056\072-\077\100\133-\135//d;
 
   # Now that the header has been parsed, return the requested information.
   # In scalar context, just the MIME type, in array context the

Added: spamassassin/trunk/t/text_bad_ctype.t
URL: http://svn.apache.org/viewvc/spamassassin/trunk/t/text_bad_ctype.t?view=auto&rev=525224
==============================================================================
--- spamassassin/trunk/t/text_bad_ctype.t (added)
+++ spamassassin/trunk/t/text_bad_ctype.t Tue Apr  3 11:08:44 2007
@@ -0,0 +1,21 @@
+#!/usr/bin/perl
+
+use lib '.'; use lib 't';
+use SATest; sa_t_init("text_bad_ctype");
+use Test; BEGIN { plan tests => 2 };
+
+# ---------------------------------------------------------------------------
+
+tstlocalrules ('
+  body NATURAL	/\btotally <br> natural/i
+');
+
+%patterns = ( q{ NATURAL } => 'NATURAL',);
+%anti_patterns = ();
+sarun ("-L -t < data/spam/badctype1", \&patterns_run_cb);
+ok_all_patterns();
+
+%patterns = ();
+%anti_patterns = ( q{ NATURAL } => 'NATURAL',);
+sarun ("-L -t < data/spam/badctype2", \&patterns_run_cb);
+ok_all_patterns();

Propchange: spamassassin/trunk/t/text_bad_ctype.t
------------------------------------------------------------------------------
    svn:executable = *