Re: [Exim] resend

Pàgina inicial
Delete this message
Reply to this message
Autor: Jim Pazarena
Data:  
A: exim-users
Assumpte: Re: [Exim] resend
here is a script *I* use to resend email preserving header info

.. this is not my creation; can't remember where I scooped it from.

-

#! /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 = "/u/exim/bin/exim";
$usage = "resend.sh <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 -oMr resend -f '$from' '$recipient'");
    }
  else { print OUTPUT $_; }
  }


close OUTPUT;
close INPUT;
print "Sent contents to $recipient\n";

# End

--

--
Jim Pazarena     mailto:paz@ccstores.com
                 http://www.qcislands.net/paz