From 893b9510dbf81f6dc25a1ae1c9161896cf1c7f82 Mon Sep 17 00:00:00 2001 From: Thomas Gleixner Date: Fri, 16 Jun 2023 22:43:42 +0200 Subject: [PATCH] remail: Use email.utils.parseaddr() Manual parsing is error prone. Suggested-by: Konstantin Ryabitsev Signed-off-by: Thomas Gleixner --- remail/mail.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/remail/mail.py b/remail/mail.py index aae8813..7d2dc3f 100644 --- a/remail/mail.py +++ b/remail/mail.py @@ -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+')