SpamAssassin Pickup Event not running?

Discussion, support and announcements for third party applications that work with MailEnable.
chrisbliss18
Posts: 11
Joined: Wed Jan 14, 2004 6:53 pm

SpamAssassin Pickup Event not running?

Post by chrisbliss18 »

I am setting up spam filtering on our server and I chose to use SpamAssassin with the ME Pickup Event plug-in. I followed the instructions that were included with the plug-in, but it would seem that the emails are not getting processed by SpamAssassin. I have tested SpamAssassin on the command line and it operates correctly on both the spam and non-spam sample messages. When I send messages that match the spam sample to an account on the server, the message does not get modified and nothing is dropped in the quarentine folder.

Anyone have ideas on ways that I can test the installation to see what my problem could be?

SeanNij
Posts: 12
Joined: Sat May 14, 2005 8:32 am
Location: South Africa

Spam PickUp Event

Post by SeanNij »

Hi, saw your posting (albeit more then a year later) - question - did you ever resolve this as i'm having the same problem?

Brett Rowbotham
Posts: 560
Joined: Mon Nov 03, 2003 7:48 am
Location: Cape Town

Post by Brett Rowbotham »

Here is the pick-up event code that I use on my server:

Code: Select all

'-------------------------------------------------------
' MTASpam.vbs - A pickup event script for MailEnable to run SpamAssassin
'
' USAGE:
'
' 1) Copy the .vbs file to the mailenable\bin directory. 
' 2) In the properties of the MTA, enable the pickup event. 
' 3) Enter the following in the Program to Execute Field: cscript //T:30 "C:\Program Files\Mail Enable\Bin\MTASpam.vbs"
'
' Note the //T:30 prevents the script from running more than 30 seconds.  This will stop a
' confused or looping script from stealing all the CPU from your server!
'
'-------------------------------------------------------

Dim WshShell						' WScript
Dim MailDataPath				' Path of registry values
Dim MessageID						' Message ID of current email
Dim ConnectorCode				' Connection path
Dim MessageFilePath			' Path to original message file
Dim MessageFilePathNew	' Path to processed message file
Dim FSO									' As FileSystemObject
Dim f										' As File
Dim oExec								' As WshScriptExec
Dim cline								' As String

Set WshShell = CreateObject("WScript.Shell")
MailDataPath = WshShell.RegRead("HKLM\SOFTWARE\Mail Enable\Mail Enable\Data Directory")
MessageID = WScript.arguments(0)
ConnectorCode = WScript.arguments(1)
MessageFilePath = MailDataPath & "\Queues\" & ConnectorCode & "\Inbound\Messages\" & MessageID

' Only call SpamAssassin for SMTP events
If ConnectorCode = "SMTP" Then
	' Check the size of the mail item
	Set FSO = WScript.CreateObject("Scripting.FileSystemObject")
	Set f = FSO.GetFile(MessageFilePath)
	' Only process files under 1 MB
	If f.size <= 1048576 Then
		' Set up processed file name
		MessageFilePathNew = MessageFilePath & ".tmp"
		cline = "C:\Perl\bin\spamassassin.bat -L -e < " & Chr(34) & MessageFilePath & Chr(34) & "> " & Chr(34) & MessageFilePathNew & Chr(34)
		Set oExec = WshShell.Exec(cline)
		Do While oExec.Status = 0
			WScript.Sleep 100
		Loop
		Set oExec = Nothing
		' Check that the processed file actually exists
		If FSO.FileExists(MessageFilePathNew) Then
			' Copy processed file over original file
			FSO.CopyFile MessageFilePathNew, MessageFilePath, true
			' For now keep a copy of the processed file
			FSO.CopyFile MessageFilePathNew, "C:\Test\", true
			' Delete the processed file
			FSO.DeleteFile MessageFilePathNew
		End If
	End If
	Set f = Nothing
	Set FSO = Nothing
End If
Set WshShell = Nothing
The code is saved in the file MTASpam.vbs. Note that I only process files less than 1MB in size (otherwise processing takes too long) that come from the SMTP connector. Also, I save a copy of all files in the folder C:\Test for manual checking. You might want to get rid of this line (it is commented in the code). The only other thing you would need to check is that the path to the SpamAssassin batch file is correct.

