Bayesian Dictionary Will Not Update! WHY?

Discussions on webmail and the Professional version.
ALLPRO
Posts: 23
Joined: Sun Apr 23, 2006 11:44 pm

Bayesian Dictionary Will Not Update! WHY?

Post by ALLPRO » Fri Jun 02, 2006 11:42 pm

I really want to get the Bayesian filtering working, but I am stumped! Since there is plenty of email traffic, I decided to just rely on the 'auto-training', but in over 3 weeks, the dictionary hasn't changed!

Here is how I have the auto-training setup...

I directed the CATCH_ALL for each domains to a SPAM@domain.com mailbox - and added these addresses as the honey-pot email addresses.

I added *@domain.com (for each domain) as ham addresses for training.

In the past few weeks, almost 6000 spams have been collected in the various spam mailboxes. I don't have a count of the outgoing ham emails, but this also will be in the thousands. YET, when I compare the MainEnable.TAB dictionary (default) from 3 weeks ago to the current one, there has been no change! (Yes, I stopped and started the MTA so that the dictionary was writtten to disk - and the 'Last Modified' date on the file reflects this)

So what am I doing wrong? Why is the auto-training not working? Is it because the emails are being 'redirected' to the Spam mailbox instead of being directly addressed to it? But even if this is so, the outgoing ham email should still have had some effect on the dictionary.

Any help would be appreciated. :?

While on the Bayesian topic, I have a couple other basic questions:

1. If Spam is 'copied' into a honeypot mailbox by way of IMAP, will this be picked up by the auto-training? I assume not since these emails would not be 'processed' by the MTA. I know that I can 'manually' merge these, but I am specifically asking about 'auto-training'.

2. Are there any additional settings for the Bayesian filter available in ME Pro? I have the 'Filter' set and enabled in ME, but there are no properties or options except for Spam Calculaton and Auto-training.

Thanks in advance.

Kevin Dalman
Server 2003
ME Pro 2.02
ME Filter 5.7

ALLPRO
Posts: 23
Joined: Sun Apr 23, 2006 11:44 pm

Anybody?

Post by ALLPRO » Thu Jun 08, 2006 6:00 pm

Does no one have any ideas on why the Baysean auto-training is not working? Do I need to create a 'custom dictionary'?

