You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by Apache Wiki <wi...@apache.org> on 2013/01/09 01:32:20 UTC

[Spamassassin Wiki] Update of "IntegratedSpamdInPostfix" by Darxus

Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Spamassassin Wiki" for change notification.

The "IntegratedSpamdInPostfix" page has been changed by Darxus:
http://wiki.apache.org/spamassassin/IntegratedSpamdInPostfix?action=diff&rev1=40&rev2=41

Comment:
Fix !/bin/sh problem

  
  1) Create a bash script to receive e-mail from Postfix and pipe it to SpamAssassin for rewriting.  Then forward the rewritten version to Postfix's sendmail implementation:
  
- {{{
- #(exclamationMark)/bin/sh
+ {{{#!highlight sh
+ #!/bin/sh
  #
  # This script should probably live at /usr/bin/spamfilter.sh
  # ... and have 'chown root:root' and 'chmod 755' applied to it.
@@ -101, +101 @@

  
  {{{#!/bin/sh
  
+ # filter.sh # # This script redirects mail flagged as spam to a separate account # You must first create a user account named "spamvac" to hold the flagged mail
- # filter.sh
- #
- # This script redirects mail flagged as spam to a separate account
- # You must first create a user account named "spamvac" to hold the flagged mail
  
+ SENDMAIL="/usr/sbin/sendmail -i" SPAMASSASSIN=/usr/bin/spamc COMMAND="$SENDMAIL $@" #If your SQL preferences set to "user" USER=`echo $COMMAND | awk '{ print $NF }' | sed 's/@.*$//'` #If your SQL preferences set to "user@domain" #USER=`echo $COMMAND | awk '{ print $NF }'`
- SENDMAIL="/usr/sbin/sendmail -i"
- SPAMASSASSIN=/usr/bin/spamc
- COMMAND="$SENDMAIL $@"
- #If your SQL preferences set to "user"
- USER=`echo $COMMAND | awk '{ print $NF }' | sed 's/@.*$//'`
- #If your SQL preferences set to "user@domain"
- #USER=`echo $COMMAND | awk '{ print $NF }'`
  
  NEW_COMMAND=`echo $COMMAND | awk '{ $6 = "spamvac"; NF = 6; print }'`
  
+ # Exit codes from <sysexits.h> EX_TEMPFAIL=75 EX_UNAVAILABLE=69
- # Exit codes from <sysexits.h>
- EX_TEMPFAIL=75
- EX_UNAVAILABLE=69
  
  umask 077
  
  OUTPUT="`mktemp /tmp/mailfilter.XXXXXXXXXX`"
  
  if [ "$?" != 0 ]; then
+ 
-     /usr/bin/logger -s -p mail.warning -t filter "Unable to create temporary file."
+  . /usr/bin/logger -s -p mail.warning -t filter "Unable to create temporary file." exit $EX_TEMPFAIL
-     exit $EX_TEMPFAIL
- fi
  
+ fi
- # Clean up when done or when aborting.
- trap "rm -f $OUTPUT" EXIT TERM
  
- $SPAMASSASSIN -x -E -u $USER > $OUTPUT
- return="$?"
- if [ "$return" = 1 ]; then
+ # Clean up when done or when aborting. trap "rm -f $OUTPUT" EXIT TERM
+ 
+ $SPAMASSASSIN -x -E -u $USER > $OUTPUT return="$?" if [ "$return" = 1 ]; then
+ 
-     $NEW_COMMAND < $OUTPUT
+  . $NEW_COMMAND < $OUTPUT exit $?
-     exit $?
+ 
  elif [ "$return" != 0 ]; then
+ 
-     /usr/bin/logger -s -p mail.warning -t filter "Temporary SpamAssassin failure (spamc returned $return)"
+  . /usr/bin/logger -s -p mail.warning -t filter "Temporary SpamAssassin failure (spamc returned $return)" exit $EX_TEMPFAIL
-     exit $EX_TEMPFAIL
- fi
  
+ fi
+ 
- $SENDMAIL "$@" < $OUTPUT
- exit $?
- }}}
- This causes incoming smtp mail to be checked for spam.  If the mail's spam score exceeds the threshold (set in local.cf, or in ~/.spamassassin/user_prefs) then `spamc -E` returns 1 and the mail is redirected to the spamvac account.  Otherwise it is passed on to the intended recipient.  Bounces no longer occur except on a true error condition.
+ $SENDMAIL "$@" < $OUTPUT exit $? }}} This causes incoming smtp mail to be checked for spam.  If the mail's spam score exceeds the threshold (set in local.cf, or in ~/.spamassassin/user_prefs) then `spamc -E` returns 1 and the mail is redirected to the spamvac account.  Otherwise it is passed on to the intended recipient.  Bounces no longer occur except on a true error condition.
  
  == Old method (original) ==
  The easiest way to integrate postfix and spamassassin is to use spamd in an [[http://www.postfix.org/FILTER_README.html|after-queue]] inspection. This configuration does not allow rejecting messages within the SMTP transaction, so it unfortunately contributes to backscatter email. On the other hand, it has important performance advantages over [[http://www.postfix.org/SMTPD_PROXY_README.html|before-queue]] inspection.
@@ -232, +218 @@

  }}}
  and create a `filter.sh` as follows:
  
+ {{{#!/bin/bash SENDMAIL="/usr/sbin/sendmail -i" SPAMASSASSIN=/usr/bin/spamc
- {{{#!/bin/bash
- SENDMAIL="/usr/sbin/sendmail -i"
- SPAMASSASSIN=/usr/bin/spamc
  
+ # Exit codes from <sysexits.h> EX_TEMPFAIL=75 EX_UNAVAILABLE=69
- # Exit codes from <sysexits.h>
- EX_TEMPFAIL=75
- EX_UNAVAILABLE=69
  
  umask 077
  
- OUTPUT="`mktemp -p /tmp mailfilter.XXXXXXXXXX`"
+ OUTPUT="`mktemp -p /tmp mailfilter.XXXXXXXXXX`" if [ "$?" != 0 ]; then
- if [ "$?" != 0 ]; then
+ 
-     /usr/bin/logger -s -p mail.warning -t filter \
+  . /usr/bin/logger -s -p mail.warning -t filter \
-         "Unable to create temporary file."
+   . "Unable to create temporary file."
-     exit $EX_TEMPFAIL
+  exit $EX_TEMPFAIL
- fi
  
+ fi
- # Clean up when done or when aborting.
- trap "rm -f $OUTPUT" EXIT TERM
  
- $SPAMASSASSIN -x > $OUTPUT
- return="$?"
- if [ "$return" = 1 ]; then
-     echo "Message content rejected"
-     exit $EX_UNAVAILABLE
+ # Clean up when done or when aborting. trap "rm -f $OUTPUT" EXIT TERM
+ 
+ $SPAMASSASSIN -x > $OUTPUT return="$?" if [ "$return" = 1 ]; then
+ 
+  . echo "Message content rejected" exit $EX_UNAVAILABLE
+ 
  elif [ "$return" != 0 ]; then
+ 
-     /usr/bin/logger -s -p mail.warning -t filter \
+  . /usr/bin/logger -s -p mail.warning -t filter \
-         "Temporary SpamAssassin failure (spamc returned $return)"
+   . "Temporary SpamAssassin failure (spamc returned $return)"
-     exit $EX_TEMPFAIL
+  exit $EX_TEMPFAIL
- fi
  
+ fi
+ 
- $SENDMAIL "$@" < $OUTPUT
- exit $?
- }}}
- You still must be careful that the script is in the right place and executable or email will bounce. However, this will defer messages on most failures.
+ $SENDMAIL "$@" < $OUTPUT exit $? }}} You still must be careful that the script is in the right place and executable or email will bounce. However, this will defer messages on most failures.
  
  A more complex solution is the one proposed in the [[http://www.postfix.org/FILTER_README.html|FILTER_README file]] that comes with the Postfix distribution. See IntegratePostfixViaSpampd for one approach.