Linux maintainer tooling and workflows
 help / color / Atom feed
* [PATCH 1/2] list-archive-maker: collect recipents in lists instead of strings
@ 2021-04-14 14:12 Uwe Kleine-König
  2021-04-14 14:12 ` [PATCH 2/2] list-archive-maker: better handle mails with misencoded real names Uwe Kleine-König
  2021-04-15 15:07 ` [PATCH 1/2] list-archive-maker: collect recipents in lists instead of strings Konstantin Ryabitsev
  0 siblings, 2 replies; 3+ messages in thread
From: Uwe Kleine-König @ 2021-04-14 14:12 UTC (permalink / raw)
  To: tools

This is more pythonic and should also be quicker to execute.

Note there is an (intended) side effect of this change. If cc already
contains "twentyone@example.com" and pair[1] is "one@example.com", the
latter was detected as already contained in cc.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 list-archive-maker.py | 22 ++++++++--------------
 1 file changed, 8 insertions(+), 14 deletions(-)

diff --git a/list-archive-maker.py b/list-archive-maker.py
index 7e1d276bdf62..b4050198e16a 100755
--- a/list-archive-maker.py
+++ b/list-archive-maker.py
@@ -139,8 +139,8 @@ def process_archives(sources, outdir, msgids, listids, rejectsfile):
             # Remove headers not in WANTHDRS list and any Received:
             # lines that do not mention the list email address
             newhdrs = []
-            to = ''
-            cc = ''
+            to = []
+            cc = []
             recvtime = None
             is_our_list = False
             for hdrname, hdrval in list(msg._headers): # noqa
@@ -196,32 +196,26 @@ def process_archives(sources, outdir, msgids, listids, rejectsfile):
 
                 elif lhdrname == 'to':
                     for pair in email.utils.getaddresses([hdrval]):
-                        if cc.find(pair[1]) >= 0:
+                        if pair[1] in cc:
                             # already in Cc, so no need to add it to To
                             continue
-                        if len(to) and to.find(pair[1]) < 0:
-                            to += ', %s' % email.utils.formataddr(pair)
-                        else:
-                            to += email.utils.formataddr(pair)
+                        to.append(email.utils.formataddr(pair))
 
                 elif lhdrname == 'cc':
                     for pair in email.utils.getaddresses([hdrval]):
-                        if to.find(pair[1]) >= 0:
+                        if pair[1] in to:
                             # already in To, so no need to add it to CCs
                             continue
-                        if len(cc) and cc.find(pair[1]) < 0:
-                            cc += ', %s' % email.utils.formataddr(pair)
-                        else:
-                            cc += email.utils.formataddr(pair)
+                        cc.append(email.utils.formataddr(pair))
 
                 else:
                     newhdrs.append((hdrname, hdrval))
 
             if len(to):
-                newhdrs.append(('To', to))
+                newhdrs.append(('To', ', '.join(to)))
 
             if len(cc):
-                newhdrs.append(('Cc', cc))
+                newhdrs.append(('Cc', ', '.join(cc)))
 
             if not is_our_list:
                 # Sometimes a message is cc'd to multiple mailing lists and the

base-commit: 45172ee760eb6210d9c153b6fe92888c79b662b0
-- 
2.29.2


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] list-archive-maker: better handle mails with misencoded real names
  2021-04-14 14:12 [PATCH 1/2] list-archive-maker: collect recipents in lists instead of strings Uwe Kleine-König
@ 2021-04-14 14:12 ` Uwe Kleine-König
  2021-04-15 15:07 ` [PATCH 1/2] list-archive-maker: collect recipents in lists instead of strings Konstantin Ryabitsev
  1 sibling, 0 replies; 3+ messages in thread
From: Uwe Kleine-König @ 2021-04-14 14:12 UTC (permalink / raw)
  To: tools

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 --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))
-- 
2.29.2


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] list-archive-maker: collect recipents in lists instead of strings
  2021-04-14 14:12 [PATCH 1/2] list-archive-maker: collect recipents in lists instead of strings Uwe Kleine-König
  2021-04-14 14:12 ` [PATCH 2/2] list-archive-maker: better handle mails with misencoded real names Uwe Kleine-König
@ 2021-04-15 15:07 ` Konstantin Ryabitsev
  1 sibling, 0 replies; 3+ messages in thread
From: Konstantin Ryabitsev @ 2021-04-15 15:07 UTC (permalink / raw)
  To: Uwe Kleine-König, tools; +Cc: Konstantin Ryabitsev

On Wed, 14 Apr 2021 16:12:34 +0200, Uwe Kleine-König wrote:
> This is more pythonic and should also be quicker to execute.
> 
> Note there is an (intended) side effect of this change. If cc already
> contains "twentyone@example.com" and pair[1] is "one@example.com", the
> latter was detected as already contained in cc.

Applied, thanks!

[1/2] list-archive-maker: collect recipents in lists instead of strings
      commit: bade6f603831c88ce54eed656f453d1101402451
[2/2] list-archive-maker: better handle mails with misencoded real names
      commit: 21a3a883974f0bc9569aef0fcc6e14706b810f31

Best regards,
-- 
Konstantin Ryabitsev <konstantin@linuxfoundation.org>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-14 14:12 [PATCH 1/2] list-archive-maker: collect recipents in lists instead of strings Uwe Kleine-König
2021-04-14 14:12 ` [PATCH 2/2] list-archive-maker: better handle mails with misencoded real names Uwe Kleine-König
2021-04-15 15:07 ` [PATCH 1/2] list-archive-maker: collect recipents in lists instead of strings Konstantin Ryabitsev

Linux maintainer tooling and workflows

Archives are clonable:
	git clone --mirror https://lore.kernel.org/tools/0 tools/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 tools tools/ https://lore.kernel.org/tools \
		tools@linux.kernel.org
	public-inbox-index tools

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.linux.tools


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git