procmail
[Top] [All Lists]

Re: Best regexp for List-Id:

2007-06-11 10:13:18
On 11-Jun-2007, at 10:00, N.J. Mann wrote:
A recent discussion on the list got me to thinking about how I might
simplify the procmail recipes I use for the various mailing lists I am
subscribed to.  I like to have mail from each mailing list in its own
mailbox and the mailman/majordomo/&c. messages in their own mailboxes.
Perhaps I am too tidy! ;-)

Sean wrote this, which I use and have used for a long time.  It works  
flawlessly, even on lists without a List-ID header:

LISTNAME
:0
* 9876543210^0 ^(List-Post:[    ]*(<mailto:)?|List-Owner:[      ]* 
(<mailto:)?owner-)\/[-A-Z0-9_+]+
* 9876543210^0 ^(List-Id:.*<|X-Mailing-List:[   ]*)\/[-A-z0-9_+]+
* 9876543210^0 ^(Sender:[       ]*owner-|X-BeenThere:[  ]*|Delivered- 
To:[       ]*mailing list )\/[-A-Za-z0-9_+]+
* 9876543210^0 ^Sender:.* List"? <(mailto:)?\/[-A-Z0-9_+]+
{ LISTNAME=$MATCH }

# OK, taht didn't work, let's try List-Subscribe
:0E
    * ^List-Subscribe:.*<mailto:\/[-A-Z0-9_+]+-(digest|on|subscribe)@
    * MATCH ?? ^^\/.+-
    * MATCH ?? ^^\/.+[^-]
    { LISTNAME = $MATCH }

At this point, $LISTNAME contains the name of the list.

I then use a recipe to sort mail into date stamped folders:

# Date contains a date in the form 2007-07
:0
* ! LISTNAME ?? ^^^^
{
    # Put the list name into a header
    :0fw
    | formail -i "X-Covisp-Listname: $LISTNAME"

    :0: $HOME/lock
    $MLDIR/$LISTNAME/$MYDATE.$LISTNAME

    # if the action failed, probably the directory does not
    # exist, so create it
    :0eW
    {
      LOG="FAILED WRITE$NL"
      MAKENEWDIR=`test -d $MLDIR/$LISTNAME || mkdir -p $MLDIR/ 
$LISTNAME/`

    }

    # Now save the message again
    :0a:
    $MLDIR/$LISTNAME/$MYDATE.$LISTNAME

    # If we get this far, something is quite wrong.
    # Still failed?  Better save the message somewhere we can check it
    :0
    {
      LOG="FAILED WRITE NEW DIRECTORY$NL"
      :0: $HOME/lock
      $MLDIR/FAILED_LIST_SORT
    }
}

The neat trick her is that when a new list is subscribed to, it  
automatically gets sorted.  The only down side is that some spam  
comes in looking like it is a list message, but this is fairly minor.


-- 
The other cats just think he's a tosser. --Neil Gaiman

____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

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