procmail
[Top] [All Lists]

Re: Better Recipe?

2001-07-25 07:54:33
* Ashley M. Kirchner <ashley(_at_)pcraft(_dot_)com> [010724 22:26]:

    This from one of my users:

    ----------

    Hey Ash,

    Can you help me and optimize my procmail rc file?  Check it out,
it's getting kinda long and there has to be a better way to do that kind
of stuff.  What do you think?

    .procmailrc

    FORMAIL = "/usr/bin/formail"
    TAG = ""
    to_ = '^((Apparently-)?To|Cc):(.*\<)?'


    :0
    *$ $to_()magick-user(_at_)imagemagick(_dot_)org
    {
        TAG = "[IMagick]"
    }

    :0E
    *$ $to_()imap(_at_)u(_dot_)washington(_dot_)edu
    {
        TAG = "[IMAP]"
    }

    :0E
    *$ $to_()info-cvs(_at_)gnu(_dot_)org
    {
        TAG = "[InfoCVS]"
    }

----------

    I snipped this, it really *IS* long - and all he's doing is matching
mailing lists and inserting the tag on the subject line.  And as he
said, the file is long - way long.  So, is there a better way to do
this?

Perhaps a perl script of some sort can make this shorter.  
Just an idea, untested.

%> cat .procmailrc

LISTS=(\
magick-user(_at_)imagemagick\(_dot_)org|\
imap(_at_)u\(_dot_)washington\(_dot_)edu|\
info-cvs(_at_)gnu\(_dot_)org)

# save list name for later access
:0
* $ ^TO_\/$LISTS
{ LISTNAME=$MATCH }

:0A  # save subject in MATCH var
* ^Subject: \/.*
{
    SUBJ=`addtag.pl`  # have perl script alter subject
    :0fhw
    | formail -I "Subject: $SUBJ"
}

%> cat addtag.pl

# addrs and their corresponding subj tags
%tags = (
  'magick-user(_at_)imagemagick(_dot_)org' => 'IMagick',
  'imap(_at_)u(_dot_)washington(_dot_)edu' => 'IMAP',
  'info-cvs(_at_)gnu(_dot_)org' => 'InfoCVS'
);

$to   = $ENV{LISTNAME};  # is this possible?
$subj = $ENV{MATCH};
if ($tags[$to]) {
  $subj = "[".$tags[$to]."] ".$subj;
}
print $subj;

-- 
- Matt Dunford <> zoot(_at_)zotikos(_dot_)com ..
-. www.zotikos.com -- o,;-
        
Random pic [www.explodingdog.com]:
http://www.explodingdog.com/feb26/voicesinmy.html
--
_______________________________________________
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>