diff mbox series

[2/2] list-archive-maker: better handle mails with misencoded real names

Message ID 20210414141235.26630-2-u.kleine-koenig@pengutronix.de (mailing list archive)
State New, archived
Headers show
Series [1/2] list-archive-maker: collect recipents in lists instead of strings | expand

Commit Message

Uwe Kleine-König April 14, 2021, 2:12 p.m. UTC
Without this change list-archive-maker just dies with an Exception

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 list-archive-maker.py | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/list-archive-maker.py b/list-archive-maker.py
index b4050198e16a..eed4807dfab8 100755
--- a/list-archive-maker.py
+++ b/list-archive-maker.py
@@ -62,6 +62,13 @@  WANTHDRS = {'return-path',
 
 __VERSION__ = '2.0'
 
+def formataddr(pair):
+    try:
+        return email.utils.formataddr(pair)
+    except UnicodeEncodeError:
+        # This might happen if the realname is encoded in a broken way; just
+        # drop the real name then.
+        return email.utils.formataddr((None, pair[1]))
 
 def process_archives(sources, outdir, msgids, listids, rejectsfile):
     outboxes = {}
@@ -199,14 +206,14 @@  def process_archives(sources, outdir, msgids, listids, rejectsfile):
                         if pair[1] in cc:
                             # already in Cc, so no need to add it to To
                             continue
-                        to.append(email.utils.formataddr(pair))
+                        to.append(formataddr(pair))
 
                 elif lhdrname == 'cc':
                     for pair in email.utils.getaddresses([hdrval]):
                         if pair[1] in to:
                             # already in To, so no need to add it to CCs
                             continue
-                        cc.append(email.utils.formataddr(pair))
+                        cc.append(formataddr(pair))
 
                 else:
                     newhdrs.append((hdrname, hdrval))