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 2006/05/16 19:39:48 UTC

svn commit: r407006 - in /spamassassin/rules/trunk/sandbox/jm: 20_sendmailid.cf SendmailID.pm

Author: jm
Date: Tue May 16 10:39:47 2006
New Revision: 407006

URL: http://svn.apache.org/viewcvs?rev=407006&view=rev
Log:
experiment with a sandbox plugin

Added:
    spamassassin/rules/trunk/sandbox/jm/20_sendmailid.cf
    spamassassin/rules/trunk/sandbox/jm/SendmailID.pm

Added: spamassassin/rules/trunk/sandbox/jm/20_sendmailid.cf
URL: http://svn.apache.org/viewcvs/spamassassin/rules/trunk/sandbox/jm/20_sendmailid.cf?rev=407006&view=auto
==============================================================================
--- spamassassin/rules/trunk/sandbox/jm/20_sendmailid.cf (added)
+++ spamassassin/rules/trunk/sandbox/jm/20_sendmailid.cf Tue May 16 10:39:47 2006
@@ -0,0 +1,12 @@
+
+loadplugin Mail::SpamAssassin::Plugin::SendmailID SendmailID.pm
+
+# thanks to BC for this tip
+ifplugin Mail::SpamAssassin::Plugin::SendmailID
+header JM_RCVD_SENDMAILID  eval:check_sendmail_id()
+endif
+
+header JM_RCVD_QMAILV1     Received =~ /by \S+ \(Qmailv1\) with ESMTP/
+
+header JM_LC_MID           ALL =~ /\nmessage-id: /s
+

Added: spamassassin/rules/trunk/sandbox/jm/SendmailID.pm
URL: http://svn.apache.org/viewcvs/spamassassin/rules/trunk/sandbox/jm/SendmailID.pm?rev=407006&view=auto
==============================================================================
--- spamassassin/rules/trunk/sandbox/jm/SendmailID.pm (added)
+++ spamassassin/rules/trunk/sandbox/jm/SendmailID.pm Tue May 16 10:39:47 2006
@@ -0,0 +1,79 @@
+=head1 NAME
+
+Mail::SpamAssassin::Plugin::SendmailID
+
+=head1 SYNOPSIS
+
+ loadplugin Mail::SpamAssassin::Plugin::SendmailID [/path/to/SendmailID.pm]
+
+=cut
+
+package Mail::SpamAssassin::Plugin::SendmailID;
+
+use Mail::SpamAssassin::Plugin;
+use strict;
+use warnings;
+
+use Time::ParseDate;
+
+our @ISA = qw(Mail::SpamAssassin::Plugin);
+
+sub new {
+  my $class = shift;
+  my $mailsaobject = shift;
+
+  $class = ref($class) || $class;
+  my $self = $class->SUPER::new($mailsaobject);
+  bless ($self, $class);
+
+  $self->register_eval_rule("check_sendmail_id");
+
+  return $self;
+}
+
+sub check_sendmail_id {
+  my ($self, $pms) = @_;
+
+  my $rcvd = $pms->get("Received");
+  $rcvd =~ s/\s+/ /gs;
+  while ($rcvd =~ / \(8\.[^\/]+\/8\.\S+\) with ESMTP id (\S+) for <[^>]+>; (\S+ \S+ \S+ \S+ ..:..:.. \S+)/g)
+  {
+    my $id = $1;
+    my $date = $2;
+    my $time = Mail::SpamAssassin::Util::parse_rfc822_date($date);
+    if (!$time) {       # Time::ParseDate failed
+      return 1;
+    }
+
+    my $id2 = time2smid($time);
+    # warn "JMD $id $id2";
+    $id =~ s/^(....).*$/$1/;
+
+    if ($id ne $id2) {
+      return 1;
+    }
+  }
+
+  return 0;
+}
+
+
+sub time2smid {
+  my $time = shift;
+  my $qidchars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
+  my $QIC_LEN = 60;
+  my $QIC_LEN_R = 62;
+  my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday) = gmtime $time;
+  my @c = split (//, $qidchars);
+
+  my $str =
+    $c[$year % $QIC_LEN] .
+    $c[$mon] .
+    $c[$mday] .
+    $c[$hour];
+    # . $c[$min % $QIC_LEN_R]
+    # . $c[$sec % $QIC_LEN_R];
+  return $str;
+}
+
+1;