[PATCH b4] Correctly quote usernames when setting From field

"Lorenzo Stoakes (ARM)" <[email protected]> Tue, 14 Jul 2026 14:28:04 +0100
Newsgroups org.kernel.linux.tools
Message-ID <[email protected]>
make_reply(), get_pr_from_github() and _build_review_email() construct the
email From field without properly quoting the user name and email.

This is especially problematic for users adopting the convention of "Joe
Bloggs (Company) <[email protected]>", as the text contained within parentheses
is interpreted as a comment and dropped.

Resolve the isssue by passing the name and email address through
format_addrs() as is already done for To and Cc fields.

We use clean=False as the username and email have been obtained from git
config user.[name,email] so do not need LoreMessage.clean_header() to be
applied to them.

Signed-off-by: Lorenzo Stoakes (ARM) <[email protected]>
---
 src/b4/__init__.py       | 2 +-
 src/b4/pr.py             | 2 +-
 src/b4/review/_review.py | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/b4/__init__.py b/src/b4/__init__.py
index d7b41ee..2682ae5 100644
--- a/src/b4/__init__.py
+++ b/src/b4/__init__.py
@@ -2530,7 +2530,7 @@ class LoreMessage:
         msg = EmailMessage()
         msg.set_payload(body, charset='utf-8')
         msg['Subject'] = subject
-        msg['From'] = f'{user_name} <{user_email}>'
+        msg['From'] = format_addrs([(user_name, user_email)], clean=False)
         msg['To'] = format_addrs(deduped_to, clean=False)
         if deduped_cc:
             msg['Cc'] = format_addrs(deduped_cc, clean=False)
diff --git a/src/b4/pr.py b/src/b4/pr.py
index 9beaa08..7cf736d 100644
--- a/src/b4/pr.py
+++ b/src/b4/pr.py
@@ -430,7 +430,7 @@ def get_pr_from_github(ghurl: str) -> Optional[b4.LoreMessage]:
         uemail = fake_email
 
     msg = email.message.EmailMessage(policy=b4.emlpolicy)
-    msg['From'] = f'{uname} <{uemail}>'
+    msg['From'] = b4.format_addrs([(uname, uemail)], clean=False)
     title = prdata.get('title', '')
     msg['Subject'] = f'[GIT PULL] {title}'
     msg['Message-Id'] = b4.make_msgid(
diff --git a/src/b4/review/_review.py b/src/b4/review/_review.py
index 8c025ea..a3d82ac 100644
--- a/src/b4/review/_review.py
+++ b/src/b4/review/_review.py
@@ -2841,7 +2841,7 @@ def _build_review_email(
     if not subject.lower().startswith('re:'):
         subject = f'Re: {subject}'
     msg['Subject'] = subject
-    msg['From'] = f'{user_name} <{user_email}>'
+    msg['From'] = b4.format_addrs([(user_name, user_email)], clean=False)
 
     # Build reply headers.  When the user has explicitly edited the
     # To/Cc fields via the ToCcScreen, honour their choices as-is.

---
base-commit: 4217c3e5d3e1eb259626142fd71b91ec6d5e3d1e
change-id: 20260714-b4-fix-from-9abdad884910

Cheers,
-- 
Lorenzo Stoakes (ARM) <[email protected]>