procmail
[Top] [All Lists]

Re: Best way to extra To: address?

1999-02-12 14:13:16
Lars Kellogg-Stedman <lars(_at_)larsshack(_dot_)org> asks:
Frequently, I want to extract just the user(_at_)host portion of the To: 
address
for use in my procmail recipes.  That is, given something like this:

 To: Lars Kellogg-Stedman <lars(_at_)larsshack(_dot_)org>

I just want:

 lars(_at_)larsshack(_dot_)org

Others have suggested clever ways to get at the autoreply extractor
built into formail, which hadn't occurred to me.  I needed to get
at the From: address, for bouncing html posts sent to my list.
Here's the sed bit I used to sift off the comments:

        RETURNADDR=`formail -zxFrom: \
                | sed -e 's/["(].*[")]//' \
                      -e "s/'.*'//" \
                          -e 's/^.*<\(.*\)>.*$/\1/'`

In English: first delete anything between pairs of double quotes
or parentheses, then anything between pairs of single quotes,
finally, extract anything between < and >.

Jim

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