[Spambayes-checkins] spambayes/scripts sb_imapfilter.py,1.40,1.41

Tony Meyer anadelonbrin at users.sourceforge.net
Wed Oct 13 04:42:06 CEST 2004


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

Modified Files:
	sb_imapfilter.py 
Log Message:
Implement [ 1039057 ] Diffs for IMAP login problems...

But in a different way.  This changes imapfilter so that if there is a problem connecting
 to the server the script doesn't just terminate, it prints out a message and keeps
 going.  This means that if it's a temporary problem and imapfilter is running continuously,
 it should work the next time.  If it's only running once, then it'll end as usual.

Also corresponding change to ImapUI in case there are problems connecting when using
 the web interface to set folder parameters (this is better than the old way, which
 would terminate the script, rather than present an error in the web interface).

Index: sb_imapfilter.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/scripts/sb_imapfilter.py,v
retrieving revision 1.40
retrieving revision 1.41
diff -C2 -d -r1.40 -r1.41
*** sb_imapfilter.py	1 Oct 2004 20:30:52 -0000	1.40
--- sb_imapfilter.py	13 Oct 2004 02:42:04 -0000	1.41
***************
*** 141,147 ****
              BaseIMAP.__init__(self, server, port)
          except (BaseIMAP.error, socket.gaierror, socket.error):
!             print "Cannot connect to server, please check your server " \
!                   "and port settings."
!             sys.exit()
          self.debug = debug
          self.do_expunge = do_expunge
--- 141,148 ----
              BaseIMAP.__init__(self, server, port)
          except (BaseIMAP.error, socket.gaierror, socket.error):
!             print "Cannot connect to server %s on port %s" % (server, port)
!             self.connected = False
!         else:
!             self.connected = True
          self.debug = debug
          self.do_expunge = do_expunge
***************
*** 156,164 ****
      def login(self, username, pwd):
          """Log in to the IMAP server, catching invalid username/password."""
          try:
              BaseIMAP.login(self, username, pwd)  # superclass login
          except BaseIMAP.error, e:
!             print "There was an error logging in to the IMAP server."
!             print "The username and/or password may be incorrect."
              sys.exit()
          self.logged_in = True
--- 157,168 ----
      def login(self, username, pwd):
          """Log in to the IMAP server, catching invalid username/password."""
+         assert self.connected, "Must be connected before logging in."
          try:
              BaseIMAP.login(self, username, pwd)  # superclass login
          except BaseIMAP.error, e:
!             msg = "There was an error logging in to the IMAP server." \
!                   " The username (%s) and/or password may " \
!                   "be incorrect." % (username,)
!             print msg
              sys.exit()
          self.logged_in = True
***************
*** 998,1014 ****
          while True:
              imap = IMAPSession(server, port, imapDebug, doExpunge)
!             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()
  
              if sleepTime:
--- 1002,1025 ----
          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:



More information about the Spambayes-checkins mailing list