handle linebreak in parseaddr_unicode

This commit is contained in:
Son NK 2020-09-16 17:28:01 +02:00
parent 5c8d31111c
commit 03dfafe1cf

View file

@ -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=?= <abcd@gmail.com>' -> ('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()