[Mimedefang] Redirecting spam
Rob MacGregor
rob.macgregor at gmail.com
Mon Oct 3 16:42:14 EDT 2005
On 03/10/05, Ashley M. Kirchner <ashley at pcraft.com> wrote:
>
> I want to redirect messages that would otherwise be bounced due to
> high spam score to a local mailbox instead. After searching the
> archives, I came across the following snippet:
>
> # Add a header with original recipients, just for info
> action_add_header("X-Orig-Rcpts", join(", ", @Recipients));
>
> # Remove original recipients
> foreach $recip (@Recipients) {
> delete_recipient($recip);
> }
>
> # Send to spam address
> add_recipient('spamdrop at mydomain.net');
>
>
> I presume this ends up in filter_end()?
Yes, though you may find this useful. This adds the original email as
a plain text attachment with the SA report as the email it's attached
to. It was shamelessly stolen from somebody else's posting some time
back.
Note that action_rebuild() is critical - if you don't call it the
email doesn't get built!
#### BEGIN ####
# This is going to be spam, so it gets wrapped
md_graphdefang_log('SPAM', $hits, $RelayAddr);
# Record who it was for
action_add_header("X-Orig-Rcpts", join(", ", @Recipients));
# Remove oroginal recipients
foreach $recip (@Recipients) {
delete_recipient($recip);
}
# Send to the spam mailbox
add_recipient('spam at example.net');
# A container for the original message
my $raw_container = MIME::Entity->build(
Type => 'text/plain',
Description => 'Raw message',
Data => [ "" ],
);
my $parser = new MIME::Parser;
open(IN, '< INPUTMSG');
my $original = $parser->parse(\*IN);
close(IN);
$original->head()->replace('X-Relay-Addr', $RelayAddr);
$RelayHostname ||= 'N/A';
$original->head()->replace('X-Relay-Host', $RelayHostname);
$original->head()->replace('X-Relay-Time', scalar(localtime));
# Add the original message to the container
$raw_container->add_part($original);
my $reportPart = MIME::Entity->build(
Type => 'text/plain',
Description => 'spam warning',
Data => [
$report
],
);
$entity->parts([$reportPart]);
$entity->head()->mime_attr('content-type' => 'multipart/mixed');
$entity->head()->mime_attr('content-type.boundary'
=> '------------=_' . scalar(time) .
"-$$-nikc");
$entity->add_part($raw_container);
action_change_header('Subject', "SPAM ($hits): $Subject");
action_rebuild();
#### END ####
--
Please keep list traffic on the list.
Rob MacGregor
Whoever fights monsters should see to it that in the process he
doesn't become a monster. Friedrich Nietzsche
More information about the MIMEDefang
mailing list