How to include an on the fly autogenerated file in procmailrc

Stefano Sabatini stefano.sabatini-lala at
Sun Nov 11 11:07:06 CET 2007

On date Saturday 2007-11-10 18:18:20 -0800, Bart Schaefer wrote:
> On Nov 10, 2007 3:36 PM, Stefano Sabatini <stefano.sabatini-lala at> wrote:
> >
> > Here it is my problem: I see that there is the possibility to include
> > a procmailrc inside another. Would be possible to include a file
> > autogenerated on the fly, for example using some script, something
> > like the:
> > source "script args|"
> >
> > feature of mutt?
> Of course that's just a shorthand for redirecting the output of the
> script into a file and then reading the file.  So it's certainly
> possible to do that from procmail.


> There are any number of ways to do
> so; one of them would be:
> AUTO_RC = "$HOME/.procmailrc.$$"
> :0
> * $ ? script args > $AUTO_RC
> This uses the "* ?" recipe mechanism to execute the script and test
> whether it exited successfully before attempting to read the resulting
> file.
> Cleaning up the file afterward has been left to the imagination of the reader.

Thank you so much, I'm including a description of my environment in
the case it could result useful to others.

I ended up with something like this:

# all messages directed to some mailing list are immediately put 
# in a corresponding folder
AUTO_RC = mailing-lists-rc
* $ ? ~/etc/mailing-lists > $AUTO_RC

The script looks like this:
#! /usr/bin/perl

use warnings;
use strict;

sub print_mailing_list_rc {
    my $address = shift @_;
    my $address_matching_re = quotemeta($address);
    my $nickname;

    # nickname is the part before any "@": e.g.
    # alice.and.friends at -> alice.and.friends
    $address =~ m/^[^@]+/; 
    # set nickname to the matched value
    $nickname = $&;

    print << "EOT";
# $nickname
:0 H 
* ^(To|C[c]): .*${address_matching_re}.*


# read from stdin of from a file in input
while (<>) {
    print_mailing_list_rc ($_);

The ~/etc/mailing-lists file contains a textual list (one per line) of
the mailing-list I'm subscribed to (and may be processed as well by
other applications, for example by an user agent).

For example the resulting procmailrc rule for this mailing list will
appear as:

# procmail
:0 H 
* ^(To|C[c]): .*procmail\@lists\.RWTH\-Aachen\.DE.*

One potential problem is that the quotemeta escaping mechanism used by
Perl might result inadequate to issue a corresponding egrep string.

For what regards the $AUTO_RC file deletion, I think it's a nice
debugging feature to keep it. I keep all the procmail configuration
files in ~/.procmail/ so it won't clutter the ~ environment.

Best regards.
Stefano Sabatini
Linux user number 337176 (see

More information about the procmail mailing list