diff src/plugins/plugin_misc_imap.py @ 254:9fc32d1d9046

Plugin IMAP, plugin MAILDIR: added IMAP's UID management, mailbox data persistence
author Goffi <goffi@goffi.org>
date Mon, 17 Jan 2011 04:23:31 +0100
parents f45ffbf211e9
children 55b750017b71
line wrap: on
line diff
--- a/src/plugins/plugin_misc_imap.py	Mon Jan 17 00:15:50 2011 +0100
+++ b/src/plugins/plugin_misc_imap.py	Mon Jan 17 04:23:31 2011 +0100
@@ -85,6 +85,7 @@
         """Retrieve the unique identifier associated with this message.
         """
         debug('getUID (message)')
+        debug ('===>%i', self.uid)
         return self.uid
 
     def getFlags(self):
@@ -176,7 +177,7 @@
         """Return the likely UID for the next message added to this mailbox.
         """
         debug ('getUIDNext')
-        return self.getMessageCount()+1
+        return self.mailbox.getNextUid()
 
     def getUID(self,message):
         """Return the UID of a message in the mailbox
@@ -184,7 +185,7 @@
         @return: The UID of the message.
         """
         debug ('getUID')
-        return self.mailbox.getId(message)
+        return self.mailbox.getUid(message)
 
     def getMessageCount(self):
         """Return the number of messages in this mailbox.
@@ -285,11 +286,24 @@
         @param uid: If true, the IDs specified in the query are UIDs;
         """
         debug('fetch (%s, %s)'%(messages,uid))
-        messages.last = self.getMessageCount()
-        for mes_idx in messages:
-            if mes_idx>self.getMessageCount():
-                continue
-            yield (mes_idx,Message(mes_idx,self.mailbox.getMessage(mes_idx-1)))
+        if uid:
+            messages.last = self.mailbox.getMaxUid()
+            messages.getnext = self.mailbox.getNextExistingUid
+            for mess_uid in messages:
+                if mess_uid == None:
+                    debug ('stopping iteration')
+                    raise StopIteration
+                try:
+                    debug ('yielding (%s,%s)' % (mess_uid,Message(mess_uid,self.mailbox.getMessageUid(mess_uid))))
+                    yield (mess_uid,Message(mess_uid,self.mailbox.getMessageUid(mess_uid)))
+                except IndexError:
+                    continue
+        else:
+            messages.last = self.getMessageCount()
+            for mess_idx in messages:
+                if mess_idx>self.getMessageCount():
+                    raise StopIteration
+                yield (mess_idx,Message(mess_idx,self.mailbox.getMessage(mess_idx-1)))
 
     def store(self, messages, flags, mode, uid):
         """Set the flags of one or more messages.