procmail
[Top] [All Lists]

Re: Using a recipe to get FROM (drawbacks)

1997-04-09 22:56:00
On Wed, 9 Apr 1997, Robert Nicholson wrote:
:0
* ^From: *\/[^ ].*
{ FROM=$MATCH }    

The big problem I've found with this is that it doesn't work well with
multiple user agents that format the From: header differently.
ie. 
robert(_at_)elastica(_dot_)com (Robert Nicholson)
Robert Nicholson <robert(_at_)elastica(_dot_)com>

Procmail's egrep is actually pretty good at this.  I have used this in
a recipe with good reliability. 

        * ^From:.*\/[_(_dot_)+a-z0-9-]+(_at_)[_(_dot_)a-z0-9-]+

When using the "\/", if you carefully describe what you expect to get,
it will restrict itself to getting only what matches the part after
\/. Try just using "* ^From: \/" and you will get nothing.

There is a way to do the same with formail and the 'cut' command, but
it might have more overhead. I use this currently in one recipes.

BARE_ADDRESS=`formail -zx"From:" | cut -d'<' -f2 | cut -d'>' -f1`

Both methods will work with all the following four address forms.

                        Some One <me(_at_)my(_dot_)com>
                        <me(_at_)my(_dot_)com> Some One
                        <me(_at_)my(_dot_)com>
                        me(_at_)my(_dot_)com

I haven't yet figured out a way to include the form 
                        me(_at_)my(_dot_)com (Some One)
when using the formail method though, but I haven't needed it either.
The MATCH \/ method will work with this last form well.

David


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