email_mirror: Fail more gracefully on empty EMAIL_GATEWAY_PATTERN.

Otherwise, this fails on `match.group(1)` as there is no match group.

The server would ideally respond with a 521 or 556 code[^1] on initial
connection, but aiosmtpd does not provide that option.

[^1]: https://www.rfc-editor.org/rfc/rfc7504
This commit is contained in:
Alex Vandiver
2025-07-01 10:59:21 -04:00
committed by Tim Abbott
parent 43a7035745
commit 8cde0af040
2 changed files with 22 additions and 0 deletions

View File

@@ -33,6 +33,8 @@ class ZulipEmailForwardUserError(ZulipEmailForwardError):
def get_email_gateway_message_string_from_address(address: str) -> str:
if settings.EMAIL_GATEWAY_PATTERN == "":
raise ZulipEmailForwardError("This server is not configured for incoming email.")
pattern_parts = [re.escape(part) for part in settings.EMAIL_GATEWAY_PATTERN.split("%s")]
if settings.EMAIL_GATEWAY_EXTRA_PATTERN_HACK:
# Accept mails delivered to any Zulip server