decode the subject

This commit is contained in:
Son NK 2020-11-09 21:16:50 +01:00
parent b2f9479bce
commit c3f73b25b2
2 changed files with 13 additions and 0 deletions

View file

@ -593,6 +593,17 @@ def get_spam_from_header(spam_status_header, max_score=None) -> (bool, str):
return spamassassin_answer.lower() == "yes", spam_status_header
def get_header_unicode(header: str):
decoded_string, charset = decode_header(header)[0]
if charset is not None:
try:
return decoded_string.decode(charset)
except UnicodeDecodeError:
LOG.warning("Cannot decode header %s", header)
return header
def parseaddr_unicode(addr) -> (str, str):
"""Like parseaddr() but return name in unicode instead of in RFC 2047 format
Should be used instead of parseaddr()

View file

@ -100,6 +100,7 @@ from app.email_utils import (
is_valid_alias_address_domain,
should_add_dkim_signature,
add_header,
get_header_unicode,
)
from app.extensions import db
from app.greylisting import greylisting_needed
@ -700,6 +701,7 @@ def forward_email_to_mailbox(
if mailbox.generic_subject:
LOG.d("Use a generic subject for %s", mailbox)
orig_subject = msg["Subject"]
orig_subject = get_header_unicode(orig_subject)
add_or_replace_header(msg, "Subject", mailbox.generic_subject)
msg = add_header(
msg,