handle case cannot parse mailbox_id

This commit is contained in:
Son NK 2020-08-16 18:55:14 +02:00
parent a3a99ac3f4
commit 6835c5b69d
1 changed files with 17 additions and 12 deletions

View File

@ -874,20 +874,25 @@ def handle_bounce(contact: Contact, alias: Alias, msg: Message, user: User):
file_path, BytesIO(orig_msg.as_bytes()), random_name file_path, BytesIO(orig_msg.as_bytes()), random_name
) )
# <<< END Store the bounced email >>> # <<< END Store the bounced email >>>
try:
mailbox_id = int(orig_msg[_MAILBOX_ID_HEADER]) mailbox_id = int(orig_msg[_MAILBOX_ID_HEADER])
mailbox = Mailbox.get(mailbox_id) except TypeError:
if not mailbox or mailbox.user_id != user.id: LOG.warning("cannot parse mailbox from %s", orig_msg[_MAILBOX_ID_HEADER])
LOG.exception(
"Tampered message mailbox_id %s, %s, %s, %s %s",
mailbox_id,
user,
alias,
contact,
full_report_path,
)
# use the alias default mailbox # use the alias default mailbox
mailbox = alias.mailbox mailbox = alias.mailbox
else:
mailbox = Mailbox.get(mailbox_id)
if not mailbox or mailbox.user_id != user.id:
LOG.exception(
"Tampered message mailbox_id %s, %s, %s, %s %s",
mailbox_id,
user,
alias,
contact,
full_report_path,
)
# use the alias default mailbox
mailbox = alias.mailbox
refused_email = RefusedEmail.create( refused_email = RefusedEmail.create(
path=file_path, full_report_path=full_report_path, user_id=user.id path=file_path, full_report_path=full_report_path, user_id=user.id