On Wed, 7 Apr 1999, Serge Koudrya wrote:
MK> Is there an easy way to extract part of the Subject line
MK> into a variable in procmail?
MK> Example:
MK> Subject: [xx] re: test
MK> I would like to assign the "xx" in the squarebrackets into a variable.
Here's the solution provided by Philip Guenther
<guenther(_at_)gac(_dot_)edu>:
How can I get procmail to strip this when handling mail from this list?
# Extact everything in the Subject: header after the "[911] "
# and use formail to make that the new Subject:
:0 fhw
* ^Subject: *\[911\] \/.*
|formail -I"Subject: $MATCH"
Unfortunately, this grabs "re: test" for the above example, whereas they
wanted the "xx" (or "911"). I tried a few simple recipes at home earlier
this morning, but was unsuccessful. Things like
:0
* ^Subject: \[\/[^\]+]\] peculiar subject
{ VARIABLE=$MATCH }
with "Subject: [hi] peculiar subject"
but then you end up with
VARIABLE="hi] peculiar subject"
You could $MATCH the entire subject, then fiddle with it with perl
(ie: $MATCH =~ s/\[([^\]]+)\].*/$1/;), but elegant solutions are escaping
me.
It might help to know what the purpose of the "xx" variable's life will
be.
-jeff
----
" ... and isn't sanity really just a one-trick pony anyway? I mean, all
you get is one trick: rational thinking. But when you're good and crazy
... ooh hoo hoo! They sky's the limit!" - The Tick