remail: Use email.utils.parseaddr()

Manual parsing is error prone.

Suggested-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
This commit is contained in:
Thomas Gleixner 2023-06-16 22:43:42 +02:00
parent c8ac6b5a08
commit 893b9510db

View file

@ -4,7 +4,7 @@
#
# Mail message related code
from email.utils import make_msgid, formatdate
from email.utils import make_msgid, formatdate, parseaddr
from email.header import Header, decode_header
from email import message_from_string, message_from_bytes
from email.generator import Generator
@ -150,10 +150,7 @@ def get_raw_email_addr(addr):
'''
Return the raw mail address, name and brackets stripped off.
'''
try:
return addr.split('<')[1].split('>')[0].strip()
except:
return addr
return parseaddr(addr)[1]
re_compress_space = re.compile('\s+')