signatures.lore.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
To: signatures@kernel.org
Subject: [PATCH 1/2] Save to/cc headers as-is for tracking
Date: Mon,  3 May 2021 17:14:57 -0400	[thread overview]
Message-ID: <20210503211458.135773-1-konstantin@linuxfoundation.org> (raw)

If we clean the to/cc headers to get rid of all unicode escaping, we run
into a Python bug that is unable to properly parse addresses, e.g.:

In [5]: from email import utils

In [6]: utils.getaddresses(['foo <foo@bar.com>'])
Out[6]: [('foo', 'foo@bar.com')]

In [7]: utils.getaddresses(['Shuming [范書銘] <shumingf@realtek.com>'])
Out[7]:
[('', 'Shuming'),
 ('', ''),
 ('', '范書銘'),
 ('', ''),
 ('', 'shumingf@realtek.com')]

If we store the headers as-is from the original message, we are less
likely to run into this bug, as all non-ascii sequences should be
qp-escaped in the original headers:

=?big5?B?U2h1bWluZyBbrVOu0bvKXQ==?= <shumingf@realtek.com>

This doesn't fix the underlying bug in Python, but works around it.

Reported-by: Mark Brown <broonie@kernel.org>
Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
---
 b4/__init__.py | 11 ++++++++---
 b4/mbox.py     |  4 ++--
 b4/pr.py       |  4 ++--
 3 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/b4/__init__.py b/b4/__init__.py
index ee07f16..32b5c02 100644
--- a/b4/__init__.py
+++ b/b4/__init__.py
@@ -2375,11 +2375,16 @@ def git_get_toplevel(path=None):
     return topdir
 
 
-def format_addrs(pairs):
+def format_addrs(pairs, clean=True):
     addrs = set()
     for pair in pairs:
-        # Remove any quoted-printable header junk from the name
-        addrs.add(email.utils.formataddr((LoreMessage.clean_header(pair[0]), LoreMessage.clean_header(pair[1]))))
+        pair = list(pair)
+        if pair[0] == pair[1]:
+            pair[0] = ''
+        if clean:
+            # Remove any quoted-printable header junk from the name
+            pair[0] = LoreMessage.clean_header(pair[0])
+        addrs.add(email.utils.formataddr(pair))  # noqa
     return ', '.join(addrs)
 
 
diff --git a/b4/mbox.py b/b4/mbox.py
index d84d390..d3bde25 100644
--- a/b4/mbox.py
+++ b/b4/mbox.py
@@ -294,8 +294,8 @@ def thanks_record_am(lser, cherrypick=None):
         'subject': lmsg.full_subject,
         'fromname': lmsg.fromname,
         'fromemail': lmsg.fromemail,
-        'to': b4.format_addrs(allto),
-        'cc': b4.format_addrs(allcc),
+        'to': b4.format_addrs(allto, clean=False),
+        'cc': b4.format_addrs(allcc, clean=False),
         'references': b4.LoreMessage.clean_header(lmsg.msg['References']),
         'sentdate': b4.LoreMessage.clean_header(lmsg.msg['Date']),
         'quote': b4.make_quote(lmsg.body, maxlines=5),
diff --git a/b4/pr.py b/b4/pr.py
index 0ff68f8..5e6c7a1 100644
--- a/b4/pr.py
+++ b/b4/pr.py
@@ -225,8 +225,8 @@ def thanks_record_pr(lmsg):
         'subject': lmsg.full_subject,
         'fromname': lmsg.fromname,
         'fromemail': lmsg.fromemail,
-        'to': b4.format_addrs(allto),
-        'cc': b4.format_addrs(allcc),
+        'to': b4.format_addrs(allto, clean=False),
+        'cc': b4.format_addrs(allcc, clean=False),
         'references': b4.LoreMessage.clean_header(lmsg.msg['References']),
         'remote': lmsg.pr_repo,
         'ref': lmsg.pr_ref,
-- 
2.30.2


             reply	other threads:[~2021-05-03 21:15 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-03 21:14 Konstantin Ryabitsev [this message]
2021-05-03 21:14 ` [PATCH 2/2] Loosen compatible release identifiers for install_requires Konstantin Ryabitsev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210503211458.135773-1-konstantin@linuxfoundation.org \
    --to=konstantin@linuxfoundation.org \
    --cc=signatures@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).