From b77338d30e5d9935f36c88e6dc8611fdebde87bf Mon Sep 17 00:00:00 2001 From: Patrick Ulbrich Date: Sat, 26 Oct 2019 19:13:43 +0200 Subject: [PATCH] Fix imaplib2 and unicode issues in pop3 and imap backends --- Mailnag/backends/imap.py | 11 ++++++----- Mailnag/backends/pop3.py | 11 ++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Mailnag/backends/imap.py b/Mailnag/backends/imap.py index e028508..5542d9c 100644 --- a/Mailnag/backends/imap.py +++ b/Mailnag/backends/imap.py @@ -1,7 +1,8 @@ -# Copyright 2011 - 2016 Patrick Ulbrich +# Copyright 2011 - 2019 Patrick Ulbrich # Copyright 2016 Timo Kankare # Copyright 2016 Thomas Haider -# Copyright 2011 Ralf Hersel # +# Copyright 2011 Ralf Hersel +# Copyright 2019 razer # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -96,7 +97,7 @@ class IMAPMailboxBackend(MailboxBackend): for response_part in msg_data: if isinstance(response_part, tuple): try: - msg = email.message_from_string(response_part[1]) + msg = email.message_from_bytes(response_part[1]) except: logging.debug("Couldn't get IMAP message.") continue @@ -111,12 +112,12 @@ class IMAPMailboxBackend(MailboxBackend): conn = self._connect() try: - status, data = conn.list('', '*') + status, data = conn.list() finally: self._disconnect(conn) for d in data: - match = re.match('.+\s+("."|"?NIL"?)\s+"?([^"]+)"?$', d) + match = re.match(r'.+\s+("."|"?NIL"?)\s+"?([^"]+)"?$', d.decode('utf-8')) if match == None: logging.warning("Folder format not supported.") diff --git a/Mailnag/backends/pop3.py b/Mailnag/backends/pop3.py index 153fdd7..e6d3eac 100644 --- a/Mailnag/backends/pop3.py +++ b/Mailnag/backends/pop3.py @@ -1,7 +1,8 @@ -# Copyright 2011 - 2016 Patrick Ulbrich +# Copyright 2011 - 2019 Patrick Ulbrich # Copyright 2016 Timo Kankare # Copyright 2016 Thomas Haider -# Copyright 2011 Ralf Hersel # +# Copyright 2011 Ralf Hersel +# Copyright 2019 razer # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -106,12 +107,12 @@ class POP3MailboxBackend(MailboxBackend): logging.debug("Couldn't get POP message.") continue - # convert list to string - message_string = '\n'.join(message) + # convert list to byte sequence + message_bytes = b'\n'.join(message) try: # put message into email object and make a dictionary - msg = dict(email.message_from_string(message_string)) + msg = dict(email.message_from_bytes(message_bytes)) except: logging.debug("Couldn't get msg from POP message.") continue