save email for debug with error name as prefix

This commit is contained in:
Son 2022-01-08 16:58:23 +01:00
parent 4298fe73e6
commit c5e4dd6d16
2 changed files with 9 additions and 3 deletions

View File

@ -1399,12 +1399,15 @@ def parse_full_address(full_address) -> (str, str):
return full_address.display_name, full_address.address
def save_email_for_debugging(msg: Message) -> str:
def save_email_for_debugging(msg: Message, file_name_prefix=None) -> str:
"""Save email for debugging to temporary location
Return the file path
"""
if TEMP_DIR:
file_name = str(uuid.uuid4()) + ".eml"
if file_name_prefix:
file_name = file_name_prefix + file_name
with open(os.path.join(TEMP_DIR, file_name), "wb") as f:
f.write(msg.as_bytes())

View File

@ -2375,13 +2375,16 @@ class MailHandler:
return status.E524
except Exception as e:
LOG.e(
"email handling fail with error:%s mail_from:%s, rcpt_tos:%s, header_from:%s, header_to:%s, saved to %s",
"email handling fail with error:%s "
"mail_from:%s, rcpt_tos:%s, header_from:%s, header_to:%s, saved to %s",
e,
envelope.mail_from,
envelope.rcpt_tos,
msg[headers.FROM],
msg[headers.TO],
save_email_for_debugging(msg), # todo: remove
save_email_for_debugging(
msg, file_name_prefix=e.__class__.__name__
), # todo: remove
)
return status.E404