procmail
[Top] [All Lists]

Re: Subject replacement

1998-05-07 22:58:09
On Thu, 7 May 1998, Bryan Albright wrote:

Hey all--

I've got a subject that's waaay to big for my mailer index to see all
of, and I want to change the subject

from:
      Trafficview Report: Estimated freeway driving time is 13.7 minutes.
to:
      Drive Time: 13.7 minutes

What's the best way to set up a recipe to do so?

If you ask for the _best_ way to do something simple, you'll get at least
a dozen replies, and start a two-week thread! Weell, I'll offer two ways.
None claim to be 'best'.

If the subject line always follows a predictable pattern, then you use
some regexp to pick out the portion you want and rewrite the subject line
with formail. For example: 

    :0 fhw # "fhw" means filter the header and wait for the program to exit.
    * ^Subject: Trafficview Report: Estimated freeway driving time is \
    ()\/[.0-9]+.*
    | formail -I"Subject: Drive Time: $MATCH"

This filters the subject. MATCH would be the part beginning with a string
of numerals, or possibly a dot. The regexp isn't perfect, but I don't know
what all the possible patterns could look like.

An alternate way is to use sed to strip out some of the fat of the text.

        :0 fhw
        * ^Subject: Trafficview Report: Estimated freeway driving time is
        | sed 's/^Subject: Trafficview Report: Estimated freeway/Subject:/'

This results in "Subject: driving time is 13.7 minutes."

David Hunt

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