procmail
[Top] [All Lists]

Re: Optimizing recipes.

2000-07-31 15:16:15
At 15:43 2000-07-31 -0400, Mike A. Harris wrote:
I'd like to optimize some of my recipes so that it minimizes
processing, and also minimizes clutter in the rc file.

Minimize processing can be a misnomer -- invariably, most things you might want to simplify will involve spawning an external process to do one or more things which procmail doesn't do internally. IMO, CPU cycles are cheap enough - I like having the script simplified (see the solution to "friends" below, which involves running two external processes, in addition to a shell).

:0:
* ^X-Mailing-List:.*zoot-list
ZOOT-LIST

Is there a better way of organizing this so that one recipe can
catch all lists?

I was thinking something that could detect the list name from the
X-Mailing-List header and automatically uppercase it and store in
that folder.

Well, it should be possible to use $MATCH.  At the simplest:

:0:
* ^X-Mailing-List:[     ]\/.*
$MATCH

This doesn't uppercase the name though (and has other issues, see below) - for that, you'd need to pipe the message into a script, something like:

:0:
* ^X-Mailing-List:[     ]\/.*
|myscript $MATCH

where myscript is:

#!/bin/sh
#script to append message to mailing list mailbox
MYLIST=`echo $1|tr "[a-z]" "[A-Z]"`
cat - >> $MYLIST

There are a number of ways to force the uppercase, including sed. However, the listname match may not be JUST the listname, it may include other junk (not the least of which is the fact it is likely the ADDRESS of the list), so you have more parsing to deal with, most of which you should be able to do from the external script. Since I don't do it this way for my lists, I can't yank this out of existing code - you shouldn't have much trouble doing it if you want to spend the time and write the solution.

You could for instance use a case insensitive grep operation against the X-Mailing-List header, then look up the appropraite translated mailbox name from there. Don't forget to deal with blank listnames which may occasionally come up after you've parsed out junk from what you think the listname is.

:0:
* From:(_dot_)*myfriend(_at_)somewhere
FRIENDS
[snip]

# Friends
:0:
* $? $FORMAIL -xFrom: | $FGREP -i -f $PMDIR/friends.dat
$MAILDIR/friends


All macros are merely full paths to their respective apps. friends.dat contains individual lines with email addresses of friends. This is even cleaner than your conceptualized OR'ing recipe, because the separate text file can be appended to by other recipes if desired (for friends, this might not be so useful, but for other classes of people, it is).

I have similar recipes for family members and other such things (i.e. different groups are in different match files).

---
 Please DO NOT carbon me on list replies.  I'll get my copy from the list.

 Sean B. Straw / Professional Software Engineering
 Post Box 2395 / San Rafael, CA  94912-2395


_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

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