#!/usr/bin/zsh -- # Program that delays mail files, to catch bulk-spam before it is send. # This script imports mail-files into the antiSPAM-delay-spool directory. # # Program released under the terms of the GNU GPL3. # This is free software. You are free to copy and redistribute. # No warranty. See http://www.gnu.org for license details. # (C) 2007 Jos Boersema # # Usage: prog MAIL_FILE [exim4in|headers|RECIPIENTS] # Manual: # Configure user-variables # -> mkdir a spool-directory for spam-delay, # point SPAM_DELAY_SPOOL (below) to it # Decide how to get to the number of recipients and sender # -> if you supply the mails in headers/body format, call # with argument "headers" # Note: When users can set the From: field freely, and # you use that to determine user, the system has # an obvious spammer hole. # -> if you supply the mails in exim4 spool format, call # with argument "exim4in" # -> if you know the amount of recipients, put that number # in the environment under MAILDLAY_AMOUNT, and put # the name/e-mail-address of the sender in MAILDLAY_NAME # Test: copy a mail-file to /tmp/whatever, run the program to # verify it gets into the spam-delay. It should have a name: # SENDER-NUMBER_OF_RECIPIENTS-ORIG_NAME, example: # joshb@xs4all.nl_2__1IKwyz-0000vW-1D-D # Operation: running program passes mail-file into antiSPAM-delay-spool # ######################################################################## ####### USER VARIABLES ############ ######################################################################## # Set this to a directory that acts as a temporary bulk-spam delay buffer. #SPAM_DELAY_SPOOL="/var/spool/mail/antispamdelay" SPAM_DELAY_SPOOL="/tmp/antispamdelay" ######################################################################## ####### END ############ ######################################################################## MAIL_FILE="${1}" #The file containing the mail. RECIPIENT_METHOD="${2}" #The method of computing the # of recipients, #Methods: "env", "headers", "exim4in" if test "headers" = "${RECIPIENT_METHOD}" then # Count how many recipients, based on To:/Cc:/Bcc: headers ... # Only greps through headers. RECN=$( echo '1,/^$/p' | ed -s "${MAIL_FILE}" | grep -E '^To:.*@|^Cc:.*@|^Bcc:.*@' | sed -e 's/@/@\n/g;' | grep -E '@' | wc -l ) # Get e-mail address in From: header # Only greps through headers. FROMUSER=$( echo '1,/^$/p' | ed -s "${MAIL_FILE}" | grep -E '^From: ' | sed -e 's/From: //;s/[, ][^@]*$//;s/.* [<]*//;s/[^a-zA-Z0-9]*$//;' ) elif test "exim4in" = "${RECIPIENT_METHOD}" then # Count how many recipients, based on what exim4 seems to store in its spool # This is based on guessing from looking at the format ... # ... gets the first single-number in the file. RECN=$( echo '/^[0-9]*$/p' | ed -s "${MAIL_FILE}" ) FROMUSER=$( echo '/@/p' | ed -s "${MAIL_FILE}" | sed -e 's/[<]*//;s/[^a-zA-Z0-9]*$//;' ) elif test "env" = "${RECIPIENT_METHOD}" then RECN="${MAILDLAY_AMOUNT}" #expected in environment... if test -z "${RECN}" then echo "maildlay: expected number of recipients in \${MAILDLAY_AMOUNT} in the environment, not found." echo "maildlay: aborting ..." #ERROR-EXIT false exit fi FROMUSER="${MAILDLAY_NAME}" # if test -z "${FROMUSER}" then echo "maildlay: expected sender in \${MAILDLAY_NAME} in the environment, not found." echo "maildlay: aborting ..." #ERROR-EXIT false exit fi else #USAGE echo "maildlay: usage error, specify a method for retreiving sender and amount of recipients [headers|exim4in|env], aborting." #ERROR-EXIT false exit fi #Move the mail-file into the spam-delay-spool #The name indicates user + number-of-recipients + original filename. mv "${MAIL_FILE}" "${SPAM_DELAY_SPOOL}/${FROMUSER}_${RECN}__${MAIL_FILE:t}"