[Remail] [patch v2 03/11] remail: Use email.utils.parseaddr()

Thomas Gleixner tglx at linutronix.de
Sun Jun 18 22:13:44 CEST 2023


Manual parsing is error prone.

Suggested-by: Konstantin Ryabitsev <konstantin at linuxfoundation.org>
Signed-off-by: Thomas Gleixner <tglx at linutronix.de>
---
 remail/mail.py |    7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

--- 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 @@ re_mail = re.compile('^\w+([\.-]?\w+)*@\
     '''
     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+')
 



More information about the Remail mailing list