Mercurial > hg
changeset 43576:14b96072797d
mail: let addressencode() / addrlistencode() return native strings
Avoids conversion to "str" on py3.
author | Denis Laxalde <denis@laxalde.org> |
---|---|
date | Sat, 09 Nov 2019 15:16:52 +0100 |
parents | 67b4439c09b2 |
children | 599e25add437 |
files | hgext/notify.py hgext/patchbomb.py mercurial/mail.py |
diffstat | 3 files changed, 10 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/notify.py Sat Nov 09 12:45:14 2019 +0100 +++ b/hgext/notify.py Sat Nov 09 15:16:52 2019 +0100 @@ -430,14 +430,14 @@ sender = self.ui.config(b'email', b'from') or self.ui.username() if b'@' not in sender or b'@localhost' in sender: sender = self.fixmail(sender) - msg['From'] = encoding.strfromlocal( - mail.addressencode(self.ui, sender, self.charsets, self.test) + msg['From'] = mail.addressencode( + self.ui, sender, self.charsets, self.test ) msg['X-Hg-Notification'] = 'changeset %s' % ctx if not msg['Message-Id']: msg['Message-Id'] = messageid(ctx, self.domain, self.messageidseed) - msg['To'] = encoding.strfromlocal(b', '.join(sorted(subs))) + msg['To'] = ', '.join(sorted(subs)) msgtext = msg.as_bytes() if pycompat.ispy3 else msg.as_string() if self.test:
--- a/hgext/patchbomb.py Sat Nov 09 12:45:14 2019 +0100 +++ b/hgext/patchbomb.py Sat Nov 09 15:16:52 2019 +0100 @@ -943,13 +943,13 @@ start_time = (start_time[0] + 1, start_time[1]) m[b'From'] = sender - m[b'To'] = b', '.join(to) + m[b'To'] = ', '.join(to) if cc: - m[b'Cc'] = b', '.join(cc) + m[b'Cc'] = ', '.join(cc) if bcc: - m[b'Bcc'] = b', '.join(bcc) + m[b'Bcc'] = ', '.join(bcc) if replyto: - m[b'Reply-To'] = b', '.join(replyto) + m[b'Reply-To'] = ', '.join(replyto) # Fix up all headers to be native strings. # TODO(durin42): this should probably be cleaned up above in the future. if pycompat.ispy3: @@ -992,7 +992,6 @@ generator = mail.Generator(fp, mangle_from_=False) generator.flatten(m, 0) alldests = to + bcc + cc - alldests = [encoding.strfromlocal(d) for d in alldests] sendmail(sender_addr, alldests, fp.getvalue()) progress.complete()
--- a/mercurial/mail.py Sat Nov 09 12:45:14 2019 +0100 +++ b/mercurial/mail.py Sat Nov 09 15:16:52 2019 +0100 @@ -385,15 +385,13 @@ addr.decode('ascii') except UnicodeDecodeError: raise error.Abort(_(b'invalid local address: %s') % addr) - return pycompat.bytesurl( - email.utils.formataddr((name, encoding.strfromlocal(addr))) - ) + return email.utils.formataddr((name, encoding.strfromlocal(addr))) def addressencode(ui, address, charsets=None, display=False): '''Turns address into RFC-2047 compliant header.''' if display or not address: - return address or b'' + return encoding.strfromlocal(address or b'') name, addr = email.utils.parseaddr(encoding.strfromlocal(address)) return _addressencode(ui, name, encoding.strtolocal(addr), charsets) @@ -405,7 +403,7 @@ for a in addrs: assert isinstance(a, bytes), '%r unexpectedly not a bytestr' % a if display: - return [a.strip() for a in addrs if a.strip()] + return [encoding.strfromlocal(a.strip()) for a in addrs if a.strip()] result = [] for name, addr in email.utils.getaddresses(