From fdac3bfe37186af2a77a2a3cf0686cd1c99c343b Mon Sep 17 00:00:00 2001 From: Mike Edmunds Date: Tue, 2 May 2023 11:26:29 -0700 Subject: [PATCH 1/2] Import make_msgid from correct package --- anymail/message.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/anymail/message.py b/anymail/message.py index ec84cbd8..7f109994 100644 --- a/anymail/message.py +++ b/anymail/message.py @@ -1,8 +1,8 @@ from email.mime.image import MIMEImage -from email.utils import unquote +from email.utils import make_msgid, unquote from pathlib import Path -from django.core.mail import EmailMessage, EmailMultiAlternatives, make_msgid +from django.core.mail import EmailMessage, EmailMultiAlternatives from .utils import UNSET From 1ba26e1be36a6c14b16f5990cc125e2b45433d7e Mon Sep 17 00:00:00 2001 From: Mike Edmunds Date: Tue, 2 May 2023 11:42:00 -0700 Subject: [PATCH 2/2] Fix empty strings in AnymailInboundMessage from/to/cc Fix AnymailInboundMessage.to, .cc, .from_email when message was built with AnymailInboundMessage.construct using empty strings for those params. (Postmark inbound relies on this.) Fixes #307 --- CHANGELOG.rst | 4 ++++ anymail/inbound.py | 5 ++++- tests/test_inbound.py | 6 ++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index d8f1c3c3..3b9be0e0 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -33,6 +33,9 @@ vNext Fixes ~~~~~ +* **Postmark:** Fix spurious AnymailInvalidAddress in ``message.cc`` when + inbound message has no Cc recipients. (Thanks to `@Ecno92`_.) + * **Postmark:** Workaround for handling inbound test webhooks. (`More info `__) @@ -1428,6 +1431,7 @@ Features .. _@dgilmanAIDENTIFIED: https://github.com/dgilmanAIDENTIFIED .. _@dimitrisor: https://github.com/dimitrisor .. _@dominik-lekse: https://github.com/dominik-lekse +.. _@Ecno92: https://github.com/Ecno92 .. _@erikdrums: https://github.com/erikdrums .. _@ewingrj: https://github.com/ewingrj .. _@fdemmer: https://github.com/fdemmer diff --git a/anymail/inbound.py b/anymail/inbound.py index 21dbee01..1b3d35c2 100644 --- a/anymail/inbound.py +++ b/anymail/inbound.py @@ -113,7 +113,10 @@ def get_address_header(self, header): """ values = self.get_all(header) if values is not None: - values = parse_address_list(values) + if "".join(values).strip() == "": + values = None + else: + values = parse_address_list(values) return values or [] def get_date_header(self, header): diff --git a/tests/test_inbound.py b/tests/test_inbound.py index b659bf27..224f827a 100644 --- a/tests/test_inbound.py +++ b/tests/test_inbound.py @@ -307,6 +307,12 @@ def test_address_props(self): self.assertEqual(msg.to, []) self.assertEqual(msg.cc, []) + # Empty strings + msg = AnymailInboundMessage.construct(from_email="", to="", cc="") + self.assertIsNone(msg.from_email) + self.assertEqual(msg.to, []) + self.assertEqual(msg.cc, []) + def test_body_props(self): msg = AnymailInboundMessage.construct(text="Test plaintext", html="Test HTML") self.assertEqual(msg.text, "Test plaintext")