Reformat offlineimap/folder/Base.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:39:31 +02:00
parent fefc3a5717
commit 9ebdbe47ee

View File

@ -78,10 +78,10 @@ class BaseFolder(object):
self.repoconfname, "dynamic_folderfilter", False)
self._sync_this = repository.should_sync_folder(self.ffilter_name)
if self._dynamic_folderfilter:
self.ui.debug('', "Running dynamic folder filtering on '%s'[%s]"%
self.ui.debug('', "Running dynamic folder filtering on '%s'[%s]" %
(self.ffilter_name, repository))
elif not self._sync_this:
self.ui.debug('', "Filtering out '%s'[%s] due to folderfilter"%
self.ui.debug('', "Filtering out '%s'[%s] due to folderfilter" %
(self.ffilter_name, repository))
# Passes for syncmessagesto.
@ -178,7 +178,7 @@ class BaseFolder(object):
if self.name == self.visiblename:
return self.name
else:
return "%s [remote name %s]"% (self.visiblename, self.name)
return "%s [remote name %s]" % (self.visiblename, self.name)
def getrepository(self):
"""Returns the repository object that this folder is within."""
@ -262,7 +262,7 @@ class BaseFolder(object):
uidfilename = self._getuidfilename()
with open(uidfilename + ".tmp", "wt") as uidfile:
uidfile.write("%d\n"% newval)
uidfile.write("%d\n" % newval)
os.rename(uidfilename + ".tmp", uidfilename)
self._base_saved_uidvalidity = newval
@ -339,7 +339,7 @@ class BaseFolder(object):
maxage is allowed to be either an integer or a date of the form
YYYY-mm-dd. This returns a time_struct."""
maxagestr = self.config.getdefault("Account %s"%
maxagestr = self.config.getdefault("Account %s" %
self.accountname, "maxage", None)
if maxagestr is None:
return None
@ -347,9 +347,9 @@ class BaseFolder(object):
try:
maxage = int(maxagestr)
if maxage < 1:
raise OfflineImapError("invalid maxage value %d"% maxage,
raise OfflineImapError("invalid maxage value %d" % maxage,
OfflineImapError.ERROR.MESSAGE)
return time.gmtime(time.time() - 60*60*24*maxage)
return time.gmtime(time.time() - 60 * 60 * 24 * maxage)
except ValueError:
pass # Maybe it was a date.
# Is it a date string?
@ -357,19 +357,19 @@ class BaseFolder(object):
date = time.strptime(maxagestr, "%Y-%m-%d")
if date[0] < 1900:
raise OfflineImapError("maxage led to year %d. "
"Abort syncing."% date[0],
"Abort syncing." % date[0],
OfflineImapError.ERROR.MESSAGE)
if (time.mktime(date) - time.mktime(time.localtime())) > 0:
raise OfflineImapError("maxage led to future date %s. "
"Abort syncing."% maxagestr,
"Abort syncing." % maxagestr,
OfflineImapError.ERROR.MESSAGE)
return date
except ValueError:
raise OfflineImapError("invalid maxage value %s"% maxagestr,
raise OfflineImapError("invalid maxage value %s" % maxagestr,
OfflineImapError.ERROR.MESSAGE)
def getmaxsize(self):
return self.config.getdefaultint("Account %s"%
return self.config.getdefaultint("Account %s" %
self.accountname, "maxsize", None)
def getstartdate(self):
@ -382,11 +382,11 @@ class BaseFolder(object):
date = time.strptime(datestr, "%Y-%m-%d")
if date[0] < 1900:
raise OfflineImapError("startdate led to year %d. "
"Abort syncing."% date[0],
"Abort syncing." % date[0],
OfflineImapError.ERROR.MESSAGE)
if (time.mktime(date) - time.mktime(time.localtime())) > 0:
raise OfflineImapError("startdate led to future date %s. "
"Abort syncing."% datestr,
"Abort syncing." % datestr,
OfflineImapError.ERROR.MESSAGE)
return date
except ValueError:
@ -416,8 +416,7 @@ class BaseFolder(object):
fd.close()
return min_uid
except:
raise IOError("Can't read %s"% uidfile)
raise IOError("Can't read %s" % uidfile)
def savemessage(self, uid, content, flags, rtime):
"""Writes a new message, with the specified uid.
@ -634,7 +633,7 @@ class BaseFolder(object):
next line\n
"""
self.ui.debug('', 'addmessageheader: called to add %s: %s'%
self.ui.debug('', 'addmessageheader: called to add %s: %s' %
(headername, headervalue))
insertionpoint = content.find(linebreak * 2)
@ -642,12 +641,12 @@ class BaseFolder(object):
self.ui.debug('', 'addmessageheader: headers were missing')
else:
self.ui.debug('',
'addmessageheader: headers end at position %d'% insertionpoint)
'addmessageheader: headers end at position %d' % insertionpoint)
mark = '==>EOH<=='
contextstart = max(0, insertionpoint - 100)
contextend = min(len(content), insertionpoint + 100)
self.ui.debug('', 'addmessageheader: header/body transition " \
"context (marked by %s): %s%s%s'% (
"context (marked by %s): %s%s%s' % (
mark, repr(content[contextstart:insertionpoint]),
mark, repr(content[insertionpoint:contextend])
)
@ -674,14 +673,13 @@ class BaseFolder(object):
suffix = suffix + linebreak
self.ui.debug('',
'addmessageheader: insertionpoint = %d'% insertionpoint)
'addmessageheader: insertionpoint = %d' % insertionpoint)
headers = content[0:insertionpoint]
self.ui.debug('', 'addmessageheader: headers = %s'% repr(headers))
new_header = prefix + ("%s: %s"% (headername, headervalue)) + suffix
self.ui.debug('', 'addmessageheader: new_header = %s'% repr(new_header))
self.ui.debug('', 'addmessageheader: headers = %s' % repr(headers))
new_header = prefix + ("%s: %s" % (headername, headervalue)) + suffix
self.ui.debug('', 'addmessageheader: new_header = %s' % repr(new_header))
return headers + new_header + content[insertionpoint:]
def __find_eoh(self, content):
"""Searches for the point where mail headers end.
@ -698,7 +696,6 @@ class BaseFolder(object):
return eoh_cr
def getmessageheader(self, content, name):
"""Return the value of the first occurence of the given header.
@ -711,20 +708,19 @@ class BaseFolder(object):
Returns: header value or None if no such header was found.
"""
self.ui.debug('', 'getmessageheader: called to get %s'% name)
self.ui.debug('', 'getmessageheader: called to get %s' % name)
eoh = self.__find_eoh(content)
self.ui.debug('', 'getmessageheader: eoh = %d'% eoh)
self.ui.debug('', 'getmessageheader: eoh = %d' % eoh)
headers = content[0:eoh]
self.ui.debug('', 'getmessageheader: headers = %s'% repr(headers))
self.ui.debug('', 'getmessageheader: headers = %s' % repr(headers))
m = re.search('^%s:(.*)$'% name, headers,
flags= re.MULTILINE | re.IGNORECASE)
m = re.search('^%s:(.*)$' % name, headers,
flags=re.MULTILINE | re.IGNORECASE)
if m:
return m.group(1).strip()
else:
return None
def getmessageheaderlist(self, content, name):
"""Return a list of values for the given header.
@ -735,15 +731,14 @@ class BaseFolder(object):
Returns: list of header values or empty list if no such header was found.
"""
self.ui.debug('', 'getmessageheaderlist: called to get %s'% name)
self.ui.debug('', 'getmessageheaderlist: called to get %s' % name)
eoh = self.__find_eoh(content)
self.ui.debug('', 'getmessageheaderlist: eoh = %d'% eoh)
self.ui.debug('', 'getmessageheaderlist: eoh = %d' % eoh)
headers = content[0:eoh]
self.ui.debug('', 'getmessageheaderlist: headers = %s'% repr(headers))
return re.findall('^%s:(.*)$'%
name, headers, flags= re.MULTILINE | re.IGNORECASE)
self.ui.debug('', 'getmessageheaderlist: headers = %s' % repr(headers))
return re.findall('^%s:(.*)$' %
name, headers, flags=re.MULTILINE | re.IGNORECASE)
def deletemessageheaders(self, content, header_list):
"""Deletes headers in the given list from the message content.
@ -756,21 +751,21 @@ class BaseFolder(object):
if type(header_list) != type([]):
header_list = [header_list]
self.ui.debug('', 'deletemessageheaders: called to delete %s'% (header_list))
self.ui.debug('', 'deletemessageheaders: called to delete %s' % (header_list))
if not len(header_list):
return content
eoh = self.__find_eoh(content)
self.ui.debug('', 'deletemessageheaders: end of headers = %d'% eoh)
self.ui.debug('', 'deletemessageheaders: end of headers = %d' % eoh)
headers = content[0:eoh]
rest = content[eoh:]
self.ui.debug('', 'deletemessageheaders: headers = %s'% repr(headers))
self.ui.debug('', 'deletemessageheaders: headers = %s' % repr(headers))
new_headers = []
for h in headers.split('\n'):
keep_it = True
for trim_h in header_list:
if len(h) > len(trim_h) and h[0:len(trim_h)+1] == (trim_h + ":"):
if len(h) > len(trim_h) and h[0:len(trim_h) + 1] == (trim_h + ":"):
keep_it = False
break
if keep_it:
@ -778,9 +773,6 @@ class BaseFolder(object):
return '\n'.join(new_headers) + rest
def change_message_uid(self, uid, new_uid):
"""Change the message from existing uid to new_uid.
@ -863,7 +855,7 @@ class BaseFolder(object):
self.deletemessage(uid)
else:
raise OfflineImapError("Trying to save msg (uid %d) on folder "
"%s returned invalid uid %d"% (uid, dstfolder.getvisiblename(),
"%s returned invalid uid %d" % (uid, dstfolder.getvisiblename(),
new_uid), OfflineImapError.ERROR.MESSAGE)
except (KeyboardInterrupt): # Bubble up CTRL-C.
raise
@ -873,7 +865,7 @@ class BaseFolder(object):
self.ui.error(e, exc_info()[2])
except Exception as e:
self.ui.error(e, exc_info()[2],
msg = "Copying message %s [acc: %s]"% (uid, self.accountname))
msg="Copying message %s [acc: %s]" % (uid, self.accountname))
raise # Raise on unknown errors, so we can fix those.
def __syncmessagesto_copy(self, dstfolder, statusfolder):
@ -928,14 +920,14 @@ class BaseFolder(object):
statusfolder.savemessage(uid, None, flags, rtime)
continue
self.ui.copyingmessage(uid, num+1, num_to_copy, self, dstfolder)
self.ui.copyingmessage(uid, num + 1, num_to_copy, self, dstfolder)
# Exceptions are caught in copymessageto().
if self.suggeststhreads():
self.waitforthread()
thread = threadutil.InstanceLimitedThread(
self.getinstancelimitnamespace(),
target=self.copymessageto,
name="Copy message from %s:%s"% (self.repository, self),
name="Copy message from %s:%s" % (self.repository, self),
args=(uid, dstfolder, statusfolder)
)
thread.start()
@ -1119,10 +1111,10 @@ class BaseFolder(object):
except OfflineImapError as e:
if e.severity > OfflineImapError.ERROR.FOLDER:
raise
self.ui.error(e, exc_info()[2], "while syncing %s [account %s]"%
self.ui.error(e, exc_info()[2], "while syncing %s [account %s]" %
(self, self.accountname))
except Exception as e:
self.ui.error(e, exc_info()[2], "while syncing %s [account %s]"%
self.ui.error(e, exc_info()[2], "while syncing %s [account %s]" %
(self, self.accountname))
raise # Raise unknown Exceptions so we can fix them.