procmail
[Top] [All Lists]

Re: Munging Subject field

1996-09-05 23:47:36
I wrote:
# Get the Submit: header (this is the list name?)
:0
* ^Submit: *\/.*
{ SUBMIT = $MATCH }
...etc


As David Tamkin <dattier(_at_)wwa(_dot_)com> has so kindly reminded me, because 
of
procmail's minimal matching on the left hand side of the \/ token, the
" *" after the colon will never match anything.  This will cause all
the following recipes to fail.  For the solution, I'll quote myself
from a message to the list in June:

Because of the minimal matching on the left hand side of the \/,
you almost always want the first character to the right of the \/ to be
unqualified by '*' or '?', as doing so may let procmail match almost
nothing on the left hand side, then match nothing at all on the left.
By forcing at least one character to be, say, a non-whitespace with
"[^    ]" you can be sure that *something* will be matched on the
right hand side, which will give the regexp matcher a foothold for
matching more.


(There's something which is supposed to go before your sanity does,
but I can never remember what it is.)


Therefore, my solution should instead be written, in toto:
(In Toto?  "Outside of a dog, a book is man's best friend..."
Tonight just seems like a night for word associations.)


# Setup a variable containing what almost every regexp below should
# end with.  We'll then use the '$' flag to expand the variable in
# the condition.  Both the brackets in the next line contain a space
# and a tab.
regexptail = "[         ]*\/[^  ].*"

# Get the Submit: header (this is the list name?)
:0
* $ ^Submit:$regexptail
{ SUBMIT = $MATCH }

# Get the Submit: header (this is the list name?)
:0
* $ ^Submit:$regexptail
{ SUBMIT = $MATCH }

# Grab the current Subject: header.
:0
* $ ^Subject:$regexptail
{ SUBJECT = $MATCH }

# Is this a "re:?  If so, chop it, but remember that it's there.
:0
* $ SUBJECT ?? ^re:$regexptail
{
    RE = "Re: "
    SUBJECT = $MATCH
}

# Chop a the listname from the subject if it's already there.
:0
* $ SUBJECT ?? ^$SUBMIT:$regexptail
{ SUBJECT = $MATCH }

# Okay, now put it back together.  The commented out action line can be
# used if you want the Re: to come before the listname.
:0 wfh
| formail -i"Subject: $SUBMIT: $RE$SUBJECT"
#| formail -i"Subject: $RE$SUBMIT: $SUBJECT"


Philip Guenther

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