I hope you can get this working as SpamAssassin is a life saver when it comes to spam.

Cheers,
Brett

SeanNij
Posts: 12
Joined: Sat May 14, 2005 8:32 am
Location: South Africa

Spam PickUp Event

Post by SeanNij »

Now, I thought all the people who lived by the mountain never worked! Works like a charm! Thankyou. Now to learn how to configure spam assassin!

jeleczko
Posts: 3
Joined: Fri May 27, 2005 1:23 pm

spamassassin complie strangeness

Post by jeleczko »

I followed all of the instructions on: http://www.openhandhome.com/howtosa300.html

and everything was going great until I get to PART IX: Testing SpamAssassin. I run the spamassassin -D -t < sample-nonspam.txt > nospam.txt and get nothing, no debug info in the dos window, nothing in the text output file, but I also get no errors either so I am at a total loss? Does anyone have any idea what the heck is going on?

Jim

bbennett
Posts: 17
Joined: Tue Mar 22, 2005 9:20 am

Post by bbennett »

Hey Guys,

I used the cscript pickup event above, but it doesn’t seem to parse RBL's whereas the saplugin does.

Does anybody have RBL lookups working with this pickup event?

Thanks,
Brian

Brett Rowbotham
Posts: 560
Joined: Mon Nov 03, 2003 7:48 am
Location: Cape Town

Post by Brett Rowbotham »

In your local.cf configuration (in perl\site\etc\mail\spamassassin) make sure you have skip_rbl_checks set to 0. This should allow the RBL checks (if I understand your question correctly).

Cheers,
Brett

bbennett
Posts: 17
Joined: Tue Mar 22, 2005 9:20 am

Post by bbennett »

Hi,

I found i had to remove the -L from the script.

cline = "C:\Perl\bin\spamassassin.bat -L -e

Brett Rowbotham
Posts: 560
Joined: Mon Nov 03, 2003 7:48 am
Location: Cape Town

Post by Brett Rowbotham »

Quite correct, I had forgotten about that required change.

Cheers,
Brett

bbennett
Posts: 17
Joined: Tue Mar 22, 2005 9:20 am

Post by bbennett »

Thanks Brett, your pickup events works great and is much faster then the plug-in from the mail enable site. I only have one lingering problem though and that is some messages are left in the SMTP/incoming/messages folder. Do you know what would cause that or if those will ever be processed? This also occurs if I use the other plug-in.

Brett Rowbotham
Posts: 560
Joined: Mon Nov 03, 2003 7:48 am
Location: Cape Town

Post by Brett Rowbotham »

I also find left over messages from time to time but have no idea what would cause that other than real-time virus scanning which in my case is disabled for the whole MailEnable folder array. These messages will never be processed as their header files have gone from SMTP\Incoming and it is only the body that remains in SMTP\Incoming\Messages.

Now that I think about I will have to check whether those messages actually got through or not but, having had no complaints, I would suspect that this is a harmless trait that just requires cleaning the folder of junk every so often. A small price to pay for the power of SpamAssassin !

pehuen
Posts: 1
Joined: Wed Dec 28, 2005 12:59 am

mtaplugin.vbs not work

Post by pehuen »

I am a spanish user of ME
I try to use your MTA plugin to spamassassin but it not work.
When i test it, it gives me an error at lines
MessageID = WScript.arguments(0)
ConnectorCode = WScript.arguments(1)
Error Text "The subscript is out of the interval"
can you help me?

netblue
Posts: 13
Joined: Wed Oct 05, 2005 4:40 pm

Post by netblue »

Can this be modifed to not send the user an email, and just quarnitine the message?

netblue
Posts: 13
Joined: Wed Oct 05, 2005 4:40 pm

Modified

Post by netblue »

This is Brett's script but modified to Quarantine Email.

Code: Select all