Anyone? Any ideas? :(

/Kevin

support@aspportal.net
Posts: 4
Joined: Mon Jul 10, 2006 8:21 am
Location: Austria

Try this!

Post by support@aspportal.net » Mon Jul 10, 2006 8:29 am

I had the same issue.
The after reading the documentation a few times i did this;
Restart the MTA and make sure you have now pickup event that executes before your MTA service.

After the restart of the MTA you will notice that the dictonary file has been changed, and you will see some changes in there.

I think this is bad development by MailEnable but this is the workaround that helped on my system.
Gerhard Kruger

ALLPRO
Posts: 23
Joined: Sun Apr 23, 2006 11:44 pm

Baysean Dictionary Never Changes

Post by ALLPRO » Mon Jul 10, 2006 4:48 pm

Thanks for the suggestion 'aspportal'. However I have stopped and started the MTA service many times, including full reboots.

The 'active dictionary' is always held 'in memory' and is only 'written' to the dictionary file when the MTA exits or when you issue a command telling it to write to file. This does work.

Every time I restart the MTA, the dictionary file is updated - the last modifided date/time changes. However the 'contents' of the dictionary is always the same! This indicates to me that the Baysean filter is running, but that it auto-training is not working.

I have an active honeypot that receives many thousands of emails a month. For ham emails, I am using over 50 email accounts - again many thousands of emails per month. There is no shortage of email for the filter to sample from, yet the dictionary never changes even a little.

I have also tried manually merging spam and ham email using the command line. I get no errors and it seems to work, but it has zero effect on the dictionary file (I force it to be written to disk).

So I am not having much luck with anything!

However based on what you said about the sequence of events, I have changed a setting to see if it makes a difference. I use MEFilter as a pickup event, so I have NOW turned ON the MTA option to:

[x] Process pickup after filters instead of before

I'll see if this makes any difference to the Baysean filter, and whether MEFilter continues to work properly.

Thanks again for the suggestion. IF this setting change has any effect, then you have solved my problem. If it works I'll update this post in a few days for the benefit of anyone else that has the same problem.

/Kevin

MailEnable
Site Admin
Posts: 4441
Joined: Tue Jun 25, 2002 3:03 am
Location: Melbourne, Victoria Australia

Post by MailEnable » Tue Jul 11, 2006 12:36 am

Bayesian Filtering dictionaries should be balanced and should contain an equal (or close to that) number of Spam and Ham messages. The reason for this is to ensure that the dictionary remains balanced. If the dictionary is not balanced, MailEnable will be more likely to detect Spam, but it introduces the risk of false positives.

As such, when Bayesian auto-training is used, it will only add Spam to the dictionary if the number of Ham messages in the dictionary is equal to the number of Spam messages in the dictionary.

So, when you use autotraining, the bayesian dictionary will only update if you are processing ham as well as spam. Even then, it will only process a spam message into the dictionary if the dictionaries are balanced.

The most likely reason that your dictionary is not changing is that you are not feeding enough ham into the dictionary, and therefore, none of the detected spam is being added.

Unfortunately, current versions of MailEnable do not allow you to determine current balance of the in memory dictionary, so it is not possible to determine the status of current training without stopping the MTA or using the command utility to instruct the MTA to dump its dictionary to disk.
Regards, Andrew

whgpjay
Posts: 40
Joined: Sat Aug 14, 2004 5:06 pm
Location: Long Island, NY, USA

Post by whgpjay » Tue Jul 11, 2006 8:33 pm

What is considered "balanced" by auto-training? Within 5%? 10%? 20%?

I have been proceeding on the assumption that auto-training would count all ham and spam, and then every few days I would manually merge some more spam or ham into the dictionary to balance it out myself.

rockinthesixstring
Posts: 844
Joined: Mon Dec 05, 2005 7:51 am
Location: Canada

Post by rockinthesixstring » Wed Jul 12, 2006 12:15 am

i turned off the auto training and used this script to process the dictionary. i got the script from MailEnable - Ben. my current setup has ME installed in the Plesk Dir, you will want to change this to accomodate your directory structure.

all you have to do is
1) copy it into a txt document
2) modify the directory structure and [domain.com]
3) save it as bayesian.bat (or whatever name .bat - as long as its a batch file)
4) set your scheduled tasks to run the file as often as you like (every hour, every day, every month... whatever)

Code: Select all

REM*****************StartsHere******************************************

REM*** This section will copy all the mail stored by your earlier configured filters into 
REM*** the dictionary Spam and NoSpam folders and delete the messages in the 
REM *** inboxes.  If you have configured other mailboxes for the collection of Spam or REM *** NoSpam you will need to create similar entries for those mailboxes.

REM *** Copy mail from Spam inbox folder to dictionary Spam folder.
Copy "C:\SWSoft\Plesk\Mail Servers\Mail Enable\Postoffices\[domain.com]\MAILROOT\Spam\Inbox\*.mai" "C:\SWSoft\Plesk\Mail Servers\Mail Enable\Dictionaries\Spam\*.*"

REM *** Delete messages from the Spam inbox folder.
del /Q "C:\SWSoft\Plesk\Mail Servers\Mail Enable\Postoffices\[domain.com]\MAILROOT\Spam\Inbox\*.mai"

REM *** Copy mail from NoSpam inbox folder to dictionary NoSpam folder.
Copy "C:\SWSoft\Plesk\Mail Servers\Mail Enable\Postoffices\[domain.com]\MAILROOT\NoSpam\Inbox\*.mai" "C:\SWSoft\Plesk\Mail Servers\Mail Enable\Dictionaries\NoSpam\*.*"

REM *** Delete messages from the NoSpam inbox folder
del /Q "C:\SWSoft\Plesk\Mail Servers\Mail Enable\Postoffices\[domain.com]\MAILROOT\NoSpam\Inbox\*.mai"





REM*** Notify the MTA filter to write out current dictionary from memory to hard REM *** drive file. 
mespamcmd -w


