HOWTO: Using SpamAssassin with hMailServer V4

Use this forum if you have installed hMailServer and want to ask a question related to a production release of hMailServer. Before posting, please read the troubleshooting guide. A large part of all reported issues are already described in detail here.
GlenC
Senior user
Senior user
Posts: 680
Joined: 2004-08-17 23:31
Location: Santiago, Chile

Post by GlenC » 2005-03-29 16:33

I found a perl script that generates reports from the spamd log. I made modifications to it so it works with the cygwin install of spamassassin. It may work ok with other versions too as long as the log files are in the same format. I also added a few options for reports. The original was found here:
http://freshmeat.net/projects/sa-stats/
and you can download mine here:
http://home.comcast.net/~carrerasg/sa-stats-mod.zip

The only thing you should have to do is modify the path in the config section so it can find your spamd log. It should run ok... but, the report for the last week and the custom report might run a little slow on a big log (I really don't know much about optimization :roll: )

EDIT: Just put up another version which corrected some errors and made the tables a little easier to read. If you had problems with the original version you might try this one. Also added an email report option. It requires the ssmtp package though (cygwin).

User avatar
john25uk
Normal user
Normal user
Posts: 102
Joined: 2004-11-30 17:07
Location: Kingston, UK
Contact:

Post by john25uk » 2005-04-08 00:35

Hi there,

I have finally installed CygWin to run SpamD on my system, and it works like a dream.

I do have problems with WinSpamC and the CygWin built SpamC.

WinSpamC buggers up most documents I have put through it - so for those who it works fine for, what system are you on? and did you build WinSpamC for yourselves or use the one distributed?

SpamC seems to replace CRs with the little square (unix CR??) and also seems to mess up the headers of the email and makes it appear with the wrong date, no subject, and no from! - Might be because I built it with CygWin, so are trying it with my 2003 windows box to build and use.

Any ideas?

John
C:\ C:\DOS C:\DOS\RUN RUN\DOS\RUN

John 8)

GlenC
Senior user
Senior user
Posts: 680
Joined: 2004-08-17 23:31
Location: Santiago, Chile

Post by GlenC » 2005-04-08 00:58

john25uk wrote:I have finally installed CygWin to run SpamD on my system, and it works like a dream. I do have problems with WinSpamC and the CygWin built SpamC.
John
Strange that you wrote this today, I've been fighting with SpamC/D all day today. As I wrote before, WinSpamC has always truncated attachments on my system. Never figured out exactly why. An now recently, the cygwin version of SpamC started acting crazy... it appears that for any message over 34k, it will not rewrite the headers or mark the subject. (although I can tell from the logs that it IS in fact being scanned, and properly).

I'd be very interested in hearing what systems others are using also.

(I'm using WinXP SP2 with the cygwin builds)

User avatar
mirb
Normal user
Normal user
Posts: 45
Joined: 2005-02-28 03:01
Location: Italy
Contact:

Post by mirb » 2005-04-08 01:52

i run spamassassin 3.0.2 on cygwin (i suggest 1.5.12 and not 1.5.13 that has some incompatibility...for example clamav stop run..), spamD as explained in our common source; winspamc is the distributed version and spamd as service (purplebear method); all work absolutily fine expecially after the introduction of user preferences functionality.

All under Windows 2003 IIS, PHP5, perl5.8, MySQL 4.1.10, and always the last bulid of HMServer;

well, i had had to remove and reinstall cuygwin many times to get the perfect stability; all problems you are encontering, i thing may depend on cygwin/spamd and never on winspamc;

i suggest to unistall cygwin and reinstall it (use 1.5.12 ..trust me) very carefully, install spamd service and get a rock solid system;

i experienced bud cygwin functionality after upgrading its installation with some other components, instead an all in one and no more action installation results fine.

procedures i installed:
Component during cygwin installation:
- All BASE packages
- under DATABASE, both the DEVEL and RUNTIME version of SleepyCat 3.1 Berkeley DB
- under DEVEL, the MAKE, GCC
- under INTERPRETERS, Perl
- under NET, the INETUTILS
- under Admin cygrunsrv for start spamd as service in cygwin
- under BASE cygwin 1.5.12-1

Once cygwin installed, under "CPAN":
- install DB_File
- install Time::HiRes
- install Net::DNS
- install HTML::Parser
- install DBI
- installation of mysql client (http://www.enstimac.fr/Perl/perl5.6.1/s ... ows/cygwin)

(last two are for activate user pref functionality)

try also to run spamd with -i HOST_IP -A IP_ALLOWED switches
and -d MAILSERVER_IP switches with WinSpamC; i feel them more solid...

GlenC
Senior user
Senior user
Posts: 680
Joined: 2004-08-17 23:31
Location: Santiago, Chile

Post by GlenC » 2005-04-08 18:55

john25uk wrote: WinSpamC buggers up most documents I have put through it - so for those who it works fine for, what system are you on?
John
John... I don't know whether this will fix your problem or not but it fixed the problem I was having with winspamc truncations AND the problem with no markup with the cygwin version of spamc. I have a choice now!! :D

At the very bottom of this page is a patched version of spamd... just rename your old and replace with the attachment he provides. I haven't tested long enough to see if anything new has cropped up but my initial tests show everything is good. Hope this does something for you.

http://bugzilla.spamassassin.org/show_bug.cgi?id=3917

User avatar
john25uk
Normal user
Normal user
Posts: 102
Joined: 2004-11-30 17:07
Location: Kingston, UK
Contact:

Post by john25uk » 2005-04-08 22:10

I tried that and it seems to be working!! Blimy, what a pain in the ass spam is!

Thanks!

John
C:\ C:\DOS C:\DOS\RUN RUN\DOS\RUN

John 8)

GlenC
Senior user
Senior user
Posts: 680
Joined: 2004-08-17 23:31
Location: Santiago, Chile

Post by GlenC » 2005-04-09 04:09

I'm glad that worked for you. I don't know why they didn't backport that fix to 3.0.2 as it seems like a fairly severe problem to me.

Horas
New user
New user
Posts: 4
Joined: 2004-08-28 17:16

Post by Horas » 2005-04-22 17:47

@john25uk: Do you still have the vbs-Script which you used in your first solution (the one that ist called by the external Virusscanner Tab)? The Link is broken...
I don't want to install hMailServer 4.0 yet so I would like to try that solution before.
Thanks

User avatar
john25uk
Normal user
Normal user
Posts: 102
Joined: 2004-11-30 17:07
Location: Kingston, UK
Contact:

Post by john25uk » 2005-04-22 17:58

Hello Horas,

I do, but not at the moment! i will re post it tomorrow somtime when I am work as I have it archived there!

John
C:\ C:\DOS C:\DOS\RUN RUN\DOS\RUN

John 8)

