From 8e63f58b22dec40d761a0a6ed54fa183aa069656 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodolfo=20Garc=C3=ADa=20Pe=C3=B1as=20=28kix=29?= Date: Sun, 30 Aug 2020 20:24:13 +0200 Subject: [PATCH] folder/IMAP.py matching uids is a list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- offlineimap/folder/IMAP.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/offlineimap/folder/IMAP.py b/offlineimap/folder/IMAP.py index b4d279c..fe0cfc7 100644 --- a/offlineimap/folder/IMAP.py +++ b/offlineimap/folder/IMAP.py @@ -391,6 +391,10 @@ class IMAPFolder(BaseFolder): try: matchinguids = imapobj.uid('search', 'HEADER', headername, headervalue)[1][0] + + # Returned value is type bytes + matchinguids = matchinguids.decode('utf-8') + except imapobj.error as err: # IMAP server doesn't implement search or had a problem. self.ui.debug('imap', "__savemessage_searchforheader: got IMAP " @@ -456,11 +460,7 @@ class IMAPFolder(BaseFolder): # Folder was empty - start from 1. start = 1 - # Imaplib quotes all parameters of a string type. That must not happen - # 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') + result = imapobj.uid('FETCH', '%d:*' % start, 'rfc822.header') if result[0] != 'OK': raise OfflineImapError('Error fetching mail headers: %s' % '. '.join(result[1]), OfflineImapError.ERROR.MESSAGE)