Description: |
I've been having trouble with spammers using my domain + a random username to send spam from. Dealing with the bounces was annoying - I'd need to check each one to see if it was genuine.
The following code looks for bounces, changes the subject to Bounced: email@email.com, where the email address is where the email was bounced to, and adds a header I can use to send it to an appropriate place with procmail. For example:
May 12 System Administ ( 153) Bounced: bobf@clueball.com |
#!/usr/bin/perl
# Simple script for catching email bounces
use strict;
use Email::Simple;
# Configuration
my @valid_email = qw( pete@clueball.com sheriff@linuxufo.com );
my $modify_subj = 1;
# Gubbins
my $email_source = join '', (<>);
my $email = Email::Simple->new($email_source);
my ( $subject, $to ) = ($email->header("Subject"), $email->header(
+"To"));
unless (
( $email->header("Return-path") eq '<>' ) ||
( $email->header("Auto-Submitted") ) ||
( $email->header("Return-path") =~ m/MAILER-DAEMON\@/i )
+ ||
( $email->header("Sender") =~ m/^CompuServe Postmaster/) |
+|
(
($email->header("From") =~ m/postmaster\@/) &&
( $email->header("Subject") =~ m/Undeliverable/ )
)
) {
dump_mail();
}
for ( @valid_email ) {
my $email_address = quotemeta $_;
dump_mail() if $to =~ m/$email_address/i;
}
$email->header_set("Subject", "[Bounced: $to]");
$email->header_set("X-SpamBounce", $to);
dump_mail();
# Return mail
sub dump_mail {
print $email->as_string;
exit;
}
|