You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by km...@apache.org on 2014/07/03 21:37:59 UTC

svn commit: r1607729 - in /spamassassin/trunk: lib/Mail/SpamAssassin/Plugin/MIMEEval.pm rulesrc/sandbox/kmcgrail/20_bug_7063.cf

Author: kmcgrail
Date: Thu Jul  3 19:37:59 2014
New Revision: 1607729

URL: http://svn.apache.org/r1607729
Log:
Added code for check_for_ascii_text_illegal in MIMEEval and added test rule to sandbox

Added:
    spamassassin/trunk/rulesrc/sandbox/kmcgrail/20_bug_7063.cf
Modified:
    spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/MIMEEval.pm

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/MIMEEval.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/MIMEEval.pm?rev=1607729&r1=1607728&r2=1607729&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/MIMEEval.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/MIMEEval.pm Thu Jul  3 19:37:59 2014
@@ -47,6 +47,7 @@ sub new {
   $self->register_eval_rule("check_for_mime_html_only");
   $self->register_eval_rule("check_mime_multipart_ratio");
   $self->register_eval_rule("check_msg_parse_flags");
+  $self->register_eval_rule("check_for_ascii_text_illegal");
   $self->register_eval_rule("check_for_faraway_charset");
   $self->register_eval_rule("check_for_uppercase");
   $self->register_eval_rule("check_ma_non_text");
@@ -68,6 +69,15 @@ sub are_more_high_bits_set {
   ($numlos <= $numhis && $numhis > 3);
 }
 
+sub has_check_for_ascii_text_illegal { 1 }
+
+sub check_for_ascii_text_illegal {
+  my ($self, $pms) = @_;
+
+  $self->_check_attachments($pms) unless exists $pms->{mime_ascii_text_illegal};
+  return ($pms->{mime_ascii_text_illegal} > 0);
+}
+
 sub check_for_faraway_charset {
   my ($self, $pms, $body) = @_;
 
@@ -246,6 +256,7 @@ sub _check_attachments {
   # $pms->{mime_qp_inline_no_charset} = 0;
   $pms->{mime_qp_long_line} = 0;
   $pms->{mime_qp_ratio} = 0;
+  $pms->{mime_ascii_text_illegal} = 0;
 
   # Get all parts ...
   foreach my $p ($pms->{msg}->find_parts(qr/./)) {
@@ -338,6 +349,21 @@ sub _check_attachments {
 	  }
         }
       }
+
+      # if our charset is ASCII, this should only contain 7-bit characters
+      # except NUL or a free-standing CR. anything else is a violation of
+      # the definition of charset="us-ascii".
+      if ($ctype eq 'text/plain' && (!defined $charset || $charset eq 'us-ascii')) {
+        if (m/[\x00\x0d\x80-\xff]+/) {
+          if (would_log('dbg', 'eval')) {
+            my $str = $_;
+            $str =~ s/[\x00\x0d\x80-\xff]+/'<' . unpack('H*', $&) . '>'/eg;
+            dbg("check: ascii_text_illegal: matches " . $str . "\n");
+          }
+          $pms->{mime_ascii_text_illegal}++;
+        }
+      }
+
       $previous = $_;
     }
   }

Added: spamassassin/trunk/rulesrc/sandbox/kmcgrail/20_bug_7063.cf
URL: http://svn.apache.org/viewvc/spamassassin/trunk/rulesrc/sandbox/kmcgrail/20_bug_7063.cf?rev=1607729&view=auto
==============================================================================
--- spamassassin/trunk/rulesrc/sandbox/kmcgrail/20_bug_7063.cf (added)
+++ spamassassin/trunk/rulesrc/sandbox/kmcgrail/20_bug_7063.cf Thu Jul  3 19:37:59 2014
@@ -0,0 +1,35 @@
+# SpamAssassin rules file: kam sandbox
+#
+# Please don't modify this file as your changes will be overwritten with
+# the next update. Use @@LOCAL_RULES_DIR@@/local.cf instead.
+# See 'perldoc Mail::SpamAssassin::Conf' for details.
+#
+# <@LICENSE>
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to you under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at:
+# 
+#     http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# </...@LICENSE>
+#
+###########################################################################
+
+ifplugin Mail::SpamAssassin::Plugin::MIMEEval
+  if can(Mail::SpamAssassin::Plugin::MIMEEval::has_check_for_ascii_text_illegal)
+    body     PP_MIME_FAKE_ASCII_TEXT  eval:check_for_ascii_text_illegal('mime_fake_ascii_text')
+    describe PP_MIME_FAKE_ASCII_TEXT  MIME text/plain claims to be ASCII but isn't
+    score    PP_MIME_FAKE_ASCII_TEXT  1.0
+    tflags   PP_MIME_FAKE_ASCII_TEXT  publish
+  endif
+endif
+
+#EOF