On Saturday 09 March 2002 09:39 pm, Rob McMillin wrote:

> Kerry Nice wrote:

> >#this one will only work for me, but if it there, it
> >is 100% GUARANTEED to be spam
> >#not sure how to make a general case for this
> >header KERRYSUBJECT       Subject =~ /kerry_nice/
> >describe KERRYSUBJECT     Personalized subject for
> >Kerry based on email address
> >score KERRYSUBJECT 4.00

> Could be done some other way (allowing expressions?).

OK, I've tried it in a way that will allow for expressions (at least what I 
understood you meant by "expressions").  I've hacked things up so that this 
rule works:

# Don't want to trip rule if whole email adress is in subject
header   USER_NAME    Subject =~ /\b${user_name}(?:[^@]|$)/i
describe USER_NAME    User name found in subject

"$user_name" is a variable global to PerMsgStatus.pm, and can be evaluated in 
regexps.  I've tested and found that, if "$user_name" is changed *after* 
"eval $evalstr" is run for "sub _xyz_tests", the test will use the new value 
of "$user_name", so it should work for checking multiple messages with spamd, 
though I haven't checked a spamd setup.  I have no idea what this does to 
runtimes though, as I haven't benchmarked it, and don't know much about Perl 
internals.

Test regexps can also use the variables "full_name", "first_name", and 
"last_name".

I also changed the get() method of PerMsgStatus so that it will now do the 
right thing for "From:name", like it currently does for "From:addr".

-- 
Visit http://dmoz.org, the world's   | Give a man a match, and he'll be warm
largest human edited web directory.  | for a minute, but set him on fire, and
                                     | he'll be warm for the rest of his life.
[EMAIL PROTECTED]  ICQ: 132152059 |
Index: lib/Mail/SpamAssassin/PerMsgStatus.pm
===================================================================
RCS file: /cvsroot/spamassassin/spamassassin/lib/Mail/SpamAssassin/PerMsgStatus.pm,v
retrieving revision 1.82
diff -u -3 -p -r1.82 PerMsgStatus.pm
--- lib/Mail/SpamAssassin/PerMsgStatus.pm	7 Mar 2002 10:51:22 -0000	1.82
+++ lib/Mail/SpamAssassin/PerMsgStatus.pm	10 Mar 2002 07:20:34 -0000
@@ -38,7 +38,7 @@ use Mail::SpamAssassin::EvalTests;
 use Mail::SpamAssassin::AutoWhitelist;
 
 use vars	qw{
-  	@ISA $base64alphabet
+  	@ISA $base64alphabet $user_name $first_name $last_name $full_name
 };
 
 @ISA = qw();
@@ -72,6 +72,18 @@ sub check {
   my ($self) = @_;
   local ($_);
 
+  my $address = $self->get("To:addr");
+  my $name    = $self->get("To:name");
+
+  $full_name = $name;
+
+  $address =~ /^(.+)\@/;
+  $user_name = quotemeta($1 || "NO_USERNAME_FOUND");
+
+  $name =~ /^(\S+)?.*(\S+)?$/;
+  $first_name = quotemeta($1 || "NO_FIRST_NAME_FOUND");
+  $last_name  = quotemeta($2 || "NO_LAST_NAME_FOUND");
+
   # in order of slowness; fastest first, slowest last.
   # we do ALL the tests, even if a spam triggers lots of them early on.
   # this lets us see ludicrously spammish mails (score: 40) etc., which
@@ -748,6 +765,9 @@ sub get {
   my $getaddr = 0;
   if ($hdrname =~ s/:addr$//) { $getaddr = 1; }
 
+  my $getname = 0;
+  if ($hdrname =~ s/:name$//) { $getname = 1; }
+
   my @hdrs = $self->{msg}->get_header ($hdrname);
   if ($#hdrs >= 0) {
     $_ = join ("\n", @hdrs);
@@ -774,6 +794,11 @@ sub get {
     chomp; s/\r?\n//gs;
     s/^.*?<(.+)>\s*$/$1/g		# Foo Blah <jm@foo>
     	or s/^(.+)\s\(.*?\)\s*$/$1/g;	# jm@foo (Foo Blah)
+
+  } elsif ($getname) {
+    chomp; s/\r?\n//gs;
+    s/^[\'\"]*(.*?)[\'\"]*\s*<.+>\s*$/$1/g # Foo Blah <jm@foo>
+    	or s/^.+\s\((.*?)\)\s*$/$1/g;	   # jm@foo (Foo Blah)
 
   } else {
     $_ = $self->mime_decode_header ($_);

Reply via email to