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