Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
email_mirror: Reject missed message email from deactivated user earlier.
PieterCK90a93d380013
diff --git a/zerver/lib/email_mirror.py b/zerver/lib/email_mirror.pyindex f36261cc424..3fb47551e35 100644--- a/zerver/lib/email_mirror.py+++ b/zerver/lib/email_mirror.py@@ -563,6 +563,10 @@ def process_message(message: EmailMessage, rcpt_to: str | None = None) -> None:def validate_to_address(address: str, rate_limit: bool = True) -> None:if is_missed_message_address(address):mm_address = get_usable_missed_message_address(address)+ if not is_user_active(mm_address.user_profile):+ raise JsonableError(+ _("Sending user is not active. Ignoring this message notification email.")+ )if mm_address.message.recipient.type == Recipient.STREAM:# ACL's on DMs are harder to apply simply, so we# just check channel messages.diff --git a/zerver/tests/test_email_mirror.py b/zerver/tests/test_email_mirror.pyindex 26cae503de2..60dfe5d818e 100644--- a/zerver/tests/test_email_mirror.py+++ b/zerver/tests/test_email_mirror.py@@ -2518,6 +2518,32 @@ class TestEmailMirrorServer(ZulipTestCase):],)+ @override_settings(EMAIL_GATEWAY_PATTERN="%[email protected]")+ async def test_handler_missedmessage_deactivated_user(self) -> None:+ othello = await sync_to_async(lambda: self.example_user("othello"))()+ usermessage = await sync_to_async(lambda: most_recent_usermessage(othello))()+ mm_address = await sync_to_async(+ lambda: create_missed_message_address(othello, usermessage.message)+ )()+ await sync_to_async(lambda: do_deactivate_user(othello, acting_user=None))()+ self.assertEqual(+ await self.handler_response(+ [+ "HELO localhost",+ "MAIL FROM: <[email protected]>",+ f"RCPT TO: <{mm_address}>",+ "QUIT",+ ]+ ),+ [+ "220 testhost Zulip 1.2.3\r\n",+ "250 testhost\r\n",+ "250 OK\r\n",+ "550 5.7.1 Permission denied: Sending user is not active. Ignoring this message notification email.\r\n",+ "221 Bye\r\n",+ ],+ )+@override_settings(EMAIL_GATEWAY_PATTERN="%[email protected]")async def test_handler_missedmessage(self) -> None:othello = await sync_to_async(lambda: self.example_user("othello"))()