Skip to content
Snippets Groups Projects
Commit 4128af39 authored by Antoine Lambert's avatar Antoine Lambert Committed by Antoine Lambert
Browse files

inbound_email/utils: Fix handling of invalid email address header

parent 833fd247
No related branches found
No related tags found
No related merge requests found
......@@ -39,6 +39,8 @@ def test_extract_recipients():
]
del message["To"]
# check invalid address header are discarded
message["x-envelope-to"] = "foo"
assert utils.extract_recipients(message) == [
Address(addr_spec="test-recipient-2@example.com"),
Address(
......
......@@ -4,7 +4,7 @@
# See top-level LICENSE file for more information
from dataclasses import dataclass
from email.headerregistry import Address
from email.headerregistry import Address, AddressHeader
from email.message import EmailMessage, Message
import logging
from typing import List, Optional, Set, Tuple, Union
......@@ -48,7 +48,9 @@ def extract_recipients(message: EmailMessage) -> List[Address]:
ret = []
for header_name in HEADERS:
for header in message.get_all(header_name, []):
for header in filter(
lambda h: isinstance(h, AddressHeader), message.get_all(header_name, [])
):
ret.extend(header.addresses)
return ret
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment