Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Spam bounces catcher

by sheriff (Sexton)
on May 12, 2003 at 09:45 UTC ( [id://257375]=sourcecode: print w/replies, xml ) Need Help??
Category: E-Mail Programs
Author/Contact Info
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;

    }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://257375]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (7)
As of 2024-03-28 19:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found