#!/usr/bin/perl # infect (07/01/2001) # # forward quarantined mail (stopped by amavis-perl) to recipient(s). # It requires a version of amavis-perl adding "X-Quarantined-From:" # and "X-Quarantined-To:" fields at the top of the headers of # quarantined mails. # # Usage: infect . If no argument is given, the standard # input is used. A confirmation is requested (interactively) # for each recipient. # # It must be configured by indicating a $mailhost and a $port # that do not feed the message through amavis-perl again. # It requires Net::SMTP. # # Furio Ercolessi, Spin Internetworking (spin.it). # # Licensing information: do whatever you want with this script. # There is no warranty. The author brings no responsibility for # any problem or damage related with the use of this script. use Net::SMTP; ################################################ to be configured: $mailhost = "localhost"; $port = 10025; ################################################################## open(TTY,"/dev/tty"); # There! To ensure it won't run on NT. $smtp = Net::SMTP->new($mailhost, Port => $port); while (<>) { if (/^X-Quarantined-From:\s*(.*)\s*$/) { print STDERR "Infected mail from $1:\n"; $smtp->mail($1); $from_found=1; } elsif (/^X-Quarantined-To:\s*(.*)\s*$/) { print STDERR "------> send on to $1 (n/y) ? "; $answ = ; chop $answ; if ( uc($answ) eq "Y" ) { $smtp->to($1); $to_found = $to_found . " " . $1; } } else { # first line of regular message headers last; } } if ( $from_found && $to_found ) { $smtp->data(); $smtp->datasend($_); # first line of regular message headers while (<>) { # rest of message $smtp->datasend($_); } $smtp->dataend(); $smtp->quit; print STDERR "Infected email sent to$to_found.\n"; } else { # no transmission $smtp->quit; if ( $from_found ) { print STDERR "No recipient selected, infected email not sent.\n"; } else { print STDERR "No sender found (missing X-Quarantine-From: ?)" . ", infected email not sent.\n"; } } close(TTY);