minor code refactoring
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
parent
9606cfcfc1
commit
e452c344d9
@ -540,6 +540,7 @@ localfolders = ~/Test
|
||||
#
|
||||
#filename_use_mail_timestamp = no
|
||||
|
||||
|
||||
# This option stands in the [Repository LocalExample] section.
|
||||
#
|
||||
# Map IMAP [user-defined] keywords to lowercase letters, similar to Dovecot's
|
||||
|
@ -453,15 +453,10 @@ def syncfolder(account, remotefolder, quick):
|
||||
localfolder.save_uidvalidity()
|
||||
remotefolder.save_uidvalidity()
|
||||
|
||||
def save_min_uid(folder, min_uid):
|
||||
uidfile = folder.get_min_uid_file()
|
||||
fd = open(uidfile, 'wt')
|
||||
fd.write(str(min_uid) + "\n")
|
||||
fd.close()
|
||||
|
||||
def cachemessagelists_upto_date(localfolder, remotefolder, date):
|
||||
def cachemessagelists_upto_date(date):
|
||||
"""Returns messages with uid > min(uids of messages newer than date)."""
|
||||
|
||||
# Warning: this makes sense only if the cached list is empty.
|
||||
localfolder.cachemessagelist(min_date=date)
|
||||
check_uid_validity(localfolder, remotefolder, statusfolder)
|
||||
# Local messagelist had date restriction applied already. Restrict
|
||||
@ -515,7 +510,7 @@ def syncfolder(account, remotefolder, quick):
|
||||
min_uid = min(positive_uids)
|
||||
else:
|
||||
min_uid = 1
|
||||
save_min_uid(partial, min_uid)
|
||||
partial.save_min_uid(min_uid)
|
||||
else:
|
||||
partial.cachemessagelist(min_uid=min_uid)
|
||||
|
||||
@ -562,7 +557,7 @@ def syncfolder(account, remotefolder, quick):
|
||||
ui.warn("Quick syncs (-q) not supported in conjunction "
|
||||
"with maxage or startdate; ignoring -q.")
|
||||
if maxage != None:
|
||||
cachemessagelists_upto_date(localfolder, remotefolder, maxage)
|
||||
cachemessagelists_upto_date(maxage)
|
||||
elif localstart != None:
|
||||
cachemessagelists_startdate(remotefolder, localfolder,
|
||||
localstart)
|
||||
|
@ -400,6 +400,12 @@ class BaseFolder(object):
|
||||
os.mkdir(startuiddir, 0o700)
|
||||
return os.path.join(startuiddir, self.getfolderbasename())
|
||||
|
||||
def save_min_uid(self, min_uid):
|
||||
uidfile = self.get_min_uid_file()
|
||||
fd = open(uidfile, 'wt')
|
||||
fd.write(str(min_uid) + "\n")
|
||||
fd.close()
|
||||
|
||||
def retrieve_min_uid(self):
|
||||
uidfile = self.get_min_uid_file()
|
||||
if not os.path.exists(uidfile):
|
||||
|
@ -91,7 +91,6 @@ class LocalStatusSQLiteFolder(BaseFolder):
|
||||
if self.filename not in LocalStatusSQLiteFolder.locks:
|
||||
LocalStatusSQLiteFolder.locks[self.filename] = DatabaseFileLock()
|
||||
self._databaseFileLock = LocalStatusSQLiteFolder.locks[self.filename]
|
||||
|
||||
self._in_transactions = 0
|
||||
|
||||
def __enter__(self):
|
||||
|
@ -34,14 +34,16 @@ except NameError:
|
||||
from offlineimap import OfflineImapError, emailutil
|
||||
from .Base import BaseFolder
|
||||
|
||||
|
||||
# Find the UID in a message filename
|
||||
re_uidmatch = re.compile(',U=(\d+)')
|
||||
# Find a numeric timestamp in a string (filename prefix)
|
||||
re_timestampmatch = re.compile('(\d+)');
|
||||
re_timestampmatch = re.compile('(\d+)')
|
||||
|
||||
timehash = {}
|
||||
timelock = Lock()
|
||||
|
||||
|
||||
def _gettimeseq(date=None):
|
||||
global timehash, timelock
|
||||
timelock.acquire()
|
||||
@ -56,6 +58,7 @@ def _gettimeseq(date=None):
|
||||
finally:
|
||||
timelock.release()
|
||||
|
||||
|
||||
class MaildirFolder(BaseFolder):
|
||||
def __init__(self, root, name, sep, repository):
|
||||
self.sep = sep # needs to be set before super().__init__
|
||||
@ -343,6 +346,7 @@ class MaildirFolder(BaseFolder):
|
||||
See folder/Base for detail. Note that savemessage() does not
|
||||
check against dryrun settings, so you need to ensure that
|
||||
savemessage is never called in a dryrun mode."""
|
||||
|
||||
# This function only ever saves to tmp/,
|
||||
# but it calls savemessageflags() to actually save to cur/ or new/.
|
||||
self.ui.savemessage('maildir', uid, flags, self)
|
||||
@ -471,6 +475,8 @@ class MaildirFolder(BaseFolder):
|
||||
oldfilename = self.messagelist[uid]['filename']
|
||||
dir_prefix, filename = os.path.split(oldfilename)
|
||||
flags = self.getmessageflags(uid)
|
||||
# TODO: we aren't keeping the prefix timestamp so we don't honor the
|
||||
# filename_use_mail_timestamp configuration option.
|
||||
newfilename = os.path.join(dir_prefix,
|
||||
self.new_message_filename(new_uid, flags))
|
||||
os.rename(os.path.join(self.getfullname(), oldfilename),
|
||||
|
Loading…
Reference in New Issue
Block a user