Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

email_mirror: Fail more gracefully on empty EMAIL_GATEWAY_PATTERN.

Alex Vandiver8cde0af040df
diff --git a/zerver/lib/email_mirror_helpers.py b/zerver/lib/email_mirror_helpers.py
index 6dac1fb0f68..2ef10f0b1b3 100644
--- a/zerver/lib/email_mirror_helpers.py
+++ b/zerver/lib/email_mirror_helpers.py
@@ -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
diff --git a/zerver/tests/test_email_mirror.py b/zerver/tests/test_email_mirror.py
index 58037fe9a2c..a5f0ba85bf1 100644
--- a/zerver/tests/test_email_mirror.py
+++ b/zerver/tests/test_email_mirror.py
@@ -2007,6 +2007,26 @@ class TestEmailMirrorServer(ZulipTestCase):
return [r.decode() for r in responses]
+ @override_settings(EMAIL_GATEWAY_PATTERN="")
+ async def test_unconfigured(self) -> None:
+ self.assertEqual(
+ await self.handler_response(
+ [
+ "HELO localhost",
+ "MAIL FROM: <[email protected]>",
+ "RCPT TO: <[email protected]>",
+ "QUIT",
+ ]
+ ),
+ [
+ "220 testhost Zulip 1.2.3\r\n",
+ "250 testhost\r\n",
+ "250 OK\r\n",
+ "550 5.1.1 Bad destination mailbox address: This server is not configured for incoming email.\r\n",
+ "221 Bye\r\n",
+ ],
+ )
+
@override_settings(EMAIL_GATEWAY_PATTERN="%[email protected]")
async def test_handler_error(self) -> None:
with (