I use these 4 categories:
RBL's = 5
SURBL's = 5
SPF = 5
SpamAssassin = Actual value
I have been "playing". This is bleeding edge code that may - or may not - declare war on Asgaard and/or Jotunheim - use at your own discretion.
sa-learn.exe do not really like curly braces "{}" in filepaths and that was the primary reason why the code was split and mails were copied into the SPAM and HAM folders.
I had a brain fart this morning and after some experimenting I believe I've cracked the nut - anyways, it works on my server.
Code: Select all
C:\hMailServer\Data\mydomain.tld\spam\D9\{D9EC1A93-6382-4DA6-AA69-C6D97C8CD944}.eml
... is simply translated to ...
C:/hMailServer/Data/mydomain.tld/spam/D9/\{D9EC1A93-6382-4DA6-AA69-C6D97C8CD944\}.eml
This is all that is needed, no cmd files and no HAM/SPAM folder, NO copying mails back and forth.
Temp, Log and Bayes_DB folders must exist however.
sa-learn.vbs Version 0.5.a
Code: Select all
Option Explicit
'
' Version 0.5.a 26/07-2018, Soren Rathje - Experimental rewrite of filelist to fix curly brace problem in sa-learn.
' Version 0.5.0 25/07-2018, Soren Rathje - Multiple domains, skipping non-existing folders plus reworked code.
' Version 0.4.3 30/05-2018, Soren Rathje - Introduced two special folders; non-delivered SPAM and False Positives.
' Version 0.4.2 28/05-2016, Soren Rathje - Compatibility issues (curly brackets bug in sa-learn).
' Version 0.4.1 25/11-2014, Soren Rathje - Compatibility issues.
' Version 0.4.0 27/10-2014, Soren Rathje - Changed error logging.
' Version 0.3.0 11/10-2014, Soren Rathje - Bugfixing & Log error to Eventlog if IMAPFolder is missing
' Version 0.2.0 30/08-2014, Soren Rathje - Selection changed to DAYS.
' Version 0.1.0 09-08-2014, Soren Rathje - Initial version.
'
' Configuration parameters
'
' Administrative and automation accounts can be excluded from processing
' by defining them in "ExcludeList"
'
Const Administrator = "Administrator"
Const Secret = "########"
Const ExcludeList = "postmaster@mydomain.tld, blog@mydomain.tld"
Const DomainList = "mydomain.tld, acme.inc"
Const SPAMFolders = "SPAM, Junk E-mail, Uønsket e-mail, UCE - HighScore"
Const HAMFolders = "INBOX, UCE - FPs"
Const TempDir = "C:\SpamAssassin\temp\" ' Need permission for create, read & write
Const LogDir = "C:\SpamAssassin\logs\" ' Need permission for create, read & write
Const BayesDir = "C:\SpamAssassin\bayes_db\" ' Need permission for create, read & write
Const RetainDays = 7
Const Verbose = 0
Sub BuildList(a, mExcludes, b, mDays, mTemp, mType)
Dim i, j, k, l, strFileName
Dim oFile, oDomain, oAccount, oMessage, oMessages
Dim mDomain, mDomains, mFolder, mFolders
Set oFile = oFSO.CreateTextFile(mTemp & mType, True)
mDomains = Split(a, ",")
mFolders = Split(b, ",")
If Verbose Then WScript.Echo "Type: " & mType
For Each mDomain in mDomains
mDomain = Trim(mDomain)
Set oDomain = oApp.Domains.ItemByName(mDomain)
If Verbose Then WScript.Echo " Domain: " & oDomain.Name
For i = 0 to oDomain.Accounts.Count - 1
Set oAccount = oDomain.Accounts.Item(i)
If InStr(mExcludes, oAccount.Address) = 0 And oAccount.Active Then
If Verbose Then WScript.Echo " Account: " & oAccount.Address
For Each mFolder In mFolders
mFolder = Trim(mFolder)
On Error Resume Next
If oAccount.IMAPFolders.ItemByName(mFolder) Is Nothing Then
On Error GoTo 0
Else
On Error GoTo 0
If Verbose Then WScript.Echo " Folder: " & mFolder
Set oMessages = oAccount.IMAPFolders.ItemByName(mFolder).Messages
If Not IsNull(oMessages) Then
For j = 0 to oMessages.Count - 1
Set oMessage = oMessages.Item(j)
If oMessage.InternalDate > CDate(Now - mDays) Then
strFileName = Replace(oMessage.FileName,"\","/")
strFileName = Replace(strFileName,"{","\{")
strFileName = Replace(strFileName,"}","\}")
oFile.Write strFileName & vbCrLf
End If
Next
End If
End If
Next
End If
Next
Next
oFile.Close
End Sub
Dim oFSO : Set oFSO = CreateObject("Scripting.FileSystemObject")
Dim oApp : Set oApp = CreateObject("hMailServer.Application")
Call oApp.Authenticate(Administrator, Secret)
'
' Find SPAM messages
'
Call BuildList(DomainList, ExcludeList, SPAMFolders, RetainDays, TempDir, "SPAM")
'
' Find HAM messages
'
Call BuildList(DomainList, ExcludeList, HAMFolders, RetainDays, TempDir, "HAM")
'
' Execute n'Stuff ...
'
CreateObject("WScript.Shell").Run "cmd /c Echo %DATE% %TIME% - START >> " & LogDir & "sa-learn.log", Verbose, True
If Verbose Then WScript.Echo "Processing HAM mails"
CreateObject("WScript.Shell").Run "cmd /c Echo HAM: >> " & LogDir & "sa-learn.log", Verbose, True
CreateObject("WScript.Shell").Run "cmd /c sa-learn.exe --ham --folders=" & TempDir & "HAM >> " & LogDir & "sa-learn.log", Verbose, True
If Verbose Then WScript.Echo "Processing SPAM mails"
CreateObject("WScript.Shell").Run "cmd /c Echo SPAM: >> " & LogDir & "sa-learn.log", Verbose, True
CreateObject("WScript.Shell").Run "cmd /c sa-learn.exe --spam --folders=" & TempDir & "SPAM >> " & LogDir & "sa-learn.log", Verbose, True
If Verbose Then WScript.Echo "Synchronizing Bayes"
CreateObject("WScript.Shell").Run "cmd /c sa-learn.exe --sync >> " & LogDir & "sa-learn.log", Verbose, True
If Verbose Then WScript.Echo "Backing up Bayes"
CreateObject("WScript.Shell").Run "cmd /c sa-learn.exe --backup > " & BayesDir & "bayes_backup", Verbose, True
CreateObject("WScript.Shell").Run "cmd /c Echo %DATE% %TIME% - STOP >> " & LogDir & "sa-learn.log", Verbose, True
SørenR.
Algorithm (noun.)
Word used by programmers when they do not want to explain what they did.