From 59572444dd5cbceba770c03ab599963becb3625f Mon Sep 17 00:00:00 2001 From: Janos SUTO Date: Wed, 27 Jan 2021 09:05:19 +0100 Subject: [PATCH] imapfetch.py fix Signed-off-by: Janos SUTO --- util/imapfetch.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/util/imapfetch.py b/util/imapfetch.py index 8e8b82b0..45852085 100755 --- a/util/imapfetch.py +++ b/util/imapfetch.py @@ -44,17 +44,20 @@ def read_folder_list(conn): if isinstance(folder, type(b'')): folder = folder.decode('utf-8') elif isinstance(folder, type(())): - folder = re.sub(r'\{\d+\}$', '', folder[0]) + folder[1] + folder = re.sub(r'\{\d+\}$', '', folder[0].decode('utf-8')) + folder[1].decode('utf-8') # The regex should match ' "/" ' and ' "." ' if folder: - f = re.split(r' \"[\/\.]\" ', folder) + f = re.split(r' \"[\/\.\\]+\" ', folder) result.append(f[1]) return [x for x in result if x not in opts['skip_folders']] def process_folder(conn, folder): + # Space in the folder name must be escaped + folder = re.sub(r' ', '\\ ', folder) + if opts['verbose']: print("Processing {}".format(folder)) @@ -75,9 +78,10 @@ def process_folder(conn, folder): rc, data = conn.fetch(num, '(RFC822)') if opts['verbose']: print(rc, num) - opts['counter'] += 1 - with open("{}.eml".format(opts['counter']), "wb") as f: - f.write(data[0][1]) + if isinstance(data[0], tuple): + opts['counter'] += 1 + with open("{}.eml".format(opts['counter']), "wb") as f: + f.write(data[0][1]) def main():