#! /usr/bin/perl # This is a utility script to read a mailbox with BSD separators, and # resend all the messages to a given address. The first argument is # the name of the mailbox file; the second is the recipient address. # You need to run this as root, or another trusted Exim user in order # to get the senders correctly set. Pushing the messages back through # Exim causes an additional Received: header to be added. This is probably # no bad thing. $exim = "/usr/lib/sendmail"; $usage = "resend-mailbox \n"; $file = shift(@ARGV) || die $usage; $recipient = shift(@ARGV) || die $usage; open(INPUT, "$file") || die "can't open $file\n"; while() { if ($_ =~ /^From\s+(\S+)\s+(?:[a-zA-Z]{3},?\s+)? # Common start (?: # Non-extracting bracket [a-zA-Z]{3}\s+\d?\d | # First form \d?\d\s+[a-zA-Z]{3}\s+\d\d(?:\d\d)? # Second form ) # End alternation \s+\d\d?:\d\d? # Start of time /x) { close OUTPUT; # If open from previous $from = ($1 =~ /^mailer-daemon$/i)? "<>" : $1; print "Message from $from\n"; open(OUTPUT, "| $exim -f '$from' '$recipient'"); } else { print OUTPUT $_; } } close OUTPUT; close INPUT; print "Sent contents to $recipient\n"; # End