[Spambayes] Outlook Options files? And would they allow seperate DBs for multiple profiles?

Aether002 Aether002 at cobaltnight.com
Thu Oct 11 01:05:37 CEST 2007


	Well, you are correct that the ability to set seperate databases for
individual Outlook Profiles is broken.  

	However, I was determined to make this work, and so I dived into the
source code - and I came out with answers and a workaround solution.  I can
now make this work, and I'll go into details here - both for the developers,
so that they can have an easier time fixing this issue in the next release -
as well as for other end users, who would like to have this functionality
now, without waiting.


	I'll do this in two parts - the first part will go into the nitty
gritty of what's going on, why it doesn't work, and why I chose to fix it
the way I did.  The second part is just the instructions on how to do it,
for anyone who's interested.

	Note that everything below is in regards to SpamBayes 1.1a4, run as
Source, specifically for the Outlook Add-In.


----------------------------------------------------------------------------
PART I - Backstory
----------------------------------------------------------------------------


	As it pertains to configuration files and data directories, here is
the current workflow of how things work on a default 1.1a4 installation:


--------------------------------------

Current Workflow (SpamBayes 1.1a4):

	Note 1:  All events in the Workflow occur in
"\Outlook2000\manager.py"
	Note 2:  Line numbers specified are starting line numbers.  Actual
code may extend further.


1.  (Line:  380) - Set "self.windows_data_directory" to the Default Data
Directory.


2.  (Line:  384) - Call "self.PrepareConfig()" which reads the primary
config files:

2a.  (Line:  661) - Grab settings from "default_configuration.ini" in the
Application Directory

2b.  (Line:  664) - Grab settings from "default_configuration.ini" in the
Default Data Directory


3.  (Line:  389) - See if the initial config files specify a custom Data
Directory.  If so, use it as the Working Data Directory.  If not, use the
Default Data Directory as the Working Data Directory.

4.  (Line:  429) - Look for "default_bayes_customize.ini" in the Application
Directory as well as the Working Data Directory.  If found, grab the
settings.

5.  (Line:  433) - Look for "{outlook-profile-name}_bayes_customize.ini" in
the Working Data Directory.  If found, grab the settings.

--------------------------------------



	If you examine this workflow, you can see what the problem is -
SpamBayes looks for a custom Data Directory ONLY within the
"default_configuration.ini" file.  By the time it  looks for the individual
"{outlook-profile-name}_bayes_customize.ini" files, the Working Data
Directory has already been determined, and it will not be changed by entries
in those files.  For that matter, it doesn't even look for the individual
profile INIs in the Application Directory - it only looks for them in the
Working Data Directory, further showing that the directory location has to
have been set prior to this step.

	Rather than get into the sticky mess of loading the general and
profile "...customize.ini" files first, it seemed to me that the least
intrusive way to address this was to add an additional INI file to the mix -
one that would serve no other purpose except to define a custom data
directory on a per-profile basis.  

	Once this is done, the new workflow looks like this:



--------------------------------------

Modified Workflow:


1.  (Line:  380) - Set "self.windows_data_directory" to the Default Data
Directory.


2.  (Line:  384) - Call "self.PrepareConfig()" which reads the primary
config files

2a.  (Line:  661) - Grab settings from "default_configuration.ini" in the
Application Directory

2b.  (Line:  664) - Grab settings from "default_configuration.ini" in the
Default Data Directory

-----------

2c.  Grab settings from "{outlook-profile-name}_datadir.ini" in the
Application Directory

2d.  Grab settings from "{outlook-profile-name}_datadir.ini" in the Default
Data Directory

-----------

3.  (Line:  389) - See if the initial config files specify a custom Data
Directory.  If so, use it as the Working Data Directory.  If not, use the
Default Data Directory as the Working Data Directory.

4.  (Line:  429) - Look for "default_bayes_customize.ini" in the Application
Directory as well as the Working Data Directory.  If found, grab the
settings.

5.  (Line:  433) - Look for "{outlook-profile-name}_bayes_customize.ini" in
the Working Data Directory.  If found, grab the settings.

--------------------------------------



	I added the implementation of the new INI files as part of the
"PrepareConfig()" function.  This necessitated one other small change, which
was to rearrange a single line of code (plus comments), so that the Outlook
Profile Name would be accessible earlier in SpamBayes' execution - which is
necessary to parse the new INI files based on the Outlook Profile that is
active.


	So, that's it for the backstory - below is a standalone section that
shows the specifics of how to implement this change, for anyone who's
interested.  To the best of my knowledge, I have broken nothing by doing
this.  I'm running SpamBayes 1.1a4 on WinXP Pro SP2, using Outlook 2007, and
everything runs fine.  When I run the Trace Collector Debugging Tool, I get
no errors on startup, and SpamBayes functions fully.



----------------------------------------------------------------------------
PART II - Instructions
----------------------------------------------------------------------------


SpamBayes 1.1a4 - Modify to Support Multiple Profile DBs



SECTION 1 - Main Steps:


1.  Modify "\Outlook2000\manager.py" in the App (i.e.  Source Code)
Directory, as indicated in SECTION 2, below. (Remember to backup the
original)

2.  Create Individual Data Directories  (Ideal: Under the Default Data Dir;
this way all the user data is in one place).

3.  Copy DB and "(profile name).ini" files into the individual data
directories if they exist.  If there are existing DB files, copy them into
whichever Individual Data Directories you would like to start with that same
training data.

4.  Create "{outlook-profile-name}_datadir.ini" files in the Application
Directory OR Default Data Directory  (Ideal - In the Default Data Dir; this
way, it survives upgrades).  See SECTION 3 below for details.


	That's it!


