handle ValueError raised by parse_full_address
This commit is contained in:
parent
c5425b0a73
commit
7f5201effa
|
@ -1853,22 +1853,26 @@ def handle(envelope: Envelope) -> str:
|
||||||
# case where From: header is a reverse alias which should never happen
|
# case where From: header is a reverse alias which should never happen
|
||||||
from_header = get_header_unicode(msg["From"])
|
from_header = get_header_unicode(msg["From"])
|
||||||
if from_header:
|
if from_header:
|
||||||
_, from_header_address = parse_full_address(from_header)
|
try:
|
||||||
if is_reply_email(from_header_address):
|
_, from_header_address = parse_full_address(from_header)
|
||||||
LOG.e("email sent from a reverse alias %s", from_header_address)
|
except ValueError:
|
||||||
# get more info for debug
|
LOG.d("cannot parse the From header %s", from_header)
|
||||||
contact = Contact.get_by(reply_email=from_header_address)
|
else:
|
||||||
if contact:
|
if is_reply_email(from_header_address):
|
||||||
LOG.d("%s %s %s", contact.user, contact.alias, contact)
|
LOG.e("email sent from a reverse alias %s", from_header_address)
|
||||||
|
# get more info for debug
|
||||||
|
contact = Contact.get_by(reply_email=from_header_address)
|
||||||
|
if contact:
|
||||||
|
LOG.d("%s %s %s", contact.user, contact.alias, contact)
|
||||||
|
|
||||||
# To investigate. todo: remove
|
# To investigate. todo: remove
|
||||||
if TEMP_DIR:
|
if TEMP_DIR:
|
||||||
file_name = str(uuid.uuid4()) + ".eml"
|
file_name = str(uuid.uuid4()) + ".eml"
|
||||||
with open(os.path.join(TEMP_DIR, file_name), "wb") as f:
|
with open(os.path.join(TEMP_DIR, file_name), "wb") as f:
|
||||||
f.write(msg.as_bytes())
|
f.write(msg.as_bytes())
|
||||||
|
|
||||||
LOG.d("email saved to %s", file_name)
|
LOG.d("email saved to %s", file_name)
|
||||||
return status.E523
|
return status.E523
|
||||||
|
|
||||||
if rate_limited(mail_from, rcpt_tos):
|
if rate_limited(mail_from, rcpt_tos):
|
||||||
LOG.w("Rate Limiting applied for mail_from:%s rcpt_tos:%s", mail_from, rcpt_tos)
|
LOG.w("Rate Limiting applied for mail_from:%s rcpt_tos:%s", mail_from, rcpt_tos)
|
||||||
|
|
Loading…
Reference in a new issue