Reformat offlineimap/folder/Maildir.py

Add some spaces, remove lines,... now format is better (lintian).
This commit is contained in:
Rodolfo García Peñas (kix) 2020-08-29 19:46:43 +02:00
parent 265de25460
commit eafd9eb51d

View File

@ -22,6 +22,7 @@ import os
import six
from sys import exc_info
from threading import Lock
try:
from hashlib import md5
except ImportError:
@ -30,7 +31,6 @@ except ImportError:
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)
@ -62,13 +62,13 @@ class MaildirFolder(BaseFolder):
self.root = root
# check if we should use a different infosep to support Win file systems
self.wincompatible = self.config.getdefaultboolean(
"Account "+self.accountname, "maildir-windows-compatible", False)
"Account " + self.accountname, "maildir-windows-compatible", False)
self.infosep = '!' if self.wincompatible else ':'
"""infosep is the separator between maildir name and flag appendix"""
self.re_flagmatch = re.compile('%s2,(\w*)'% self.infosep)
#self.ui is set in BaseFolder.init()
self.re_flagmatch = re.compile('%s2,(\w*)' % self.infosep)
# self.ui is set in BaseFolder.init()
# Everything up to the first comma or colon (or ! if Windows):
self.re_prefixmatch = re.compile('([^'+ self.infosep + ',]*)')
self.re_prefixmatch = re.compile('([^' + self.infosep + ',]*)')
# folder's md, so we can match with recorded file md5 for validity.
self._foldermd5 = md5(self.getvisiblename().encode('utf-8')).hexdigest()
# Cache the full folder path, as we use getfullname() very often.
@ -106,7 +106,7 @@ class MaildirFolder(BaseFolder):
return True
timestampstr = timestampmatch.group()
timestamplong = int(timestampstr)
if(timestamplong < time.mktime(date)):
if (timestamplong < time.mktime(date)):
return False
else:
return True
@ -132,7 +132,7 @@ class MaildirFolder(BaseFolder):
prefixmatch = self.re_prefixmatch.match(filename)
if prefixmatch:
prefix = prefixmatch.group(1)
folderstr = ',FMD5=%s'% self._foldermd5
folderstr = ',FMD5=%s' % self._foldermd5
foldermatch = folderstr in filename
# If there was no folder MD5 specified, or if it mismatches,
# assume it is a foreign (new) message and ret: uid, fmd5 = None, None
@ -246,7 +246,6 @@ class MaildirFolder(BaseFolder):
return True
return False # Nope, nothing changed.
# Interface from BaseFolder
def msglist_item_initializer(self, uid):
return {'flags': set(), 'filename': '/no-dir/no-such-file/'}
@ -268,7 +267,7 @@ class MaildirFolder(BaseFolder):
file = open(filepath, 'rt')
retval = file.read()
file.close()
#TODO: WHY are we replacing \r\n with \n here? And why do we
# TODO: WHY are we replacing \r\n with \n here? And why do we
# read it as text?
return retval.replace("\r\n", "\n")
@ -291,7 +290,6 @@ class MaildirFolder(BaseFolder):
uid, self._foldermd5, self.infosep, ''.join(sorted(flags)))
return uniq_name.replace(os.path.sep, self.sep_subst)
def save_to_tmp_file(self, filename, content):
"""Saves given content to the named temporary file in the
'tmp' subdirectory of $CWD.
@ -311,7 +309,7 @@ class MaildirFolder(BaseFolder):
tries = tries - 1
try:
fd = os.open(os.path.join(self.getfullname(), tmpname),
os.O_EXCL|os.O_CREAT|os.O_WRONLY, 0o666)
os.O_EXCL | os.O_CREAT | os.O_WRONLY, 0o666)
break
except OSError as e:
if not hasattr(e, 'EEXIST'):
@ -323,7 +321,7 @@ class MaildirFolder(BaseFolder):
severity = OfflineImapError.ERROR.MESSAGE
six.reraise(OfflineImapError,
OfflineImapError(
"Unique filename %s already exists."%
"Unique filename %s already exists." %
filename, severity),
exc_info()[2])
else:
@ -339,7 +337,6 @@ class MaildirFolder(BaseFolder):
return tmpname
# Interface from BaseFolder
def savemessage(self, uid, content, flags, rtime):
"""Writes a new message, with the specified uid.
@ -381,7 +378,7 @@ class MaildirFolder(BaseFolder):
datestr = Parser().parsestr(content, True).get("Date")
ui = getglobalui()
ui.warn("UID %d has invalid date %s: %s\n"
"Not using message timestamp as file prefix"%
"Not using message timestamp as file prefix" %
(uid, datestr, e))
# No need to check if message_timestamp is None here since it
# would be overridden by _gettimeseq.
@ -402,7 +399,7 @@ class MaildirFolder(BaseFolder):
datestr = Parser().parsestr(content, True).get("Date")
ui = getglobalui()
ui.warn("UID %d has invalid date %s: %s\n"
"Not changing file modification time"% (uid, datestr, e))
"Not changing file modification time" % (uid, datestr, e))
self.messagelist[uid] = self.msglist_item_initializer(uid)
self.messagelist[uid]['flags'] = flags
@ -439,8 +436,8 @@ class MaildirFolder(BaseFolder):
# off existing infostring
infomatch = self.re_flagmatch.search(filename)
if infomatch:
filename = filename[:-len(infomatch.group())] #strip off
infostr = '%s2,%s'% (self.infosep, ''.join(sorted(flags)))
filename = filename[:-len(infomatch.group())] # strip off
infostr = '%s2,%s' % (self.infosep, ''.join(sorted(flags)))
filename += infostr
newfilename = os.path.join(dir_prefix, filename)
@ -451,7 +448,7 @@ class MaildirFolder(BaseFolder):
except OSError as e:
six.reraise(OfflineImapError,
OfflineImapError(
"Can't rename file '%s' to '%s': %s"%
"Can't rename file '%s' to '%s': %s" %
(oldfilename, newfilename, e[1]),
OfflineImapError.ERROR.FOLDER),
exc_info()[2])
@ -470,7 +467,7 @@ class MaildirFolder(BaseFolder):
"""
if not uid in self.messagelist:
raise OfflineImapError("Cannot change unknown Maildir UID %s"% uid,
raise OfflineImapError("Cannot change unknown Maildir UID %s" % uid,
OfflineImapError.ERROR.MESSAGE)
if uid == new_uid: return
@ -508,7 +505,7 @@ class MaildirFolder(BaseFolder):
filepath = os.path.join(self.getfullname(), filename)
os.unlink(filepath)
# Yep -- return.
del(self.messagelist[uid])
del (self.messagelist[uid])
def migratefmd5(self, dryrun=False):
"""Migrate FMD5 hashes from versions prior to 6.3.5
@ -537,7 +534,7 @@ class MaildirFolder(BaseFolder):
except OSError as e:
six.reraise(OfflineImapError,
OfflineImapError(
"Can't rename file '%s' to '%s': %s"%
"Can't rename file '%s' to '%s': %s" %
(filename, newfilename, e[1]),
OfflineImapError.ERROR.FOLDER),
exc_info()[2])