[Spambayes-checkins] spambayes imapfilter.py,1.28,1.29

Tony Meyer anadelonbrin at users.sourceforge.net
Sun Apr 20 03:41:17 EDT 2003


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

Modified Files:
	imapfilter.py 
Log Message:
Set the user interface web pages to no cache as this is bad for the
configuration pages.
Fixed the checking of entered parameters so that both imapfilter
and pop3proxy work (in my testing, at least).
Changed parm_ini_map to a simpler version with just option and
section names (html keys are auto generated).
Move the select folder config for imap into two pages rather than
one - one for folder to train, one for filtering folders.  If this still
results in pages that are too long for people with lots of folders,
then this can be further split into one page per option.
Fixed the folder selector config so that it actually works.
Now that it works, made the folder selector config accessible.
Added a check to see if parsedate works so that we handle
things gracefully if it does not.
Fixed the re that got the internal date so that it can handle the
other half of the world.
Added in a fallback option in case imap can't find the uid of the
replacement message, although I'm not convinced this is a good
fallback (better than nothing, though).
Happy Easter, all ;)

Index: imapfilter.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/imapfilter.py,v
retrieving revision 1.28
retrieving revision 1.29
diff -C2 -d -r1.28 -r1.29
*** imapfilter.py	20 Apr 2003 06:58:52 -0000	1.28
--- imapfilter.py	20 Apr 2003 09:41:15 -0000	1.29
***************
*** 176,181 ****
          message_date = self["Date"]
          if message_date is not None:
!             return imaplib.Time2Internaldate(\
!                        time.mktime(parsedate(message_date)))
          else:
              return imaplib.Time2Internaldate(time.time())
--- 176,182 ----
          message_date = self["Date"]
          if message_date is not None:
!             parsed_date = parsedate(message_date)
!             if parsed_date is not None:
!                 return imaplib.Time2Internaldate(time.mktime(parsed_date))
          else:
              return imaplib.Time2Internaldate(time.time())
***************
*** 195,204 ****
          response = imap.uid("FETCH", self.id, "(FLAGS INTERNALDATE)")
          self._check(response, 'fetch (flags internaldate)')
!         response_pattern = r"[\d]+ \(UID [\w]+ FLAGS (\([\\\w]+\)) "
!         response_pattern += r'INTERNALDATE ["]?([\w\-: ]+)["]?\)'
          mo = re.match(response_pattern, response[1][0])
          if mo is None:
              msg_time = self.extractTime()
!             flags = None
          else:
              flags = mo.group(1)
--- 196,205 ----
          response = imap.uid("FETCH", self.id, "(FLAGS INTERNALDATE)")
          self._check(response, 'fetch (flags internaldate)')
!         response_pattern = r"[\d]+ \(UID [\w]+ FLAGS (\([\\\w]*\)) "
!         response_pattern += r'INTERNALDATE ["]?([\w\-\+: ]+)["]?\)'
          mo = re.match(response_pattern, response[1][0])
          if mo is None:
              msg_time = self.extractTime()
!             flags = ""
          else:
              flags = mo.group(1)
***************
*** 227,237 ****
          # header that we add for this explicit purpose.
          imap.SelectFolder(self.folder.name, False)
!         response = imap.uid("SEARCH", "HEADER", "X-Spambayes-IMAP-OldID",
                              old_id)
          self._check(response, 'search')
          new_id = response[1][0]
  
          # now that we know the new id, we need to correct the flags
!         if flags != None:
              response = imap.uid("STORE", new_id, "+FLAGS.SILENT", flags)
              self._check(response, "store flags")
--- 228,248 ----
          # header that we add for this explicit purpose.
          imap.SelectFolder(self.folder.name, False)
!         response = imap.uid("SEARCH", "(HEADER)", "X-Spambayes-IMAP-OldID",
                              old_id)
          self._check(response, 'search')
          new_id = response[1][0]
+         # This works with NetMail, but not with Courier.  Very strange,
+         # and needs more examination.  For the moment, if the search
+         # turns up empty, we make the very big assumption that the new
+         # message is the last one with a recent flag
+         if new_id == "":
+             response = imap.uid("SEARCH", "(RECENT)")
+             new_id = response[1][0]
+             if new_id.find(' ') > -1:
+                 ids = new_id.split(' ')
+                 new_id = ids[-1]
  
          # now that we know the new id, we need to correct the flags
!         if flags != "":
              response = imap.uid("STORE", new_id, "+FLAGS.SILENT", flags)
              self._check(response, "store flags")





More information about the Spambayes-checkins mailing list