Ben Cantrick (mackys) wrote,
Ben Cantrick
mackys

Say goodbye to procmail forever.


Mail::Audit is officially my favorite PERL module ever:

Mail::Audit itself isn't a mail filter - it's a toolkit that makes it very easy for you to build mail filters. You write a program that describes what should happen to your mail, and this replaces your procmail command in your .forward or .qmail file.

Mail::Audit provides the functionality for extracting mail headers, bouncing, accepting, rejecting, forwarding, and filtering incoming mail.

Here's the simplest filter program we can make with Mail::Audit.

use Mail::Audit;
my $incoming = Mail::Audit->new;
$incoming->reject;


If you save this as ~/bin/chuckmail, then you can put the following in a .forward file:

|~/bin/chuckmail

Every mail message you receive will now pass through this program. The mail comes into the program via standard input, and the new() method takes it from there and turns it into a Mail::Audit object.

Next, we bounce it as undeliverable:

$incoming->reject;

We could even get fancy, and supply a reason with the bounce:

$incoming->reject(<<EOF);
The local user was silly enough to leave chuckmail as his
mail filter. Too bad you can't mail him to let him know.
EOF


This reason will be relayed back to the sender as part of the bounce message.


http://www.perl.com/pub/a/2001/07/17/mailfiltering.html?page=1
Subscribe
  • Post a new comment

    Error

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 0 comments