Don't forget ro run addrcache -t regularly (i.e. from corn) for this to maek
sense.

It could be used from procmailrc as follows.

MY_XLOOP = "X-Loop: $LOGNAME@$HOST"

#Find out the sender
:0 h
FROM=| formail -rt -xTo:

:0 hc
* !^FROM_DAEMON
* !^$MY_XLOOP
* ? addrcache $FOM
{
# compose reply:
| (formail -rtA"Precedence: junk" -A"$MY_XLOOP" ; \
   echo "sample text"; \
   cat /messages/autorply; \
   sed $SomeVarsToMakeItPersonal;
  ) | $SENDMAIL -oi -t



#!/usr/bin/perl 
#
#  addrcache - maintains a cache of data for a specified time.
#
#  based on poprelayd by:
#  This code was written by Curt Sampson <cjs@cynic.net> and placed into
#  the public domain in 1998 by Western Internet Portal Services, Inc.
#  $Id: poprelayd,v 1.1.1.1 2000/07/27 03:10:31 cjs Exp $
#
#  -a unconditionally adds an addres (with current time)
#  -r unconditionally removes an address
#  -c checks wether an address is already in the cache and if not adds it
#  -t timeouts expiered entries

#
#  Configuration settings.
#

$dbfile = "/etc/mail/addrcache.db";		# Sendmail map to update.
$dbtype = "DB_HASH";
$timeout_seconds = 86400;			# Seconds an entry lasts.

#
#  Modules
#

use Getopt::Std;
use Fcntl;
use DB_File;
use POSIX;

# You may need to uncomment this if your fcntl.ph doesn't export it.
sub O_EXLOCK { 0x20 };

#
#  Variables
#

undef %db;				# Hash into database file.

#
#  Subroutines
#

sub opendb_read {
    tie(%db, "DB_File", $dbfile, O_RDONLY, 0, $$dbtype) ||\
	die "Can't open $dbfile";
}

sub opendb_write {
    my $count=0;
    unless (tie(%db, "DB_File", $dbfile, O_RDWR|O_CREAT|O_EXLOCK, 0, $$dbtype) ||
            $count ++ < 5) {
      sleep 5;
    }
    if (! ($count < 5)) {
	die "Can't open $dbfile";
    }
}

sub closedb {
    untie %db;
}

sub adddb {
    my $addr = $_[0];
    $db{$addr} = time;
}

sub checkdb {
    my $addr = $_[0];
    if (!defined($db{$addr})) {
       adddb($addr);
       return 0;
    }
    return 1;
}

sub removedb {
    my $addr = $_[0];
    delete $db{$addr};
}

# timeoutdb(secs)
#
# Remove all entries from %db more than secs seconds old.
#
sub timeoutdb {
    # Convert timeout in secs to a time_t before which we delete.
    my $to = time - $_[0];

    foreach $key (sort(keys(%db))) {
	if ($db{$key} < $to)  {
	    delete $db{$key};
	}
    }
}


#
#  Main Program
#

$countopts = 0;
getopts('a:c:r:t:p') || \
    die "Usage: addrcache [-c <addr>] [-a <addr>] [-r <addr>] [[-t] <timeout>]\n";

# Add an address.
if ($opt_a)  {
    $countopts++;
    opendb_write;
    adddb($opt_a);
    closedb;
    exit 0;
}

if ($opt_c)  {
    my $ret;

    $countopts++;
    opendb_write;
    $ret = checkdb($opt_c);
    closedb;
    exit $ret;
}

# Remove an address.
if ($opt_r)  {
    $countopts++;
    opendb_write;
    removedb($opt_r);
    closedb;
    exit 0;
}

# Timeout entries.
if ($opt_t)  {
    $countopts++;
    die "Invalid timeout value: $opt_t.\n" unless $opt_t > 0;
    $opt_t = $timeout_seconds if ($opt_t == 1);
    opendb_write;
    timeoutdb($opt_t);
    closedb;
    exit 0;
}

# Print address list.
if ($opt_p)  {
    $countopts++;
    opendb_read;
    foreach $key (sort(keys(%db))) {
	print "$key\t",  $db{$key}, "\n";
    }
    closedb;
}

if (! $countopts)  {
    die "Usage: addrcache [-c <addr>] [-a <addr>] [-r <addr>] [[-t] <timeout>]\n";
}

