mirror of https://github.com/zulip/zulip.git
email_mirror: Reuse exception messages in mirror_email_message.
This commit is contained in:
parent
38ac8e9f3e
commit
90a69ab24f
|
@ -113,7 +113,7 @@ def get_missed_message_address(address: str) -> MissedMessageEmailAddress:
|
|||
timestamp__gt=timezone_now() - timedelta(seconds=MissedMessageEmailAddress.EXPIRY_SECONDS)
|
||||
)
|
||||
except MissedMessageEmailAddress.DoesNotExist:
|
||||
raise ZulipEmailForwardError("Missed message address expired or doesn't exist")
|
||||
raise ZulipEmailForwardError("Missed message address expired or doesn't exist.")
|
||||
|
||||
def create_missed_message_address(user_profile: UserProfile, message: Message) -> str:
|
||||
if settings.EMAIL_GATEWAY_PATTERN == '':
|
||||
|
@ -369,28 +369,24 @@ def process_message(message: message.Message, rcpt_to: Optional[str]=None) -> No
|
|||
else:
|
||||
log_and_report(message, str(e), to)
|
||||
|
||||
def validate_to_address(rcpt_to: str) -> None:
|
||||
if is_missed_message_address(rcpt_to):
|
||||
mm_address = get_missed_message_address(rcpt_to)
|
||||
if not mm_address.is_usable():
|
||||
raise ZulipEmailForwardError("Missed message address out of uses.")
|
||||
else:
|
||||
extract_and_validate(rcpt_to)
|
||||
|
||||
def mirror_email_message(data: Dict[str, str]) -> Dict[str, str]:
|
||||
rcpt_to = data['recipient']
|
||||
if is_missed_message_address(rcpt_to):
|
||||
try:
|
||||
mm_address = get_missed_message_address(rcpt_to)
|
||||
if not mm_address.is_usable():
|
||||
raise ZulipEmailForwardError("Missed message address out of uses.")
|
||||
except ZulipEmailForwardError:
|
||||
return {
|
||||
"status": "error",
|
||||
"msg": "5.1.1 Bad destination mailbox address: "
|
||||
"Bad or expired missed message address."
|
||||
}
|
||||
else:
|
||||
try:
|
||||
extract_and_validate(rcpt_to)
|
||||
except ZulipEmailForwardError:
|
||||
return {
|
||||
"status": "error",
|
||||
"msg": "5.1.1 Bad destination mailbox address: "
|
||||
"Please use the address specified in your Streams page."
|
||||
}
|
||||
try:
|
||||
validate_to_address(rcpt_to)
|
||||
except ZulipEmailForwardError as e:
|
||||
return {
|
||||
"status": "error",
|
||||
"msg": "5.1.1 Bad destination mailbox address: {}".format(e)
|
||||
}
|
||||
|
||||
queue_json_publish(
|
||||
"email_mirror",
|
||||
{
|
||||
|
|
|
@ -1008,7 +1008,7 @@ class TestEmailMirrorTornadoView(ZulipTestCase):
|
|||
self.assert_json_error(
|
||||
result,
|
||||
"5.1.1 Bad destination mailbox address: "
|
||||
"Please use the address specified in your Streams page.")
|
||||
"Bad stream token from email recipient " + stream_to_address)
|
||||
|
||||
def test_success_to_stream_with_good_token_wrong_stream_name(self) -> None:
|
||||
stream = get_stream("Denmark", get_realm("zulip"))
|
||||
|
@ -1032,7 +1032,7 @@ class TestEmailMirrorTornadoView(ZulipTestCase):
|
|||
result = self.send_offline_message(mm_address, self.example_email('cordelia'))
|
||||
self.assert_json_error(
|
||||
result,
|
||||
"5.1.1 Bad destination mailbox address: Bad or expired missed message address.")
|
||||
"5.1.1 Bad destination mailbox address: Missed message address out of uses.")
|
||||
|
||||
def test_wrong_missed_email_private_message(self) -> None:
|
||||
self.send_private_message()
|
||||
|
@ -1040,7 +1040,7 @@ class TestEmailMirrorTornadoView(ZulipTestCase):
|
|||
result = self.send_offline_message(mm_address, self.example_email('cordelia'))
|
||||
self.assert_json_error(
|
||||
result,
|
||||
"5.1.1 Bad destination mailbox address: Bad or expired missed message address.")
|
||||
"5.1.1 Bad destination mailbox address: Missed message address expired or doesn't exist.")
|
||||
|
||||
|
||||
class TestStreamEmailMessagesSubjectStripping(ZulipTestCase):
|
||||
|
|
Loading…
Reference in New Issue