diff mbox series

Quote author name when creating am message.

Message ID 5de6864e5999c398700712fdce5d52c77d8b0a2a.1686057776.git.dev@jpoiret.xyz (mailing list archive)
State Superseded
Headers show
Series Quote author name when creating am message. | expand

Commit Message

Josselin Poiret June 6, 2023, 1:23 p.m. UTC
From: Josselin Poiret <dev@jpoiret.xyz>

Previously, if an author name needed to be quoted, `git am` would create an mbox
with invalid From: lines, such as with [1].  Escape author name in all cases.

[1] https://yhetil.org/guix-patches/20230428191905.13860-1-paren@disroot.org/

Signed-off-by: Josselin Poiret <dev@jpoiret.xyz>
---
 b4/__init__.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)


base-commit: c6835b7538331fc84b3743f57812181acd71dab6

Comments

Konstantin Ryabitsev June 22, 2023, 8:51 p.m. UTC | #1
On Tue, Jun 06, 2023 at 03:23:18PM +0200, Josselin Poiret wrote:
> From: Josselin Poiret <dev@jpoiret.xyz>
> 
> Previously, if an author name needed to be quoted, `git am` would create an mbox
> with invalid From: lines, such as with [1].  Escape author name in all cases.

Thank you for the report. I didn't take the patch, because there is a better
way to do it, but I did give you credit in the commit:

https://git.kernel.org/pub/scm/utils/b4/b4.git/commit/?id=87aacf279afc3c1eda7b2e6e02e70842b4f99bc7

Best regards,
Konstantin
Josselin Poiret June 24, 2023, 10:13 a.m. UTC | #2
Hi Konstantin,

Konstantin Ryabitsev <konstantin@linuxfoundation.org> writes:

> Thank you for the report. I didn't take the patch, because there is a better
> way to do it, but I did give you credit in the commit:
>
> https://git.kernel.org/pub/scm/utils/b4/b4.git/commit/?id=87aacf279afc3c1eda7b2e6e02e70842b4f99bc7

It was my first time looking at b4's source so I'm thankful for the more
idiomatic code!  I'm hoping to contribute more to b4 in the future since
we're trying to use that more and more in GNU Guix.

Best,
diff mbox series

Patch

diff --git a/b4/__init__.py b/b4/__init__.py
index 9b1f69c..a1a5c92 100644
--- a/b4/__init__.py
+++ b/b4/__init__.py
@@ -2026,7 +2026,8 @@  class LoreMessage:
 
         am_msg = email.message.EmailMessage()
         if i.get('Author'):
-            hfrom = f'{i.get("Author")} <{i.get("Email")}>'
+            quoted_author = email.utils.quote(i.get("Author"))
+            hfrom = f'"{quoted_author}" <{i.get("Email")}>'
         else:
             hfrom = i.get('Email')
         am_msg.add_header('Subject', self.get_am_subject(indicate_reroll=False, use_subject=i.get('Subject')))