Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7A297C433ED for ; Mon, 3 May 2021 21:15:00 +0000 (UTC) Received: by mail.kernel.org (Postfix) id 5B6AF61104; Mon, 3 May 2021 21:15:00 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 19F3861176 for ; Mon, 3 May 2021 21:15:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620076500; bh=7yuQ9WgLXMLMKNwWDe84cPF/KRpyC9+krBam/EZLHf0=; h=From:List-Id:To:Subject:Date:From; b=hT4px1AFCgWo3Fj4lyYlV+2T5FOuMyu8CbGCXIYk79hHzHPttfZAeg9SS4/HUhnpn TcxE/lrpBpURVtkkGTdAtwCWZn+23LiIAe6eLdUV7jnC67SEz1hbM2qlQxS/TEGygu ZphRmtzhZ5c7IWTDxXA0knfDQalm2BBoyma8K7U0= From: Konstantin Ryabitsev List-Id: 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 Message-Id: <20210503211458.135773-1-konstantin@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Developer-Signature: v=1; a=openpgp-sha256; h=from:subject; l=3128; bh=/yZjhtdR78EKKD5q7jZrMZJHyKFtlz618hhhN90bxG8=; b=owGbwMvMwCG27YjM47CUmTmMp9WSGBImpG0Jl5ur5z6poCTh1nfp4pvtZ74vUVGaY+9RfCbM92Ne /QntjlIWBjEOBlkxRZayfbGbggofesil95jCzGFlAhnCwMUpABNhSGBkuHdTiXVHoeUNve8JszgjTV bfWV5RdUjf/f77z84nlbsWqjD8d5ntdGzBwuSMhb0B96xuL5985E4oS/q984vD4kzjurqOswAA Content-Transfer-Encoding: quoted-printable If we clean the to/cc headers to get rid of all unicode escaping, we run=0D into a Python bug that is unable to properly parse addresses, e.g.:=0D =0D In [5]: from email import utils=0D =0D In [6]: utils.getaddresses(['foo '])=0D Out[6]: [('foo', 'foo@bar.com')]=0D =0D In [7]: utils.getaddresses(['Shuming [=E8=8C=83=E6=9B=B8=E9=8A=98] '])=0D Out[7]:=0D [('', 'Shuming'),=0D ('', ''),=0D ('', '=E8=8C=83=E6=9B=B8=E9=8A=98'),=0D ('', ''),=0D ('', 'shumingf@realtek.com')]=0D =0D If we store the headers as-is from the original message, we are less=0D likely to run into this bug, as all non-ascii sequences should be=0D qp-escaped in the original headers:=0D =0D =3D?big5?B?U2h1bWluZyBbrVOu0bvKXQ=3D=3D?=3D =0D =0D This doesn't fix the underlying bug in Python, but works around it.=0D =0D Reported-by: Mark Brown =0D Signed-off-by: Konstantin Ryabitsev =0D ---=0D b4/__init__.py | 11 ++++++++---=0D b4/mbox.py | 4 ++--=0D b4/pr.py | 4 ++--=0D 3 files changed, 12 insertions(+), 7 deletions(-)=0D =0D diff --git a/b4/__init__.py b/b4/__init__.py=0D index ee07f16..32b5c02 100644=0D --- a/b4/__init__.py=0D +++ b/b4/__init__.py=0D @@ -2375,11 +2375,16 @@ def git_get_toplevel(path=3DNone):=0D return topdir=0D =0D =0D -def format_addrs(pairs):=0D +def format_addrs(pairs, clean=3DTrue):=0D addrs =3D set()=0D for pair in pairs:=0D - # Remove any quoted-printable header junk from the name=0D - addrs.add(email.utils.formataddr((LoreMessage.clean_header(pair[0]= ), LoreMessage.clean_header(pair[1]))))=0D + pair =3D list(pair)=0D + if pair[0] =3D=3D pair[1]:=0D + pair[0] =3D ''=0D + if clean:=0D + # Remove any quoted-printable header junk from the name=0D + pair[0] =3D LoreMessage.clean_header(pair[0])=0D + addrs.add(email.utils.formataddr(pair)) # noqa=0D return ', '.join(addrs)=0D =0D =0D diff --git a/b4/mbox.py b/b4/mbox.py=0D index d84d390..d3bde25 100644=0D --- a/b4/mbox.py=0D +++ b/b4/mbox.py=0D @@ -294,8 +294,8 @@ def thanks_record_am(lser, cherrypick=3DNone):=0D 'subject': lmsg.full_subject,=0D 'fromname': lmsg.fromname,=0D 'fromemail': lmsg.fromemail,=0D - 'to': b4.format_addrs(allto),=0D - 'cc': b4.format_addrs(allcc),=0D + 'to': b4.format_addrs(allto, clean=3DFalse),=0D + 'cc': b4.format_addrs(allcc, clean=3DFalse),=0D 'references': b4.LoreMessage.clean_header(lmsg.msg['References']),= =0D 'sentdate': b4.LoreMessage.clean_header(lmsg.msg['Date']),=0D 'quote': b4.make_quote(lmsg.body, maxlines=3D5),=0D diff --git a/b4/pr.py b/b4/pr.py=0D index 0ff68f8..5e6c7a1 100644=0D --- a/b4/pr.py=0D +++ b/b4/pr.py=0D @@ -225,8 +225,8 @@ def thanks_record_pr(lmsg):=0D 'subject': lmsg.full_subject,=0D 'fromname': lmsg.fromname,=0D 'fromemail': lmsg.fromemail,=0D - 'to': b4.format_addrs(allto),=0D - 'cc': b4.format_addrs(allcc),=0D + 'to': b4.format_addrs(allto, clean=3DFalse),=0D + 'cc': b4.format_addrs(allcc, clean=3DFalse),=0D 'references': b4.LoreMessage.clean_header(lmsg.msg['References']),= =0D 'remote': lmsg.pr_repo,=0D 'ref': lmsg.pr_ref,=0D -- =0D 2.30.2=0D =0D