[Spambayes-checkins] spambayes/windows autoconfigure.py,1.5,1.6

Tony Meyer anadelonbrin at users.sourceforge.net
Tue Sep 30 01:23:55 EDT 2003


Update of /cvsroot/spambayes/spambayes/windows
In directory sc8-pr-cvs1:/tmp/cvs-serv2300/windows

Modified Files:
	autoconfigure.py 
Log Message:
Add some (limited) smarts to find the expected location of the
various configuration files.  Now to autoconfigure you should
only have to call configure(mailer), where mailer is the name
of one of the mailers the script is aware of.  This coud probably
be wrapped into the install process somehow (maybe a gui
around it?  I don't know what the Inno scripting is like).

Index: autoconfigure.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/windows/autoconfigure.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** autoconfigure.py	9 Sep 2003 08:55:51 -0000	1.5
--- autoconfigure.py	30 Sep 2003 05:23:53 -0000	1.6
***************
*** 3,10 ****
  """Automatically set up the user's mail client and SpamBayes.
  
  Currently works with:
   o Eudora (POP3/SMTP only)
   o Mozilla Mail (POP3/SMTP only)
!  o Opera Mail (M2) (POP3/SMTP only)
   o Outlook Express (POP3/SMTP only)
   o PocoMail (POP3/SMTP only)
--- 3,14 ----
  """Automatically set up the user's mail client and SpamBayes.
  
+ Example usage:
+     >>> configure("mailer name")
+ Where "mailer name" is any of the names below.
+ 
  Currently works with:
   o Eudora (POP3/SMTP only)
   o Mozilla Mail (POP3/SMTP only)
!  o M2 (Opera Mail) (POP3/SMTP only)
   o Outlook Express (POP3/SMTP only)
   o PocoMail (POP3/SMTP only)
***************
*** 21,26 ****
     only one is necessary.  We should check the existing proxies before
     adding a new one.
-  o Figure out Outlook Express's pop3uidl.dbx file and how to hook into it
-    (use the oe_mailbox.py module)
   o Other mail clients?  Other platforms?
   o This won't work all that well if multiple mail clients are used (they
--- 25,28 ----
***************
*** 31,35 ****
     something does wrong, it's corrupted.  We also write into the file,
     rather than a temporary one and then copy across.  This should all be
!    fixed.
   o Suggestions?
  """
--- 33,42 ----
     something does wrong, it's corrupted.  We also write into the file,
     rather than a temporary one and then copy across.  This should all be
!    fixed.  Richie's suggestion is for the script to create a clone of an
!    existing account with the new settings.  Then people could test the
!    cloned account, and if they're happy with it they can either delete
!    their old account or delete the new one and run the script again in
!    "modify" rather than "clone" mode.  This sounds like a good idea,
!    although a lot of work...
   o Suggestions?
  """
***************
*** 63,67 ****
  import ConfigParser
  
! # Allow for those without SpamBayes on the PYTHONPATH
  sys.path.insert(-1, os.getcwd())
  sys.path.insert(-1, os.path.dirname(os.getcwd()))
--- 70,74 ----
  import ConfigParser
  
! # Allow for those without SpamBayes on their PYTHONPATH
  sys.path.insert(-1, os.getcwd())
  sys.path.insert(-1, os.path.dirname(os.getcwd()))
***************
*** 114,118 ****
              if c.get(sect, "UsesIMAP") == "0":
                  # Eudora stores the POP3 server name in two places.
!                 # Why?  Who knows?  We do the popaccount one
                  # separately, because it also has the username.
                  p = c.get(sect, "popaccount")
--- 121,125 ----
              if c.get(sect, "UsesIMAP") == "0":
                  # Eudora stores the POP3 server name in two places.
!                 # Why?  Who cares.  We do the popaccount one
                  # separately, because it also has the username.
                  p = c.get(sect, "popaccount")
***************
*** 413,417 ****
      # here.
  
! def configure_outlook_express():
      """Configure OE to use the SpamBayes POP3 and SMTP proxies, and
      configure SpamBayes to proxy the servers that OE was connecting to."""
--- 420,424 ----
      # here.
  
! def configure_outlook_express(unused):
      """Configure OE to use the SpamBayes POP3 and SMTP proxies, and
      configure SpamBayes to proxy the servers that OE was connecting to."""
***************
*** 546,550 ****
      rules_file.close()
  
! def configure_pocomail():
       import win32api
       import win32con
--- 553,557 ----
      rules_file.close()
  
! def configure_pocomail(unused):
       import win32api
       import win32con
***************
*** 657,660 ****
--- 664,714 ----
  
  
+ def find_config_location(mailer):
+     """Attempt to find the location of the config file for
+     the given mailer, to pass to the configure_* scripts
+     above."""
+     import win32api
+     from win32com.shell import shell, shellcon
+     if mailer in ["Outlook Express", "PocoMail"]:
+         # Outlook Express and PocoMail can be configured without a
+         # config location, because it's all in the registry
+         return ""
+     windowsUserDirectory = shell.SHGetFolderPath(0,shellcon.CSIDL_APPDATA,0,0)
+     potential_locations = {"Eudora" : ("Qualcomm%(sep)sEudora",),
+                            "Mozilla" : ("Mozilla%(sep)sProfiles%(sep)s%(user)s",
+                                         "Mozilla%(sep)sProfiles%(sep)sdefault",),
+                            "M2" : ("Opera%(sep)sOpera7",),
+                            }
+     # We try with the username that the user uses [that's a lot of 'use'!]
+     # for Windows, even though that might not be the same as their profile
+     # names for mailers.  We can get smarter later.
+     username = win32api.GetUserName()
+     loc_dict = {"sep" : os.sep,
+                 "user" : username}
+     for loc in potential_locations[mailer]:
+         loc = loc % loc_dict
+         loc = os.path.join(windowsUserDirectory, loc)
+         if os.path.exists(loc):
+             return loc
+     return None
+ 
+ 
+ def configure(mailer):
+     """Automatically configure the specified mailer and SpamBayes.
+     Return True if successful, False otherwise.
+     """
+     loc = find_config_location(mailer)
+     if loc is None:
+         return False
+     funcs = {"Eudora" : configure_eudora,
+              "Mozilla" : configure_mozilla,
+              "M2" : configure_m2,
+              "Outlook Express" : configure_outlook_express,
+              "PocoMail" : configure_pocomail,
+              }
+     funcs[mailer](loc)
+     return True
+ 
+ 
  if __name__ == "__main__":
      pmail_ini_dir = "C:\\Program Files\\PMAIL\\MAIL\\ADMIN"
***************
*** 665,667 ****
      #configure_pocomail()
      #configure_pegasus_mail(pmail_ini_dir)
!     pass
--- 719,722 ----
      #configure_pocomail()
      #configure_pegasus_mail(pmail_ini_dir)
!     for mailer in ["Eudora", "Mozilla", "M2", "Outlook Express", "PocoMail"]:
!         print find_config_location(mailer)





More information about the Spambayes-checkins mailing list