procmail
[Top] [All Lists]

Re: Appending text to subject line

2000-02-14 05:34:27
On Sun, 13 Feb 2000 10:41:37 -0600 (CST), Glen Lee Edwards
<GLEdwards(_at_)uswest(_dot_)net> wrote:
Speaking as one totally ignorant in Formail, in the following recipe how
does Formail determine which part is being set aside as the $MATCH?

* ^Subject:.*\[SLE\] \/.*

Procmail, not formail, understands the \/ token to mean, if there's a
match, remember the string that matched at this point and to the end
of the match, and put it in the MATCH variable. So Procmail supplies
the grabbed string when you invoke formail -I "Subject: $MATCH" ...
and that also means you are by no means confined to using this with
Formail only. You could say

    :0fhw
    * ^Subject:.*\[SLE\][       ]*\/[^  ].*
    | sed -e "s/^Subject:.*/Subject: $MATCH/"

and accomplish roughly the same thing. Sed is not ideal here because
it is always case sensitive. But you could grab the SuBjEcT header
too, and the capitalization of the grabbed string will be correct for
Sed.

... Okay, maybe we want to discuss how to do that, too, because it's a
little bit more involved. It involves two grabs, because there are two
things we want to remember and pass to Sed.

    :0
    * ^\/Subject:
    {
        # Remember MATCH so we can overwrite it with a new \/ grab operation
        SUBJECT=$MATCH

        # Grab the part of the tail we want to keep (same as earlier)
        :0fhw
        * ^Subject:.*\[SLE\][   ]*\/[^  ].*
        | sed -e "s/$SUBJECT.*/Subject: $MATCH/"
    }

This also has the hiiiiiiiighly valued side effect of returning the
capitalization of the Subject: header to the canonical form, with
uppercase S, rest in lowercase.

/* era */

-- 
 Too much to say to fit into this .signature anyway: <http://www.iki.fi/era/>
  Fight spam in Europe: <http://www.euro.cauce.org/> * Sign the EU petition