Re: [Exim] Rerunning messages through exim

Αρχική Σελίδα
Delete this message
Reply to this message
Συντάκτης: Odhiambo G. Washington
Ημερομηνία:  
Προς: exim-users
Αντικείμενο: Re: [Exim] Rerunning messages through exim
* John Jetmore <jetmore@???> [20031209 16:38]: wrote:
> On Tue, 9 Dec 2003, Odhiambo G. Washington wrote:
>
> > It was called resend.pl. I don't know who posted it but here is a copy.
>
> I believe that was my script, inline below. After I posted this the first
> time someone responded that formail from the procmail package did this
> type of stuff, but I've never investigated.


It must have been me? I do that stuff with formail, even for mail in Maildir/
. I must swear I have never checked the headers to see if they undergo mods
in the process, but the mail has always been delivered correctly.

For mbox I do
formail -Y -s sendmail some@address < /path/to/mbox

For maildir, I've done

for mail in `ls -1`; do formail -Y -s sendmail some@address < $mail; done

Of course I do move the mbox (or Maildir/) to a different name before I do this
so that I do not end up with two copies of each mail.



> I also noticed that I wrote this on solaris and it uses /usr/lib/sendmail instead of
> /usr/sbin/sendmail. Most people probably want to change it.
>
> --John


If the original one (whose copy I have) was written by you, then it seems to have
undergone alot of changes, since the one in my possession behaves differently ;)
Here..


<cut>

#! /usr/local/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/local/sbin/exim";
$usage = "resend.pl <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
</cut>

I must swear I haven't used this script ever since I first saw it.

In a few days, I will need to move thousands of mail from

/var/spool/$domain/$user -> /var/spool/$domain/$user/Maildir

/var/spool/$domain/$user is Maildir in itself because it contains
new, cur, tmp.
I am thinking of writing a small shell script to do this but would
appreciate some other script from a "quick thinking" expert;)



        cheers
       - wash
+----------------------------------+-----------------------------------------+
Odhiambo Washington                     . WANANCHI ONLINE LTD (Nairobi, KE)  |
<wash at wananchi dot com>              . 1ere Etage, Loita Hse, Loita St.,  |
GSM: (+254) 722 743 223                 . # 10286, 00100 NAIROBI             |
GSM: (+254) 733 744 121                 . (+254) 020 313 985 - 9             |
+---------------------------------+------------------------------------------+
"Oh My God! They killed init! You Bastards!"
                         --from a /. post