From ab313325a94d1ce86f568b9ede961d25b9357853 Mon Sep 17 00:00:00 2001 From: AT0myks <49416996+AT0myks@users.noreply.github.com> Date: Tue, 10 Aug 2021 06:03:08 +0200 Subject: [PATCH 1/2] Unnecessary major version check The project this was copied from supports Python 2 but Imbox is 3.3+. --- imbox/parser.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/imbox/parser.py b/imbox/parser.py index c083725..2a7638e 100644 --- a/imbox/parser.py +++ b/imbox/parser.py @@ -5,7 +5,6 @@ import chardet import base64 import quopri -import sys import time from datetime import datetime from email.header import decode_header @@ -168,8 +167,7 @@ def parse_flags(headers): """Copied from https://github.com/girishramnani/gmail/blob/master/gmail/message.py""" if len(headers) == 0: return [] - if sys.version_info[0] == 3: - headers = bytes(headers, "ascii") + headers = bytes(headers, "ascii") return list(imaplib.ParseFlags(headers)) From d1dbf38cc5345f5fa6a7fd0816f07613340a951f Mon Sep 17 00:00:00 2001 From: AT0myks <49416996+AT0myks@users.noreply.github.com> Date: Tue, 10 Aug 2021 06:12:29 +0200 Subject: [PATCH 2/2] Fix ignored headers `data[1]` seems to only contain a closing parenthesis for some servers but for others it contains the flags, like for Outlook. --- imbox/parser.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/imbox/parser.py b/imbox/parser.py index 2a7638e..2a1b5b2 100644 --- a/imbox/parser.py +++ b/imbox/parser.py @@ -154,7 +154,8 @@ def fetch_email_by_uid(uid, connection, parser_policy): message, data = connection.uid('fetch', uid, '(BODY.PEEK[] FLAGS)') logger.debug("Fetched message for UID {}".format(int(uid))) - raw_headers, raw_email = data[0] + raw_headers = data[0][0] + data[1] + raw_email = data[0][1] email_object = parse_email(raw_email, policy=parser_policy) flags = parse_flags(raw_headers.decode())