try parsing the alias from the from header which might contain the reverse alias when handling hotmail complaint
This commit is contained in:
parent
8aa7b1b773
commit
7c182d20a4
|
@ -1356,20 +1356,33 @@ def handle_hotmail_complaint(msg: Message) -> bool:
|
||||||
"""
|
"""
|
||||||
orig_msg = get_orig_message_from_hotmail_complaint(msg)
|
orig_msg = get_orig_message_from_hotmail_complaint(msg)
|
||||||
to_header = orig_msg[headers.TO]
|
to_header = orig_msg[headers.TO]
|
||||||
|
from_header = orig_msg[headers.FROM]
|
||||||
if not to_header:
|
if not to_header:
|
||||||
LOG.e("cannot find the alias")
|
LOG.e("to header empty")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
_, alias_address = parse_full_address(get_header_unicode(to_header))
|
_, alias_address = parse_full_address(get_header_unicode(to_header))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
# to_header can be something like 'Undisclosed recipients:;'
|
# to_header can be something like 'Undisclosed recipients:;'
|
||||||
LOG.w("cannot parse %s", to_header)
|
LOG.w("cannot find alias from to header %s", to_header)
|
||||||
|
# try parsing the alias from the from header which might contain the reverse alias
|
||||||
|
_, reverse_alias = parse_full_address(get_header_unicode(from_header))
|
||||||
|
contact = Contact.get_by(reply_email=reverse_alias)
|
||||||
|
if contact:
|
||||||
|
alias = contact.alias
|
||||||
|
LOG.d("find %s through %s", alias, contact)
|
||||||
|
else:
|
||||||
return False
|
return False
|
||||||
|
else:
|
||||||
alias = Alias.get_by(email=alias_address)
|
alias = Alias.get_by(email=alias_address)
|
||||||
|
|
||||||
if not alias:
|
if not alias:
|
||||||
LOG.w("No alias for %s", alias_address)
|
LOG.w(
|
||||||
|
"Cannot parse alias from to header %s and from header %s",
|
||||||
|
to_header,
|
||||||
|
from_header,
|
||||||
|
)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
user = alias.user
|
user = alias.user
|
||||||
|
|
Loading…
Reference in a new issue