procmail
[Top] [All Lists]

Re: Local redelivery of procmail'd spool?

2001-08-16 01:42:08
Dan Hollis <goemon(_at_)anime(_dot_)net> writes:
I typo'd a global /etc/procmailrc rule, and as a result I have a single
file with 185mb of system-wide mail that needs to be delivered.

Whats a simple way to re-inject the mail back into the system?
...
It looks like there is enough info in the first 'Received:' line of each
message to determine the single unique local recipient for each mail. But
before I go write something from scratch I'd like to know if someone has
done this already.

I don't know of any pre-packaged scripts to do this.  Extracting the
address from the "for" clause of the first Received: header field will
work for those messages which have such a clause.  Messages which were
delivered to multiple recipients don't necessarily have such a clause.

Still, we can handle the easy cases quickly by checking that:

        # Extract the first Received: header field and then look for
        # a "for" clause in it.
        :0 w
        * ^Received:\/.*
        * MATCH ?? [    ]for[   ]+\/<[^>]+>
        ! $MATCH

        :0:
        hard-cases

Run that across the message file with something like
        formail -Y -s procmail /path/to/that/rcfile <mailbox

(In case you haven't learned your lesson regarding testing-before-using,
do so with the above!  I believe it to be correct, but I haven't tested
it at all...)

Note that the above is *quite* different from trying to extract
the for clause from the Received: line in one fell swoop:

        # DON'T USE THIS!!!
        :0 w
        * ^Received:.*[         ]for[   ]+\/<[^>]+>
        ! $MATCH

That'll extract the address from the first Received: header field that
has a "for" clause, which might not be the first Received: header field.
That would be Bad.


So, what do you do with the "hard-cases" messages?  Your best bet is to
look up the unique identifier that your MTA put on the message, as shown
in that first Received: header field, in the MTA maillog, and extract the
list of correct recipients from there.  You'll have to deal with the fact
that there'll be multiple messages in the hard-cases file for each such
identifier--one per final local recipient--and only send each recipient
one copy...and not all of the copies to just one of the recipients.

Don't despair: there might not be too many such messages.  If nothing else
it'll give you an excuse to practice your <language-of-choice> skills.


Philip Guenther

_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail