# Based on: # Blocking spam with an accept list, version 070514 # Info at http://angel.net/~nic/spam-x.html # Poorly coded bits are not Nic's fault. # Customize all these constants: # Your e-mail address MY_EMAIL= # Your name MY_NAME="" # This should be either blank, or a regex that matches any addresses from which # you get lots of mail that you want to archive but not read: #BOTS=(root@.*angel.net|domainA|domainB|domainC) #BOTS=() # This should be a regex that matches all domains from which you know you # won't get spammed: #KNOWN_DOMAINS=(angel.net|domain1.com|domain2.com)$ KNOWN_DOMAINS=(mit.edu)$ # This should be either blank, or a regex that matches the To: headers of any # mailing lists you're on: LISTS= # Customize this to change the autoreply sent to messages from addresses # that are not in the accept list AUTOREPLY="Hi! Your message has been received, but it hasn't been delivered to me yet. Since I don't have any record of your sending me mail from this address before, I need to verify that you're not a spammer. Please just hit 'Reply' and send this message back to me, and your previous message will be delivered, as will all your future messages. Thanks, and sorry for the inconvenience -" # Customize these if they're not right on your system: FORMAIL=/usr/local/bin/formail GREP=/usr/bin/grep HEAD=/usr/bin/head POSTFIX=/usr/local/sbin/postfix SENDMAIL=/usr/sbin/sendmail LS=/bin/ls TR=/usr/bin/tr SHELL=/bin/sh PATH=/usr/bin:/bin:/usr/local/bin:. # Customize these if you want to put addresses and pending messages elsewhere - # make sure PENDING_DIR exists! DB=$HOME/.procmail/accept-list DENY_DB=$HOME/.procmail/deny-list DEFAULT=$HOME/Maildir/ PENDING_DIR=$HOME/pending_messages MAILDIR=$HOME/Maildir/ PMDIR=$HOME/.procmail VERBOSE=no LOGFILE=$HOME/ProcmailLog LOCKFILE=$HOME/.lockmail # Sorting lists on server BULK=$HOME/.procmail/bulk-list BSD=$HOME/.procmail/bsd-list COM=$HOME/.procmail/commerce-list IMP=$HOME/.procmail/impersonal-list SRL=$HOME/.procmail/srl-list TRAV=$HOME/.procmail/travel-list #NOW="$HH:$MM" #TODAY="$YY-$MM-$DD $NOW" MLOG=$HOME/procpro.log ############################## # Don't change anything else unless you know why you're doing it! SHELL=/bin/sh PATH COMSAT VERBOSE=no #LOGFILE=${LOGFILE-".procmail_log"} :0 c $HOME/.save_all # Get sender :0 hw FROM=|$FORMAIL -rzxTo:|$TR / _ # Get sender domain :0 * ^Return-Path:.*<[^@]+@\/[^>]+ { FROMD="@$MATCH" } # Use procmail match feature to get subject :0 * ^Subject:\/.* { SUBJ="$MATCH" } # You can mail yourself a request for the list of pending senders :0 * ^Subject: List senders { :0 fbw | $LS -t $PENDING_DIR :0: ${DEFAULT} } # You can mail yourself to approve an address :0 fw * ^Subject: Accept \/.* * $ FROM ?? $MY_EMAIL * ? echo $MATCH >> $DB * ? test -e $PENDING_DIR/$MATCH | ( cat $PENDING_DIR/$MATCH || true ) # You can mail yourself to deny an address :0 fw * ^Subject: Deny \/.* * $ FROM ?? $MY_EMAIL * ? echo $MATCH >> $DENY_DB /dev/null # If message is from a local bot then archive it #:0 #* BOTS ?? (.) #* $ FROM ?? $BOTS #notifications # If message is an NDN then archive it :0 h * MAILER-DAEMON NDNs # If message is from a known domain then deliver it :0 * KNOWN_DOMAINS ?? (.) * $ FROM ?? $KNOWN_DOMAINS $DEFAULT # whitelist check :0 * ? $GREP -i ^$FROM $DB { # :0 hwic: # | echo "WHL: $FROM" >> $MLOG :0 $DEFAULT } # If message is to a list we're on then deliver it :0 * LISTS ?? (.) * $ ^TO_$LISTS $DEFAULT # Checks bulkmail sources :0 * BULK ?? (.) * ? $GREP -i ^$FROM $BULK { # :0 hwic: # | echo "BLK: $FROM" >> $MLOG :0 .Bulkmail/ } # checks BSD sources :0 * BSD ?? (.) * ? $GREP -i ^$FROM $BSD { # :0 hwic: # | echo "BSD: $FROM" >> $MLOG :0 .BSD/ } # checks Commerce sources :0 * COM ?? (.) * ? $GREP -i ^$FROM $COM { # :0 hwic: # | echo "COM: $FROM" >> $MLOG :0 .Commerce/ } # checks impersonal info only sources :0 * IMP ?? (.) * ? $GREP -i ^$FROM $IMP { # :0 hwic: # | echo "IMP: $FROM" >> $MLOG :0 .Impersonal/ } # checks SRL sources :0 * SRL ?? (.) * ? $GREP -i ^$FROM $SRL { # :0 hwic: # | echo "SRL: $FROM" >> $MLOG :0 .SRL/ } # checks Travel (reservations) sources :0 * TRAV ?? (.) * ? $GREP -i ^$FROM $TRAV { # :0 hwic: # | echo "TRV: $FROM" >> $MLOG :0 .Travel/ } # If message is from a known non-spam UCE sender then dump it :0 h * ? $GREP -i ^$FROM $DENY_DB /dev/null # I think copy thse tests inverted to run spam test (only if no chicken) then these tests. #Run spam assassin but only if no chicken - so need anti-chicken test :0fw: spamassassin.lock * ! $ ^Subject:.*Verify.*for.*$MY_EMAIL | /usr/local/bin/spamc #SPAM CHECK - if the message isn't spammy, deliver it. :0: * ^X-Spam-Status: No * ! $ ^Subject:.*Verify.*for.*$MY_EMAIL { :0 * BULK ?? (.) * ? $GREP -i ^$FROMD $BULK { :0 hwic: | echo "DBLK: $FROM" >> $MLOG :0 .Bulkmail/ } # checks BSD sources :0 * BSD ?? (.) * ? $GREP -i ^$FROMD $BSD { :0 hwic: | echo "DBSD: $FROM" >> $MLOG :0 .BSD/ } # checks commerce sources :0 * COM ?? (.) * ? $GREP -i ^$FROMD $COM { :0 hwic: | echo "DCOM: $FROM" >> $MLOG :0 .Commerce/ } :0 hwic: | echo "NSPM: $FROM" >> $MLOG :0 $DEFAULT } # Else if message has chicken then register sender and deliver stored messages :0 Efw * $ ^Subject:.*Verify.*for.*$MY_EMAIL * $ ^Subject:.*Verify \/[^ ]+ * ? echo $MATCH >> $DB * ? echo $FROM >> $DB * ? test -e $PENDING_DIR/$MATCH | ( ( cat $PENDING_DIR/$MATCH && rm $PENDING_DIR/$MATCH ) || true ) # Else if sender isn't in DB then send request for chicken and store message :0 E * $ ! ^X-Loop: $MY_EMAIL * ! ? $GREP -i ^$FROM $DB { :0 c * ? test ! -e $PENDING_DIR/$FROM | ( $FORMAIL -rt -I"To: $FROM" -A"X-Loop: $MY_EMAIL" -I"Subject: Verify $FROM for $MY_EMAIL"; echo "$AUTOREPLY"; echo; echo "$MY_NAME" ) | $SENDMAIL -t :0 hwic: | echo "CHIX: $FROM - $SUBJ" >> $MLOG :0: $PENDING_DIR/$FROM } :0 hwic: | echo "DLN: $FROM" >> $MLOG # Else deliver normally