You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by do...@apache.org on 2006/07/25 21:29:28 UTC

svn commit: r425491 - in /spamassassin/branches/3.1: MANIFEST lib/Mail/SpamAssassin/PerMsgStatus.pm t/get_headers.t

Author: dos
Date: Tue Jul 25 12:29:27 2006
New Revision: 425491

URL: http://svn.apache.org/viewvc?rev=425491&view=rev
Log:
bug 3979: better handling of quoted text when stripping email addresses

Added:
    spamassassin/branches/3.1/t/get_headers.t   (with props)
Modified:
    spamassassin/branches/3.1/MANIFEST
    spamassassin/branches/3.1/lib/Mail/SpamAssassin/PerMsgStatus.pm

Modified: spamassassin/branches/3.1/MANIFEST
URL: http://svn.apache.org/viewvc/spamassassin/branches/3.1/MANIFEST?rev=425491&r1=425490&r2=425491&view=diff
==============================================================================
--- spamassassin/branches/3.1/MANIFEST (original)
+++ spamassassin/branches/3.1/MANIFEST Tue Jul 25 12:29:27 2006
@@ -380,6 +380,7 @@
 t/desc_wrap.t
 t/dnsbl.t
 t/forged_rcvd.t
+t/get_headers.t
 t/gtube.t
 t/hashcash.t
 t/html_colors.t

Modified: spamassassin/branches/3.1/lib/Mail/SpamAssassin/PerMsgStatus.pm
URL: http://svn.apache.org/viewvc/spamassassin/branches/3.1/lib/Mail/SpamAssassin/PerMsgStatus.pm?rev=425491&r1=425490&r2=425491&view=diff
==============================================================================
--- spamassassin/branches/3.1/lib/Mail/SpamAssassin/PerMsgStatus.pm (original)
+++ spamassassin/branches/3.1/lib/Mail/SpamAssassin/PerMsgStatus.pm Tue Jul 25 12:29:27 2006
@@ -1555,10 +1555,13 @@
       # Foo Blah <jm...@foo>
       # "Foo Blah" <jm...@foo>
       # "'Foo Blah'" <jm...@foo>
+      # "_$B!z8=6b$=$N>l$GEv$?$j!*!zEv_(B_$B$?$k!*!)$/$8!z7|>^%\%s%P!<!z_(B" <jm...@foo>  (bug 3979)
       #
       # strip out the (comments)
       $result =~ s/\s*\(.*?\)//g;
-      # "Foo Blah" <jm...@xxx> or <jm...@xxx>
+      # strip out the "quoted text"
+      $result =~ s/(?<!<)"[^"]*"(?!@)//g;
+      # Foo Blah <jm...@xxx> or <jm...@xxx>
       $result =~ s/^[^<]*?<(.*?)>.*$/$1/;
       # multiple addresses on one line? remove all but first
       $result =~ s/,.*$//;

Added: spamassassin/branches/3.1/t/get_headers.t
URL: http://svn.apache.org/viewvc/spamassassin/branches/3.1/t/get_headers.t?rev=425491&view=auto
==============================================================================
--- spamassassin/branches/3.1/t/get_headers.t (added)
+++ spamassassin/branches/3.1/t/get_headers.t Tue Jul 25 12:29:27 2006
@@ -0,0 +1,86 @@
+#!/usr/bin/perl -w
+
+BEGIN {
+  if (-e 't/test_dir') { # if we are running "t/rule_tests.t", kluge around ...
+    chdir 't';
+  }
+
+  if (-e 'test_dir') {            # running from test directory, not ..
+    unshift(@INC, '../blib/lib');
+  }
+}
+
+my $prefix = '.';
+if (-e 'test_dir') {            # running from test directory, not ..
+  $prefix = '..';
+}
+
+use strict;
+use Test;
+use SATest; sa_t_init("get_headers");
+
+use Mail::SpamAssassin;
+
+plan tests => 11;
+
+##############################################
+
+# initialize SpamAssassin
+my $sa = create_saobj({'dont_copy_prefs' => 1});
+
+$sa->init(0); # parse rules
+
+my $raw_message = <<'EOF';
+To1: <jm...@foo>
+To2: jm@foo
+To3: jm@foo (Foo Blah)
+To4: jm@foo, jm@bar
+To5: display: jm@foo (Foo Blah), jm@bar ;
+To6: Foo Blah <jm...@foo>
+To7: "Foo Blah" <jm...@foo>
+To8: "'Foo Blah'" <jm...@foo>
+To9: "_$B!z8=6b$=$N>l$GEv$?$j!*!zEv_(B_$B$?$k!*!)$/$8!z7|>^%\%s%P!<!z_(B" <jm...@foo>
+To10: "Some User" <"Some User"@foo>
+To11: "Some User"@foo
+
+Blah!
+
+EOF
+
+my $mail = $sa->parse( $raw_message );
+my $msg = Mail::SpamAssassin::PerMsgStatus->new($sa, $mail);
+
+##############################################
+
+sub try {
+  my ($try, $expect) = @_;
+  my $result = $msg->get($try);
+
+  # undef might be valid in some situations, so deal with it...
+  if (!defined $expect) {
+    return !defined $result;
+  }
+  elsif (!defined $result) {
+    return 0;
+  }
+
+  if ($expect eq $result) {
+    return 1;
+  } else {
+    warn "try: '$try' failed! expect: '$expect' got: '$result'\n";
+    return 0;
+  }
+}
+
+ok(try('To1:addr', 'jm@foo'));
+ok(try('To2:addr', 'jm@foo'));
+ok(try('To3:addr', 'jm@foo'));
+ok(try('To4:addr', 'jm@foo'));
+ok(try('To5:addr', 'jm@foo'));
+ok(try('To6:addr', 'jm@foo'));
+ok(try('To7:addr', 'jm@foo'));
+ok(try('To8:addr', 'jm@foo'));
+ok(try('To9:addr', 'jm@foo'));
+ok(try('To10:addr', '"Some User"@foo'));
+ok(try('To11:addr', '"Some User"@foo'));
+

Propchange: spamassassin/branches/3.1/t/get_headers.t
------------------------------------------------------------------------------
    svn:executable = *