mirror of
https://github.com/zulip/zulip.git
synced 2025-11-09 08:26:11 +00:00
bug: Fix traceback in get_missed_message_token_from_address().
If you supplied an unrecognizable address to our email system, or you had EMAIL_GATEWAY_PATTERN configured wrong, the get_missed_message_token_from_address() used to crash hard and cryptically with a traceback saying that you can't call startswith() on a None object. Now we throw a ZulipEmailForwardError exception. This will still lead to a traceback, but it should be easier to diagnose the problem.
This commit is contained in:
@@ -90,6 +90,9 @@ def get_missed_message_token_from_address(address):
|
|||||||
# type: (text_type) -> text_type
|
# type: (text_type) -> text_type
|
||||||
msg_string = get_email_gateway_message_string_from_address(address)
|
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):
|
if not is_mm_32_format(msg_string):
|
||||||
raise ZulipEmailForwardError('Could not parse missed message address')
|
raise ZulipEmailForwardError('Could not parse missed message address')
|
||||||
|
|
||||||
|
|||||||
@@ -65,6 +65,14 @@ class TestEmailMirrorLibrary(ZulipTestCase):
|
|||||||
with self.assertRaises(ZulipEmailForwardError):
|
with self.assertRaises(ZulipEmailForwardError):
|
||||||
get_token(address)
|
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):
|
class TestStreamEmailMessagesSuccess(ZulipTestCase):
|
||||||
def test_receive_stream_email_messages_success(self):
|
def test_receive_stream_email_messages_success(self):
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user