User avatar
mirb
Normal user
Normal user
Posts: 45
Joined: 2005-02-28 03:01
Location: Italy
Contact:

Post by mirb » 2005-04-22 18:14

Wasn't this one?

Code: Select all

dim filename, args
set args = wscript.arguments
if args.count = 0 then wscript.quit(99)
filename = args(0)
filename = filename & " " & args(1)
dim infile, outfile
dim fso, ts
set fso = createobject("Scripting.FileSystemObject")
if not fso.fileexists(filename) then script.quit(89)
infile = fso.getabsolutepathname(filename)
testfile = infile & ".tmp"
dim cmd, sh, rc
fso.movefile infile, testfile
cmd = "cmd /c perl -S -T -w spamassassin < """ & testfile & """ > """ & infile & """"
set sh = CreateObject("WScript.Shell")
rc = sh.Run( cmd , 0 , TRUE)
fso.deletefile testfile
wscript.quit(7)

thegregor
New user
New user
Posts: 12
Joined: 2005-01-27 22:44

My OnDeliverMessage script, with learning support

Post by thegregor » 2005-05-11 21:54

Here's the OnDeliverMessage script I wrote today to hook SpamAssassin into hMail v4.

This is a first run, there some changes I know I want to make, but it's working. I've also only written 2 or 3 VBScripts in my life so I don't know the language too well, if people see places for improvement, let me know.

This builds on the examples in this thread and adds support for emailing into SpamAssassin's bayesian learning script. This uses a setup with spamd running in cygwin as a service, called by WinSpamC.

You'll need to edit the learning addresses and path to WinSpamC for your application (at least).

Code: Select all


Sub OnDeliverMessage(oMessage)
	' set some default values
	spamAddress = "report_spam@[mydomain.com]"
	hamAddress  = "report_ham@[mydomain.com]"

	fname = oMessage.filename

	Dim infile, outfile
	Dim fso
	Set fso = CreateObject("Scripting.FileSystemObject")
	If Not fso.fileexists(fname) then
		result.Value = 0
		Exit Sub
	End If
	infile = fso.GetAbsolutePathname(fname)
	testfile = infile & ".tmp"
	Dim cmd,sh,rc
	fso.MoveFile infile,testfile

	' LEARN IF NECESSARY
	Dim oRecipients
	Set oRecipients = oMessage.Recipients
	For i = 0 to oRecipients.Count - 1
		Dim sAddress
		sAddress = oRecipients.Item(i).Address
		If sAddress = spamAddress Then
			LearnSpam( testfile )
			result.Value = 1
		End If
		If sAddress = hamAddress Then
			LearnHam( testfile )
			result.Value = 1
		End If
	Next

	cmd = "cmd /c D:\WinSpamC\WinSpamC.exe -t 15 -x < """ & testfile & """ > """ & infile & """"

	Set sh = CreateObject("WScript.Shell")
	rc = sh.Run( cmd, 0, TRUE )
	'msgbox rc

	' Uncomment if you want to reject spam
	'If rc = 1 Then
	'	result.Value = 1
	'	Exit Sub
	'End If

	fso.DeleteFile testfile
	Set fso = Nothing
	result.Value = 0
End Sub

Sub LearnHam( f )
	Dim lrnCom
	lrnCmd = "cmd /c perl -T -S sa-learn --ham """ & Replace( f, "\", "\\" ) & """"
	Dim lrnSh, lrnRc
	Set lrnSh = CreateObject( "WScript.Shell" )
	rc = lrnSh.Run( lrnCmd, 0, True )
End Sub

Sub LearnSpam( f )
	Dim lrnCmd
	lrnCmd = "cmd /c perl -T -S sa-learn --spam """ & Replace( f, "\", "\\" ) & """"
	Dim lrnSh, lrnRc
	Set lrnSh = CreateObject( "WScript.Shell" )
	rc = lrnSh.Run( lrnCmd, 0, True )
End Sub

User avatar
john25uk
Normal user
Normal user
Posts: 102
Joined: 2004-11-30 17:07
Location: Kingston, UK
Contact:

Post by john25uk » 2005-05-12 16:17

I thought that learning for forwarded messages is not a good idea? (Because the email address will be your own)

One way to do it would be to forward the un caught spam as a attachment, extract the attachment and then learn that one?

I have been meaning to do somthing similar for ages, but never got around to it! (usual story)
C:\ C:\DOS C:\DOS\RUN RUN\DOS\RUN

John 8)

thegregor
New user
New user
Posts: 12
Joined: 2005-01-27 22:44

Post by thegregor » 2005-05-12 17:10

I thought that learning for forwarded messages is not a good idea?
You want to redirect the message in your mail client, not forward it.
g.

User avatar
john25uk
Normal user
Normal user
Posts: 102
Joined: 2004-11-30 17:07
Location: Kingston, UK
Contact:

Post by john25uk » 2005-05-12 17:15

Where do you do that then?

I can see no "Redirect" button in Thunderbird (Maybe I am being a dumbass today!)
C:\ C:\DOS C:\DOS\RUN RUN\DOS\RUN

John 8)

thegregor
New user
New user
Posts: 12
Joined: 2005-01-27 22:44

Thunderbird redirect extension

Post by thegregor » 2005-05-12 19:48

Yes, it's an odd omission in Thunderbird. Most other clients have it built-in.

You need this extension:

http://mailredirect.mozdev.org/

g.

User avatar
john25uk
Normal user
Normal user
Posts: 102
Joined: 2004-11-30 17:07
Location: Kingston, UK
Contact:

Post by john25uk » 2005-05-12 20:49

cool, thanks.
C:\ C:\DOS C:\DOS\RUN RUN\DOS\RUN

John 8)

User avatar
mirb
Normal user
Normal user
Posts: 45
Joined: 2005-02-28 03:01
Location: Italy
Contact:

attachment truncated

Post by mirb » 2005-05-27 19:13

installed spamassassin version 3.0.3 under cygwin and winspamc; attachments are truncated after passing trough spamc/spamd/spamassassin; even if i use the wspamd.bat modified... anyone?

GlenC
Senior user
Senior user
Posts: 680
Joined: 2004-08-17 23:31
Location: Santiago, Chile

Re: attachment truncated

Post by GlenC » 2005-05-27 23:38

mirb wrote:installed spamassassin version 3.0.3 under cygwin and winspamc; attachments are truncated after passing trough spamc/spamd/spamassassin; even if i use the wspamd.bat modified... anyone?
I am a glutton for punishment sooo, I installed 3.0.3 :) But, I'm not having the problem with truncated attachments. I only tried a few though so I might be in for a surprise treat later. Anything in particular that the attachments might have in common that I can try?

My current setup:
Spamassassin/Spamd ver. 3.0.3
Spamc (I think I built this version from 3.0.2 but it made no difference with my previous truncation problems)
cygwin dll 1.5.17-1

EDIT: oops, I lied... kinda. It wasn't truncating the files but it wasn't actually working either. It was giving me back my original message with no mark-up.

Using SA 3.0.3 and the modified spamd (bugfix) it is now working properly. I don't know why they didn't fix the bug in 3.0.3 but apparently it will be fixed in 3.1. Anyway, copy everything from this link and paste it into your spamd file. Here's the link from bugzilla.spamassasin.org

http://bugzilla.spamassassin.org/attachment.cgi?id=2588

User avatar
mirb
Normal user
Normal user
Posts: 45
Joined: 2005-02-28 03:01
Location: Italy
Contact:

Post by mirb » 2005-05-28 05:49

glenc: you talked about spamc built from spamassassin source? don't you use winspanc.exe adapted version for windows (http://sourceforge.net/projects/winspamc) instead?

GlenC
Senior user
Senior user
Posts: 680
Joined: 2004-08-17 23:31
Location: Santiago, Chile

Post by GlenC » 2005-05-28 14:27

mirb wrote:glenc: you talked about spamc built from spamassassin source? don't you use winspanc.exe adapted version for windows (http://sourceforge.net/projects/winspamc) instead?
When I was having troubles (like yours) about a month ago, I built spamc in an effort to fix the problem. I later found out the problem was actually with spamd. I just never changed back to winspamc. It made no real difference so I kept it.

Did you try the bugfix for spamd and did it correct your problem?

User avatar
mirb
Normal user
Normal user
Posts: 45
Joined: 2005-02-28 03:01
Location: Italy
Contact:

Post by mirb » 2005-05-28 14:56

i always used spamd bugfixed version, but problem is not corrected

GlenC
Senior user
Senior user
Posts: 680
Joined: 2004-08-17 23:31
Location: Santiago, Chile

Post by GlenC » 2005-05-28 16:04

hmmm... I'm at a loss then. Are you getting errors in your eventlog that contain something similar to this?

The following information is part of the event: spamc : PID 4596 : failed sanity check, 41425 bytes claimed, 40401 bytes seen.

devil_dog
New user
New user
Posts: 8
Joined: 2005-06-12 11:54

Re: SPAMASSASSIN for hMailServer

Post by devil_dog » 2005-06-21 18:23

john25uk wrote:Hi there, just incase anyone was wondering how to - I created a directory (which is shared to my network) on my server with two subs, one called SPAM, the other HAM (EG C:\SALEARN\SPAM). They are for users to copy examples of spam that they recieve that hasn't been marked, and also for examples of regular 'proper' mail so SA can tell the difference. Then i created a batch file on a scheduler to update the database twice a day (to save logging onto the server and doing it manually) The Batch file I use can be downloaded from HERE

.
i just installed the SM and its workin gr8....
i wanna use that script of yrs....
i have loads of spam to train SA on....but the problem is from outlook or outlook express i can get only .msg files....not .eml files....
will yrscript work if i use it wid msg files??
even if i rename *.eml with *.msg can spamassassin process the .msg files??

btw tx a lot for the detailed guide....

devil_dog
New user
New user
Posts: 8
Joined: 2005-06-12 11:54

Post by devil_dog » 2005-06-21 18:44

Code: Select all

E:\spam>spamlearn

E:\spam>Rem Put SET RES_NAMESERVERS here

E:\spam>REM where SET RES_NAMESERVERS=158.152.1.58
LEARNING NEW NON-SPAM
Use of uninitialized value in concatenation (.) or string at C:/Perl/lib/File/Sp
ec/Win32.pm line 291.
Learned from 0 message(s) (0 message(s) examined).
New HAM Learned
LEARNING NEW SPAM
Use of uninitialized value in concatenation (.) or string at C:/Perl/lib/File/Sp
ec/Win32.pm line 291.
Learned from 0 message(s) (0 message(s) examined).
New SPAM Learned

E:\spam>


is this normal....
i put in abt 9 MB of spams/non spams....

GlenC
Senior user
Senior user
Posts: 680
Joined: 2004-08-17 23:31
Location: Santiago, Chile

Re: My OnDeliverMessage script, with learning support

Post by GlenC » 2005-06-30 04:37

thegregor wrote:Here's the OnDeliverMessage script I wrote today to hook SpamAssassin into hMail v4.
thegregor,
Thanks for this mod, I finally got around to implementing it and I like it a lot. I made a few modifications, one was to delete the tmp files in the data directory. Other things I added are just some of my own preferences.

One thing that caused me a lot of grief when trying to implement this was the recipient part. Maybe because I have a catch-all address, but until I actually added accounts in my domain for the users "report_spam" and "report_ham", the recipient was always MY account, thus the script was aborting. After adding those accounts everything worked fine. Here's my latest version of the script:
(PS If anyone sees improvements to make here, or stupid code, please let me know... I'm a copycat coder and do a lot of things I probably shouldn't) :roll:

Code: Select all

Sub OnDeliverMessage(oMessage)
' set addresses for Spam-Ham reporting (modify these)
spamAddress = "report_spam@yourdomain.com"
hamAddress  = "report_ham@yourdomain.com"

fname = oMessage.filename

Dim infile, testfile
Dim fso
Set fso = createobject("Scripting.FileSystemObject")
If Not fso.fileexists(fname) then
	result.Value = 0
	Exit sub
End If

infile = fso.getabsolutepathname(fname)
testfile = infile & ".tmp"
fso.CopyFile infile, testfile

'LEARN IF NECESSARY
dim oRecipients
set oRecipients = oMessage.Recipients

for i = 0 to oRecipients.Count - 1
  dim sAddress
  sAddress = oRecipients.Item(i).Address

If sAddress = spamAddress Then
	LearnSpam( testfile )
	fso.Deletefile testfile
	Set fso = Nothing
  result.Value = 1
End If
If sAddress = hamAddress Then
	LearnHam( testfile )
	fso.Deletefile testfile
	Set fso = Nothing
	result.Value = 1
End If
Next

'DENY CHECKS FOR MAIL FROM LOCAL DOMAIN
Dim s1, ts1, SearchString
Const ForReading = 1
Set ts1 = fso.OpenTextFile(fname, ForReading)
s1 = ts1.ReadLine
ts1.Close
'SearchString = whatever your machine inserts in the msg (modify this)
SearchString ="Received: FROM [192.168.1."

If InStr(1, s1, SearchString, 1) > 0 Then
	'Comment next two lines to allow local domain spam checks
	Set fso = Nothing
	Exit Sub
End If

'CALL SPAMASSASSIN (modify as required)
Dim cmd, cmd1, rc, rc1, sh
cmd = "cmd /c spamc -E -s 512000 < """ & testfile & """ > """ & infile & """"
cmd1 = "cmd /c perl -S -T -w spamassassin < """ & testfile & """ > """ & infile & """"

Set sh = CreateObject("WScript.Shell")
rc = sh.Run( cmd , 0 , TRUE)
If rc = 0 Then									'Do something for HAM
	ElseIf rc = 1 Then						'Do something for SPAM
		'Uncomment next two lines to reject spam
		' result.Value = 1
		' Exit Sub
	Else  rc1 = sh.Run( cmd1 , 0 , TRUE)			'There was an error, call SpamAssassin directly
End If

If fso.GetFile(infile).Size = 0 Then		'Failsafe: In the event an error causes a zero byte msg
	fso.CopyFile testfile, infile
End if

fso.Deletefile testfile
Set fso = Nothing
result.value = 0
End Sub

Sub LearnHam( f )
   Dim lrnCmd
   lrnCmd = "cmd /c perl -T -S sa-learn --ham """ & Replace( f, "", "\" ) & """"
   Dim lrnSh, lrnRc
   Set lrnSh = CreateObject( "WScript.Shell" )
   rc = lrnSh.Run( lrnCmd, 0, True )
'   MsgBox "Learning Ham, RC=" & rc,0,"Woohoo HAM!"
End Sub

Sub LearnSpam( f )
   Dim lrnCmd
   lrnCmd = "cmd /c perl -T -S sa-learn --spam """ & Replace( f, "", "\" ) & """"
   Dim lrnSh, lrnRc
   Set lrnSh = CreateObject( "WScript.Shell" )
   rc = lrnSh.Run( lrnCmd, 0, True )
'   MsgBox "Learning Spam, RC=" & rc,0,"Boohoo SPAM!"
End Sub

bazporter
Normal user
Normal user
Posts: 98
Joined: 2005-06-03 16:14

Post by bazporter » 2005-07-05 21:25

Great script.

One question with regard to the learn ham/spam process.

You are still picking up the message and parsing that for the learning process, so presumably you are relying on the message being forwarded inline? This will lose virtually all the original headers and may affect the efficiency of SpamAssassin.

Is there a way to be able to extract an attachment from a message and then process that, as that would allow users to forward the mails as attachments which would capture the full headers?

GlenC
Senior user
Senior user
Posts: 680
Joined: 2004-08-17 23:31
Location: Santiago, Chile

Post by GlenC » 2005-07-06 02:15

I'm using the Redirect extension for Thunderbird which thegregor suggested further up in the thread. I don't think it changes the headers much. I think it adds one x-header.

I don't think you can currently extract the attachment (somebody correct me if I'm wrong)

GlenC
Senior user
Senior user
Posts: 680
Joined: 2004-08-17 23:31
Location: Santiago, Chile

Post by GlenC » 2005-07-07 15:29

Didn't notice this until now, my script is not deleting tmp files for outgoing (local) msgs. These lines:

Code: Select all

If InStr(1, s1, SearchString, 1) > 0 Then
	'Comment next two lines to allow local domain spam checks
	Set fso = Nothing
	Exit Sub
End If
 
Should be changed to this:

Code: Select all

If InStr(1, s1, SearchString, 1) > 0 Then
	'Comment next three lines to allow local domain spam checks
	fso.Deletefile testfile
	Set fso = Nothing
	Exit Sub
End If

User avatar
FAWTS
Normal user
Normal user
Posts: 74
Joined: 2005-06-18 15:25
Location: Paris
Contact:

Post by FAWTS » 2005-07-12 12:01

Well, those 2 pages are very interresting. I start with the begining, and I got lost after the creation of spam and ham folders...

Is there one of you nice enough to make a HOW TO as the one in the begining of the topic with all the upgrade you made?

Thanks a lot!!!!!!!!!!!!!!!!
Apache 1.3.33 PHP Version 4.4 hMailServer 4.1-B136 OS : Win XP SP2 AV : ClamAV 0.86.1

User avatar
FAWTS
Normal user
Normal user
Posts: 74
Joined: 2005-06-18 15:25
Location: Paris
Contact:

Post by FAWTS » 2005-07-13 14:17

I found a solution to my problem : ASSP, just go to http://www.hmailserver.com/forum/viewtopic.php?t=1881 it is more complete than the how to http://www.hmailserver.com/documentatio ... o_use_assp and it works perfectly! :lol:
Apache 1.3.33 PHP Version 4.4 hMailServer 4.1-B136 OS : Win XP SP2 AV : ClamAV 0.86.1

GlenC
Senior user
Senior user
Posts: 680
Joined: 2004-08-17 23:31
Location: Santiago, Chile

Re: User Preferences instead local.cf

Post by GlenC » 2005-10-07 01:02

mirb wrote: the only one, and pretty good, i was able to run is:
http://www.aub.dk/~misak/index.php?cat=6
changing some code parts..
mirb, if you are still around, and still using phpsaadmin to set userprefs, could you let me know what code parts you had to change to make it work?

Thanks,
Glen

User avatar
PeterK2003
Normal user
Normal user
Posts: 129
Joined: 2005-07-20 17:08
Location: Catawissa, PA

spam assassin & clam win

Post by PeterK2003 » 2005-11-03 22:38

Is it poosible to run clamwin and spam assassin at the same time since you need to use the external scanner box for spam assassin?

GlenC
Senior user
Senior user
Posts: 680
Joined: 2004-08-17 23:31
Location: Santiago, Chile

Post by GlenC » 2005-11-03 23:59

You don't need to use the external box for SA if you set it up to run in the eventhandler script. Somewhere buried in these two pages are instructions to do it that way.

User avatar
TheAngryPenguin
Senior user
Senior user
Posts: 341
Joined: 2004-10-11 20:51

Post by TheAngryPenguin » 2005-11-04 04:35

Sorry to chime in so late in the game -- I have only recently become interested in trying to get SA running in a Windows environment. Have any of you seen SpamAssassin for Win32 (or SpamAssassin POP3 Proxy for Win32)? I've been testing the latter with some other mail server (sorry Martin) and it seems to work rather well, albeit slow. Wouldn't something like what Eugene Pivovarov has been working on be much more easy to implement with hMS than what's been already been discussed?

GlenC
Senior user
Senior user
Posts: 680
Joined: 2004-08-17 23:31
Location: Santiago, Chile

Post by GlenC » 2005-11-04 14:48

Wow, this will be nice if it really works as advertised. Sounds like the installation will be much simplified without all the perl/cygwin crap to deal with.

jnolan
New user
New user
Posts: 12
Joined: 2005-10-22 17:12

Post by jnolan » 2005-11-08 17:53

Link to step 6 is dead. Does anyone know of another place to find the tutorial?

GlenC
Senior user
Senior user
Posts: 680
Joined: 2004-08-17 23:31
Location: Santiago, Chile

Post by GlenC » 2005-11-09 02:43


User avatar
PeterK2003
Normal user
Normal user
Posts: 129
Joined: 2005-07-20 17:08
Location: Catawissa, PA

SpamAssassin for Win32

Post by PeterK2003 » 2005-11-24 19:49

i have sucessfully used SpamAssassin for Win32 with this script:

' Sub OnClientConnect(oClient)
' End Sub

Sub OnAcceptMessage(oClient, oMessage)
Dim commandln, infile, testfile, fso
Set fso = createobject("Scripting.FileSystemObject")
fname = oMessage.filename
infile = fso.getabsolutepathname(fname)
testfile = infile & ".tmp"
fso.CopyFile infile, testfile
Set commandln = CreateObject( "WScript.Shell" )
res = commandln.Run("cmd /c spamc < " & testfile & " > " & infile & "", 0, true)
res = commandln.Run("cmd /c ", 0, true)
fso.DeleteFile testfile, true
End Sub

'Sub OnDeliverMessage(oMessage)
'End Sub

The only problem i see is that it seems to scan both outgoing and incoming mail.

I also haven't figured out how to submit spam that isn't caught so that it can learn and false positives so that it won't catch them in the future.

If any one knows that anwsers to thoe questions let me know.

GlenC
Senior user
Senior user
Posts: 680
Joined: 2004-08-17 23:31
Location: Santiago, Chile

Post by GlenC » 2005-11-24 21:16

I'll post some portions of the script which I was experimenting with. Perhaps you can do something with them to work it out. I can't guarantee they work anymore as I haven't been using them for a while. To skip checks on the local domain:

Code: Select all

'DENY CHECKS FOR MAIL FROM LOCAL DOMAIN
Dim s1, ts1, SearchString
Const ForReading = 1
Set ts1 = fso.OpenTextFile(fname, ForReading)
s1 = ts1.ReadLine
ts1.Close
'SearchString = whatever your machine inserts in the msg (modify this)
SearchString ="Received: FROM [192.168.15.1"

If InStr(1, s1, SearchString, 1) > 0 Then
	'Comment next three lines to allow local domain spam checks
	fso.Deletefile testfile
	Set fso = Nothing
	Exit Sub
End If
As for training... probably the best way is using Sa-learn. There are some who redirect their messages via a "bounce" but I personally think this probably negatively affects the bayes database. If you'd like to play with that here is some more code that you can tinker with. Again, not sure if it still works or not as I don't use it anymore. This also requires SpamD (which I see that you are using) This code was borrowed from Devil_Dog above and modified somewhat:

Code: Select all

'LEARN IF NECESSARY
spamAddress = "report_spam@example.com"
hamAddress  = "report_ham@example.com"
forgetAddress = "report_forget@example.com"

dim oRecipients
set oRecipients = oMessage.Recipients

for i = 0 to oRecipients.Count - 1
  dim sAddress
  sAddress = oRecipients.Item(i).Address

If sAddress = spamAddress Then
	Dim Spam_cmd, Spam_rc
	Spam_cmd = "cmd /c spamc -L spam -u username < """ & testfile & """"
	Spam_rc = sh.Run( Spam_cmd , 0 , TRUE)
	'MsgBox "Spam, RC=" & Spam_rc,0,"Learned SPAM"
	fso.Deletefile testfile
	Set fso = Nothing
  result.Value = 1 'Set to 1 to delete msg
  Exit Sub
End If

If sAddress = hamAddress Then
	Dim Ham_cmd, Ham_rc
	Ham_cmd = "cmd /c spamc -L ham -u username < """ & testfile & """"
	Ham_rc = sh.Run( Ham_cmd , 0 , TRUE)
	'MsgBox "Ham, RC=" & Ham_rc,0,"Learned HAM"
	fso.Deletefile testfile
	Set fso = Nothing
	result.Value = 1 'Set to 1 to delete msg
	Exit Sub
End If

If sAddress = forgetAddress Then
	Dim Forget_cmd, Forget_rc
	Forget_cmd = "cmd /c spamc -L forget -u username < """ & testfile & """"
	Forget_rc = sh.Run( Forget_cmd , 0 , TRUE)
	'MsgBox "Forget, RC=" & Forget_rc,0,"Msg Unlearned"
	fso.Deletefile testfile
	Set fso = Nothing
	result.Value = 1 'Set to 1 to delete msg
	Exit Sub
End If
Next
I don't think I ever got the "Forget" command to work right so it might help to worry about that portion last.

GlenC
Senior user
Senior user
Posts: 680
Joined: 2004-08-17 23:31
Location: Santiago, Chile

Post by GlenC » 2005-11-25 16:19

For those of you using the Cygwin version of SpamAssassin, you might like to try this ClamAV plugin http://wiki.apache.org/spamassassin/ClamAVPlugin I've been using it for about a day now and it appears to work pretty well. Here's some of the advantages I think this has over the regular way of scanning:

Mail is only passed off in one operation... potentilally saving a few cpu cycles.

Instead of deleting the mails, or attachments, it inserts a "X-Spam-Status Yes" header which you can test for. With a little script work, you should be able to move those messages to a quarantine area for observation, validation or delete them or whatever.

Personally, I only did it to see if it worked, and I kinda like it.

Couple of things about installing. You of course need to be runnning Clamd to use it. You also need to install a perl module - File::Scan::ClamAV - from cpan. However, the tests run by the installation for that module fail (because it tries to connect to ClamAV through a socket vice TCPIP). But you can just force the install and it works fine.

GlenC
Senior user
Senior user
Posts: 680
Joined: 2004-08-17 23:31
Location: Santiago, Chile

Re: SpamAssassin for Win32

Post by GlenC » 2005-11-26 18:19

PeterK2003 wrote: The only problem i see is that it seems to scan both outgoing and incoming mail.
I did a little testing and due a recent change Martin made to the header structure, the "Deny Checks For Local Domain" code I posted above won't work anymore. (It was really not a good way to do that anyway) I've been testing the following code and it works well for me:

Code: Select all

'SKIP SPAM CHECKS ON OUTGOING MAIL
Dim s1, SearchString
s1 = oMessage.HeaderValue("Received")

'SearchString = Modify this to a unique, unchanging portion of the "Received: from" header inserted by hMailserver
SearchString = "from [192.168.15.153] ([127.0.0.1]) by Yourdomain.com with hMailServer"

If InStr(1, s1, SearchString, 1) > 0 Then

' Comment out the next two lines if you don't want a header created
  oMessage.HeaderValue("X-SpamCheck-Status") = "Spam checks skipped,on mail sent from local domain"
  oMessage.Save()
'  fso.Deletefile testfile 'uncomment this if you previously created "testfile"

	Set fso = Nothing
	Exit Sub
End If

User avatar
martin
Developer
Developer
Posts: 6846
Joined: 2003-11-21 01:09
Location: Sweden
Contact:

Post by martin » 2005-11-28 22:43

Are you guys trying to take a world record in writing a long thread? :)

Something tells me that I should write together a short summary.. if I just get the time to read through the entire thread... :)

GlenC
Senior user
Senior user
Posts: 680
Joined: 2004-08-17 23:31
Location: Santiago, Chile

Post by GlenC » 2005-11-28 23:24

:roll:

I did post a new summary on cygwin installs. Maybe someone could do one for the installs using Activestate perl and you can trash this thread altogether.

bazporter
Normal user
Normal user
Posts: 98
Joined: 2005-06-03 16:14

Post by bazporter » 2005-11-29 00:12

If you want a really long thread I could post my complete EventHandler script which also does basic auto-responder, whitelist, blacklist, spamassassin/spamc, and allows non-sa processing for local users. That might add a bit! :-)

User avatar
Slug
Moderator
Moderator
Posts: 1369
Joined: 2005-03-13 05:42
Location: Sydney Australia
Contact:

Post by Slug » 2005-11-29 06:16

martin wrote:Are you guys trying to take a world record in writing a long thread? :)
No, it just proves that spam is a big issue, thats why these guys are trying so hard to make this work.

Michael
Missing Hmailserver ... Now running Debian servers

GlenC
Senior user
Senior user
Posts: 680
Joined: 2004-08-17 23:31
Location: Santiago, Chile

Post by GlenC » 2005-11-29 22:54

Updated URLs for Step 6 of the John25uk's original post:

These are good references / tools for SA with an ActiveState Perl installation.

SpamAssassin 3.10 (Using SpamAssassin with Win32) http://64.142.36.76/howtosa310.html

SpamAssassin Configuration Tool (SaConf) http://64.142.36.76/saconf.html

vdrew
New user
New user
Posts: 9
Joined: 2005-12-10 12:38
Location: Vancouver, Canada

Issues Running spamd as Service with cygrunsrv

Post by vdrew » 2005-12-10 12:48

Hi!

I've been following along and have setup cygwin and spamassassin. It's all working great except I can't get it to work as a service using cygrunsrv... I'm using (as suggested by purplebear):

Code: Select all

cygrunsrv -I Spamassassin -p /usr/bin/spamd -a "-c /etc/mail/spamassassin -s /var/log/spamd.log"
The command is sucessful and the service appears in the services admin. When I run it however, it says "Could not start the SpamAssassin service on Local Computer. Error 1053: The service did not respond to the start or control request in a timely fashion."

I should also mention that if from the cygwin shell i run:

Code: Select all

/usr/bin/spamd -c /etc/mail/spamassassin -s /var/log/spamd.log
everything works perfectly, spamd starts, processes requests from winspamc and logs correctly.

Can anyone offer a suggestion... please.. i've been googling for hours! LOL

Thanks muchly!
Andrew

GlenC
Senior user
Senior user
Posts: 680
Joined: 2004-08-17 23:31
Location: Santiago, Chile

Post by GlenC » 2005-12-10 15:28

It is probably a permission problem. With cygwin it's important when troubleshooting that you use the same user for everything. What I do is load spamd like this

Code: Select all

cygrunsrv -I SpamD -p /usr/bin/spamd -a "-l -s /var/log/SpamD.log -u username --round-robin"
and I use MY username (cygwin username). That way when I do anything from the shell it is the same as doing it with the service. This also means that when you call spamc from the eventhandler script, you should call it with a -u username also, like so

Code: Select all

cmd = "cmd /c spamc -E -u username < """ & testfile & """ > """ & infile & """"
(note: --round-robin is only used with SA 3.1, and only because the default method of spawning children has problems. Roundrobin is the old style and works fine, just a little less efficient)

dila125
New user
New user
Posts: 18
Joined: 2005-11-25 06:23

Post by dila125 » 2006-01-03 06:14

I've read through all the posts in this thread and using the various code samples I have created the following code to run SA with no checking on outgoing emails. Thanks very much to the users (especially Glen) who posted the code originally :D .

Code: Select all

Sub OnDeliverMessage(oMessage) 

  fname = oMessage.filename 

  Dim infile, testfile 
  Dim fso 
  Set fso = createobject("Scripting.FileSystemObject") 
  If Not fso.fileexists(fname) then 
    result.Value = 0 
    Exit sub 
  End If 

  infile = fso.getabsolutepathname(fname) 
  testfile = infile & ".tmp" 
  fso.CopyFile infile, testfile 

  'SKIP SPAM CHECKS ON OUTGOING MAIL 
  Dim s1, SearchString 
  s1 = oMessage.HeaderValue("Received") 

  'SearchString = Modify this to a unique, unchanging portion of the "Received: from" header inserted by hMailserver 
  SearchString = "FROM [81.178."

  If InStr(1, s1, SearchString, 1) > 0 Then 
    'Comment out the next two lines if you don't want a header created 
    oMessage.HeaderValue("X-SpamCheck-Status") = "Spam checks skipped,on mail sent from local domain" 
    oMessage.Save() 
    fso.Deletefile testfile 'uncomment this if you previously created "testfile" 
    Set fso = Nothing 
    Exit Sub 
  End If

  'CALL SPAMASSASSIN (modify as required) 
  Dim cmd, cmd1, rc, rc1, sh 
  'cmd = "cmd /c spamc -E -s 512000 < """ & testfile & """ > """ & infile & """" 
  cmd1 = "cmd /c perl -S -T -w spamassassin < """ & testfile & """ > """ & infile & """" 

  Set sh = CreateObject("WScript.Shell") 
  rc = sh.Run( cmd1 , 0 , TRUE) 
  If rc = 0 Then                           'Do something for HAM 
  ElseIf rc = 1 Then                  'Do something for SPAM 
    'Uncomment next two lines to reject spam 
    ' result.Value = 1 
    ' Exit Sub 
  Else 
    'rc1 = sh.Run( cmd1 , 0 , TRUE)         'There was an error, call SpamAssassin directly 
  End If 

  If fso.GetFile(infile).Size = 0 Then      'Failsafe: In the event an error causes a zero byte msg 
    fso.CopyFile testfile, infile 
  End if 

  fso.Deletefile testfile 
  Set fso = Nothing 
  result.value = 0 
End Sub 
I now want to add to this script, so that if SA finds spam then it is copied to me and not the intended recipient.

Is this possible? Any advice would be much appreciated.

GlenC
Senior user
Senior user
Posts: 680
Joined: 2004-08-17 23:31
Location: Santiago, Chile

Post by GlenC » 2006-01-03 16:18

I can't think of an easy way to do it. If we had this feature: http://www.hmailserver.com/forum/viewto ... ight=event (vote for it) then it would be easier, you could just set a global rule based on the headers created by SA.

You may be able to do something with the "ElseIf rc = 1 Then 'Do something for SPAM" line, but it would get pretty complicated if you had more than a few recipients.

elpresidente
New user
New user
Posts: 21
Joined: 2006-01-04 22:23

Post by elpresidente » 2006-01-04 22:29

I have gone through the tutorial and upon testing, received blank emails.

hmail logs show code return of 7

Code: Select all

"DEBUG"	2556	"2006-01-04 12:49:41.343"	"CustomVirusScanner::Scan()"
"DEBUG"	2556	"2006-01-04 12:49:41.531"	"CustomVirusScanner::Scan() - c:\windows\system32\cscript.exe //nologo c:\sa.vbs C:\Program Files\hMailServer\Data\{ACF25BD6-9DBE-45A7-94FA-091CBAEE9239}.eml - Returned 7"
"DEBUG"	2556	"2006-01-04 12:49:41.531"	"CustomVirusScanner::~Scan()"
Any suggestions would be helpful.

GlenC
Senior user
Senior user
Posts: 680
Joined: 2004-08-17 23:31
Location: Santiago, Chile

Post by GlenC » 2006-01-04 22:58

Blank emails can occur if for some reason SA is not working (or getting called properly). I would suggest not using the CustomVirusScanner method and using a script in your eventhandlers.vbs to call spamassassin. The post above yours by dila125 is a good example for a script that you can modify to work for you. However, I just looked through it though and I noticed that two lines need to be uncommented in order to work properly.

Code: Select all

'cmd = "cmd /c spamc -E -s 512000 < """ & testfile & """ > """ & infile & """" 

and 

'rc1 = sh.Run( cmd1 , 0 , TRUE)         'There was an error, call SpamAssassin directly 
The sa.vbs script that John25UK made was good when it was written but I think maybe some things have changed since then. (besides, eventhandlers gives you more control).

elpresidente
New user
New user
Posts: 21
Joined: 2006-01-04 22:23

Post by elpresidente » 2006-01-05 18:06

GlenC wrote:Blank emails can occur if for some reason SA is not working (or getting called properly). I would suggest not using the CustomVirusScanner method and using a script in your eventhandlers.vbs to call spamassassin. The post above yours by dila125 is a good example for a script that you can modify to work for you. However, I just looked through it though and I noticed that two lines need to be uncommented in order to work properly.

Code: Select all

'cmd = "cmd /c spamc -E -s 512000 < """ & testfile & """ > """ & infile & """" 

and 

'rc1 = sh.Run( cmd1 , 0 , TRUE)         'There was an error, call SpamAssassin directly 
The sa.vbs script that John25UK made was good when it was written but I think maybe some things have changed since then. (besides, eventhandlers gives you more control).
Thanks. This seems better. I have tried it out but I also uncommented the following 2 lines(they were commented out):

Code: Select all

'Uncomment next two lines to reject spam
    result.Value = 1
    Exit Sub
Unfortunately, now every email sent or received from outside is stopped.

Code: Select all

"DEBUG"	8128	"2006-01-05 11:06:54.250"	"RuleApplier::~ApplyRules"
"APPLICATION"	8128	"2006-01-05 11:06:54.281"	"SMTPDeliverer - Message 7054: Message deleted. Action was taken by script subscribing to OnDeliverMessage."

dila125
New user
New user
Posts: 18
Joined: 2005-11-25 06:23

Post by dila125 » 2006-01-05 18:40

I had those lines commented because when using the spamc command, the mail was delivered without being spam checked. I therefore used the direct spam assassin command.

elpresidente
New user
New user
Posts: 21
Joined: 2006-01-04 22:23

Post by elpresidente » 2006-01-05 20:53

dila125 wrote:I had those lines commented because when using the spamc command, the mail was delivered without being spam checked. I therefore used the direct spam assassin command.
It appears that I am having that same issue. With those 2 lines commented, email is not being spam checked. With them uncommented, all emails are rejected.

I admit that I have no experience with these type of scripts. Any suggestions would be helpfull.

GlenC
Senior user
Senior user
Posts: 680
Joined: 2004-08-17 23:31
Location: Santiago, Chile

Post by GlenC » 2006-01-05 21:03

elpresidente: Those lines are meant to delete the message. Result.Value = 1 means to discard the message. You can comment them out, or change it to Result.Value = 0 if that is not the solution you are wanting.

dila125: you are correct, the full script has two pairs of commands, but in the example you posted above you have mismatched the pairs. In effect, when it runs the line "rc = sh.run....." it will not find the command to expand to because it is commented out (i.e. "cmd = cmd /c......". In other words, cmd and rc are a pair, and cmd1 and rc1 are a pair.

Edit: ok... I see how you did it now. you modifed the rc line to use cmd1 instead of cmd. elpresidente... you will need to change that line also. It should be

Code: Select all

 rc = sh.Run( cmd , 0 , TRUE)
I'm not sure why spamc wouldn't work for you. I haven't run it in this way in a while. Perhaps I need to try this script myself again and see if it needs tweaking.

GlenC
Senior user
Senior user
Posts: 680
Joined: 2004-08-17 23:31
Location: Santiago, Chile

Post by GlenC » 2006-01-06 00:30

ok... I had to go back and research some things.... When you run SpamC, if you use the -E switch, it will return via the rc code a "1" if the message was spam, and a "0" if the message is ham OR if an error occurs.

If you run SpamC with the -x -E swtiches (both) it will then return a "1" for spam, a "0" for ham, and something greater than "1" for an error.

So, the IF/ELSEIF/ELSE checks the RC for 0, then 1, and if not either of those then there must have been a SpamD communication failure and it will call SpamAssassin directly.

Of course, using one or both switches results in a tradeoff... using -E alone will only return a 1 or a 0, so there is NO indication of a failure that will call spamassassin directly.

However, if you use -x -E, then you no longer have what is known as "Safe Fallback" mode (the message is returned unaltered in the case of an error) and the message NEEDS to be resubmitted and scanned by SpamAssassin directly.

I know it's a little confusing, especially because this thread is cut and pasted to death! But, personally I just use SpamC with the -E swtich now and allow it to do its Safe Fallback mode if something goes wrong. There was a time for me when SpamD wasn't reliable and I needed the extra check to make sure mail got scanned, but nowadays it is solid as a rock (knock on wood).

Hope this helps.

elpresidente
New user
New user
Posts: 21
Joined: 2006-01-04 22:23

Post by elpresidente » 2006-01-06 16:22

I'm starting to think that I might want to install cygwin now. I assume I need to remove activestate's perl - not sure the best way to do that. Is this a good idea or should I stick with what I have and try to get the script working right?

GlenC
Senior user
Senior user
Posts: 680
Joined: 2004-08-17 23:31
Location: Santiago, Chile

Post by GlenC » 2006-01-06 16:39

I think plenty of people have SA working with Activestate Perl. Can you post the relavant portions of your eventhandlers.vbs? Maybe something will be easier to pinpoint then.

elpresidente
New user
New user
Posts: 21
Joined: 2006-01-04 22:23

Post by elpresidente » 2006-01-06 17:31

I had done a little tinkering but have revertted back to this:

Code: Select all

Sub OnDeliverMessage(oMessage)

  fname = oMessage.filename

  Dim infile, testfile
  Dim fso
  Set fso = createobject("Scripting.FileSystemObject")
  If Not fso.fileexists(fname) then
    result.Value = 0
    Exit sub
  End If

  infile = fso.getabsolutepathname(fname)
  testfile = infile & ".tmp"
  fso.CopyFile infile, testfile

  'SKIP SPAM CHECKS ON OUTGOING MAIL
  Dim s1, SearchString
  s1 = oMessage.HeaderValue("Received")

  'SearchString = Modify this to a unique, unchanging portion of the "Received: from" header inserted by hMailserver
  SearchString = "FROM [81.178."

  If InStr(1, s1, SearchString, 1) > 0 Then
    'Comment out the next two lines if you don't want a header created
    oMessage.HeaderValue("X-SpamCheck-Status") = "Spam checks skipped,on mail sent from local domain"
    oMessage.Save()
    fso.Deletefile testfile 'uncomment this if you previously created "testfile"
    Set fso = Nothing
    Exit Sub
  End If

  'CALL SPAMASSASSIN (modify as required)
  Dim cmd, cmd1, rc, rc1, sh
  cmd = "cmd /c spamc -E -s 512000 < """ & testfile & """ > """ & infile & """"
  cmd1 = "cmd /c perl -S -T -w spamassassin < """ & testfile & """ > """ & infile & """"

  Set sh = CreateObject("WScript.Shell")
  rc = sh.Run( cmd , 0 , TRUE)
  If rc = 0 Then                           'Do something for HAM
  ElseIf rc = 1 Then                  'Do something for SPAM
    'Uncomment next two lines to reject spam
    ' result.Value = 1
    ' Exit Sub
  Else
    rc1 = sh.Run( cmd1 , 0 , TRUE)         'There was an error, call SpamAssassin directly
  End If

  If fso.GetFile(infile).Size = 0 Then      'Failsafe: In the event an error causes a zero byte msg
    fso.CopyFile testfile, infile
  End if

  fso.Deletefile testfile
  Set fso = Nothing
  result.value = 0
End Sub
Which does not appear to stop the sample spam messages I send from an external account.

Post Reply