##// END OF EJS Templates
mail: let addressencode() / addrlistencode() return native strings...
Denis Laxalde -
r43976:14b96072 default
parent child Browse files
Show More
@@ -430,14 +430,14 b' class notifier(object):'
430 430 sender = self.ui.config(b'email', b'from') or self.ui.username()
431 431 if b'@' not in sender or b'@localhost' in sender:
432 432 sender = self.fixmail(sender)
433 msg['From'] = encoding.strfromlocal(
434 mail.addressencode(self.ui, sender, self.charsets, self.test)
433 msg['From'] = mail.addressencode(
434 self.ui, sender, self.charsets, self.test
435 435 )
436 436
437 437 msg['X-Hg-Notification'] = 'changeset %s' % ctx
438 438 if not msg['Message-Id']:
439 439 msg['Message-Id'] = messageid(ctx, self.domain, self.messageidseed)
440 msg['To'] = encoding.strfromlocal(b', '.join(sorted(subs)))
440 msg['To'] = ', '.join(sorted(subs))
441 441
442 442 msgtext = msg.as_bytes() if pycompat.ispy3 else msg.as_string()
443 443 if self.test:
@@ -943,13 +943,13 b' def email(ui, repo, *revs, **opts):'
943 943
944 944 start_time = (start_time[0] + 1, start_time[1])
945 945 m[b'From'] = sender
946 m[b'To'] = b', '.join(to)
946 m[b'To'] = ', '.join(to)
947 947 if cc:
948 m[b'Cc'] = b', '.join(cc)
948 m[b'Cc'] = ', '.join(cc)
949 949 if bcc:
950 m[b'Bcc'] = b', '.join(bcc)
950 m[b'Bcc'] = ', '.join(bcc)
951 951 if replyto:
952 m[b'Reply-To'] = b', '.join(replyto)
952 m[b'Reply-To'] = ', '.join(replyto)
953 953 # Fix up all headers to be native strings.
954 954 # TODO(durin42): this should probably be cleaned up above in the future.
955 955 if pycompat.ispy3:
@@ -992,7 +992,6 b' def email(ui, repo, *revs, **opts):'
992 992 generator = mail.Generator(fp, mangle_from_=False)
993 993 generator.flatten(m, 0)
994 994 alldests = to + bcc + cc
995 alldests = [encoding.strfromlocal(d) for d in alldests]
996 995 sendmail(sender_addr, alldests, fp.getvalue())
997 996
998 997 progress.complete()
@@ -385,15 +385,13 b' def _addressencode(ui, name, addr, chars'
385 385 addr.decode('ascii')
386 386 except UnicodeDecodeError:
387 387 raise error.Abort(_(b'invalid local address: %s') % addr)
388 return pycompat.bytesurl(
389 email.utils.formataddr((name, encoding.strfromlocal(addr)))
390 )
388 return email.utils.formataddr((name, encoding.strfromlocal(addr)))
391 389
392 390
393 391 def addressencode(ui, address, charsets=None, display=False):
394 392 '''Turns address into RFC-2047 compliant header.'''
395 393 if display or not address:
396 return address or b''
394 return encoding.strfromlocal(address or b'')
397 395 name, addr = email.utils.parseaddr(encoding.strfromlocal(address))
398 396 return _addressencode(ui, name, encoding.strtolocal(addr), charsets)
399 397
@@ -405,7 +403,7 b' def addrlistencode(ui, addrs, charsets=N'
405 403 for a in addrs:
406 404 assert isinstance(a, bytes), '%r unexpectedly not a bytestr' % a
407 405 if display:
408 return [a.strip() for a in addrs if a.strip()]
406 return [encoding.strfromlocal(a.strip()) for a in addrs if a.strip()]
409 407
410 408 result = []
411 409 for name, addr in email.utils.getaddresses(
General Comments 0
You need to be logged in to leave comments. Login now