fix(imap): handle multi-address headers in _parse_singular_addr (#15006)

Replace the RuntimeError with a warning + first-address fallback so a
single email whose From header contains multiple addresses no longer
crashes the entire IMAP sync task. Also add regression tests covering:

- #14963: RFC 5322 quoted display names with commas (e.g. "Schlüter,
Sabine" <s@x>) parsed as one address, not two.
- #14964: multi-address headers warn instead of raising.

Closes #14964
Refs #14963
This commit is contained in:
dripsmvcp
2026-05-20 11:14:32 +09:00
committed by Jin Hai
parent 85caad5558
commit ce9a4425d2
2 changed files with 105 additions and 4 deletions

View File

@@ -751,11 +751,11 @@ def _parse_singular_addr(raw_header: str) -> tuple[str, str]:
addrs = _parse_addrs(raw_header=raw_header)
if not addrs:
return ("Unknown", "unknown@example.com")
elif len(addrs) >= 2:
raise RuntimeError(
f"Expected a singular address, but instead got multiple; {raw_header=} {addrs=}"
if len(addrs) >= 2:
logging.warning(
"Multiple addresses in header expected to be singular; using first. parsed_count=%d",
len(addrs),
)
return addrs[0]