Fix imaplib2 and unicode issues in pop3 and imap backends

This commit is contained in:
Patrick Ulbrich
2019-10-26 19:13:43 +02:00
parent e7ad095937
commit b77338d30e
2 changed files with 12 additions and 10 deletions

View File

@@ -1,7 +1,8 @@
# Copyright 2011 - 2016 Patrick Ulbrich <zulu99@gmx.net>
# Copyright 2011 - 2019 Patrick Ulbrich <zulu99@gmx.net>
# Copyright 2016 Timo Kankare <timo.kankare@iki.fi>
# Copyright 2016 Thomas Haider <t.haider@deprecate.de>
# Copyright 2011 Ralf Hersel <ralf.hersel@gmx.net>#
# Copyright 2011 Ralf Hersel <ralf.hersel@gmx.net>
# Copyright 2019 razer <razerraz@free.fr>
#
# 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.")

View File

@@ -1,7 +1,8 @@
# Copyright 2011 - 2016 Patrick Ulbrich <zulu99@gmx.net>
# Copyright 2011 - 2019 Patrick Ulbrich <zulu99@gmx.net>
# Copyright 2016 Timo Kankare <timo.kankare@iki.fi>
# Copyright 2016 Thomas Haider <t.haider@deprecate.de>
# Copyright 2011 Ralf Hersel <ralf.hersel@gmx.net>#
# Copyright 2011 Ralf Hersel <ralf.hersel@gmx.net>
# Copyright 2019 razer <razerraz@free.fr>
#
# 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