]> code.delx.au - offlineimap/commitdiff
fix behaviour for delete/expunge, when lacking rights
authorFlorian Friesdorf <flow@mytum.de>
Thu, 12 Jul 2007 03:44:11 +0000 (04:44 +0100)
committerFlorian Friesdorf <flow@mytum.de>
Thu, 12 Jul 2007 03:44:11 +0000 (04:44 +0100)
This patch maneuvers around python imaplib's mysterious read-only detection
algorithm and correctly calls the UI's deletetoreadonly(), when trying to
delete/expunge in a mailbox without having the necessary rights.

offlineimap/folder/IMAP.py

index 12a9660894405b40c668babc56cfa66964915892..df1b3297cb2afb9b125a3af827ceabc483ee6936 100644 (file)
@@ -424,12 +424,17 @@ class IMAPFolder(BaseFolder):
         self.addmessagesflags_noconvert(uidlist, ['T'])
         imapobj = self.imapserver.acquireconnection()
         try:
-            try:
-                imapobj.select(self.getfullname())
-            except imapobj.readonly:
+            # Making sure, that we have the necessary rights
+            # ensuring that we access readonly: python's braindead imaplib.py
+            # otherwise might raise an exception during the myrights() call
+            imapobj.select(self.getfullname(),readonly=1)
+            if not 'd' in imapobj.myrights(self.getfullname())[1][0].split()[1]:
+                # no delete/expunge rights
                 UIBase.getglobalui().deletereadonly(self, uidlist)
                 return
+
             if self.expunge:
+                imapobj.select(self.getfullname())
                 assert(imapobj.expunge()[0] == 'OK')
         finally:
             self.imapserver.releaseconnection(imapobj)