Merge pull request #55 from sudipm-mukherjee/gmail

BUG: Gmail FETCH error with synclabels enabled
This commit is contained in:
Rodolfo García Peñas (kix) 2021-05-09 11:24:03 +02:00 committed by GitHub
commit f6848015ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -128,11 +128,10 @@ class GmailFolder(IMAPFolder):
if not msgsToFetch: if not msgsToFetch:
return # No messages to sync return # No messages to sync
# Get the flags and UIDs for these. single-quotes prevent # Get the flags and UIDs for these.
# 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':
raise OfflineImapError( raise OfflineImapError(
@ -150,6 +149,9 @@ class GmailFolder(IMAPFolder):
# Discard initial message number. # Discard initial message number.
if messagestr is None: if messagestr is None:
continue continue
# We need a str messagestr
if isinstance(messagestr, bytes):
messagestr = messagestr.decode(encoding='utf-8')
messagestr = messagestr.split(' ', 1)[1] messagestr = messagestr.split(' ', 1)[1]
# 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)
@ -167,6 +169,8 @@ class GmailFolder(IMAPFolder):
else: else:
labels = set() labels = set()
labels = labels - self.ignorelabels labels = labels - self.ignorelabels
if isinstance(messagestr, str):
messagestr = bytes(messagestr, 'utf-8')
rtime = imaplibutil.Internaldate2epoch(messagestr) rtime = imaplibutil.Internaldate2epoch(messagestr)
self.messagelist[uid] = {'uid': uid, 'flags': flags, 'labels': labels, 'time': rtime} self.messagelist[uid] = {'uid': uid, 'flags': flags, 'labels': labels, 'time': rtime}