From e3ee85bc13b141c2c380d94f6a93e77e8cf1f311 Mon Sep 17 00:00:00 2001 From: Rikus Goodell Date: Thu, 29 May 2025 13:46:04 -0500 Subject: [PATCH] Additional encoding fix for use with formataddr() in subscription approval. Case CPANEL-47086: A previous fix to decode name into a str before feeding it into formataddr() needed to also be applied to 2 other calls to formataddr(). Changelog: Mailman subscription approval: Fix AttributeError 'bytes' object has no attribute 'encode'. --- Mailman/MailList.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Mailman/MailList.py b/Mailman/MailList.py index a7514d69..32af36de 100644 --- a/Mailman/MailList.py +++ b/Mailman/MailList.py @@ -1024,6 +1024,11 @@ def AddMember(self, userdesc, remote=None): del msg['auto-submitted'] msg['Auto-Submitted'] = autosub msg.send(self) + + # formataddr() expects a str and does its own encoding + if isinstance(name, bytes): + name = name.decode(Utils.GetCharSet(lang)) + who = formataddr((name, email)) syslog('subscribe', '%s: pending %s %s', self.internal_name(), who, by) @@ -1100,6 +1105,12 @@ def ApprovedAddMember(self, userdesc, ack=None, admin_notif=None, text='', kind = ' (digest)' else: kind = '' + + # The formataddr() function, used in two places below, takes a str and performs + # its own encoding, so we should not allow the name to be pre-encoded. + if isinstance(name, bytes): + name = name.decode(Utils.GetCharSet(lang)) + syslog('subscribe', '%s: new%s %s, %s', self.internal_name(), kind, formataddr((name, email)), whence) if ack: @@ -1122,10 +1133,6 @@ def ApprovedAddMember(self, userdesc, ack=None, admin_notif=None, text='', finally: i18n.set_translation(otrans) - # The formataddr() function takes a str and performs its own encoding, so we should not allow the name to be pre-encoded - if isinstance(name, bytes): - name = name.decode(Utils.GetCharSet(lang)) - text = Utils.maketext( "adminsubscribeack.txt", {"listname" : realname,