[Spambayes-checkins] spambayes imapfilter.py,1.30,1.31

Tony Meyer anadelonbrin at users.sourceforge.net
Tue Apr 22 16:47:16 EDT 2003


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

Modified Files:
	imapfilter.py 
Log Message:
Made the processing of the fetch response in keys()
more robust.  It should now handle the response in any
(valid) order.  Works for me, but the old one did too :)
Testers take your places... :)

Index: imapfilter.py
===================================================================
RCS file: /cvsroot/spambayes/spambayes/imapfilter.py,v
retrieving revision 1.30
retrieving revision 1.31
diff -C2 -d -r1.30 -r1.31
*** imapfilter.py	22 Apr 2003 13:14:20 -0000	1.30
--- imapfilter.py	22 Apr 2003 22:47:13 -0000	1.31
***************
*** 295,305 ****
          r = re.compile(r"[0-9]+ \(UID ([0-9]+) FLAGS \(([\\\w]*)\)\)")
          uids = []
!         for i in response[1]:
!             mo = r.match(i)
!             if mo is not None:
!                 # We are not interested in messages marked as deleted
!                 if mo.group(2).lower() != "\\deleted":
!                     uids.append(mo.group(1))
          return uids
  
      def __getitem__(self, key):
--- 295,324 ----
          r = re.compile(r"[0-9]+ \(UID ([0-9]+) FLAGS \(([\\\w]*)\)\)")
          uids = []
!         for resp in response[1]:
!             data = self._extract_fetch_data(resp)
!             if data.has_key("FLAGS"):
!                 if data["FLAGS"].lower().find("\\deleted") == -1:
!                     # We are interested in messages not marked as deleted
!                     uids.append(data["UID"])
!             else:
!                 uids.append(data["UID"])
          return uids
+ 
+     def _extract_fetch_data(self, response):
+         '''Extract data from the response given to an IMAP FETCH command.'''
+         data = {}
+         # the first item will always be the message number
+         mo = re.match(r"([0-9]+) \(?([\w\\\(\) ]*)\)?", response)
+         if mo is None:
+             print """IMAP server gave strange fetch response.  Please
+             report this as a bug."""
+         else:
+             data["message_number"] = mo.group(1)
+             response = mo.group(2)
+         mo = re.findall(r"([\w]+) \(?([\w\\]+)\)?", response)
+         for key, val in mo:
+             data[key] = val
+         return data
+         
  
      def __getitem__(self, key):





More information about the Spambayes-checkins mailing list