Differences between revisions 4 and 5
Revision 4 as of 2015-05-04 21:59:15
Size: 5055
Editor: BretMiller
Comment: List integration methods
Revision 5 as of 2015-05-04 22:09:21
Size: 5167
Editor: BretMiller
Comment:
Deletions are marked like this. Additions are marked like this.
Line 16: Line 16:
{{{#!/bin/sh {{{
#!/bin/sh
Line 19: Line 20:
# Script to call Spam Assassin from CommuniGate Pro Rules v1.1 Ed Fang # If you have any improvements, drop me a line at edfang@visi.net # Thanks for Stefan Seiz for the original template # # Script will call SpamAssassin spamc from CommuniGate. Since SA modifies # the actual message, it must be re-delivered via the Submitted directory. # Sneaky Header Tagging is used to prevent the message from being scanned # again, and/or being caught in a loop is spamd fails. # # DATA # Communigate Pro Rules # Any Recipient in *@domain.com # Message Size less than 32768 # Header Field is not X-Spam-Status* # # ACTION # Execute [STDERR] [FILE] [RETPATH] [RCPT] /var/CommuniGate/scanspam.sh # Discard # # You must discard the message as the script will re-submit the marked message through the # Submitted directory of CommuniGate. If you don't, you'll get every message # twice - once scanned, once clear through. (which is a good way to test # before actually discarding the message. Stalker has asked that messages # not be modified in the Queue directory, so it's just safer to play by their # rules. # # 1.1 - Changed to run using gawk. Highly advised as awk will occasionally # crap out with trememdously long html lines. # # Note: The global variables aren't used all over the place, so I'll clean that # up in a later version. I think there might be a more efficient awk script # so any other awk gurus out there might be able to give me a better awk # than the one I have (which skips everything until it matches Received # and then to the end of the file. # # Script to call Spam Assassin from CommuniGate Pro Rules v1.1 Ed Fang
# If you have any improvements, drop me a line at edfang@visi.net
# Thanks for Stefan Seiz for the original template
#
# Script will call SpamAssassin spamc from CommuniGate. Since SA modifies
# the actual message, it must be re-delivered via the Submitted directory.
# Sneaky Header Tagging is used to prevent the message from being scanned
# again, and/or being caught in a loop is spamd fails.
#
# DATA
# Communigate Pro Rules
# Any Recipient in *@domain.com
# Message Size less than 32768
# Header Field is not X-Spam-Status*
#
# ACTION
# Execute [STDERR] [FILE] [RETPATH] [RCPT] /var/CommuniGate/scanspam.sh
# Discard
#
# You must discard the message as the script will re-submit the marked message through the
# Submitted directory of CommuniGate. If you don't, you'll get every message
# twice - once scanned, once clear through. (which is a good way to test
# before actually discarding the message. Stalker has asked that messages
# not be modified in the Queue directory, so it's just safer to play by their
# rules.
#
# 1.1 - Changed to run using gawk. Highly advised as awk will occasionally
# crap out with trememdously long html lines.
#
# Note: The global variables aren't used all over the place, so I'll clean that
# up in a later version. I think there might be a more efficient awk script
# so any other awk gurus out there might be able to give me a better awk
# than the one I have (which skips everything until it matches Received
# and then to the end of the file.
#
Line 26: Line 61:
#Comment out following two lines if you don't want to echo the passed variable info to #the spam-result.out file. myDate=`date +%Y-%m-%d\ %H:%M:%S` echo "Date $myDate " $@ >> $myLogFile #Comment out following two lines if you don't want to echo the passed variable info to
#the spam-result.out file.
myDate=`date +%Y-%m-%d\ %H:%M:%S`
echo "Date $myDate " $@ >> $myLogFile
Line 28: Line 66:
#Get the fileid of the message file QueuePath=$2 NewFile=`basename $QueuePath`'.tmp' FinalFile=$NewFile'.sub' #Get the fileid of the message file
QueuePath=$2
NewFile=`basename $QueuePath`'.tmp'
FinalFile=$NewFile'.sub'
Line 30: Line 71:
# Formulate return-path and Envelope-To addresses from command line args. # shift out the first 3 arguments, make sure one > to create a new file shift 3 # Formulate return-path and Envelope-To addresses from command line args.
# shift out the first 3 arguments, make sure one > to create a new file shift 3
Line 32: Line 74:
# If you are using Spamprep, the following line should be commented out echo "Return-Path:" $1 > /var/CommuniGate/Submitted/$NewFile # If you are using Spamprep, the following line should be commented out
echo "Return-Path:" $1 > /var/CommuniGate/Submitted/$NewFile
Line 34: Line 77:
# If you are using Spamprep, the following line should be uncommented # ReturnPath=$1 # If you are using Spamprep, the following line should be uncommented
# ReturnPath=$1
Line 36: Line 80:
# shift out 5 command arguments. and start appending shift 2 Envelope=$1 shift while [ $# -gt 0 ] do # shift out 5 command arguments. and start appending shift 2
Envelope=$1
shift
while [ $# -gt 0 ] do
Line 44: Line 91:
# If you are using Spamprep, the following line should be commented out echo "Envelope-To: " $Envelope >> $myCgate/Submitted/$NewFile # If you are using Spamprep, the following line should be commented out
echo "Envelope-To: " $Envelope >> $myCgate/Submitted/$NewFile
Line 46: Line 94:
# Append an X-Spam header in there. This is very important. Without this # tag, if spamc fails to call spamd, it will send the message back without # a tag and your message will fall into an UGLY loop. This alleviates that. # Append an X-Spam header in there. This is very important. Without this
# tag, if spamc fails to call spamd, it will send the message back without
# a tag and your message will fall into an UGLY loop. This alleviates that.
Line 48: Line 98:
# If you are using Spamprep, the following line should be commented out echo "X-Spam-Status: Scanner Called" >> $myCgate/Submitted/$NewFile # If you are using Spamprep, the following line should be commented out
echo "X-Spam-Status: Scanner Called" >> $myCgate/Submitted/$NewFile
Line 50: Line 101:
# strip out CommuniGate stuff for SpamAssassin first # using awk, and then send to spamc. # strip out CommuniGate stuff for SpamAssassin first
# using awk, and then send to spamc.
Line 52: Line 104:
# If you are using Spamprep, the following line should be commented out gawk '/Received/, /\n/' $myCgate/$QueuePath | /usr/local/bin/spamc -d 127.0.0.1 -f >> /var/CommuniGate/Submitted/$NewFile # If you are using Spamprep, the following line should be commented out
gawk '/Received/, /\n/' $myCgate/$QueuePath | /usr/local/bin/spamc -d 127.0.0.1 -f >> /var/CommuniGate/Submitted/$NewFile
Line 54: Line 107:
# If you are using Spamprep, the following line should be uncommented #/var/CommuniGate/spam/spamprep "$myCgate/$QueuePath" "$ReturnPath" "$Envelope" | /usr/bin/spamc -d 127.0.0.1 -f >> "$myCgate/Submitted/$NewFile" # If you are using Spamprep, the following line should be uncommented
#/var/CommuniGate/spam/spamprep "$myCgate/$QueuePath" "$ReturnPath" "$Envelope" | /usr/bin/spamc -d 127.0.0.1 -f >> "$myCgate/Submitted/$NewFile"
Line 56: Line 110:
#Now submit the file by renameing it to .sub mv /var/CommuniGate/Submitted/$NewFile /var/CommuniGate/Submitted/$FinalFile #Now submit the file by renameing it to .sub
mv /var/CommuniGate/Submitted/$NewFile /var/CommuniGate/Submitted/$FinalFile
Line 58: Line 113:
# done. exit 0; }}} # done.
exit 0;
}}}

Integrating with Communigate Pro

There are a number of different way to integrate SpamAssassin with Communigate Pro. Note that some of these are pretty old and haven't been modified recently.

scanspam.sh

Script to call Spam Assassin from CommuniGate Pro Rules v1.1 Ed Fang If you have any improvements, drop me a line at edfang@visi.net Thanks for Stefan Seiz for the original template

Script will call SpamAssassin spamc from CommuniGate. Since SA modifies the actual message, it must be re-delivered via the Submitted directory. Sneaky Header Tagging is used to prevent the message from being scanned again, and/or being caught in a loop is spamd fails.

Source code

################################################################################
#  Script to call Spam Assassin from CommuniGate Pro Rules  v1.1  Ed Fang 
#     If you have any improvements, drop me a line at edfang@visi.net 
#         Thanks for Stefan Seiz for the original template 
# 
# Script will call SpamAssassin spamc from CommuniGate.  Since SA modifies 
# the actual message, it must be re-delivered via the Submitted directory.
# Sneaky Header Tagging is used to prevent the message from being scanned 
# again, and/or being caught in a loop is spamd fails. 
# 
# DATA
# Communigate Pro Rules 
# Any Recipient in     *@domain.com 
# Message Size  less than   32768 
# Header Field   is not     X-Spam-Status* 
# 
# ACTION 
# Execute       [STDERR] [FILE] [RETPATH] [RCPT] /var/CommuniGate/scanspam.sh 
# Discard 
# 
#  You must discard the message as the script will re-submit the marked message through the 
#  Submitted directory of CommuniGate.  If you don't, you'll get every message 
#  twice - once scanned, once clear through.  (which is a good way to test 
#  before actually discarding the message.  Stalker has asked that messages 
#  not be modified in the Queue directory, so it's just safer to play by their 
#  rules. 
# 
#  1.1 - Changed to run using gawk.  Highly advised as awk will occasionally 
#        crap out with trememdously long html lines. 
# 
#  Note: The global variables aren't used all over the place, so I'll clean that 
#  up in a later version.  I think there might be a more efficient awk script 
#  so any other awk gurus out there might be able to give me a better awk 
#  than the one I have (which skips everything until it matches Received 
#  and then to the end of the file. 
#

################################################################################
#### START user configurable variables
# CGate base directory myCgate="/var/CommuniGate" myLogFile="/var/CommuniGate/spam-result.out"

#### END user configurable variables
#Comment out following two lines if you don't want to echo the passed variable info to 
#the spam-result.out file. 
myDate=`date +%Y-%m-%d\ %H:%M:%S` 
echo "Date $myDate " $@ >> $myLogFile

#Get the fileid of the message file 
QueuePath=$2 
NewFile=`basename $QueuePath`'.tmp' 
FinalFile=$NewFile'.sub'

# Formulate return-path and Envelope-To addresses from command line args. 
# shift out the first 3 arguments, make sure one > to create a new file shift 3

# If you are using Spamprep, the following line should be commented out 
echo "Return-Path:" $1 > /var/CommuniGate/Submitted/$NewFile

# If you are using Spamprep, the following line should be uncommented 
# ReturnPath=$1

# shift out 5 command arguments.  and start appending shift 2 
Envelope=$1 
shift 
while [ $# -gt 0 ] do

 . Envelope=$Envelope','$1 shift

done

# Formulate the envelope Header file.

# If you are using Spamprep, the following line should be commented out 
echo "Envelope-To: " $Envelope >> $myCgate/Submitted/$NewFile

# Append an X-Spam header in there.  This is very important.  Without this 
# tag, if spamc fails to call spamd, it will send the message back without 
# a tag and your message will fall into an UGLY loop.  This alleviates that.

# If you are using Spamprep, the following line should be commented out 
echo "X-Spam-Status: Scanner Called" >> $myCgate/Submitted/$NewFile

# strip out CommuniGate stuff for SpamAssassin first 
# using awk, and then send to spamc.

# If you are using Spamprep, the following line should be commented out 
gawk '/Received/, /\n/' $myCgate/$QueuePath | /usr/local/bin/spamc -d 127.0.0.1 -f >> /var/CommuniGate/Submitted/$NewFile

# If you are using Spamprep, the following line should be uncommented 
#/var/CommuniGate/spam/spamprep "$myCgate/$QueuePath" "$ReturnPath" "$Envelope" | /usr/bin/spamc -d 127.0.0.1 -f >> "$myCgate/Submitted/$NewFile"

#Now submit the file by renameing it to .sub 
mv /var/CommuniGate/Submitted/$NewFile /var/CommuniGate/Submitted/$FinalFile

# done. 
exit 0; 

CommuniGate (last edited 2015-05-04 22:09:21 by BretMiller)