Fix getuidvalidity crash (UIDVALIDITY returning None)

Rename getuidvalidity -> get_uidvalidity and cache the IMAP result.

1) Start modernizing our function names using more underscores
2) IMAPs implementation of get_uidvalidity was removing the UIDVALIDITY result
   from the imaplib2 result stack, so subsequent calls would return "None".
   As various functions can invoke this, this led to some errors that we
   avoid by caching the current UIDVALIDITY value in the Folder instance.

There are more simplifications and improvements to be made.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
This commit is contained in:
Sebastian Spaeth
2012-01-19 11:24:16 +01:00
parent 7c4fea906f
commit 9453e1d955
7 changed files with 34 additions and 20 deletions

View File

@ -110,13 +110,14 @@ class BaseFolder(object):
return basename
def isuidvalidityok(self):
"""Does the cached UID match the real UID
"""Tests if the cached UIDVALIDITY match the real current one
If required it caches the UID. In this case the function is not
threadsafe. So don't attempt to call it from concurrent threads."""
If required it saves the UIDVALIDITY value. In this case the
function is not threadsafe. So don't attempt to call it from
concurrent threads."""
if self.getsaveduidvalidity() != None:
return self.getsaveduidvalidity() == self.getuidvalidity()
return self.getsaveduidvalidity() == self.get_uidvalidity()
else:
self.saveuidvalidity()
return 1
@ -142,7 +143,7 @@ class BaseFolder(object):
This function is not threadsafe, so don't attempt to call it
from concurrent threads."""
newval = self.getuidvalidity()
newval = self.get_uidvalidity()
uidfilename = self._getuidfilename()
file = open(uidfilename + ".tmp", "wt")
@ -151,7 +152,11 @@ class BaseFolder(object):
os.rename(uidfilename + ".tmp", uidfilename)
self._base_saved_uidvalidity = newval
def getuidvalidity(self):
def get_uidvalidity(self):
"""Retrieve the current connections UIDVALIDITY value
This function needs to be implemented by each Backend
:returns: UIDVALIDITY as a (long) number"""
raise NotImplementedException
def cachemessagelist(self):