procmail
[Top] [All Lists]

Re: Removing [somelist] from subject lines

2001-01-21 09:13:41
From: Holger Wahlen <H(_dot_)Wahlen(_at_)gmx(_dot_)de>

Mike A. Harris wrote:

Would the following be correct?

:0
* ^X-BeenThere:(_dot_)*xpert(_at_)XFree86(_dot_)Org
{
    :0hf
    * ^Subject:.*\[Xpert\]
    | sed 's/\[Xpert\] //'

    :0:
    XPERT-XFREE
}

That's fine - just a few details: (1) Do you really need to check
the subject line after you've already identified the message as
coming from the list? Don't all list messages have the "[Xpert]"
added anyway? (2) Your sed script removes "[Xpert] ", with a
trailing space, from the subject line; the lists I know all do
have such a space after the bracket, but it doesn't appear in your
example header, so nothing would happen there. (3) There's no need
to put a "\" before the "]" (though it doesn't do any harm either),
neither in procmail's condition nor in the sed script; only the
"[" has to be escaped.  (4) You might consider adding a "w" flag
to the first recipe in the braces (:0 hfw). This way you have some
kind of safety net: if sed fails, e.g., because of a typo causing a
syntax error in the script, procmail will continue to process the
original message instead of sed's empty output, so you don't lose
anything. In this case here the danger is probably neglectible, but
as soon as you start to have more complicated filters, this can
become useful pretty soon.

All good points.  Now that Mike knows how to do it with sed,
let's simplify things further, process-wise, and call only formail
from within procmail for efficiency's sake.

See "man procmail" for details, and see "man procmailex" and the
FAQs for help with using the "\/" matching tokens.  (Or dredge up
archives to the list from 11/99, I think it was, from me asking
how in blazes it works and the follow-up stellar answers.  :-)

A previous contributor explained about the "f", "h", and "i" flags
already.  So:

:0
* ^X-BeenThere:(_dot_)*xpert(_at_)XFree86(_dot_)Org
{
  :0 fih
  * ^Subject:.*]\/.*
  | formail -I"Subject: $MATCH"

  :0:
  XPERT-XFREE
}

Because procmail is parsimonious favoring the left side of a string
wrt regex expansion (while the "\/" match token is greedy to its
right), other "]" chars that might be in the Subject beyond the one
that ends the part you want to cut won't be bothered.

And, Mike - Wie geht's?

-- 
Netcom has imploded.  Please now use NOTnetcom.com for mail.
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Ex-Netcommies:  Mail "forwards" for free forwarding service!
NOT affiliated with EarthLink, Inc.'s Netcom brand identity.
_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail