[PATCH] Prettify and use new uidexists() helper function

Sebastian Spaeth Sebastian at SSpaeth.de
Sat May 7 10:11:20 BST 2011


Make the folder classes use uidexists() more. Add some code
documentation while going through.

Signed-off-by: Sebastian Spaeth <Sebastian at SSpaeth.de>
---
Just a smallish cleanup patch while I was going through some code. Patch
non-critical and against 'next'.

 offlineimap/folder/IMAP.py    |    2 +-
 offlineimap/folder/Maildir.py |   10 +++++++++-
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/offlineimap/folder/IMAP.py b/offlineimap/folder/IMAP.py
index 6ff73ec..9f60ded 100644
--- a/offlineimap/folder/IMAP.py
+++ b/offlineimap/folder/IMAP.py
@@ -562,7 +562,7 @@ class IMAPFolder(BaseFolder):
 
     def deletemessages_noconvert(self, uidlist):
         # Weed out ones not in self.messagelist
-        uidlist = [uid for uid in uidlist if uid in self.messagelist]
+        uidlist = [uid for uid in uidlist if self.uidexists(uid)]
         if not len(uidlist):
             return
 
diff --git a/offlineimap/folder/Maildir.py b/offlineimap/folder/Maildir.py
index 02e64d2..e360619 100644
--- a/offlineimap/folder/Maildir.py
+++ b/offlineimap/folder/Maildir.py
@@ -295,8 +295,16 @@ class MaildirFolder(BaseFolder):
         assert final_dir != tmpdir
 
     def deletemessage(self, uid):
-        if not uid in self.messagelist:
+        """Unlinks a message file from the Maildir.
+
+        :param uid: UID of a mail message
+        :type uid: String
+        :return: Nothing, or an Exception if UID but no corresponding file
+                 found.
+        """
+        if not self.uidexists(uid):
             return
+
         filename = self.messagelist[uid]['filename']
         try:
             os.unlink(filename)
-- 
1.7.4.1





More information about the OfflineIMAP-project mailing list