From 5fb99c1d9abe77eaa3901f71396af8afcbdcdd4c Mon Sep 17 00:00:00 2001 From: Luiz Guilherme Fonseca Rosa Date: Mon, 20 Jan 2020 11:46:22 -0300 Subject: [PATCH] Support less seen versions of Message-ID --- gmail_wrapper/entities.py | 2 +- tests/test_entities.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/gmail_wrapper/entities.py b/gmail_wrapper/entities.py index 16323b0..361a065 100644 --- a/gmail_wrapper/entities.py +++ b/gmail_wrapper/entities.py @@ -91,7 +91,7 @@ def message_id(self): While self.id is the user-bound id of the message, self.message_id is the global id of the message, valid for every user on the thread. """ - return self.headers.get("Message-ID") + return self.headers.get("Message-ID", self.headers.get("Message-Id")) @property def thread_id(self): diff --git a/tests/test_entities.py b/tests/test_entities.py index 16979ac..22c4784 100644 --- a/tests/test_entities.py +++ b/tests/test_entities.py @@ -115,6 +115,20 @@ def test_it_archives_a_message(self, mocker, client, raw_complete_message): raw_complete_message["id"], add_labels=None, remove_labels=["INBOX"] ) + def test_message_id_property(self, client, raw_complete_message): + message = Message(client, raw_complete_message) + assert ( + message.message_id + == "" + ) + raw_complete_message["payload"]["headers"][3]["name"] = "Message-Id" + assert ( + message.message_id + == "" + ) + raw_complete_message["payload"]["headers"][3]["name"] = "Invalid" + assert message.message_id is None + class TestAttachment: def test_it_has_basic_properties_without_additional_fetch(