Skip to contentSkip to conversation

Fix broken fallback to user.email

PATCH Applied Jonas Rebmann 3 participants 3 messages Jul 18, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix broken fallback to user.email

After conversion to string, fromaddr becomes "None" as a string literal, so the user.email fallback would never be reached if sendemail.from is unset, eventually leading to smtplib.SMTPSenderRefused (<None>: sender address must contain a domain').

Convert to string after the check.

Fixes 742e017c1b ("Cleanup: initial round addressing typing issues reported by mypy")
---
 src/b4/__init__.py | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
src/b4/__init__.py +4 -2
index ff6075e..c116344 100644
@@ -3949,8 +3949,10 @@ def get_sendemail_config() -> Dict[str, Optional[Union[str, List[str]]]]:
 def get_smtp(dryrun: bool = False) -> Tuple[Union[smtplib.SMTP, smtplib.SMTP_SSL, List[str], None], str]:
     sconfig = get_sendemail_config()
     # Limited support for smtp settings to begin with, but should cover the vast majority of cases
-    fromaddr = str(sconfig.get('from'))
-    if not fromaddr:
+    fromaddr = sconfig.get('from')
+    if fromaddr:
+        fromaddr = str(fromaddr)
+    else:
         # We fall back to user.email
         usercfg = get_user_config()
         fromaddr = str(usercfg['email'])

---
base-commit: a9b2aba54be85ea2933c43b8a6d71c1611230b59
change-id: 20250718-fromaddr-80e73bb6fd2d

Best regards,

Signature · 1 line
Jonas Rebmann <[email protected]>
Reviewed-by on v1 1/1
#1 lore raw
Quoted 20 lines · Jonas Rebmann

After conversion to string, fromaddr becomes "None" as a string literal, so the user.email fallback would never be reached if sendemail.from is unset, eventually leading to smtplib.SMTPSenderRefused (<None>: sender address must contain a domain').

Convert to string after the check.

Fixes 742e017c1b ("Cleanup: initial round addressing typing issues reported by mypy")
---
 src/b4/__init__.py | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
src/b4/__init__.py +0 -0
index ff6075e..c116344 100644
@@ -3949,8 +3949,10 @@ def get_sendemail_config() -> Dict[str, Optional[Union[str, List[str]]]]:
 def get_smtp(dryrun: bool = False) -> Tuple[Union[smtplib.SMTP, smtplib.SMTP_SSL, List[str], None], str]:
     sconfig = get_sendemail_config()

src/b4/__init__.py def get_sendemail_config() -> Dict[str, Optional[Union[str, List[str]]]]: · line 3958

Quoted 10 lines
src/b4/__init__.py +4 -2
     # Limited support for smtp settings to begin with, but should cover the vast majority of cases
-    fromaddr = str(sconfig.get('from'))
-    if not fromaddr:
+    fromaddr = sconfig.get('from')
+    if fromaddr:
+        fromaddr = str(fromaddr)
+    else:
         # We fall back to user.email
         usercfg = get_user_config()
         fromaddr = str(usercfg['email'])
Reviewed-by [email protected]
#2 lore raw
In reply to Jonas Rebmann
Quoted 8 lines · Jonas Rebmann

After conversion to string, fromaddr becomes "None" as a string literal, so the user.email fallback would never be reached if sendemail.from is unset, eventually leading to smtplib.SMTPSenderRefused (<None>: sender address must contain a domain').

Convert to string after the check.

[...]

Applied, thanks!

[1/1] Fix broken fallback to user.email

      commit: 5c822eded2b6f9df67f3e860a8a0017b440471da

Best regards,

Signature · 1 line
Konstantin Ryabitsev <[email protected]>