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