On 27 Jul 1999 nbecker@??? wrote:
> This isn't really exim-specific. Suppose a batch of mail is delivered
> to a file. Now you want to requeue it for delivery elsewhere. For
> example, suppose someone left the company, and now you want to forward
> all his mail - but he already has mail in /var/mail/user. What's an
> easy way to do this? That is - so he receives the mail as individual
> messages - not as one big mail.
This is sufficiently small that I am just going to post it. It
originated from an Exim user who had the same problem.
--
Philip Hazel University of Cambridge Computing Service,
ph10@??? Cambridge, England. Phone: +44 1223 334714.
#! /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 <mailbox file> <recipient>\n";
$file = shift(@ARGV) || die $usage;
$recipient = shift(@ARGV) || die $usage;
open(INPUT, "$file") || die "can't open $file\n";
while(<INPUT>)
{
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