]> code.delx.au - offlineimap/blobdiff - offlineimap/folder/IMAP.py
fixes behaviour when changing flags, without corresp. rights (s,d,w)
[offlineimap] / offlineimap / folder / IMAP.py
index 12a9660894405b40c668babc56cfa66964915892..0ab8892029ca501f91908fe54c642af3fa57cf97 100644 (file)
@@ -365,9 +365,24 @@ class IMAPFolder(BaseFolder):
         
         imapobj = self.imapserver.acquireconnection()
         try:
+            # 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)
+            myrights = imapobj.myrights(self.getfullname())[1][0].split()[1]
+           if 'T' in flags and not 'd' in myrights or \
+                   'S' in flags and not 's' in myrights or \
+                   filter(lambda x: x not in 'TS', flags) and not 'w' in myrights:
+               # no delete/expunge right, but needed or
+               # no store seen right, but needed or
+               # no write right, but needed
+                UIBase.getglobalui().flagstoreadonly(self, uidlist, flags)
+                return
+
             try:
                 imapobj.select(self.getfullname())
             except imapobj.readonly:
+               # unsure, whether this can be reached
                 UIBase.getglobalui().flagstoreadonly(self, uidlist, flags)
                 return
             r = imapobj.uid('store',
@@ -424,12 +439,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)