procmail
[Top] [All Lists]

Re: User functions in procmail?

1999-03-25 15:12:13
As others have pointed out, you can shove a chunk of procmailrc code that you
want to repeat into a separate file, and include it multiple places with
INCLUDERC, and parameterize it with variables. Besides being forced to manage
multiple files --- might be a convenient organizational aid, might be a
hassle, but you don't have a choice --- the other potential issue is
performance; procmail is renowned for being breathtakingly fast, and in some
settings you might not want to be adding an extra directory lookup, file open,
read, and close cycle for every call.

Another approach that might work better, depending on your needs, would be to
generate your procmailrc file from a separate "source code" maintained in some
other language; the most straightforward for this application would probably
be m4, though I've not gotten expert enough in m4 to be able to flip out an
example of what it'd look like used this way.

He said. So having written that, I couldn't resist taking a peek at the m4
info page, and cool, it isn't hard at all. This input:

        define(`save_and_archive',`{
                :0c
                $2

                :0A
                $1
        }')dnl

        :0
        * ^Subject: .*foo\/.*bar
        save_and_archive($MATCH, arch.$DATE)

        :0
        * ^TO_ someguy(_at_)thisaddress(_dot_)com
        save_and_archive($HOME/someguy.babblings, $HOME/archive/woot.txt)

filtered through m4 produced this output:

        :0
        * ^Subject: .*foo\/.*bar
        {
                :0c
                arch.$DATE

                :0A
                $MATCH
        }

        :0
        * ^TO_ someguy(_at_)thisaddress(_dot_)com
        {
                :0c
                $HOME/archive/woot.txt

                :0A
                $HOME/someguy.babblings
        }

So modulo a little spasm of weird in your macro definition, you can do almost
exactly what you want with m4:-).

-Bennett

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