diff options
author | Uwe Kleine-König <u.kleine-koenig@pengutronix.de> | 2021-04-14 16:12:34 +0200 |
---|---|---|
committer | Konstantin Ryabitsev <konstantin@linuxfoundation.org> | 2021-04-15 11:02:58 -0400 |
commit | bade6f603831c88ce54eed656f453d1101402451 (patch) | |
tree | 6e4403b62650c89ebd14cc7078695a0278556333 | |
parent | cbf789d9fd29470e8c120a5a7f17a46d8fd2a99b (diff) | |
download | korg-helpers-bade6f603831c88ce54eed656f453d1101402451.tar.gz |
list-archive-maker: collect recipents in lists instead of strings
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>
Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
Link: https://lore.kernel.org/r/20210414141235.26630-1-u.kleine-koenig@pengutronix.de
-rwxr-xr-x | list-archive-maker.py | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/list-archive-maker.py b/list-archive-maker.py index 7e1d276..b405019 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 |