diff --git a/zerver/lib/email_mirror.py b/zerver/lib/email_mirror.py index 8ccd36d6b7..98908c45ba 100644 --- a/zerver/lib/email_mirror.py +++ b/zerver/lib/email_mirror.py @@ -90,6 +90,9 @@ def get_missed_message_token_from_address(address): # type: (text_type) -> text_type msg_string = get_email_gateway_message_string_from_address(address) + if msg_string is None: + raise ZulipEmailForwardError('Address not recognized by gateway.') + if not is_mm_32_format(msg_string): raise ZulipEmailForwardError('Could not parse missed message address') diff --git a/zerver/tests/test_email_mirror.py b/zerver/tests/test_email_mirror.py index b91413fb74..b6f28358c5 100644 --- a/zerver/tests/test_email_mirror.py +++ b/zerver/tests/test_email_mirror.py @@ -65,6 +65,14 @@ class TestEmailMirrorLibrary(ZulipTestCase): with self.assertRaises(ZulipEmailForwardError): get_token(address) + # Now test the case where we our address does not match the + # EMAIL_GATEWAY_PATTERN. + # This used to crash in an ugly way; we want to throw a proper + # exception. + address = 'alice@not-the-domain-we-were-expecting.com' + with self.assertRaises(ZulipEmailForwardError): + get_token(address) + class TestStreamEmailMessagesSuccess(ZulipTestCase): def test_receive_stream_email_messages_success(self):