procmail
[Top] [All Lists]

Re: Removing pesky Subject line tags

1997-08-06 23:38:00
On Thu, 07 Aug 1997 00:58:35 -0400, "Lance A. Brown"
<brown9(_at_)niehs(_dot_)nih(_dot_)gov> wrote:
Several of the mailing lists I receive have started adding those pesky
[LISTNAME] or {listname} tags to their Subject lines.
I've developed this recipe to get rid of them but it seems rather
inefficient.  Can anyone suggest improvements?

You can save some processes by doing the extraction part right in
Procmail, using the \/ token to grab the part you want into MATCH.

:0
* ^TOxxx@
{
    NEW_SUBJECT=`formail -XSubject: | sed -e "s/\[XXX\] //"`

    :0 fh
    | formail -i "$NEW_SUBJECT"

You can change this to

    :0
    * ^TOxxx@
    * ^Subject:[        ]*\[[^]]+\][    ]*\/[^  ].*
    {
        :0fhw
        | formail -i "Subject: $MATCH"
    ...

Do you really want to preserve the old Subject: as Old-Subject:?
(If not, use -I instead of -i)

/* era */

The tricky regular expression consists of:

    [   ]* any number of whitespace (that's a space and a tab)
    \[     literal opening bracket
    [^]]+  any number of characters other than closing bracket
    \]     literal closing bracket (the backslash is not strictly required)
    [   ]* more whitespace
    \/     MATCH token
    [^  ]  one non-whitespace character
    .*     the rest of the line

This recipe will un-wrap any wrapped Subject lines as a side effect.

-- 
Defin-i-t-e-ly. Sep-a-r-a-te. Gram-m-a-r.  <http://www.iki.fi/~era/>
 * Enjoy receiving spam? Register at <http://www.iki.fi/~era/spam.html>

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