Reformat offlineimap/folder/Gmail.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:41:19 +02:00
parent 9ebdbe47ee
commit af18230a2a

View File

@ -60,7 +60,6 @@ class GmailFolder(IMAPFolder):
ignorelabels = self.repository.account.getconf('ignorelabels', '') ignorelabels = self.repository.account.getconf('ignorelabels', '')
self.ignorelabels = set([l for l in re.split(r'\s*,\s*', ignorelabels) if len(l)]) self.ignorelabels = set([l for l in re.split(r'\s*,\s*', ignorelabels) if len(l)])
def getmessage(self, uid): def getmessage(self, uid):
"""Retrieve message with UID from the IMAP server (incl body). Also """Retrieve message with UID from the IMAP server (incl body). Also
gets Gmail labels and embeds them into the message. gets Gmail labels and embeds them into the message.
@ -72,7 +71,7 @@ class GmailFolder(IMAPFolder):
data = self._fetch_from_imap(str(uid), self.retrycount) data = self._fetch_from_imap(str(uid), self.retrycount)
# data looks now e.g. # data looks now e.g.
#[('320 (X-GM-LABELS (...) UID 17061 BODY[] {2565}','msgbody....')] # [('320 (X-GM-LABELS (...) UID 17061 BODY[] {2565}','msgbody....')]
# we only asked for one message, and that msg is in data[0]. # we only asked for one message, and that msg is in data[0].
# msbody is in [0][1]. # msbody is in [0][1].
body = data[0][1].replace("\r\n", "\n") body = data[0][1].replace("\r\n", "\n")
@ -92,12 +91,12 @@ class GmailFolder(IMAPFolder):
body = self.deletemessageheaders(body, self.labelsheader) body = self.deletemessageheaders(body, self.labelsheader)
body = self.addmessageheader(body, '\n', self.labelsheader, labels_str) body = self.addmessageheader(body, '\n', self.labelsheader, labels_str)
if len(body)>200: if len(body) > 200:
dbg_output = "%s...%s"% (str(body)[:150], str(body)[-50:]) dbg_output = "%s...%s" % (str(body)[:150], str(body)[-50:])
else: else:
dbg_output = body dbg_output = body
self.ui.debug('imap', "Returned object from fetching %d: '%s'"% self.ui.debug('imap', "Returned object from fetching %d: '%s'" %
(uid, dbg_output)) (uid, dbg_output))
return body return body
@ -111,7 +110,6 @@ class GmailFolder(IMAPFolder):
def msglist_item_initializer(self, uid): def msglist_item_initializer(self, uid):
return {'uid': uid, 'flags': set(), 'labels': set(), 'time': 0} return {'uid': uid, 'flags': set(), 'labels': set(), 'time': 0}
# TODO: merge this code with the parent's cachemessagelist: # TODO: merge this code with the parent's cachemessagelist:
# TODO: they have too much common logics. # TODO: they have too much common logics.
def cachemessagelist(self, min_date=None, min_uid=None): def cachemessagelist(self, min_date=None, min_uid=None):
@ -133,14 +131,14 @@ class GmailFolder(IMAPFolder):
# imaplib2 from quoting the sequence. # imaplib2 from quoting the sequence.
# #
# NB: msgsToFetch are sequential numbers, not UID's # NB: msgsToFetch are sequential numbers, not UID's
res_type, response = imapobj.fetch("'%s'"% msgsToFetch, res_type, response = imapobj.fetch("'%s'" % msgsToFetch,
'(FLAGS X-GM-LABELS UID)') '(FLAGS X-GM-LABELS UID)')
if res_type != 'OK': if res_type != 'OK':
six.reraise(OfflineImapError, six.reraise(OfflineImapError,
OfflineImapError( OfflineImapError(
"FETCHING UIDs in folder [%s]%s failed. "% "FETCHING UIDs in folder [%s]%s failed. " %
(self.getrepository(), self) + (self.getrepository(), self) +
"Server responded '[%s] %s'"% "Server responded '[%s] %s'" %
(res_type, response), (res_type, response),
OfflineImapError.ERROR.FOLDER), OfflineImapError.ERROR.FOLDER),
exc_info()[2]) exc_info()[2])
@ -156,9 +154,9 @@ class GmailFolder(IMAPFolder):
# e.g.: {'X-GM-LABELS': '("Webserver (RW.net)" "\\Inbox" GInbox)', 'FLAGS': '(\\Seen)', 'UID': '275440'} # e.g.: {'X-GM-LABELS': '("Webserver (RW.net)" "\\Inbox" GInbox)', 'FLAGS': '(\\Seen)', 'UID': '275440'}
options = imaputil.flags2hash(messagestr) options = imaputil.flags2hash(messagestr)
if not 'UID' in options: if not 'UID' in options:
self.ui.warn('No UID in message with options %s' %\ self.ui.warn('No UID in message with options %s' % \
str(options), str(options),
minor = 1) minor=1)
else: else:
uid = int(options['UID']) uid = int(options['UID'])
self.messagelist[uid] = self.msglist_item_initializer(uid) self.messagelist[uid] = self.msglist_item_initializer(uid)
@ -269,7 +267,7 @@ class GmailFolder(IMAPFolder):
for uid in uidlist: for uid in uidlist:
self.messagelist[uid]['labels'] = self.messagelist[uid]['labels'] - labels self.messagelist[uid]['labels'] = self.messagelist[uid]['labels'] - labels
def copymessageto(self, uid, dstfolder, statusfolder, register = 1): def copymessageto(self, uid, dstfolder, statusfolder, register=1):
"""Copies a message from self to dst if needed, updating the status """Copies a message from self to dst if needed, updating the status
Note that this function does not check against dryrun settings, Note that this function does not check against dryrun settings,
@ -353,10 +351,10 @@ class GmailFolder(IMAPFolder):
statuslabels = set() statuslabels = set()
if selflabels != statuslabels: if selflabels != statuslabels:
self.ui.settinglabels(uid, i+1, len(uidlist), sorted(selflabels), dstfolder) self.ui.settinglabels(uid, i + 1, len(uidlist), sorted(selflabels), dstfolder)
if self.repository.account.dryrun: if self.repository.account.dryrun:
continue #don't actually add in a dryrun continue # don't actually add in a dryrun
dstfolder.savemessagelabels(uid, selflabels, ignorelabels = self.ignorelabels) dstfolder.savemessagelabels(uid, selflabels, ignorelabels=self.ignorelabels)
mtime = dstfolder.getmessagemtime(uid) mtime = dstfolder.getmessagemtime(uid)
mtimes[uid] = mtime mtimes[uid] = mtime
labels[uid] = selflabels labels[uid] = selflabels