Notes:  

1.  I have not tested any of this with Profiles that have spaces in their
names.
2.  For obvious reasons, this is designed to work when running SpamBayes
from source, as opposed to the EXE installer.
3.  The Default Data Directory for a Windows OS is typically "C:\Documents
and Settings\<Windows Login Name>\Application Data\SpamBayes"






SECTION 2 - Modifications to "\Outlook2000\manager.py":


Note 1:  These instructions are for 1.1a4 ONLY.  If you're running a
different version, the code may be different, and thus, would have to be
adapted accordingly.

Note 2:  Whitespace above and below lines is fine - I prefer to add them for
readability.  HOWEVER, you must be careful not to change the amount each
line is Indented.  Each line of code represented below (except the comment
lines - for them, it doesn't matter) must be indented by exactly EIGHT
spaces.  Otherwise it causes problems.



1.  Find this:

-----------------------

        # Get the message store before loading config, as we use the profile
        # name.
        self.message_store = msgstore.MAPIMsgStore(outlook)

-----------------------



2.  ...and move it ABOVE this:

-----------------------

        # where windows would like our data stored (and where
        # we do, unless overwritten via a config file)
        self.windows_data_directory = self.LocateDataDirectory()

-----------------------



3.  Find this:

-----------------------

        filename = os.path.join(self.application_directory,
"default_configuration.ini")
        self._MergeConfigFile(filename)

        filename = os.path.join(self.windows_data_directory,
"default_configuration.ini")
        self._MergeConfigFile(filename)

-----------------------



4.  ...and BELOW that, add this:

-----------------------

        filename = os.path.join(self.application_directory,
self.GetProfileName() + "_datadir.ini")
        self._MergeConfigFile(filename)

        filename = os.path.join(self.windows_data_directory,
self.GetProfileName() + "_datadir.ini")
        self._MergeConfigFile(filename)

-----------------------



** That's it for the "manager.py" edits. **




SECTION 3 - Profile Data Directory INI Files


1.  Create a text file named with the following syntax:
"{outlook-profile-name}_datadir.ini"

	For example, if your Outlook Profile is called "Stephen", then the
file will be named "stephen_datadir.ini"


2.  The contents of this text file should be the following (follow the
syntax):

--------------------

[General]
data_directory: <path to Profile Data Directory>

--------------------




For example, if you are creating a Profile Data Directory for your Outlook
Profile named "Stephen", you log into Windows with the username "Porche",
and you chose to put it under the Default Data Directory (recommended) with
the directory name the same as the profile name (not necessary, but a good
idea), the contents would be the following:

--------------------

[General]
data_directory: c:\documents and settings\porche\application
data\spambayes\stephen

--------------------



Notes:

1.  No quotes of any kind are needed to surround the path.
2.  Spaces within the path are fine.


----------------------------------------------------------------------------
END OF PART II
----------------------------------------------------------------------------



	Well, that's it.  Any comments on my workaround or documentation are
welcome.  




> -----Original Message-----
> From: Mark Hammond [mailto:mhammond at skippinet.com.au]
> Sent: Monday, October 08, 2007 10:07 PM
> To: 'Aether002'; spambayes at python.org
> Subject: RE: [Spambayes] Outlook Options files? And would they allow
seperate DBs for
> multiple profiles?
> 
> The Outlook addin always looks for a config file named
> "{profile_name}_bayes_customize.ini" in your spambayes ApplicationData
> directory.  Inside this file you can specify a "data directory" option in
a
> [General] section, which is where spambayes will save and load its
databases
> from.
> 
> See also
>
http://spambayes.sourceforge.net/faq.html#how-can-i-change-the-directory-tha
> t-spambayes-st - but that doesn't make it clear that you can have
different
> values for each profile by using that profile's INI file.
> 
> Sadly, that is only theory at this stage -
>
https://sourceforge.net/tracker/?func=detail&atid=498104&aid=939543&group_id
> =61702 implies it doesn't work :(  If it indeed doesn't work, I'd consider
> it a bug (which sadly doesn't really help you)
> 
> Mark
> 
> > -----Original Message-----
> > From: spambayes-bounces at python.org [mailto:spambayes-
> > bounces at python.org] On Behalf Of Aether002
> > Sent: Saturday, 6 October 2007 7:35 AM
> > To: spambayes at python.org
> > Subject: [Spambayes] Outlook Options files? And would they allow
> > seperate DBs for multiple profiles?
> >
> >
> > 	I'm still trying to figure out if there's any way 1.1a4 on
> > Outlook
> > 2007 (WinXP Pro) can be configured to use a seperate database for each
> > Outlook Profile.  It occurs to me that this might be one of the
> > advanced
> > options that can be set in the INI files, however, while the
> > documentation
> > mentions the "outlook-options.ini" file as the place to go to see what
> > all
> > the Outlook specific options are, I can't for the life of me find that
> > file.
> >
> > 	Am I blind, or is it not where it's supposed to be?  Also, if
> > anyone
> > knows how to accomplish my original goal (of the seperate DBs for each
> > Outlook Profile), I still need help there!
> >
> >
> > 	Thanks!
> >
> >
> > _______________________________________________
> > SpamBayes at python.org
> > http://mail.python.org/mailman/listinfo/spambayes
> > Info/Unsubscribe: http://mail.python.org/mailman/listinfo/spambayes
> > Check the FAQ before asking: http://spambayes.sf.net/faq.html



More information about the SpamBayes mailing list