'------------------------------------------------------- 
' MTASpam.vbs - A pickup event script for MailEnable to run SpamAssassin 
' 
' USAGE: 
' 
' 1) Copy the .vbs file to the mailenable\bin directory. 
' 2) In the properties of the MTA, enable the pickup event. 
' 3) Enter the following in the Program to Execute Field: cscript //T:30 "C:\Program Files\Mail Enable\Bin\MTASpam.vbs" 
' 
' Note the //T:30 prevents the script from running more than 30 seconds.  This will stop a 
' confused or looping script from stealing all the CPU from your server! 
' 
'------------------------------------------------------- 

Dim WshShell                  ' WScript 
Dim MailDataPath            ' Path of registry values 
Dim MessageID                  ' Message ID of current email 
Dim ConnectorCode            ' Connection path 
Dim MessageFilePath         ' Path to original message file 
Dim MessageFilePathNew   ' Path to processed message file
Dim MessageJunk			'Quaratnine
Dim MessageJunkMsg		'Quanrantine Msg Folder
Dim FSO                           ' As FileSystemObject 
Dim f                              ' As File 
Dim oExec                        ' As WshScriptExec 
Dim cline                        ' As String 
Dim result			'As Integer

Set WshShell = CreateObject("WScript.Shell") 
MailDataPath = WshShell.RegRead("HKLM\SOFTWARE\Mail Enable\Mail Enable\Data Directory") 
MessageID = WScript.arguments(0) 
ConnectorCode = WScript.arguments(1) 
MessageJunk = MailDataPath & "\Quarantine\" & MessageID
MessageJunkMsg = MailDataPath & "\Quarantine\Messages\" & MessageID
MessageFilePath = MailDataPath & "\Queues\" & ConnectorCode & "\Inbound\Messages\" & MessageID 

' Only call SpamAssassin for SMTP events 
If ConnectorCode = "SMTP" Then 
   ' Check the size of the mail item 
   Set FSO = WScript.CreateObject("Scripting.FileSystemObject") 
   Set f = FSO.GetFile(MessageFilePath) 
   ' Only process files under 1 MB 
   If f.size <= 1048576 Then 
      	
	'Set up processed file name 
     	MessageFilePathNew = MessageFilePath & ".tmp" 
	cline = "C:\Perl\bin\spamassassin.bat -e < " & Chr(34) & MessageFilePath & Chr(34) & "> " & Chr(34) & MessageFilePathNew & Chr(34) 
	
	'Run SpamAssassin and wait until its finished This is the slowest part of the process
	Set oExec = WshShell.Exec(cline) 
	Do While oExec.Status = 0 
        	WScript.Sleep 100 
	Loop 
	Set oExec = Nothing 
      
	' Check that the processed file actually exists
      	If FSO.FileExists(MessageFilePathNew) Then
	
		'Look in the file for the SPAM FLAG
		const ForReading = 1
		const TristateFalse = 0
		dim strMail
		dim objFile
		dim okjTS
		set objFile = FSO.GetFile(MessageFilePathNew)
		set objTS = objFile.OpenAsTextStream(ForReading, TristateFalse)

		'Specifying the file size will reduce the read time for processing significantly
		strMail = objTS.Read(objFile.Size)

		If instr(strMail, "X-Spam-Status: Yes") > 0 Then
			result = 1
		End If

		'Release the file from memory so it can be manipulated
		set strMail = Nothing
		set objFile = Nothing
		set objTS = Nothing
		Set f = Nothing 

		If result = 0 Then
         		' Copy processed file over original file 
	         	FSO.CopyFile MessageFilePathNew, MessageFilePath, true 
        	 	' Delete the processed file 
         		FSO.DeleteFile MessageFilePathNew 
		Else
			FSO.DeleteFile MessageFilePathNew
			FSO.CopyFile MessageFilePath, MessageJunkMsg, True
			FSO.MoveFile MessageFilePath, MessageJunk
		End If
	End If 
   End If 
   Set FSO = Nothing 
End If 
Set WshShell = Nothing 

Brett Rowbotham
Posts: 560
Joined: Mon Nov 03, 2003 7:48 am
Location: Cape Town

Post by Brett Rowbotham »

Quarantining of spam messages on my system is done through an MTA message filter that checks for X-Spam-Status and quarantines messages as appropriate. This is why there is no code in my original script to move spam messages into quarantine.

Cheers,
Brett

Post Reply