#!/bin/sh

# procmail converter for spamdb.  
# original written by Joey Hess # <joey@kitenet.net> Dec 1 1997
# modified by Craig Sanders <cas@taz.net.au> Dec 3 1997

# this script generates a /var/spamdb/procmail.spam procmailrc file.
#
# Add 'INCLUDERC=/var/spamdb/procmail.spam' to the end of your
# /etc/procmailrc to activate it.
#
# Make sure that /usr/lib/spamdb/procmail.recipe contains an appropriate
# rule to define where to put spam (e.g. /root/mail/spam or /dev/null)
#
# Note that in the procmail.recipe template, __spam__ is replaced by the
# regexp that matches the incoming spam.

source /usr/lib/spamdb/constants
source /etc/spamdb/config

PROCMAIL_RECIPE=`cat /usr/lib/spamdb/procmail.recipe |
	sed -e '/^#/d' \
		-e 's/#.*$//' `

perl -ne '
	BEGIN {
		$procmail_recipe=shift @ARGV;
		print "# This file is automatically generated. Do not edit.\n";
	}
	chomp;
	$collect=quotemeta($_)."|$collect";
	if (length($collect) > 1000) {
		$collect=~s/\|$//;
		$pr=$procmail_recipe;
		$pr=~s/__spam__/$collect/ig;
		print "$pr\n\n";
		undef $collect;
	}
' "$PROCMAIL_RECIPE" $SPAMDB/SpamDomains $SPAMDB/Spammers \
	> $SPAMDB/procmail.spam