REM*** This is the command line that will process the messages in the dictionary files
REM*** and convert them to the dictionary token file.
mespamcmd -m "C:\SWSoft\Plesk\Mailse~1\Mailen~1\Dictionaries\mailenable.tab" "C:\SWSoft\Plesk\Mailse~1\Mailen~1\Dictionaries\Spam" "C:\SWSoft\Plesk\Mailse~1\Mailen~1\Dictionaries\NoSpam"


REM*** Notify the Spam filter to reload the dictionary from the new update. 
mespamcmd -r






REM*** The following section will copy all the mail from the dictionary Spam folders to 
REM *** the backup storage folders.  These back up folders can come in handy if you 
REM *** need to create a new dictionary are some point in time.

Copy "C:\SWSoft\Plesk\Mail Servers\Mail Enable\Dictionaries\Spam\*.*" "C:\SWSoft\Plesk\Mail Servers\Mail Enable\Dictionaries\KeepSpam\*.*"
Copy "C:\SWSoft\Plesk\Mail Servers\Mail Enable\Dictionaries\NoSpam\*.*" "C:\SWSoft\Plesk\Mail Servers\Mail Enable\Dictionaries\KeepNoSpam\*.*"

REM*** Now clean up the dictionary Spam and NoSpam folders
del /Q "C:\SWSoft\Plesk\Mail Servers\Mail Enable\Dictionaries\Spam\*.*"
del /Q "C:\SWSoft\Plesk\Mail Servers\Mail Enable\Dictionaries\NoSpam\*.*"

exit

REM*****************EndsHere******************************************
I find that this works way better than the auto training did.
Chase
Server 2008 Standard (x64)
ME Ent 6.51 (SQL Server 2008 Config)
ASSP 1.9

ALLPRO
Posts: 23
Joined: Sun Apr 23, 2006 11:44 pm

Post by ALLPRO » Thu Jul 13, 2006 3:33 am

rockinthesixstring wrote:i turned off the auto training and used this script to process the dictionary. i got the script from MailEnable - Ben.
FYI, I have tried 'manually' merging Spam & Ham EXACTLY as this script does. The dictionary STILL would not update!

However I am going to keep trying - but will have to give up on 'auto-training' since it seems hopeless.

:) Thanks for this script. For anyone interested, I've rewritten it so that it sets everything in variables at the top instead of having the paths scattered all throughout the code. This makes it much easier to customize for your system. This is especially useful if you collect Spam and Ham in 'multiple Postoffices' - just enter them all in the list at top. (This assumes the 'Ham' and 'Spam' mailboxes are named the same in each postoffice.)

It is also possible to 'scan' the entire Postoffice root for EVERY folder named HAM or SPAM instead of hard-coding Domains at all! But that's another day :wink:

Code: Select all

@echo off
rem =====================================
rem =======   BAYESIAN FILTER UPDATE SCRIPT  =======
rem =====================================

rem ***  Set the Domains (ie, "Post-Office Names") you use as Spam and Ham Sources
rem ***  These must  match the spellings of the folders in the "Postoffices" folder
rem ***  Use spaces to separate Domain/Postoffice Names

SET Domains=mydomain.com yourdomain.net herdomain.org hisdomain.biz


rem ***  NOTE:  Be careful to NOT have any 'trailing spaces' when setting variables below

rem ***  Set the 'PostOffice'  and 'Dictionary' folders - WITHOUT A trailing ""
SET  PO=E:\Email\Postoffices
SET  DIC=E:\Email\Dictionaries

rem ***  Set the 'Dictionary' file path
SET Dictionary=%DIC%\Bayesian_Dic.TAB

rem ***  Set Spam and Ham 'Storage folders' - WITHOUT A trailing ""
SET  NewSpam=%DIC%\NewSpam
SET  NewHam=%DIC%\NewHam
SET  OldSpam=%DIC%\OldSpam
SET  OldHam=%DIC%\OldHam


rem ***************  NOW START PROCESSING *******************


rem ***  NOTE: "echo" mean display the comments (or blank line) on-screen

echo.
echo ***  Copy email stored by your configured filters into the dictionary folders, 
echo ***  and then empty the email collection inboxes. 

