Skip to content

Commit 1ba26e1

Browse files
committed
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
1 parent fdac3bf commit 1ba26e1

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

CHANGELOG.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ vNext
3333
Fixes
3434
~~~~~
3535

36+
* **Postmark:** Fix spurious AnymailInvalidAddress in ``message.cc`` when
37+
inbound message has no Cc recipients. (Thanks to `@Ecno92`_.)
38+
3639
* **Postmark:** Workaround for handling inbound test webhooks.
3740
(`More info <https://github.com/anymail/django-anymail/issues/304>`__)
3841

@@ -1428,6 +1431,7 @@ Features
14281431
.. _@dgilmanAIDENTIFIED: https://github.com/dgilmanAIDENTIFIED
14291432
.. _@dimitrisor: https://github.com/dimitrisor
14301433
.. _@dominik-lekse: https://github.com/dominik-lekse
1434+
.. _@Ecno92: https://github.com/Ecno92
14311435
.. _@erikdrums: https://github.com/erikdrums
14321436
.. _@ewingrj: https://github.com/ewingrj
14331437
.. _@fdemmer: https://github.com/fdemmer

anymail/inbound.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,10 @@ def get_address_header(self, header):
113113
"""
114114
values = self.get_all(header)
115115
if values is not None:
116-
values = parse_address_list(values)
116+
if "".join(values).strip() == "":
117+
values = None
118+
else:
119+
values = parse_address_list(values)
117120
return values or []
118121

119122
def get_date_header(self, header):

tests/test_inbound.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,12 @@ def test_address_props(self):
307307
self.assertEqual(msg.to, [])
308308
self.assertEqual(msg.cc, [])
309309

310+
# Empty strings
311+
msg = AnymailInboundMessage.construct(from_email="", to="", cc="")
312+
self.assertIsNone(msg.from_email)
313+
self.assertEqual(msg.to, [])
314+
self.assertEqual(msg.cc, [])
315+
310316
def test_body_props(self):
311317
msg = AnymailInboundMessage.construct(text="Test plaintext", html="Test HTML")
312318
self.assertEqual(msg.text, "Test plaintext")

0 commit comments

Comments
 (0)