SHARE
TWEET

Dovecot Antispam 2.0 Example Script

a guest Jun 19th, 2013 98 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. # Add "starting now" string to log.
  4. echo "$$-start ($*)" >> /tmp/sa-learn-pipe.log
  5.  
  6. CURRENT_USER=$(whoami)
  7.  
  8. # Copy the message contents to a temporary text file.
  9. #echo $* > /tmp/sendmail-parms.txt
  10. cat<&0 >> /tmp/sendmail-msg-$$.txt
  11.  
  12. mode=
  13. for opt; do
  14.         echo "Checking if the command-line input argument string ($*) contains the string \"ham\" or \"spam\"" >> /tmp/sa-learn-pipe.log
  15.         if [[ "$*" =~ .*ham.* ]]
  16.         then
  17.             mode=HAM
  18.             break
  19.         elif [[ "$*" =~ .*spam.* ]]
  20.         then
  21.             mode=SPAM
  22.             break
  23.         else
  24.             echo "Mode (HAM or SPAM) cannot be determined from command-line arguments; check the calling script" >> /tmp/sa-learn-pipe.log
  25.             exit 0
  26.         fi
  27. done
  28.  
  29. echo "Mode is \"$mode\"" >> /tmp/sa-learn-pipe.log
  30.  
  31. if test -n "$mode"; then
  32.         echo "Calling (as user $CURRENT_USER) '/usr/lib/dovecot/deliver -d \"sa-training@dv.level8ds.com\" -m \"Training.$mode\" -p \"/tmp/sendmail-msg-$$.txt\"'" >> /tmp/sa-learn-pipe.log
  33.                
  34.         # options from http://wiki.dovecot.org/LDA
  35.         /usr/lib/dovecot/deliver -d "sa-training@example.com" -m "Training.$mode" -p "/tmp/sendmail-msg-$$.txt"
  36. fi
  37.  
  38. # Remove the temporary message.
  39. rm -f /tmp/sendmail-msg-$$.txt
  40.  
  41. # Add "ending now" string to log.
  42. echo "$$-end" >> /tmp/sa-learn-pipe.log
  43.  
  44. # Exit with "success" status code.
  45. exit 0
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top