##// END OF EJS Templates
notify: a ton of encoding dancing to deal with the email module...
Augie Fackler -
r40340:f6ef89cf default
parent child Browse files
Show More
@@ -149,6 +149,7 b' import time'
149
149
150 from mercurial.i18n import _
150 from mercurial.i18n import _
151 from mercurial import (
151 from mercurial import (
152 encoding,
152 error,
153 error,
153 logcmdutil,
154 logcmdutil,
154 mail,
155 mail,
@@ -361,13 +362,14 b' class notifier(object):'
361
362
362 p = emailparser.Parser()
363 p = emailparser.Parser()
363 try:
364 try:
364 msg = p.parsestr(data)
365 msg = p.parsestr(encoding.strfromlocal(data))
365 except emailerrors.MessageParseError as inst:
366 except emailerrors.MessageParseError as inst:
366 raise error.Abort(inst)
367 raise error.Abort(inst)
367
368
368 # store sender and subject
369 # store sender and subject
369 sender, subject = msg['From'], msg['Subject']
370 sender = encoding.strtolocal(msg[r'From'])
370 del msg['From'], msg['Subject']
371 subject = encoding.strtolocal(msg[r'Subject'])
372 del msg[r'From'], msg[r'Subject']
371
373
372 if not msg.is_multipart():
374 if not msg.is_multipart():
373 # create fresh mime message from scratch
375 # create fresh mime message from scratch
@@ -380,7 +382,8 b' class notifier(object):'
380 for k, v in headers:
382 for k, v in headers:
381 msg[k] = v
383 msg[k] = v
382
384
383 msg['Date'] = dateutil.datestr(format="%a, %d %b %Y %H:%M:%S %1%2")
385 msg[r'Date'] = encoding.strfromlocal(
386 dateutil.datestr(format="%a, %d %b %Y %H:%M:%S %1%2"))
384
387
385 # try to make subject line exist and be useful
388 # try to make subject line exist and be useful
386 if not subject:
389 if not subject:
@@ -392,25 +395,26 b' class notifier(object):'
392 maxsubject = int(self.ui.config('notify', 'maxsubject'))
395 maxsubject = int(self.ui.config('notify', 'maxsubject'))
393 if maxsubject:
396 if maxsubject:
394 subject = stringutil.ellipsis(subject, maxsubject)
397 subject = stringutil.ellipsis(subject, maxsubject)
395 msg['Subject'] = mail.headencode(self.ui, subject,
398 msg[r'Subject'] = encoding.strfromlocal(
396 self.charsets, self.test)
399 mail.headencode(self.ui, subject, self.charsets, self.test))
397
400
398 # try to make message have proper sender
401 # try to make message have proper sender
399 if not sender:
402 if not sender:
400 sender = self.ui.config('email', 'from') or self.ui.username()
403 sender = self.ui.config('email', 'from') or self.ui.username()
401 if '@' not in sender or '@localhost' in sender:
404 if '@' not in sender or '@localhost' in sender:
402 sender = self.fixmail(sender)
405 sender = self.fixmail(sender)
403 msg['From'] = mail.addressencode(self.ui, sender,
406 msg[r'From'] = encoding.strfromlocal(
404 self.charsets, self.test)
407 mail.addressencode(self.ui, sender, self.charsets, self.test))
405
408
406 msg['X-Hg-Notification'] = 'changeset %s' % ctx
409 msg[r'X-Hg-Notification'] = r'changeset %s' % ctx
407 if not msg['Message-Id']:
410 if not msg[r'Message-Id']:
408 msg['Message-Id'] = ('<hg.%s.%s.%s@%s>' %
411 msg[r'Message-Id'] = encoding.strfromlocal(
409 (ctx, int(time.time()),
412 '<hg.%s.%d.%d@%s>' % (ctx, int(time.time()),
410 hash(self.repo.root), socket.getfqdn()))
413 hash(self.repo.root),
411 msg['To'] = ', '.join(sorted(subs))
414 encoding.strtolocal(socket.getfqdn())))
415 msg[r'To'] = encoding.strfromlocal(', '.join(sorted(subs)))
412
416
413 msgtext = msg.as_string()
417 msgtext = encoding.strtolocal(msg.as_string())
414 if self.test:
418 if self.test:
415 self.ui.write(msgtext)
419 self.ui.write(msgtext)
416 if not msgtext.endswith('\n'):
420 if not msgtext.endswith('\n'):
@@ -418,7 +422,7 b' class notifier(object):'
418 else:
422 else:
419 self.ui.status(_('notify: sending %d subscribers %d changes\n') %
423 self.ui.status(_('notify: sending %d subscribers %d changes\n') %
420 (len(subs), count))
424 (len(subs), count))
421 mail.sendmail(self.ui, stringutil.email(msg['From']),
425 mail.sendmail(self.ui, stringutil.email(msg[r'From']),
422 subs, msgtext, mbox=self.mbox)
426 subs, msgtext, mbox=self.mbox)
423
427
424 def diff(self, ctx, ref=None):
428 def diff(self, ctx, ref=None):
General Comments 0
You need to be logged in to leave comments. Login now