procmail
[Top] [All Lists]

Re: Help for a newbie-ish

2002-02-09 00:44:58
"Walter H. Hopgood" <walterh(_at_)meer(_dot_)net> writes:
I've not used Procmail for quite a while (used to run procmail & smartlist)
and recently came upon a new need.  I would like to have my mail come in,
save it to a file, then send it to my mailbox.  The complicated thing is,
I'm saving the mail to my $HOME/Mail directory in filenames that match the
part of the email address prior to the "@" sign (eg. 
walterh(_at_)meer(_dot_)net saves
to file $HOME/Mail/walterh).  Here's what I've put together in my
.procmailrc for my root user (as a test), but it's not working:
===================
PATH=$PATH:/usr/bin:/usr/sbin:.:

/usr/bin and /usr/sbin are almost certainly both in the default path.
Given that, and the fact that you *don't* want the current directory
in your path (especially for root!), I suggest you completely remove
that line.  (As a point of record, the above adds the current directory
to the path *twice*, once from the "." and once from the empty component
at the end.)


MAILDIR=/root/Mail
LOGFILE=/root/procmail.log

Those are more generally written as
        MAILDIR = $HOME/Mail
        LOGFILE = $HOME/procmail.log

but that's just a matter of style.


:0
{
MAILEDFROM = `formail -x "From "|awk -F\@ '{print $1}'`
}
$MAILDIR/$MAILEDFROM

A recipe can only have one action.  Ergo, the above needs to be written
in one of the following forms:

        :0
        {
                MAILEDFROM = `formail -x "From "|awk -F\@ '{print $1}'`
                :0
                $MAILDIR/$MAILEDFROM
        }

or

        :0
        {
                MAILEDFROM = `formail -x "From "|awk -F\@ '{print $1}'`
        }
        :0
        $MAILDIR/$MAILEDFROM

or, since the braces are pointless then there are no conditions or flags
on the nesting recipe:

        MAILEDFROM = `formail -x "From "|awk -F\@ '{print $1}'`
        :0
        $MAILDIR/$MAILEDFROM

One way to vastly improve the efficiency of this is to use procmail's
builtin extraction ability to get the filename to use.

        :0:
        * ^From \/[-a-z0-9_][-a-z0-9_.]*
        $MATCH

The \/ tells procmail take what is matched by everything to the right of
it and store that in the MATCH variable.  The "[-a-z0-9_][-a-z0-9_.]*"
matches one or more letters, numbers, hyphens, underbars, and periods,
not beginning with a period.  Note that this *doesn't* match slashes
or leading periods, so the resulting filenames will all be in your Mail
directory and will show up in normal 'ls' commands.  Note that if there
are disallowed characters, the above regexp will just stop at the first
such one.  So an X.500 address like
        DN=org/DN=procmail/O=maintainers/CN=guenther(_at_)somewhere
will store the message into
        DN

I also eliminated the $MAILDIR reference, as that's the default for any
filename that doesn't begin with a slash.

You'll need to decide what to do if the email address in the "From "
lines doesn't match the regexp at all because it starts with a character
outside of the set "-a-z0-9_".  For example, you could follow the above
recipe with

        :0:
        badaddr


Philip Guenther
_______________________________________________
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>