procmail
[Top] [All Lists]

Re: Striping First Word from Subject Line(Again)

1997-01-29 00:40:21
I am having a terrible time getting this to work.  I am trying to strip
the first word off the Subject line of messages that I receive from a
mailing list. 

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

You aren't matching the REGEXP exact enough.  I don't use the '\/'
convention so I can't help you there, but I could do it this way which is
ugly and not efficient.  One of these days I suppose I'll have to read the
MAN page on that '\/' stuff.

        # Get the subject.
        SUBJ=`$FORMAIL -zx 'Subject: '`

        # SED it for what you want.
        NEWSUBJ=`echo $SUBJ | sed -e 's/^\[.*\]//'`

        :0fhw
        * ^Subject:.*JEEP-L
        | formail -I"Subject: $NEWSUBJ"

        :0a
        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.  

This should do what you want -- leave a Subject of:

Sample Text Subject Line

deleting everything starting with the first '[' and ending when it hits
the first ']' after that.

What am I doing wrong?

Not exact enough REGEXP for the MATCH.

Also, How do I get it to correctly get the message to go into the
INBOX.JEEP-L mailbox?  (Currently it doesnt do that either)

PROCMAIL acts on the first action line, after it pumps your data thru
FORMAIL, and that's it.  It expects to see the start of a new recipe after
that, which you didn't have.  The 'a' flag tells the next recipe to be
acted on only if the previous one was true.

However, as I said, I'm sure someone else will do this in a more efficient
way with a proper '\/' MATCH and not the wasteful SED call.

Lates!
---------------------------------------------------------------------------
Tim <bodysurf(_at_)pobox(_dot_)com>                          
mailto:bodysurf(_at_)pobox(_dot_)com
Finger bodysurf(_at_)pobox(_dot_)com for my PGP public key (Bits 1024/KeyID 
09DA5C49).
PGP Key FPrint (09/03/94): 4C 97 F1 FA 70 55 68 91  49 D1 AD F2 DD 63 0C 15
---------------------> Please PGP encrypt your email <---------------------