From c686767d4d761e5ecd6054704683a95797a171e3 Mon Sep 17 00:00:00 2001 From: Son NK <> Date: Sun, 5 Apr 2020 12:56:17 +0200 Subject: [PATCH] Fix parseaddr_unicode: take into account email only case --- app/email_utils.py | 9 ++++++--- tests/test_email_utils.py | 3 +++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/app/email_utils.py b/app/email_utils.py index 14fe9f74..ed44c56b 100644 --- a/app/email_utils.py +++ b/app/email_utils.py @@ -440,10 +440,13 @@ def parseaddr_unicode(addr) -> (str, str): '=?UTF-8?B?TmjGoW4gTmd1eeG7hW4=?= ' -> ('Nhơn Nguyễn', "abcd@gmail.com") """ name, email = parseaddr(addr) - email = email.lower() + email = email.strip().lower() if name: + name = name.strip() decoded_string, charset = decode_header(name)[0] if charset is not None: - return decoded_string.decode(charset), email + name = decoded_string.decode(charset) else: - return decoded_string, email + name = decoded_string + + return name, email diff --git a/tests/test_email_utils.py b/tests/test_email_utils.py index d87ba7e9..16777ca7 100644 --- a/tests/test_email_utils.py +++ b/tests/test_email_utils.py @@ -65,6 +65,9 @@ def test_add_or_replace_header(): def test_parseaddr_unicode(): + # only email + assert parseaddr_unicode("abcd@gmail.com") == ("", "abcd@gmail.com",) + # ascii address assert parseaddr_unicode("First Last ") == ( "First Last",