#!/usr/bin/zsh -- # Program that delays mail files, to catch bulk-spam before it is send. # This script reports on possible SPAM (bulk-mail from one user) # # 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, # same as in maildlay-input # -> configure an email adress to send warnings to # -> configure the amount of mails / user to send a # warning # Operation: cron job ######################################################################## ####### 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" # Temp file for spam-report SPAM_REPORT_TMP="/tmp/spamdelayreport.temp" SPAM_REPORT="/tmp/spamdelayreport" # Set a warning-limit, when one user has more mails then this, mail # a warning to ${WARN_EMAIL_TO} WARN_LIMIT=200 #Email adress to send warning to WARN_EMAIL_TO=nospam@someadmin.org ######################################################################## ####### END ############ ######################################################################## # Make a count of all mails for each user cd "${SPAM_DELAY_SPOOL}" echo -n "" > "${SPAM_REPORT_TMP}" # empty for FROMUSER in $( ls -1 | sed -e 's/_Bye__.*//;s/_[0-9]*__.*//;' | uniq ) do VAL=$(( $( ls ${FROMUSER}_* | sed -e "s/^${FROMUSER}_//;s/Bye/1/;s/__.*//;s/$/ +/;" | sed -e '$s/ +//;' ) )) echo "${VAL} ${FROMUSER}" >> "${SPAM_REPORT_TMP}" #note ` ' done #sort most first sort -rn "${SPAM_REPORT_TMP}" > "${SPAM_REPORT}" HIGHEST="$( head -1 "${SPAM_REPORT}" | sed -e 's/ .*//;' )" #note ` ' echo "maildlay: highest number of mails: $HIGHEST" if test "${WARN_LIMIT}" -le "${HIGHEST}" then echo "maildlay: send warning to ${WARN_EMAIL_TO}" head "${SPAM_REPORT}" | mail -s "maildlay: user with ${HIGHEST} mails, $( date )" "${WARN_EMAIL_TO}" fi