This will be my first contribution to the Development Community so go easy on me.
Overview:
I have written a script that can be executed on a Task Scheduler or whatever your choosing may be that will pragmatically go through your entire Mail Server, all possibly existing post offices, and all possibly existing mailboxes, and train your Bayesian Dictionary with Spam and Ham based on the folders the emails are stored in.
As of now all it does is look for key words such as "Junk" and "Deleted" in the folder name and anything that doesn't match these two attributes is automatically trained as Ham.
Since we have no way of distinguishing "Junk" email from "Regular" email in the deleted folder I choose not to take the risk and avoid it entirely.
Code:
Code: Select all
@echo off
SET FOLDER=C:\Program Files (x86)\Mail Enable\Postoffices
FOR /D %%I in ("%FOLDER%\*") DO CALL :PostOffice %%I
goto END
:PostOffice
FOR /D %%I IN ("%*\MAILROOT\*") DO CALL :InboxParse %%I
goto END
:InboxParse
FOR /D %%I IN ("%*\*") DO CALL :Logic %%I
goto END
:Logic
echo "%*"|findstr /C:"Junk" >nul 2>&1
if not errorlevel 1 (
set TRAINTYPE=spam
) else (
echo "%*"|findstr /C:"Delete" >nul 2>&1
if not errorlevel 1 (
goto END
) else (
set TRAINTYPE=ham
)
)
echo Checking if SpamAssassin daemon (spamd) is available on local host...
spamc -K > nul
echo.
if %errorlevel%==0 (
echo Spamd is available. Using spamc for training.
set METHOD=spamc
) else (
echo Spamd is not available. Using sa-learn for training.
set METHOD=sa-learn
)
if %METHOD% == spamc (
goto spamc
) else (
goto sa-learn
)
goto END
:spamc
echo "%*"
for %%X in ("%*\*") do spamc -L %TRAINTYPE% < "%%X"
if %errorlevel%==74 (
echo Learning is not allowed by spamd, please start spamd with --allow-tell switch.
goto end
)
goto end
:sa-learn:
echo "%*"
for %%X in ("%*\*") do sa-learn --%TRAINTYPE% < "%%X"
goto end
:END
http://pastebin.com/00mXPDS5
Requirements:
You must be running JAM Software's version of Spam Assassin and it can be the free or paid version.
I personally use the Free Version with a daemon.
If you have any questions or concerns feel free to leave a response.
If you have an urgent request regarding this and want more information, in the event I don't see a response in my inbox, my email is cody at garrett dot ms
Cheers guys!