Mailing List Archive

svn commit: rev 6212 - in incubator/spamassassin/trunk: . lib/Mail lib/Mail/SpamAssassin lib/Mail/SpamAssassin/MIME
Author: felicity
Date: Sun Jan 18 10:58:37 2004
New Revision: 6212

Modified:
incubator/spamassassin/trunk/lib/Mail/SpamAssassin.pm
incubator/spamassassin/trunk/lib/Mail/SpamAssassin/MIME.pm
incubator/spamassassin/trunk/lib/Mail/SpamAssassin/MIME/Parser.pm
incubator/spamassassin/trunk/lib/Mail/SpamAssassin/NoMailAudit.pm
incubator/spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm
incubator/spamassassin/trunk/spamassassin.raw
Log:
get rid of the last 'delivery' code (log-to-mbox), move pristine header into the mime parser.

Modified: incubator/spamassassin/trunk/lib/Mail/SpamAssassin.pm
==============================================================================
--- incubator/spamassassin/trunk/lib/Mail/SpamAssassin.pm (original)
+++ incubator/spamassassin/trunk/lib/Mail/SpamAssassin.pm Sun Jan 18 10:58:37 2004
@@ -70,10 +70,8 @@

if ($status->is_spam ()) {
$status->rewrite_mail ();
- $mail->accept("spamfolder");
-
} else {
- $mail->accept(); # to default incoming mailbox
+ ...
}
...


Modified: incubator/spamassassin/trunk/lib/Mail/SpamAssassin/MIME.pm
==============================================================================
--- incubator/spamassassin/trunk/lib/Mail/SpamAssassin/MIME.pm (original)
+++ incubator/spamassassin/trunk/lib/Mail/SpamAssassin/MIME.pm Sun Jan 18 10:58:37 2004
@@ -71,9 +71,10 @@
$class = ref($class) || $class;

my $self = {
- headers => {},
- raw_headers => {},
- body_parts => [],
+ headers => {},
+ raw_headers => {},
+ body_parts => [],
+ header_order => [],
};