echo.
echo    COPY  messages from Spam Source folder(s) to dictionary Spam folder...
echo.
FOR  %%D  IN  (%Domains%)  DO   COPY  "%PO%\%%D\MAILROOT\SPAM\Inbox\*.mai"  "%NewSpam%" 

echo.
echo    COPY messages from Ham Source folder(s) to dictionary Ham folder...
echo.
FOR  %%D  IN  (%Domains%)  DO   COPY  "%PO%\%%D\MAILROOT\HAM\Inbox\*.mai"  "%NewHam%" 


echo.
echo    DELETE  messages from the Spam Source folder(s)...
echo.
FOR  %%D  IN  (%Domains%)  DO   DEL /Q  "%PO%\%%D\MAILROOT\SPAM\Inbox\*.mai"  

echo.
echo    DELETE messages from the Ham Source folder(s)...
echo.
FOR  %%D  IN  (%Domains%)  DO   DEL /Q  "%PO%\%%D\MAILROOT\HAM\Inbox\*.mai"



echo.
echo.
echo ***  Tell  MTA filter to write current dictionary from memory to file. 
echo.
MESPAMCMD  -w 

echo.
echo ***  Process the messages in the dictionary files to update the dictionary. 
echo.
MESPAMCMD  -m  "%Dictionary%"  "%NewSpam%"  "%NewHam%" 

echo.
echo ***  Tell MTA filter to reload the dictionary from the updated file 
echo.
MESPAMCMD  -r 
echo.




echo.
echo ***  Copy all the mail from the dictionary folders to the backup folders
echo ***  These will come in handy if you ever need to create a new dictionary.

echo.
echo    COPY NewSpam to OldSpam...
echo.
COPY  "%NewSpam%\*.*"  "%OldSpam%" 
echo.
echo    COPY NewHam to OldHam...
echo.
COPY  "%NewHam%\*.*"  "%OldHam%" 

echo.
echo ***  Now clean up the dictionary Spam and Ham folders 
echo.
echo    DELETE NewSpam...
DEL /Q  "%NewSpam%\*.*" 
echo.
echo    DELETE NewHam...
echo.
DEL /Q  "%NewHam%\*.*" 



rem ***  Enable the PAUSE command to test the batch file and see the output
echo.
rem PAUSE

EXIT 

MailEnable-Ben
Posts: 5858
Joined: Fri Jan 16, 2004 6:49 am
Location: Melbourne

Post by MailEnable-Ben » Thu Jul 13, 2006 6:30 am

Thanks ALLPRO that could make things a little easier.

For the best system if you wanted to make an advanced script you could compare the total of spam and ham messages before adding to the dictionary then only add the total of the least amount for each type.

Sorry about the wording there, but basically the best system is one that has the same amount of ham and spam messages in the dictionary. If you only added the same amount of both messages each time the script ran you could effectively have a Bayesian Filter that started equal and stayed equal. This could mean less admin and checking would be needed because the levels of each would stay the same which is ideal.
Regards,

Product Services
MailEnable Pty Ltd

To keep track of all ME company updates and version releases you should subscribe to the MailEnable list at http://www.mailenable.com or the RSS feed http://www.mailenable.com/rss.

ALLPRO
Posts: 23
Joined: Sun Apr 23, 2006 11:44 pm

Bayesian Filter Training Script

Post by ALLPRO » Thu Jul 13, 2006 10:53 pm

MailEnable-Ben wrote:For the best system if you wanted to make an advanced script you could compare the total of spam and ham messages before adding to the dictionary then only add the total of the least amount for each type.
Ask and you shall receive! 8) Here is a revised and simplied script. There are 2 new capabilities:

1) You can set 'MinMsgsBeforeProcessing' so that it will update the dictionary ONLY when you have a minumum number of BOTH Spam and Ham messages. The script will keep 'accumulating them' in the dictionary folders until there is enough. This should help optimize the process.

2) The script ensures there are EXACTLY the same number of Ham and Spam messages. Any 'extra messages' are moved to the storage folders. For example: If you have 1000 Ham and 1250 Spam, then 250 Spam are moved to the 'OldSpam' storage folder so that the dictionary folders now have 1000 each -- then they are processed.

It would not be too hard to adjust the math to create a 2-1 ratio of Ham to Spam or other preference, but I tried to keep this script simple.

