procmail
[Top] [All Lists]

Re: sorting mail based on incoming From: headers?

1999-07-24 01:49:11
Cheers from Southwind :)

On Fri, 23 Jul 1999, Dean Karres wrote:

sorting incoming mail into files in the MAILDIR that are named
from the address in the "From: " header line. I know that I can do
this if I enumerate all likely addresses.  Instead, I want to do
this without foreknowledge. Is this possible?

Technically, yes. The basic idea being:

:0
* ^From: \/.*
$MATCH

You'll have to send that through sed or perl to get rid of the
brackets and other cruft.
Of course, as you realize, just about anything can be in the From:
line. The real trouble lies in that it can be impossible to grab
anything particularly useful out of it at all.  If you have other
condition lines that will narrow your target group down to reasonable
people, then you can try to pull them out.
Here's a snippet from one of my perl filters for a mailing list:

      # winblows ... "blah[mailto:name(_at_)addr]blah"
      s/^From: .*\[mailto:([^ ]+(_at_)[^ ]+)\]/$1/;

      # typical ... "blah<name(_at_)addr>blah"
      s/^From: .*<([^ ]+(_at_)[^ ]+)>/$1/;

      # sorta typical ... "name(_at_)addr (blah)"
      s/^From: ([^ ]+(_at_)[^ ]+) \(.*\)/$1/;

      # typical ... "name(_at_)addr"
      s/^From: ([^ ]+(_at_)[^ ]+)/$1/;

As far as getting either the name (comment) part or 'real' address
part, the name/comment isn't required, and the 'real' address can be
faked.

-jeff
-- 
"The generation of random numbers is too important to be left to chance."

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