From 03dfafe1cf0d75fe3e10bff2355598eb5227c7fa Mon Sep 17 00:00:00 2001 From: Son NK <> Date: Wed, 16 Sep 2020 17:28:01 +0200 Subject: [PATCH] handle linebreak in parseaddr_unicode --- app/email_utils.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/email_utils.py b/app/email_utils.py index c592cee9..732a1a0d 100644 --- a/app/email_utils.py +++ b/app/email_utils.py @@ -572,9 +572,12 @@ def get_spam_from_header(spam_status_header, max_score=None) -> (bool, str): def parseaddr_unicode(addr) -> (str, str): - """Like parseaddr but return name in unicode instead of in RFC 2047 format + """Like parseaddr() but return name in unicode instead of in RFC 2047 format + Should be used instead of parseaddr() '=?UTF-8?B?TmjGoW4gTmd1eeG7hW4=?= ' -> ('Nhơn Nguyễn', "abcd@gmail.com") """ + # sometimes linebreaks are present in addr + addr = addr.replace("\n", "").strip() name, email = parseaddr(addr) # email can have whitespace so we can't remove whitespace here email = email.strip().lower()