folder/IMAP.py matching uids is a list

matchinguids variable is a list of UIDs, separated by spaces. You can
check it some lines later, using the split command.

We need decode the bytes value returned by imaplib2 and convert it to
sting.

Signed-off-by: Rodolfo García Peñas (kix) <kix@kix.es>
This commit is contained in:
Rodolfo García Peñas (kix) 2020-08-30 20:24:13 +02:00
parent 898ae18f77
commit 8e63f58b22

View File

@ -391,6 +391,10 @@ class IMAPFolder(BaseFolder):
try: try:
matchinguids = imapobj.uid('search', 'HEADER', matchinguids = imapobj.uid('search', 'HEADER',
headername, headervalue)[1][0] headername, headervalue)[1][0]
# Returned value is type bytes
matchinguids = matchinguids.decode('utf-8')
except imapobj.error as err: except imapobj.error as err:
# IMAP server doesn't implement search or had a problem. # IMAP server doesn't implement search or had a problem.
self.ui.debug('imap', "__savemessage_searchforheader: got IMAP " self.ui.debug('imap', "__savemessage_searchforheader: got IMAP "
@ -456,11 +460,7 @@ class IMAPFolder(BaseFolder):
# Folder was empty - start from 1. # Folder was empty - start from 1.
start = 1 start = 1
# Imaplib quotes all parameters of a string type. That must not happen result = imapobj.uid('FETCH', '%d:*' % start, 'rfc822.header')
# with the range X:*. So we use bytearray to stop imaplib from getting
# in our way.
result = imapobj.uid('FETCH', bytearray('%d:*' % start), 'rfc822.header')
if result[0] != 'OK': if result[0] != 'OK':
raise OfflineImapError('Error fetching mail headers: %s' % raise OfflineImapError('Error fetching mail headers: %s' %
'. '.join(result[1]), OfflineImapError.ERROR.MESSAGE) '. '.join(result[1]), OfflineImapError.ERROR.MESSAGE)