procmail
[Top] [All Lists]

Re: Striping First Word from Subject Line(Again)

1997-01-29 09:20:15
The Subject line in my mailing list messages allways looks like:

[JEEP-L:341278] Sample Text Subject Line

I would like to strip out everything starting withthe first bracket and
ending with the second.

The current recipe that I have is:

 :0
 * ^Subject: *JEEP-L\>.*\/.*
 | formail -I"Subject: $MATCH"

 INBOX.JEEP-L

All it does is strip off the first of the tok untill the colon.  For the
example above it would return ":341278] Sample Text Subject..." for the
subject of the message.  

What am I doing wrong?

Okay, there are several problems here...the first is that you're 
delivering the message to formail and then losing it; if you don't tell 
procmail otherwise, it assumes that when you pipe a message to a program 
you're done with it.

In this case, you want formail to act as a filter, i.e., you want to 
continue processing the stdout from formail.  To do that, you need to add 
the 'f' (filter) option to your recipe:

:0f

At this point, mail still won't be delivered to INBOX.JEEP-L.  As far as 
procmail is concerned, the line:

INBOX.JEEP-L

Is meant to clear a variable called "INBOX.JEEP-L" from the environment.  
Recall, from the procmail man page, that a recipe can have one and only 
one action statement.  In the recipe above, your "action" statement is 
the pipe to formail.

You'll need a second recipe to get the delivery to work; the easiest way 
to do this is probably to use the 'A' flag (think of it as "and"), which 
makes a recipe depend on the execution of the preceding recipe.

:0A
INBOX.JEEP-L

Will make any messages matched by the regular expression in the first 
recipe to be delivered into the local mailbox INBOX.JEEP-L.

The last thing that needs work is the regular expression you're using.  
If you try to match a subject line like this:

Subject: [JEEP-L:341278] Sample Text Subject Line

With a regular expression like this:

Subject: *JEEP-L\>.*\/.*

It's not going to work.  Your regular expression is looking for 
"Subject:", at the beginning of a line, followed by zero or more spaces, 
followed by JEEP-L...and so forth.  Since the subject begins with "[", 
this should never match.  Try the following:

Subject: *\[JEEP-L[^]]*\] *\/.*

Essentially, this is looking for "Subject:" followed by zero or more 
spaces followed by "[JEEP-L" followed by any number of characters that are 
not "]" followed by "]" followed by zero or more spaces.  Everything after 
that is placed in MATCH.

This mess boils down to:

:0f
* ^Subject: *\[JEEP-L[^]]*\] *\/.*
| formail -I "Subject: $MATCH"
 
        :0A
        INBOX.JEEP-L

-- Lars

---
Lars Kellogg-Stedman * lars(_at_)bu(_dot_)edu * (617)353-8277
Office of Information Technology, Boston University