procmail
[Top] [All Lists]

Re: Is it possible to both add and delete headers in a single call to formail?

1997-07-05 13:32:00
Jeremy Mathers asked,

| Actually, I'd like to use a single call to formail to do all of the following:
| 
|       1) Delete all the other headers except From: and Subject:
|       2) Split an execute a program on each email.
|       3) Add a custom header
| 
| I can get 1 and 2 by doing:
| 
|       formail -k -XFrom: -XSubject: -s someprogram < somefile
| 
| But whenever I try to add a -a/-A/-i/-I to the mix, it just gets ignored.
| Is there any reason why the following should not work?
| 
|       formail -A"X-Foo-Bar: This is the foobar header" -k -XFrom: -XSubject: 
-s someprogram < somefile

Yes: formail, regardless of the sequence of options on the command line,
saves -x and -X for last.  You're telling formail to do some extractions but
not to extract X-Foo-Bar:.  Try this:

  formail -A"X-Foo-Bar: This is the foobar header I found on the Midway." \
        -XFrom: -XSubject: -XX-Foo-Bar: -ks someprogram < somefile

| Does the placement of the -A and or the -k matter?

No.  Formail rearranges its command line options -- at least those that
precede -s -- its own internally preset way, often producing counterintuitive
or downright silly results (why would you add a header here, for example,
only to let it vanish?).  I've suggested to Stephen that formail could use
a -L(iteral) or -V(erbatim) or -S(equential) option to say, "process command
line options in order of their appearance" so that we get the results we
expect, but he turned me down.

So even if Jeremy had put -A after the -X's, it would still be necessary
to specify -XX-Foo-Bar: as well (but one could put -XX-Foo-Bar: before
-A"X-Foo-Bar: something").

Here's another example of formail's strange resequencing of options.  Say
you want to drop the garbled From: and move Reply-To: to From:.  This looks
sensible,

   formail -I From: -R Reply-To: From:

but formail will do the -R first and then delete *both* From: headers (the
original and the one that was renamed from Reply-To:)!  This, however, will
accomplish the task:

   formail -i From: -R Reply-To: From: -I Old-From:

because apparently formail does -i before -R.

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