[Spambayes-checkins] spambayes/spambayes ImapUI.py, 1.44, 1.45 Options.py, 1.121, 1.122

Tony Meyer anadelonbrin at users.sourceforge.net
Mon Feb 14 07:10:48 CET 2005


Update of /cvsroot/spambayes/spambayes/spambayes
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv10058/spambayes

Modified Files:
	ImapUI.py Options.py 
Log Message:
Handle multiple imap servers.  Adds [ 1122067 ] Feature Request: Config sb_imapfilter for multiple accounts

Index: ImapUI.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/spambayes/ImapUI.py,v
retrieving revision 1.44
retrieving revision 1.45
diff -C2 -d -r1.44 -r1.45
*** ImapUI.py	10 Jan 2005 02:36:20 -0000	1.44
--- ImapUI.py	14 Feb 2005 06:10:45 -0000	1.45
***************
*** 111,115 ****
  class IMAPUserInterface(UserInterface.UserInterface):
      """Serves the HTML user interface for the proxies."""
!     def __init__(self, cls, imap, pwd, imap_session_class,
                   lang_manager=None, stats=None):
          global parm_map
--- 111,115 ----
  class IMAPUserInterface(UserInterface.UserInterface):
      """Serves the HTML user interface for the proxies."""
!     def __init__(self, cls, imaps, pwds, imap_session_class,
                   lang_manager=None, stats=None):
          global parm_map
***************
*** 126,132 ****
                                               lang_manager, stats)
          self.classifier = cls
!         self.imap = imap
!         self.imap_pwd = pwd
!         self.imap_logged_in = False
          self.app_for_version = "SpamBayes IMAP Filter"
          self.imap_session_class = imap_session_class
--- 126,131 ----
                                               lang_manager, stats)
          self.classifier = cls
!         self.imaps = imaps
!         self.imap_pwds = pwds
          self.app_for_version = "SpamBayes IMAP Filter"
          self.imap_session_class = imap_session_class
***************
*** 170,175 ****
  
      def onSave(self, how):
!         if self.imap is not None:
!             self.imap.logout()
          UserInterface.UserInterface.onSave(self, how)
  
--- 169,175 ----
  
      def onSave(self, how):
!         for imap in self.imaps:
!             if imap:
!                 imap.logout()
          UserInterface.UserInterface.onSave(self, how)
  
***************
*** 177,203 ****
          self._writePreamble(_("Select Filter Folders"))
          self._login_to_imap()
!         if self.imap_logged_in:
!             available_folders = self.imap.folder_list()
!             content = self.html.configForm.clone()
!             content.configFormContent = ""
!             content.introduction = _("This page allows you to change " \
!                                      "which folders are filtered, and " \
!                                      "where filtered mail ends up.")
!             content.config_submit.value = _("Save Filter Folders")
!             content.optionsPathname = optionsPathname
  
!             for opt in ("unsure_folder", "spam_folder",
!                         "filter_folders"):
!                 folderBox = self._buildFolderBox("imap", opt, available_folders)
!                 content.configFormContent += folderBox
  
!             self.write(content)
!             self._writePostamble()
  
      def _login_to_imap(self):
!         if self.imap_logged_in:
!             return
!         if self.imap is None and len(options["imap", "server"]) > 0:
!             server = options["imap", "server"][0]
              if server.find(':') > -1:
                  server, port = server.split(':', 1)
--- 177,220 ----
          self._writePreamble(_("Select Filter Folders"))
          self._login_to_imap()
!         available_folders = []
!         for imap in self.imaps:
!             if imap and imap.logged_in:
!                 available_folders.extend(imap.folder_list())
  
!         content = self.html.configForm.clone()
!         content.configFormContent = ""
!         content.introduction = _("This page allows you to change " \
!                                  "which folders are filtered, and " \
!                                  "where filtered mail ends up.")
!         content.config_submit.value = _("Save Filter Folders")
!         content.optionsPathname = optionsPathname
  
!         for opt in ("unsure_folder", "spam_folder",
!                     "filter_folders"):
!             folderBox = self._buildFolderBox("imap", opt, available_folders)
!             content.configFormContent += folderBox
! 
!         self.write(content)
!         self._writePostamble()
  
      def _login_to_imap(self):
!         new_imaps = []
!         for i in xrange(len(self.imaps)):
!             imap = self.imaps[i]
!             new_imaps.append(self._login_to_imap_server(imap, i))
!         self.imaps = new_imaps
!             
!     def _login_to_imap_server(self, imap, i):
!         if imap and imap.logged_in:
!             return imap
!         if imap is None or not imap.connected:
!             try:
!                 server = options["imap", "server"][i]
!             except KeyError:
!                 content = self._buildBox(_("Error"), None,
!                                          _("Please check server/port details."))
!                 self.write(content)
!                 self._writePostamble()
!                 return None
              if server.find(':') > -1:
                  server, port = server.split(':', 1)
***************
*** 208,267 ****
                  else:
                      port = 143
!             self.imap = self.imap_session_class(server, port)
!             if not self.imap.connected:
!               # Failed to connect.
!               content = self._buildBox(_("Error"), None,
!                                        _("Please check server/port details."))
!               self.write(content)
!               self._writePostamble()
!               return
!         if self.imap is None:
!             content = self._buildBox(_("Error"), None,
!                                      _("Must specify server details first."))
!             self.write(content)
!             self._writePostamble()
!             return
!         username = options["imap", "username"]
!         if isinstance(username, types.TupleType):
!             username = username[0]
!         if not username:
              content = self._buildBox(_("Error"), None,
                                       _("Must specify username first."))
              self.write(content)
              self._writePostamble()