********** IMPORTANT **********

There is one caveat - you MUST update your registry to enable an enhancement to the Command environment. Copy this text into a file and save with a ".REG" extension - THEN RUN IT.

Code: Select all

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor]
"DelayedExpansion"=dword:00000001
This change is totally safe and should not affect anything else. I have no idea why it is not enabled by default?

OK - here is the updated script. NOTE that I left "PAUSE" enabled so that you can see the results, but YOU MUST REM THIS OUT if you are going to 'schedule it' to run unattended.

/Kevin Dalman

NOTE: Script has been updated with "fixes" noted in later posts (Aug 22/06)

Code: Select all

@echo off
echo ****************************************************************
echo ******************   BAYESIAN FILTER UPDATE SCRIPT  ******************
echo ****************************************************************
echo.


rem ****************************************************************
rem ***************  CUSTOMIZE VARS FOR YOUR SYSTEM  *******************
rem ****************************************************************

rem ***  Set the Domains (ie, "Post-Office Names") you use as Spam and Ham Sources
rem ***  These must  match the spellings of the folders in the "Postoffices" folder
rem ***  Use spaces to separate Domain/Postoffice Names

SET Domains=mydomain.com yourdomain.net herdomain.org hisdomain.biz


rem ***  Set the 'minimum number of messages' required before updating the dictionary
rem ***  Ham & Spam messages will ACCUMULATE each time - until there are enough!

SET  MinMsgsBeforeProcessing=1000


rem ***  NOTE:  Be careful to NOT have any 'trailing spaces' when setting variables below

rem ***  Set the 'PostOffice'  and 'Dictionary' folders - WITHOUT a trailing ""
SET  PO_Folder=E:\Email\Postoffices
SET  DIC_Folder=E:\Email\Dictionaries

rem ***  Set the 'Dictionary' path exactly the same as in the 'Bayesian Filter' Properties
SET Dictionary=%DIC_Folder%\Bayesian_Dic.TAB

rem ***  Set the 'Mailbox Names' you are using to collect Spam and Ham messages
rem ***  It is assumed you use the 'Inbox' of these mailboxes to store these emails
rem ***  If this is not so, then adjust the MOVE command(s) in the next section
SET  SpamMailbox=SPAM
SET  HamMailbox=HAM

rem ***  Set Spam and Ham 'Dictionary' and 'Storage' folders - WITHOUT a trailing ""
SET  NewSpam=%DIC_Folder%\NewSpam
SET  NewHam=%DIC_Folder%\NewHam
SET  OldSpam=%DIC_Folder%\OldSpam
SET  OldHam=%DIC_Folder%\OldHam



rem ****************************************************************
rem **************  COLLECT THE HAM AND SPAM MESSAGES  ******************
rem ****************************************************************

rem ***  Move email stored by your configured filters to the dictionary folders 

echo.
echo    MOVE  messages from Spam Source folder(s) to dictionary Spam folder...
echo.
FOR  %%D  IN  (%Domains%)  DO   MOVE /Y  "%PO_Folder%\%%D\MAILROOT\%SpamMailbox%\Inbox\*.mai"  "%NewSpam%" 

echo.
echo    MOVE messages from Ham Source folder(s) to dictionary Ham folder...
echo.
FOR  %%D  IN  (%Domains%)  DO   MOVE /Y  "%PO_Folder%\%%D\MAILROOT\%HamMailbox%\Inbox\*.mai"  "%NewHam%" 



rem *******************************************************
rem ***  IMPORTANT NOTE - DO NOT IGNORE OR THIS WON'T WORK *****
rem *******************************************************
rem 
rem ***  You MUST add this registry entry to enable 'Delayed Expansion' ***
rem 
rem    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor]
rem    "DelayedExpansion"=dword:00000001
rem 
rem *******************************************************


rem ***  This section will count and move EXCESS Ham OR Spam to the storages folders
rem ***  The target is 1-to-1 -- equal quantities of Ham and Spam messages


rem ***  Initialize counter variables
SET  NewSpam_Count=0
SET  NewHam_Count=0
SET  ExcessSpam=0
SET  ExcessHam=0

