[Spambayes-checkins] spambayes/scripts sb_imapfilter.py,1.29,1.30

Tony Meyer anadelonbrin at users.sourceforge.net
Sun May 2 22:12:34 EDT 2004


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

Modified Files:
	sb_imapfilter.py 
Log Message:
Temporary fix for [ 941596 ] sb_imapfilter.py not adding headers / moving messages

The problem is that not all IMAP servers recognise that the new message is there
immediately after an APPEND, but we need to find it.  A no-op generally gives enough
time for the server to do its thing, and won't hit anyone else significantly.

The proper fix is to put in a loop waiting for the server to dish out the new "EXISTS"
data, but I'll leave that for post 1.0.

Also change the exception catching to catch any exception.  A new message parsing
problem raises a TypeError not an email.Error, so was causing imapfilter to crash.  We
really want to keep going no matter what, otherwise we leave the user's mailbox in an
ugly state.

Index: sb_imapfilter.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/scripts/sb_imapfilter.py,v
retrieving revision 1.29
retrieving revision 1.30
diff -C2 -d -r1.29 -r1.30
*** sb_imapfilter.py	25 Apr 2004 03:45:30 -0000	1.29
--- sb_imapfilter.py	3 May 2004 02:12:32 -0000	1.30
***************
*** 399,403 ****
          try:
              new_msg = email.Parser.Parser().parsestr(data[self.rfc822_key])
!         except email.Errors.MessageParseError, e:
              # Yikes!  Barry set this to return at this point, which
              # would work ok for training (IIRC, that's all he's
--- 399,409 ----
          try:
              new_msg = email.Parser.Parser().parsestr(data[self.rfc822_key])
!         # We use a general 'except' because the email package doesn't
!         # always return email.Errors (it can return a TypeError, for
!         # example) if the email is invalid.  In any case, we want
!         # to keep going, and not crash, because we might leave the
!         # user's mailbox in a bad state if we do.  Better to soldier
!         # on.
!         except:
              # Yikes!  Barry set this to return at this point, which
              # would work ok for training (IIRC, that's all he's
***************
*** 508,511 ****
--- 514,522 ----
          response = imap.uid("STORE", self.uid, "+FLAGS.SILENT", "(\\Deleted \\Seen)")
          self._check(response, 'store')
+         # Not all IMAP servers immediately offer the new message
+         # (stupidly), but we need to find it.  Generally a 'no-op' will
+         # allow the server time to handle it, so do that.
+         # See [ 941596 ] sb_imapfilter.py not adding headers / moving messages
+         imap.noop()
  
          # We need to update the uid, as it will have changed.




More information about the Spambayes-checkins mailing list