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

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

Index: sb_imapfilter.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/scripts/sb_imapfilter.py,v
retrieving revision 1.52
retrieving revision 1.53
diff -C2 -d -r1.52 -r1.53
*** sb_imapfilter.py    13 Jan 2005 21:47:25 -0000      1.52
--- sb_imapfilter.py    14 Feb 2005 06:08:10 -0000      1.53
***************
*** 4,10 ****
  messages are scored and (where necessary) filtered.
  
- The original filter design owed much to isbg by Roger Binns
- (http://www.rogerbinns.com/isbg).
- 
  Usage:
      sb_imapfilter [options]
--- 4,7 ----
***************
*** 67,71 ****
  
  __author__ = "Tony Meyer <[EMAIL PROTECTED]>, Tim Stone"
! __credits__ = "All the SpamBayes folk."
  
  from __future__ import generators
--- 64,69 ----
  
  __author__ = "Tony Meyer <[EMAIL PROTECTED]>, Tim Stone"
! __credits__ = "All the SpamBayes folk. The original filter design owed " \
!               "much to isbg by Roger Binns (http://www.rogerbinns.com/isbg)."
  
  from __future__ import generators
***************
*** 151,154 ****
--- 149,154 ----
          self.debug = debug
          self.do_expunge = do_expunge
+         self.server = server
+         self.port = port
          self.logged_in = False
  
***************
*** 1011,1016 ****
      promptForPass = False
      launchUI = False
!     server = ""
!     username = ""
  
      for opt, arg in opts:
--- 1011,1016 ----
      promptForPass = False
      launchUI = False
!     servers = ""
!     usernames = ""
  
      for opt, arg in opts:
***************
*** 1055,1073 ****
  
      if options["imap", "server"]:
!         # The options class is ahead of us here:
!         #   it knows that imap:server will eventually be able to have
!         #   multiple values, but for the moment, we just use the first one
!         server = options["imap", "server"]
!         if len(server) > 0:
!             server = server[0]
!         username = options["imap", "username"]
!         if len(username) > 0:
!             username = username[0]
          if not promptForPass:
!             pwd = options["imap", "password"]
!             if len(pwd) > 0:
!                 pwd = pwd[0]
      else:
!         pwd = None
          if not launchUI and not force_UI:
              print "You need to specify both a server and a username."
--- 1055,1064 ----
  
      if options["imap", "server"]:
!         servers = options["imap", "server"]
!         usernames = options["imap", "username"]
          if not promptForPass:
!             pwds = options["imap", "password"]
      else:
!         pwds = None
          if not launchUI and not force_UI:
              print "You need to specify both a server and a username."
***************
*** 1075,1088 ****
  
      if promptForPass:
!         pwd = getpass()
  
!     if server.find(':') > -1:
!         server, port = server.split(':', 1)
!         port = int(port)
!     else:
!         if options["imap", "use_ssl"]:
!             port = 993
          else:
!             port = 143
  
      imap_filter = IMAPFilter(classifier)
--- 1066,1084 ----
  
      if promptForPass:
!         pwds = []
!         for i in xrange(len(usernames)):
!             pwds.append(getpass("Enter password for %s:" % (usernames[i],)))
  
!     servers_data = []
!     for server, username, password in zip(servers, usernames, pwds or []):
!         if server.find(':') > -1:
!             server, port = server.split(':', 1)
!             port = int(port)
          else:
!             if options["imap", "use_ssl"]:
!                 port = 993
!             else:
!                 port = 143
!         servers_data.append((server, port, username, password))
  
      imap_filter = IMAPFilter(classifier)
***************
*** 1101,1108 ****
      # don't want to slow classification/training down, either.
      if sleepTime or not (doClassify or doTrain):
!         if server == "":
!             imap = None
!         else:
!             imap = IMAPSession(server, port, imapDebug, doExpunge)
  
          # Load stats manager.
--- 1097,1106 ----
      # don't want to slow classification/training down, either.
      if sleepTime or not (doClassify or doTrain):
!         imaps = []
!         for server, port, username, password in servers_data:
!             if server == "":
!                 imaps.append(None)
!             else:
!                 imaps.append(IMAPSession(server, port, imapDebug, doExpunge))
  
          # Load stats manager.
***************
*** 1110,1114 ****
          
          httpServer = UserInterfaceServer(options["html_ui", "port"])
!         httpServer.register(IMAPUserInterface(classifier, imap, pwd,
                                                IMAPSession, stats=stats))
          launchBrowser=launchUI or options["html_ui", "launch_browser"]
--- 1108,1112 ----
          
          httpServer = UserInterfaceServer(options["html_ui", "port"])
!         httpServer.register(IMAPUserInterface(classifier, imaps, pwds,
                                                IMAPSession, stats=stats))
          launchBrowser=launchUI or options["html_ui", "launch_browser"]
***************
*** 1120,1145 ****
              Dibbler.run(launchBrowser=launchBrowser)
      if doClassify or doTrain:
          while True:
!             imap = IMAPSession(server, port, imapDebug, doExpunge)
!             if imap.connected:
!                 imap.login(username, pwd)
!                 imap_filter.imap_server = imap
  
!                 if doTrain:
!                     if options["globals", "verbose"]:
!                         print "Training"
!                     imap_filter.Train()
!                 if doClassify:
!                     if options["globals", "verbose"]:
!                         print "Classifying"
!                     imap_filter.Filter()
  
!                 imap.logout()
!             else:
!                 # Failed to connect.  This may be a temporary problem,
!                 # so just continue on and try again.  If we are only
!                 # running once we will end, otherwise we'll try again
!                 # in sleepTime seconds.
!                 pass
  
              if sleepTime:
--- 1118,1149 ----
              Dibbler.run(launchBrowser=launchBrowser)
      if doClassify or doTrain:
+         imaps = []
+         for server, port, username, password in servers_data:
+             imaps.append((IMAPSession(server, port, imapDebug, doExpunge),
+                           username, password))
          while True:
!             for imap, username, password in imaps:
!                 if options["globals", "verbose"]:
!                     print "Account: %s:%s" % (imap.server, imap.port)
!                 if imap.connected:
!                     imap.login(username, password)
!                     imap_filter.imap_server = imap
  
!                     if doTrain:
!                         if options["globals", "verbose"]:
!                             print "Training"
!                         imap_filter.Train()
!                     if doClassify:
!                         if options["globals", "verbose"]:
!                             print "Classifying"
!                         imap_filter.Filter()
  
!                     imap.logout()
!                 else:
!                     # Failed to connect.  This may be a temporary problem,
!                     # so just continue on and try again.  If we are only
!                     # running once we will end, otherwise we'll try again
!                     # in sleepTime seconds.
!                     pass
  
              if sleepTime:

_______________________________________________
Spambayes-checkins mailing list
[email protected]
http://mail.python.org/mailman/listinfo/spambayes-checkins

Reply via email to