save email whose bounce info can't be parsed for debugging
This commit is contained in:
parent
4a5983993e
commit
52a19818b7
|
@ -1350,3 +1350,18 @@ def parse_full_address(full_address) -> (str, str):
|
||||||
raise ValueError
|
raise ValueError
|
||||||
|
|
||||||
return full_address.display_name, full_address.address
|
return full_address.display_name, full_address.address
|
||||||
|
|
||||||
|
|
||||||
|
def save_email_for_debugging(msg: Message) -> str:
|
||||||
|
"""Save email for debugging to temporary location
|
||||||
|
Return the file path
|
||||||
|
"""
|
||||||
|
if TEMP_DIR:
|
||||||
|
file_name = str(uuid.uuid4()) + ".eml"
|
||||||
|
with open(os.path.join(TEMP_DIR, file_name), "wb") as f:
|
||||||
|
f.write(msg.as_bytes())
|
||||||
|
|
||||||
|
LOG.d("email saved to %s", file_name)
|
||||||
|
return file_name
|
||||||
|
|
||||||
|
return ""
|
||||||
|
|
|
@ -124,6 +124,7 @@ from app.email_utils import (
|
||||||
parse_full_address,
|
parse_full_address,
|
||||||
get_orig_message_from_yahoo_complaint,
|
get_orig_message_from_yahoo_complaint,
|
||||||
get_mailbox_bounce_info,
|
get_mailbox_bounce_info,
|
||||||
|
save_email_for_debugging,
|
||||||
)
|
)
|
||||||
from app.log import LOG, set_message_id
|
from app.log import LOG, set_message_id
|
||||||
from app.models import (
|
from app.models import (
|
||||||
|
@ -1261,7 +1262,7 @@ def handle_bounce_forward_phase(msg: Message, email_log: EmailLog):
|
||||||
email=mailbox.email, info=bounce_info.as_bytes().decode(), commit=True
|
email=mailbox.email, info=bounce_info.as_bytes().decode(), commit=True
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
LOG.w("cannot get bounce info")
|
LOG.w("cannot get bounce info, debug at %s", save_email_for_debugging(msg))
|
||||||
Bounce.create(email=mailbox.email, commit=True)
|
Bounce.create(email=mailbox.email, commit=True)
|
||||||
|
|
||||||
LOG.d(
|
LOG.d(
|
||||||
|
@ -1489,7 +1490,7 @@ def handle_bounce_reply_phase(envelope, msg: Message, email_log: EmailLog):
|
||||||
commit=True,
|
commit=True,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
LOG.w("cannot get bounce info")
|
LOG.w("cannot get bounce info, debug at %s", save_email_for_debugging(msg))
|
||||||
Bounce.create(email=sanitize_email(contact.website_email), commit=True)
|
Bounce.create(email=sanitize_email(contact.website_email), commit=True)
|
||||||
|
|
||||||
# Store the bounced email
|
# Store the bounced email
|
||||||
|
@ -1753,7 +1754,7 @@ def handle_transactional_bounce(envelope: Envelope, msg, rcpt_to):
|
||||||
commit=True,
|
commit=True,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
LOG.w("cannot get bounce info")
|
LOG.w("cannot get bounce info, debug at %s", save_email_for_debugging(msg))
|
||||||
Bounce.create(email=transactional.email, commit=True)
|
Bounce.create(email=transactional.email, commit=True)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue