spamassassin-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Spamassassin Wiki] Update of "IntegratedSpamdInPostfix" by jez9999
Date Fri, 18 Jan 2013 14:48:54 GMT
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 jez9999:
http://wiki.apache.org/spamassassin/IntegratedSpamdInPostfix?action=diff&rev1=51&rev2=52

  # ... and have 'chown root:root' and 'chmod 755' applied to it.
  # 
  # For use with:
- #    Postfix 20010228 or later
+ #     Postfix 20010228 or later
- #    SpamAssassin 2.42 or later
+ #     SpamAssassin 2.42 or later
  
- # Note: Modify the file locations to match your particular
+ # Note: Modify the file locations to suit your particular
  #       server and installation of SpamAssassin.
  # File locations:
- # (CHANGE AS REQUIRED TO MATCH YOUR SERVER)
+ # (CHANGE AS REQUIRED TO SUIT YOUR SERVER)
  SENDMAIL=/usr/sbin/sendmail
  SPAMASSASSIN=/usr/bin/spamc
  
@@ -74, +74 @@

    # Set the threshold at which a message is considered spam (3 is usually sufficient)
    required_score 3.0
  }}}
- == Perl script to discard very obvious spam method ==
- TODO: describe a similar method to above, but with a Perl script that looks at the rewritten
headers and discards spam that is, say, scored higher than 7.  That means < 3 is OK, 3-7
is marked as spam but delivered, > 7 is discarded.
+ == advanced bash script to discard 'likely spam' method ==
+ '''NOTE:''' At the time of writing, the following script will only work with a patched version
of spamc from SVN trunk (which can be found at http://svn.apache.org/repos/asf/spamassassin/trunk
).  It needs to be patched with the 'Second patch' from the following Bugzilla bug:
+ https://issues.apache.org/SpamAssassin/show_bug.cgi?id=6890
+ It introduces a -T (override threshold) parameter which is necessary for this shell script's
operation.  I'm hoping it will be merged into SpamAssassin trunk one day.
  
+ This is a more advanced method to integrate SpamAssassin.  The script will set a threshold,
and only messages with a score above that threshold will be discarded.  Messages between the
normal configured SpamAssassin threshold and the threshold set in the script will be considered
"grey area" messages, and whilst they will be rewritten as spam by Spamassassin, they will
still be delivered to the mailbox.  Messages below the normal configured SpamAssassin threshold
will be delivered as normal.
+ 
+ 1) Create a bash script to receive e-mail from Postfix and pipe it to SpamAssassin for rewriting.
 Check whether SpamAssassin tells us whether the message is over the threshold or not; if
so, discard the message.  Otherwise, deliver it through Postfix's sendmail implementation:
+ 
+ {{{#!highlight bash
+ #!/bin/bash
+ # 
+ # spamfilter.sh
+ # 
+ # Advanced filter to plug SpamAssassin into the Postfix MTA
+ # Only discards messages that are above the threshold that is
+ # passed in to spamc; other spam messages that are below this
+ # threshold will be rewritten, but not discarded.
+ # 
+ # Modified by Jeremy Morton
+ # 
+ # This script should probably live at /usr/bin/spamfilter.sh
+ # ... and have 'chown root:root' and 'chmod 755' applied to it.
+ # 
+ # For use with:
+ #     Postfix 20010228 or later
+ #     ??? SpamAssassin 2.42 or later ??? - should change to the latest version when/if spamc
patch gets applied to trunk
+ 
+ # Note: Modify the file locations to suit your particular
+ #       server and installation of SpamAssassin.
+ # File locations and settings:
+ # (CHANGE AS REQUIRED TO SUIT YOUR SERVER)
+ THRESHOLD_OFFSET=4.0
+ # ^ Remember, we're using the threshold offset build, not the absolute value one.  Passing
in a -T value of 4.0 will give us an absolute threshold of
+ # maybe (base) 5.0 + 4.0 = 9.0.
+ MAX_MESSAGE_SIZE=10240000
+ # ^ Allow e-mails up to size 10240000 (10MB) - they're not too intensive to process, and
any e-mails above that size don't get processed, and are assumed
+ # to be non-spam.  Clearly it's important that we process as many messages as possible,
and there should be very few messages indeed that exceed 10MB size.
+ SENDMAIL=/usr/sbin/sendmail
+ SPAMASSASSIN=/usr/bin/spamc
+ 
+ # We use -4 to force IPv4 because alas at the time of writing, spamd doesn't listen out
for connections on IPv6...
+ logger -s -p mail.notice -t spamfilter <<<"Spam filter piping to SpamAssassin:
$SPAMASSASSIN -4 -x -E -s $MAX_MESSAGE_SIZE -T $THRESHOLD_OFFSET"
+ CAUGHT_OUTPUT=`${SPAMASSASSIN} -4 -x -E -s $MAX_MESSAGE_SIZE -T $THRESHOLD_OFFSET`
+ SPAMASSASSIN_EXITCODE=$?
+ 
+ if [ "$SPAMASSASSIN_EXITCODE" -gt 1 ]; then
+     logger -s -p mail.warning -t spamfilter <<<"Error code $SPAMASSASSIN_EXITCODE
processing spam!"
+     exit $SPAMASSASSIN_EXITCODE
+ elif [ "$SPAMASSASSIN_EXITCODE" -eq 1 ]; then
+     logger -s -p mail.notice -t spamfilter <<<"SpamAssassin says message is likely
spam; discarding."
+     exit 0
+ fi
+ 
+ # Message is OK, or grey-area and has been rewritten.  Deliver to mailbox.
+ logger -s -p mail.notice -t spamfilter <<<"OK.  Piping to sendmail: $SENDMAIL $@"
+ ${SENDMAIL} "$@" <<<"$CAUGHT_OUTPUT"
+ exit $?
+ }}}
  == Old alternative method ==
  A major problem with the old method filter (below) is that Postfix attempts to bounce messages
flagged as spam.  This is a waste of resources as most spams have fake return addresses. 
Furthermore, if they fake a return address that doesn't belong to them, you may end up bouncing
the message to an innocent 3rd party.  Enough of this can result in YOU being on an RBL.
  

Mime
View raw message