Advertisement
Guest User

Dovecot Antispam plugin pipe script example

a guest
Jul 29th, 2014
603
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.74 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #export PATH=$PATH:/usr/lib/dovecot
  4.  
  5. #MYENV=$(env)
  6.  
  7. # Add "starting now" string to log.
  8. echo "$$-start ($*)" >> /tmp/sa-learn-pipe.log
  9.  
  10. #echo "ENV value is: $MYENV" >> /tmp/sa-learn-pipe.log
  11.  
  12. #echo "PATH value is: $PATH" >> /tmp/sa-learn-pipe.log
  13.  
  14. CURRENT_USER=$(whoami)
  15.  
  16. #echo $* > /tmp/sendmail-parms.txt
  17. # Copy the message contents to a temporary text file.
  18. #cat<&0 >> /tmp/sendmail-msg-$$.txt
  19.  
  20. mode=
  21. for opt; do
  22.         echo "Checking if the command-line input argument string ($*) contains the string \"ham\" or \"spam\"" >> /tmp/sa-learn-pipe.log
  23.         if [[ "$*" =~ .*ham.* ]]
  24.         then
  25.             mode=HAM
  26.             break
  27.         elif [[ "$*" =~ .*spam.* ]]
  28.         then
  29.             mode=SPAM
  30.             break
  31.         else
  32.             echo "Mode (HAM or SPAM) cannot be determined from command-line arguments; check the calling script" >> /tmp/sa-learn-pipe.log
  33.             exit 0
  34.         fi
  35. done
  36.  
  37. echo "Mode is \"$mode\"" >> /tmp/sa-learn-pipe.log
  38.  
  39. if test -n "$mode"; then
  40.         echo "Calling (as user $CURRENT_USER) '/usr/lib/dovecot/deliver -d \"sa-training@example.com\" -m \"Training.$mode\" -p \"/tmp/sendmail-msg-$$.txt\"'" >> /tmp/sa-learn-pipe.log
  41.        
  42.         # options from http://wiki.dovecot.org/LDA
  43.         #strace -f -F /usr/lib/dovecot/deliver -d "sa-training@example.com" -m "Training.$mode" -p "/tmp/sendmail-msg-$$.txt" >>/tmp/strace.txt 2>&1
  44.        
  45.         /usr/lib/dovecot/deliver -d "sa-training@example.com" -m "Training.$mode"
  46.        
  47.         echo "Exit status was $?" >> /tmp/sa-learn-pipe.log
  48. fi
  49.  
  50. # Remove the temporary message.
  51. ##rm -f /tmp/sendmail-msg-$$.txt
  52.  
  53. # Add "ending now" string to log.
  54. echo "$$-end" >> /tmp/sa-learn-pipe.log
  55.  
  56. # Exit with "success" status code.
  57. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement