procmail
[Top] [All Lists]

Re: re-filtering messages in a mailbox

1998-09-25 15:10:45
I swear there are posts I'm not receiving.  Sean Straw wrote in reply to
an article from Jonathan Crockett that I never saw, where Jonathan must
have asked how to use

C> procmail to refilter all the individual messages contained in this mailbox?

S> formail -b -s procmail < mailbox

S> should do the trick (you may or may-not want to use -b).  Make sure to move
S> the input mailbox somewhere so that it isn't the OUTPUT mailbox of any of
S> your procmail rules - if you don't, you could be in for a nasty loop.

Sean's use of "nasty" is a greatly restrained understatement.  It is vital
to prevent that loop, or procmail will add copies of messages to the end of
the input file, and formail will find them there and invoke procmail again,
and not only will formail keep running and keep forking procmails (the
procmails will exit, but formail will keep forking another and another), and
meanwhile the input file will grow and grow.

If you cannot mv the input mailbox to a place where the rcfile won't add to
it, there is an alternative.  Count the messages in the input first and
tell formail to stop after finding that number of messages [unless it exits
sooner by reaching the end of the input].  Of two basic approaches,

  formail -b -`grep -c '^From ' mailbox` -s procmail < mailbox

is more efficient but may count a message or two too many if there are
embedded unescaped "From "s protected by Content-Length: headers, which grep
won't notice.

This way is more reliable but involves more cycles:

 msgcount=`formail -I'From x' -x'From ' -s | wc -l`
 formail -b -$msgcount -s procmail < mailbox

<Prev in Thread] Current Thread [Next in Thread>