D5100: notify: a ton of encoding dancing to deal with the email module
durin42 (Augie Fackler)
phabricator at mercurial-scm.org
Sun Oct 14 09:03:36 EDT 2018
durin42 updated this revision to Diff 12133.
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D5100?vs=12116&id=12133
REVISION DETAIL
https://phab.mercurial-scm.org/D5100
AFFECTED FILES
hgext/notify.py
CHANGE DETAILS
diff --git a/hgext/notify.py b/hgext/notify.py
--- a/hgext/notify.py
+++ b/hgext/notify.py
@@ -149,6 +149,7 @@
from mercurial.i18n import _
from mercurial import (
+ encoding,
error,
logcmdutil,
mail,
@@ -361,13 +362,14 @@
p = emailparser.Parser()
try:
- msg = p.parsestr(data)
+ msg = p.parsestr(encoding.strfromlocal(data))
except emailerrors.MessageParseError as inst:
raise error.Abort(inst)
# store sender and subject
- sender, subject = msg['From'], msg['Subject']
- del msg['From'], msg['Subject']
+ sender = encoding.strtolocal(msg[r'From'])
+ subject = encoding.strtolocal(msg[r'Subject'])
+ del msg[r'From'], msg[r'Subject']
if not msg.is_multipart():
# create fresh mime message from scratch
@@ -380,7 +382,8 @@
for k, v in headers:
msg[k] = v
- msg['Date'] = dateutil.datestr(format="%a, %d %b %Y %H:%M:%S %1%2")
+ msg[r'Date'] = encoding.strfromlocal(
+ dateutil.datestr(format="%a, %d %b %Y %H:%M:%S %1%2"))
# try to make subject line exist and be useful
if not subject:
@@ -392,33 +395,34 @@
maxsubject = int(self.ui.config('notify', 'maxsubject'))
if maxsubject:
subject = stringutil.ellipsis(subject, maxsubject)
- msg['Subject'] = mail.headencode(self.ui, subject,
- self.charsets, self.test)
+ msg[r'Subject'] = encoding.strfromlocal(
+ mail.headencode(self.ui, subject, self.charsets, self.test))
# try to make message have proper sender
if not sender:
sender = self.ui.config('email', 'from') or self.ui.username()
if '@' not in sender or '@localhost' in sender:
sender = self.fixmail(sender)
- msg['From'] = mail.addressencode(self.ui, sender,
- self.charsets, self.test)
+ msg[r'From'] = encoding.strfromlocal(
+ mail.addressencode(self.ui, sender, self.charsets, self.test))
- msg['X-Hg-Notification'] = 'changeset %s' % ctx
- if not msg['Message-Id']:
- msg['Message-Id'] = ('<hg.%s.%s.%s@%s>' %
- (ctx, int(time.time()),
- hash(self.repo.root), socket.getfqdn()))
- msg['To'] = ', '.join(sorted(subs))
+ msg[r'X-Hg-Notification'] = r'changeset %s' % ctx
+ if not msg[r'Message-Id']:
+ msg[r'Message-Id'] = encoding.strfromlocal(
+ '<hg.%s.%d.%d@%s>' % (ctx, int(time.time()),
+ hash(self.repo.root),
+ encoding.strtolocal(socket.getfqdn())))
+ msg[r'To'] = encoding.strfromlocal(', '.join(sorted(subs)))
- msgtext = msg.as_string()
+ msgtext = encoding.strtolocal(msg.as_string())
if self.test:
self.ui.write(msgtext)
if not msgtext.endswith('\n'):
self.ui.write('\n')
else:
self.ui.status(_('notify: sending %d subscribers %d changes\n') %
(len(subs), count))
- mail.sendmail(self.ui, stringutil.email(msg['From']),
+ mail.sendmail(self.ui, stringutil.email(msg[r'From']),
subs, msgtext, mbox=self.mbox)
def diff(self, ctx, ref=None):
To: durin42, #hg-reviewers
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list