Fix parseaddr_unicode: take into account email only case
This commit is contained in:
parent
6c68b3cda7
commit
c686767d4d
|
@ -440,10 +440,13 @@ def parseaddr_unicode(addr) -> (str, str):
|
||||||
'=?UTF-8?B?TmjGoW4gTmd1eeG7hW4=?= <abcd@gmail.com>' -> ('Nhơn Nguyễn', "abcd@gmail.com")
|
'=?UTF-8?B?TmjGoW4gTmd1eeG7hW4=?= <abcd@gmail.com>' -> ('Nhơn Nguyễn', "abcd@gmail.com")
|
||||||
"""
|
"""
|
||||||
name, email = parseaddr(addr)
|
name, email = parseaddr(addr)
|
||||||
email = email.lower()
|
email = email.strip().lower()
|
||||||
if name:
|
if name:
|
||||||
|
name = name.strip()
|
||||||
decoded_string, charset = decode_header(name)[0]
|
decoded_string, charset = decode_header(name)[0]
|
||||||
if charset is not None:
|
if charset is not None:
|
||||||
return decoded_string.decode(charset), email
|
name = decoded_string.decode(charset)
|
||||||
else:
|
else:
|
||||||
return decoded_string, email
|
name = decoded_string
|
||||||
|
|
||||||
|
return name, email
|
||||||
|
|
|
@ -65,6 +65,9 @@ def test_add_or_replace_header():
|
||||||
|
|
||||||
|
|
||||||
def test_parseaddr_unicode():
|
def test_parseaddr_unicode():
|
||||||
|
# only email
|
||||||
|
assert parseaddr_unicode("abcd@gmail.com") == ("", "abcd@gmail.com",)
|
||||||
|
|
||||||
# ascii address
|
# ascii address
|
||||||
assert parseaddr_unicode("First Last <abcd@gmail.com>") == (
|
assert parseaddr_unicode("First Last <abcd@gmail.com>") == (
|
||||||
"First Last",
|
"First Last",
|
||||||
|
|
Loading…
Reference in New Issue