(Note: I haven't tried this sort o' thing before, so this is
guesswork, and untested to boot).
I believe you should be able to do this with a minimum of external
program invocations, with great precision.
This will have to happen in two passes, because procmail will only
take one action in a given recipe, and you have two actions to take:
first, filter the subject header, and second, deliver the message
into a folder. There are plenty of ways to write this, but the two
commonest would probably be either:
:0 fW
* ^X-Mailing-List: .*idiot-list@
* ^Subject: \[idiot-list\] *\/.*
| formail -I"Subject: $MATCH"
:0 a:
IDIOT-LIST
There are some who find procmail's flow of control flags to be
creepy beyond words, actually hair-raisingly horrifying, and avoid
them wherever possible; we'd probably rather write that
:0
* ^X-Mailing-List: .*idiot-list@
* ^Subject: \[idiot-list\] *\/.*
{
:0 fW
| formail -I"Subject: $MATCH"
:0:
IDIOT-LIST
}
As a separate matter, I've seen such idiot lists creating seriously
irritating strings of Subject: [idiot-list] Re: [idiot-list] ...
stuff, and so I'd probably be tempted to write the Subject pattern
as
* ^Subject: .*\[idiot-list\] *\/.*
Now to explain what I'm doing here. The Subject pattern is using a
bit of procmail weirdness; if you deposit a \/ (think of it as a
pointer) into the middle of a regexp, procmail will capture
everything that follows it into the variable MATCH. This is
procmail's version of the more traditional parenthesized
subexpressions for capturing parts of a match.
The "f" flag says that a recipe is a filter, and should be combined
with "W", so that procmail will pay attention to the exit status of
the filtering command, and not trust it if it fails. Otherwise a
failing filter can silently eat a message. In the first approach I
gave, the second recipe uses the "a" flag, which means it will only
execute if the previous recipe executed and succeeded. In the second
version, I use the braces block construct, which makes one big
recipe, whose action is the block containing the two little
action-only recipes.
And the last bit, when you want to whack on the headers of a
message, don't turn to sed, turn to formail, it is brilliant about
transforming email messages with great control. formail comes with
procmail, and is a whole drawer full of helpful tools packed into
one oddly lumpy and misshapen wad. Picture here a dachshund that
just ate a kitchenaid mixer.
-Bennett
pgp70JuwXElA5.pgp
Description: PGP signature