!             return
!         if not self.imap_pwd:
              self.imap_pwd = options["imap", "password"]
!             if isinstance(self.imap_pwd, types.TupleType):
!                 self.imap_pwd = self.imap_pwd[0]
!         if not self.imap_pwd:
              content = self._buildBox(_("Error"), None,
                                       _("Must specify password first."))
              self.write(content)
              self._writePostamble()
!             return
!         self.imap.login(username, self.imap_pwd)
!         self.imap_logged_in = True
  
      def onTrainingfolders(self):
          self._writePreamble(_("Select Training Folders"))
          self._login_to_imap()
!         if self.imap_logged_in:
!             available_folders = self.imap.folder_list()
!             content = self.html.configForm.clone()
!             content.configFormContent = ""
!             content.introduction = _("This page allows you to change " \
!                                      "which folders contain mail to " \
!                                      "train Spambayes.")
!             content.config_submit.value = _("Save Training Folders")
!             content.optionsPathname = optionsPathname
  
!             for opt in ("ham_train_folders",
!                         "spam_train_folders"):
!                 folderBox = self._buildFolderBox("imap", opt, available_folders)
!                 content.configFormContent += folderBox
  
!             self.write(content)
!             self._writePostamble()
  
      def onChangeopts(self, **parms):
--- 225,285 ----
                  else:
                      port = 143
!             imap = self.imap_session_class(server, port)
!             if not imap.connected:
!                 # Failed to connect.
!                 content = self._buildBox(_("Error"), None,
!                                          _("Please check server/port details."))
!                 self.write(content)
!                 self._writePostamble()
!                 return None
!         usernames = options["imap", "username"]
!         if not usernames:
              content = self._buildBox(_("Error"), None,
                                       _("Must specify username first."))
              self.write(content)
              self._writePostamble()
!             return None
!         if not self.imap_pwds:
              self.imap_pwd = options["imap", "password"]
!         if not self.imap_pwds:
              content = self._buildBox(_("Error"), None,
                                       _("Must specify password first."))
              self.write(content)
              self._writePostamble()
!             return None
!         print usernames[i], self.imap_pwds[i]
!         try:
!             imap.login(usernames[i], self.imap_pwds[i])
!         except KeyError:
!             content = self._buildBox(_("Error"), None,
!                                      _("Please check username/password details."))
!             self.write(content)
!             self._writePostamble()
!             return None
!         return imap
  
      def onTrainingfolders(self):
          self._writePreamble(_("Select Training Folders"))
          self._login_to_imap()
!         available_folders = []
!         for imap in self.imaps:
!             if imap and imap.logged_in:
!                 available_folders.extend(imap.folder_list())
  
!         content = self.html.configForm.clone()
!         content.configFormContent = ""
!         content.introduction = _("This page allows you to change " \
!                                  "which folders contain mail to " \
!                                  "train Spambayes.")
!         content.config_submit.value = _("Save Training Folders")
!         content.optionsPathname = optionsPathname
  
!         for opt in ("ham_train_folders",
!                     "spam_train_folders"):
!             folderBox = self._buildFolderBox("imap", opt, available_folders)
!             content.configFormContent += folderBox
! 
!         self.write(content)
!         self._writePostamble()
  
      def onChangeopts(self, **parms):

Index: Options.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/spambayes/Options.py,v
retrieving revision 1.121
retrieving revision 1.122
diff -C2 -d -r1.121 -r1.122
*** Options.py	4 Jan 2005 03:04:01 -0000	1.121
--- Options.py	14 Feb 2005 06:10:45 -0000	1.122
***************
*** 981,996 ****
    "imap" : (
      ("server", _("Server"), (),
!      _("""This is the name and port of the imap server that stores your mail,
!      and which the imap filter will connect to - for example:
       mail.example.com or imap.example.com:143.  The default IMAP port is
!      143, or 993 if using SSL; if you connect via one of those ports, you
!      can leave this blank. If you use more than one server, then things are
!      a bit more complicated for you at the moment, sorry.  You will need to
!      have multiple instances of the imap filter running, each with a
!      different server (and possibly username and password) value.  You can
!      do this if you have a different configuration file for each instance,
!      but you'll have to do it by hand for the moment.  Please let the
!      mailing list know if you are in this situation so that we can consider
!      coming up with a better solution."""),
       SERVER, DO_NOT_RESTORE),
  
--- 981,990 ----
    "imap" : (
      ("server", _("Server"), (),
!      _("""These are the names and ports of the imap servers that store your
!      mail, and which the imap filter will connect to - for example:
       mail.example.com or imap.example.com:143.  The default IMAP port is
!      143 (or 993 if using SSL); if you connect via one of those ports, you
!      can leave this blank. If you use more than one server, use a comma
!      delimited list of the server:port values."""),
       SERVER, DO_NOT_RESTORE),
  
***************
*** 998,1004 ****
       _("""This is the id that you use to log into your imap server.  If your
       address is funkyguy at example.com, then your username is probably
!      funkyguy. If you are using multiple imap servers, or multiple accounts
!      on the same server, please see the comments regarding the server
!      value."""),
       IMAP_ASTRING, DO_NOT_RESTORE),
  
--- 992,996 ----
       _("""This is the id that you use to log into your imap server.  If your
       address is funkyguy at example.com, then your username is probably
!      funkyguy."""),
       IMAP_ASTRING, DO_NOT_RESTORE),
  



More information about the Spambayes-checkins mailing list