rem ***  NOTE: "SET /A" lets us do math!  Use SET /? to see all available options

rem ***  COUNT the messages in the Dictionary folders
FOR  %%M  IN  ("%NewHam%\*.mai")  DO  SET /A  NewHam_Count += 1 
FOR  %%M  IN  ("%NewSpam%\*.mai")  DO  SET /A  NewSpam_Count += 1 

echo.
echo    There are %NewHam_Count% Ham messages and %NewSpam_Count% Spam messages
echo.


rem ***  If either message count is below the minimum required, then just exit

IF  %NewHam_Count%  LSS  %MinMsgsBeforeProcessing%  (
	ECHO There are only %NewHam_Count% Ham Messages - EXITING...
	GOTO  DONE
)

IF  %NewSpam_Count%  LSS  %MinMsgsBeforeProcessing%  (
	ECHO There are only %NewSpam_Count% Spam Messages - EXITING...
	GOTO  DONE
)


rem ***  Calculate number of 'Excess Messages' - only 1 can be 'positive'
SET /A  ExcessHam=NewHam_Count - NewSpam_Count
SET /A  ExcessSpam=NewSpam_Count - NewHam_Count

rem *** MOVE any Excess Messages to Storage - of whichever type is 'excess'

IF  %ExcessHam%  GTR 0  (
	echo There are %ExcessHam% TOO MANY HAM Messages
	FOR  %%M  IN  ("%NewHam%\*.mai")  DO  ( 
		rem ***  MUST delimit with "!" here (delayed expansion) to update in a loop
		IF  !ExcessHam!  GTR 0  MOVE /Y  "%%M"  "%OldHam%" 
		SET /A  ExcessHam = !ExcessHam! - 1 
	)
) 

IF  %ExcessSpam%  GTR 0  (
	echo There are %ExcessSpam% TOO MANY SPAM Messages
	FOR  %%M  IN  ("%NewSpam%\*.mai")  DO  ( 
		rem ***  MUST delimit with "!" here (delayed expansion) to update in a loop
		IF  !ExcessSpam!  GTR 0  MOVE /Y  "%%M"  "%OldSpam%" 
		SET /A  ExcessSpam = !ExcessSpam! - 1 
	)
)




rem ****************************************************************
rem ***************  UPDATE & RELOAD THE DICTIONARY  *******************
rem ****************************************************************

echo.
echo.
echo ***  Tell  MTA filter to write current dictionary from memory to file. 
echo.
MESPAMCMD  -w 

echo.
echo ***  Process the new Spam and Ham messages to update the dictionary. 
echo.
MESPAMCMD  -m  "%Dictionary%"  "%NewSpam%"  "%NewHam%" 

echo.
echo ***  Tell MTA filter to reload the dictionary from the newly updated file 
echo.
MESPAMCMD  -r 
echo.




rem ****************************************************************
rem ****************  EMPTY THE DICTIONARY FOLDERS  ********************
rem ****************************************************************

echo.
echo ***  Copy all the mail from the dictionary folders to the storage folders
echo ***  These will come in handy if you ever need to create a new dictionary

echo.
echo    MOVE NewHam to OldHam ...
echo.
MOVE /Y  "%NewHam%\*.*"  "%OldHam%" 

echo.
echo    MOVE NewSpam to OldSpam ...
echo.
MOVE /Y  "%NewSpam%\*.*"  "%OldSpam%" 




rem ***************  FINISHED -- PAUSE IF TESTING THE SCRIPT  *******************
:DONE

rem ***  Enable PAUSE while testing the batch file so you can see the output
rem ***  Otherwise the DOS window immediately closes upon completion
echo.
PAUSE


EXIT 
Last edited by ALLPRO on Wed Aug 23, 2006 2:39 am, edited 3 times in total.

MailEnable-Ben
Posts: 5858
Joined: Fri Jan 16, 2004 6:49 am
Location: Melbourne

Post by MailEnable-Ben » Fri Jul 14, 2006 12:37 am

That all looks pretty good to me :) I have a server that I need to set up next week and will use this script. But in theory this really is right on track.
Regards,

Product Services
MailEnable Pty Ltd

