comparison mercurial/mail.py @ 39031:2cf3bd4ae55e

mail: properly handle email addresses typically being unicodes Visible progress in test-patchbomb.t on Python 3. Differential Revision: https://phab.mercurial-scm.org/D4221
author Augie Fackler <augie@google.com>
date Thu, 09 Aug 2018 18:27:36 -0400
parents 713126389ef2
children ede768cfe83e
comparison
equal deleted inserted replaced
39030:1eb779a86c4e 39031:2cf3bd4ae55e
150 return send 150 return send
151 151
152 def _sendmail(ui, sender, recipients, msg): 152 def _sendmail(ui, sender, recipients, msg):
153 '''send mail using sendmail.''' 153 '''send mail using sendmail.'''
154 program = ui.config('email', 'method') 154 program = ui.config('email', 'method')
155 cmdline = '%s -f %s %s' % (program, stringutil.email(sender), 155 stremail = lambda x: stringutil.email(encoding.strtolocal(x))
156 ' '.join(map(stringutil.email, recipients))) 156 cmdline = '%s -f %s %s' % (program, stremail(sender),
157 ' '.join(map(stremail, recipients)))
157 ui.note(_('sending mail: %s\n') % cmdline) 158 ui.note(_('sending mail: %s\n') % cmdline)
158 fp = procutil.popen(cmdline, 'wb') 159 fp = procutil.popen(cmdline, 'wb')
159 fp.write(util.tonativeeol(msg)) 160 fp.write(util.tonativeeol(msg))
160 ret = fp.close() 161 ret = fp.close()
161 if ret: 162 if ret:
167 '''write mails to mbox''' 168 '''write mails to mbox'''
168 fp = open(mbox, 'ab+') 169 fp = open(mbox, 'ab+')
169 # Should be time.asctime(), but Windows prints 2-characters day 170 # Should be time.asctime(), but Windows prints 2-characters day
170 # of month instead of one. Make them print the same thing. 171 # of month instead of one. Make them print the same thing.
171 date = time.strftime(r'%a %b %d %H:%M:%S %Y', time.localtime()) 172 date = time.strftime(r'%a %b %d %H:%M:%S %Y', time.localtime())
172 fp.write('From %s %s\n' % (sender, date)) 173 fp.write('From %s %s\n' % (encoding.strtolocal(sender),
174 encoding.strtolocal(date)))
173 fp.write(msg) 175 fp.write(msg)
174 fp.write('\n\n') 176 fp.write('\n\n')
175 fp.close() 177 fp.close()
176 178
177 def connect(ui, mbox=None): 179 def connect(ui, mbox=None):