bless($self,$class);
@@ -122,6 +123,7 @@
if (@_) {
my ( $decoded_value, $raw_value ) = @_;
$raw_value = $decoded_value unless defined $raw_value;
+ push @{ $self->{'header_order'} }, $rawkey;
if ( exists $self->{'headers'}{$key} ) {
push @{ $self->{'headers'}{$key} }, $decoded_value;
push @{ $self->{'raw_headers'}{$key} }, $raw_value;

Modified: incubator/spamassassin/trunk/lib/Mail/SpamAssassin/MIME/Parser.pm
==============================================================================
--- incubator/spamassassin/trunk/lib/Mail/SpamAssassin/MIME/Parser.pm (original)
+++ incubator/spamassassin/trunk/lib/Mail/SpamAssassin/MIME/Parser.pm Sun Jan 18 10:58:37 2004
@@ -64,15 +64,15 @@
}

# trim mbox seperator if it exists
- shift @message if ( scalar @message > 0 && $message[0] =~ /^From\s/ );
+ shift @message if ( @message > 0 && $message[0] =~ /^From\s/ );

# Generate the main object and parse the appropriate MIME-related headers into it.
my $msg = Mail::SpamAssassin::MIME->new();
my $header = '';

while ( my $last = shift @message ) {
- $last =~ s/\r\n/\n/;
- chomp($last);
+ $msg->{'pristine_headers'} .= $last;
+ $last =~ s/\r?\n//;

# NB: Really need to figure out special folding rules here!
if ( $last =~ s/^[ \t]+// ) { # if its a continuation
@@ -91,6 +91,7 @@
last if ( $last =~ /^$/m );
}

+ #$msg->{'pristine_body'} = \@message;
my ($boundary);
($msg->{'type'}, $boundary) = Mail::SpamAssassin::Util::parse_content_type($msg->header('content-type'));
dbg("main message type: ".$msg->{'type'});

Modified: incubator/spamassassin/trunk/lib/Mail/SpamAssassin/NoMailAudit.pm
==============================================================================
--- incubator/spamassassin/trunk/lib/Mail/SpamAssassin/NoMailAudit.pm (original)
+++ incubator/spamassassin/trunk/lib/Mail/SpamAssassin/NoMailAudit.pm Sun Jan 18 10:58:37 2004
@@ -91,7 +91,6 @@

$self->{is_spamassassin_wrapper_object} = 1;
$self->{has_spamassassin_methods} = 1;
- $self->{headers_pristine} = '';
$self->{headers} = { };
$self->{header_order} = [ ];

@@ -109,7 +108,7 @@
}

# Parse the message for MIME parts
- $self->{mime_parts} = Mail::SpamAssassin::MIME::Parser->parse(join("", @{$self->{textarray}}));
+ $self->{mime_parts} = Mail::SpamAssassin::MIME::Parser->parse($self->{textarray});

# Parse the message to get header information
$self->parse_headers();
@@ -122,15 +121,11 @@
my ($self) = @_;
local ($_);

- $self->{headers_pristine} = '';
$self->{headers} = { };
$self->{header_order} = [ ];
my ($prevhdr, $hdr, $val, $entry);

while (defined ($_ = shift @{$self->{textarray}})) {
- # absolutely unmodified!
- $self->{headers_pristine} .= $_;
-
# warn "parse_headers $_";
if (/^\r*$/) { last; }

@@ -229,7 +224,7 @@

sub get_pristine_header {
my ($self, $hdr) = @_;
- my(@ret) = $self->{headers_pristine} =~ /^(?:$hdr:[ ]+(.*\n(?:\s+\S.*\n)*))/mig;
+ my(@ret) = $self->{mime_parts}->{pristine_headers} =~ /^(?:$hdr:[ ]+(.*\n(?:\s+\S.*\n)*))/mig;
if (@ret) {
return wantarray ? @ret : $ret[0];
}
@@ -359,11 +354,10 @@
}

# ---------------------------------------------------------------------------
-# bonus, not-provided-in-Mail::Audit methods.

sub get_pristine {
my ($self) = @_;
- return join ('', $self->{headers_pristine}, @{ $self->{textarray} });
+ return join ('', $self->{mime_parts}->{pristine_headers}, @{ $self->{textarray} });
}

sub get_pristine_body {
@@ -415,121 +409,10 @@

# ---------------------------------------------------------------------------

-sub accept {
- my $self = shift;
- my $file = shift;
-
- # we don't support maildir or qmail here yet. use the real Mail::Audit
- # for those.
-
- # note that we cannot use fcntl() locking portably from perl. argh!
- # if this is an issue, we will have to enforce use of procmail for
- # local delivery to mboxes.
-
- {
- my $gotlock = $self->dotlock_lock ($file);
- my $nodotlocking = 0;
-
- if (!defined $gotlock) {
- # dot-locking not supported here (probably due to file permissions
- # on the /var/spool/mail dir). just use flock().
- $nodotlocking = 1;
- }
-
- local $SIG{TERM} = sub { $self->dotlock_unlock (); die "killed"; };
- local $SIG{INT} = sub { $self->dotlock_unlock (); die "killed"; };
-
- if ($gotlock || $nodotlocking) {
- my $umask = umask 077;
- if (!open (MBOX, ">>$file")) {
- umask $umask;
- die "Couldn't open $file: $!";
- }
- umask $umask;
-
- flock(MBOX, LOCK_EX) or warn "failed to lock $file: $!";
- print MBOX $self->as_string()."\n";
- flock(MBOX, LOCK_UN) or warn "failed to unlock $file: $!";
- close MBOX;
-
- if (!$nodotlocking) {
- $self->dotlock_unlock ();
- }
-
- if (!$self->{noexit}) { exit 0; }
- return;
-
- } else {
- die "Could not lock $file: $!";
- }
- }
-}
-
-sub dotlock_lock {
- my ($self, $file) = @_;
-
- my $lockfile = $file.".lock";
- my $locktmp = $file.".lk.$$.".time();
- my $gotlock = 0;
- my $retrylimit = 30;
-
- my $umask = 0;
- if (!sysopen (LOCK, $locktmp, O_WRONLY | O_CREAT | O_EXCL, 0644)) {
- umask $umask;
- #die "lock $file failed: create $locktmp: $!";
- $self->{dotlock_not_supported} = 1;
- return;
- }
- umask $umask;
-
- print LOCK "$$\n";
- close LOCK or die "lock $file failed: write to $locktmp: $!";
-
- for (my $retries = 0; $retries < $retrylimit; $retries++) {
- if ($retries > 0) {
- my $sleeptime = 2*$retries;
- if ($sleeptime > 60) { $sleeptime = 60; } # max 1 min
- sleep ($sleeptime);
- }
-
- if (!link ($locktmp, $lockfile)) { next; }
-
- # sanity: we should always be able to see this
- my @tmpstat = lstat ($locktmp);
- if (!defined $tmpstat[3]) { die "lstat $locktmp failed"; }
-
- # sanity: see if the link() succeeded
- my @lkstat = lstat ($lockfile);
- if (!defined $lkstat[3]) { next; } # link() failed
-
- # sanity: if the lock succeeded, the dev/ino numbers will match
- if ($tmpstat[0] == $lkstat[0] && $tmpstat[1] == $lkstat[1]) {
- unlink $locktmp;
- $self->{dotlock_locked} = $lockfile;
- $gotlock = 1; last;
- }
- }
-
- return $gotlock;
-}
-
-sub dotlock_unlock {
- my ($self) = @_;
-
- if ($self->{dotlock_not_supported}) { return; }
-
- my $lockfile = $self->{dotlock_locked};
- if (!defined $lockfile) { die "no dotlock_locked"; }
- unlink $lockfile or warn "unlink $lockfile failed: $!";
-}
-
-# ---------------------------------------------------------------------------
-
# does not need to be called it seems. still, keep it here in case of
# emergency.
sub finish {
my $self = shift;
- delete $self->{headers_pristine};
delete $self->{textarray};
foreach my $key (keys %{$self->{headers}}) {
delete $self->{headers}->{$key};

Modified: incubator/spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm
==============================================================================
--- incubator/spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm (original)
+++ incubator/spamassassin/trunk/lib/Mail/SpamAssassin/PerMsgStatus.pm Sun Jan 18 10:58:37 2004
@@ -72,7 +72,6 @@
my $status = $spamtest->check ($mail);
if ($status->is_spam()) {
$status->rewrite_mail ();
- $mail->accept("caught_spam");
}
...


Modified: incubator/spamassassin/trunk/spamassassin.raw
==============================================================================
--- incubator/spamassassin/trunk/spamassassin.raw (original)
+++ incubator/spamassassin/trunk/spamassassin.raw Sun Jan 18 10:58:37 2004
@@ -85,7 +85,6 @@
'siteconfigpath=s' => \$opt{'siteconfigpath'},
'create-prefs!' => \$opt{'create-prefs'},
'x' => sub { $opt{'create-prefs'} = 0 },
- 'log-to-mbox|l=s' => \$opt{'log-to-mbox'},
'error-code|exit-code|e:i' => \$opt{'error-code'},
'test-mode|test|t' => \$opt{'test-mode'},
'lint' => \$opt{'lint'},
@@ -102,6 +101,7 @@
'whitelist-factory|M=s' => sub { warn "The -M option has been removed.\n" },
'auto-whitelist|a' => sub { warn "The -a option has been removed.\n" },
'warning-from|w=s' => sub { warn "The -w option has been removed.\n" },
+ 'log-to-mbox|l=s' => sub { warn "The -l option has been removed.\n" },
) or usage(0, "Unknown option!");
if (defined $opt{'help'}) { usage(0, "For more information read the spamassassin man page"); }
if (defined $opt{'version'}) {
@@ -123,32 +123,11 @@

my $mail;

-# 1.
-# Standard Mail::Audit start. No longer used due to bugs in M:A, regarding
-# handling of slightly misformatted input.
-#
-# require Mail::Audit;
-# $mail = Mail::Audit->new();
-
-# 2.
-# No use of Mail::Audit at all, apart from the accept(), reject() and
-# resend() methods (which are proxied transparently). Lovely.
-#
use Mail::SpamAssassin::NoMailAudit;
if (!$opt{'lint'} && !$doing_address_only_whitelisting) {
$mail = Mail::SpamAssassin::NoMailAudit->new ();
}

-# For Mail::Audit users -- this is the magic. Just create a Mail::SpamAssassin
-# object like this, then run the check() method as below; if it returns a
-# non-undef value, then you've got spam, otherwise it's normal mail.
-#
-# You can then use the rewrite() method (passing in the Mail::Audit object) to
-# rewrite the spam.
-#
-# (This implementation does other stuff though, such as -t support; ignore that
-# stuff.)
-
# create the tester factory
my $spamtest = new Mail::SpamAssassin ({
rules_filename => $opt{'configpath'},
@@ -172,13 +151,6 @@
if ($levels !~ /^\s*$/) {
usage(0, "bad areas in --debug option ($levels)!");
}
- }
-
-# handle logging of received mails
- if ($opt{'log-to-mbox'}) {
- $mail->{noexit} = 1;
- $mail->accept ($opt{'log-to-mbox'});
- $mail->{noexit} = 0;
}

if ($opt{'lint'}) {