To keep track of all ME company updates and version releases you should subscribe to the MailEnable list at http://www.mailenable.com or the RSS feed http://www.mailenable.com/rss.

Hutch
Posts: 27
Joined: Wed Aug 09, 2006 9:14 am

Post by Hutch » Wed Aug 09, 2006 1:50 pm

Hi, I'm just trying to set this script up and am having problems with the part that counts new ham and spam mails. Has anyone else had this problem?

Code: Select all

rem ***  COUNT the messages in the Dictionary folders 
FOR  %%M  IN  (%NewHam%\*.mai)  DO  SET /A  NewHam_Count += 1 
FOR  %%M  IN  (%NewSpam%\*.mai)  DO  SET /A  NewSpam_Count += 1
That code always returns '0' for both lines.
In my setup %NewHam% equates to:
"D:\Mail Enable\Dictionaries\Custom\NewHam"
I have also tried "D:\MAILEN~1\Dictionaries\Custom\NewHam" just in case theres an 8.3 naming prob but it makes no differnce.
Oh and of course there ARE files in the directories with .mai extensions.

Any help greatly appreciated, thanks, Ben

ALLPRO
Posts: 23
Joined: Sun Apr 23, 2006 11:44 pm

Re: Script Problem

Post by ALLPRO » Thu Aug 10, 2006 1:28 am

Hutch,

First, ensure you have added the registry entry described in the instructions. Without this, the counter will not work! (But I don't think this is the problem else you would get a count of "1" and not "0")

To deal with directories that have a space in them, add quotes around the 'file path'. (I should have done this in the first place.) Also find and fix the other 2 lines listed below by adding quotes there as well.

Code: Select all

rem ***  COUNT the messages in the Dictionary folders
FOR  %%M  IN  ("%NewHam%\*.mai")  DO  SET /A  NewHam_Count += 1 
FOR  %%M  IN  ("%NewSpam%\*.mai")  DO  SET /A  NewSpam_Count += 1

---
IF  %ExcessHam%  GTR 0  (
    FOR  %%M  IN  ("%NewHam%\*.mai")  DO  ( 
---
IF  %ExcessSpam%  GTR 0  (
    FOR  %%M  IN  ("%NewSpam%\*.mai")  DO  ( 
---

However, it still should have worked for you when you used the 8.1 filename - assuming you have the correct short-name and that your system is set to generate short names. I tested this on my server and it did work.

I recommend you add the quotes shown above, and use the 'long filename' for your dictionary folder, like so:

Code: Select all

SET  DIC=D:\Mail Enable\Dictionaries\Custom 
If you still have problems, add some test output so you can verify that the paths being created are actually as you think they are. Here is an example:

Code: Select all

rem ***  COUNT the messages in the Dictionary folders
FOR  %%M  IN  ("%NewHam%\*.mai")  DO  SET /A  NewHam_Count += 1 
FOR  %%M  IN  ("%NewSpam%\*.mai")  DO  SET /A  NewSpam_Count += 1 

echo.
echo    There are %NewHam_Count% Ham messages and %NewSpam_Count% Spam messages
echo.

echo.
echo  NewHam Path = "%NewHam%\*.mai"
echo  NewSpam Path = "%NewSpam%\*.mai"
echo.

PAUSE
GOTO  DONE
If you still have trouble, temporarily copy your Ham/Spam folders to a path with no spaces in the name, like: "D:\Test\Ham". If this doesn't do it, then at least you definately eliminated the space as the cause.

Lastly, note that I have only tested this script on Windows Server 2003. However it should work on any version of Windows from Win2000 onwards.

Let me know if this works for you.

/Kevin Dalman

Grenzer
Posts: 4
Joined: Mon Aug 21, 2006 11:01 pm

Post by Grenzer » Tue Aug 22, 2006 1:29 pm

For me your fixes worked... Cheers.

ALLPRO
Posts: 23
Joined: Sun Apr 23, 2006 11:44 pm

Script is Updated

Post by ALLPRO » Tue Aug 22, 2006 7:48 pm

:idea: FYI, I updated the script I previously posted with the 'fixes' mentioned above, so all you need to do is copy the script in the post dated: Thu Jul 13, 2006

Post Reply