Clean up the maxsize maxage code
Do away with the wrapping of this code in a try...except KeyError, as this code cannot conceivably throw a KeyError. Even if it could, it should be documented why we should simply return() in this case. Shorten some of the variable names and minor code cleanup while taking the git blame anyway. Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de> Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
parent
06bfff7c04
commit
8532a69458
@ -107,51 +107,48 @@ class IMAPFolder(BaseFolder):
|
|||||||
|
|
||||||
# TODO: Make this so that it can define a date that would be the oldest messages etc.
|
# TODO: Make this so that it can define a date that would be the oldest messages etc.
|
||||||
def cachemessagelist(self):
|
def cachemessagelist(self):
|
||||||
imapobj = self.imapserver.acquireconnection()
|
maxage = self.config.getdefaultint("Account %s" % self.accountname,
|
||||||
|
"maxage", -1)
|
||||||
|
maxsize = self.config.getdefaultint("Account %s" % self.accountname,
|
||||||
|
"maxsize", -1)
|
||||||
self.messagelist = {}
|
self.messagelist = {}
|
||||||
|
|
||||||
|
imapobj = self.imapserver.acquireconnection()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Primes untagged_responses
|
# Primes untagged_responses
|
||||||
imaptype, imapdata = imapobj.select(self.getfullname(), readonly = 1, force = 1)
|
imaptype, imapdata = imapobj.select(self.getfullname(), readonly = 1, force = 1)
|
||||||
|
|
||||||
maxage = self.config.getdefaultint("Account " + self.accountname, "maxage", -1)
|
|
||||||
maxsize = self.config.getdefaultint("Account " + self.accountname, "maxsize", -1)
|
|
||||||
|
|
||||||
if (maxage != -1) | (maxsize != -1):
|
if (maxage != -1) | (maxsize != -1):
|
||||||
try:
|
search_cond = "(";
|
||||||
search_condition = "(";
|
|
||||||
|
|
||||||
if(maxage != -1):
|
if(maxage != -1):
|
||||||
#find out what the oldest message is that we should look at
|
#find out what the oldest message is that we should look at
|
||||||
oldest_time_struct = time.gmtime(time.time() - (60*60*24*maxage))
|
oldest_struct = time.gmtime(time.time() - (60*60*24*maxage))
|
||||||
|
|
||||||
#format this manually - otherwise locales could cause problems
|
#format months manually - otherwise locales cause problems
|
||||||
monthnames_standard = ["Jan", "Feb", "Mar", "Apr", "May", \
|
monthnames = ["Jan", "Feb", "Mar", "Apr", "May", \
|
||||||
"Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
|
"Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
|
||||||
|
|
||||||
our_monthname = monthnames_standard[oldest_time_struct[1]-1]
|
month = monthnames[oldest_struct[1]-1]
|
||||||
daystr = "%(day)02d" % {'day' : oldest_time_struct[2]}
|
daystr = "%(day)02d" % {'day' : oldest_struct[2]}
|
||||||
date_search_str = "SINCE " + daystr + "-" + our_monthname \
|
|
||||||
+ "-" + str(oldest_time_struct[0])
|
|
||||||
|
|
||||||
search_condition += date_search_str
|
search_cond += "SINCE %s-%s-%s" % (daystr, month,
|
||||||
|
oldest_struct[0])
|
||||||
|
|
||||||
if(maxsize != -1):
|
if(maxsize != -1):
|
||||||
if(maxage != -1): #There are two conditions - add a space
|
if(maxage != -1): # There are two conditions, add space
|
||||||
search_condition += " "
|
search_cond += " "
|
||||||
|
search_cond += "SMALLER %d" % maxsize
|
||||||
|
|
||||||
search_condition += "SMALLER " + self.config.getdefault("Account " + self.accountname, "maxsize", -1)
|
search_cond += ")"
|
||||||
|
|
||||||
search_condition += ")"
|
res_type, res_data = imapobj.search(None, search_cond)
|
||||||
|
# Result UIDs seperated by space, coalesce into ranges
|
||||||
res_type, res_data = imapobj.search(None, search_condition)
|
|
||||||
#result UIDs come back seperated by space
|
|
||||||
messagesToFetch = imaputil.uid_sequence(res_data.split())
|
messagesToFetch = imaputil.uid_sequence(res_data.split())
|
||||||
except KeyError:
|
|
||||||
return
|
|
||||||
if not messagesToFetch:
|
if not messagesToFetch:
|
||||||
# No messages; return
|
return # No messages to sync
|
||||||
return
|
|
||||||
else:
|
else:
|
||||||
# 1. Some mail servers do not return an EXISTS response
|
# 1. Some mail servers do not return an EXISTS response
|
||||||
# if the folder is empty. 2. ZIMBRA servers can return
|
# if the folder is empty. 2. ZIMBRA servers can return
|
||||||
|
Loading…
Reference in New Issue
Block a user