Mercurial > hg
comparison hgext/notify.py @ 9313:8736b1c853ff
notify: do not mime encode multipart templates
Mulitpart templates should take care of this themselves.
See http://www.selenic.com/pipermail/mercurial/2009-July/027017.html
Also catch potential parsing errors gracefully.
author | Christian Ebert <blacktrash@gmx.net> |
---|---|
date | Wed, 05 Aug 2009 17:19:08 +0200 |
parents | f4f0e902b750 |
children | 23cf7b52785a 74e717a21779 |
comparison
equal
deleted
inserted
replaced
9302:73bec717b825 | 9313:8736b1c853ff |
---|---|
64 if you like, you can put notify config file in repository that users | 64 if you like, you can put notify config file in repository that users |
65 can push changes to, they can manage their own subscriptions.''' | 65 can push changes to, they can manage their own subscriptions.''' |
66 | 66 |
67 from mercurial.i18n import _ | 67 from mercurial.i18n import _ |
68 from mercurial import patch, cmdutil, templater, util, mail | 68 from mercurial import patch, cmdutil, templater, util, mail |
69 import email.Parser, fnmatch, socket, time | 69 import email.Parser, email.Errors, fnmatch, socket, time |
70 | 70 |
71 # template for single changeset can include email headers. | 71 # template for single changeset can include email headers. |
72 single_template = ''' | 72 single_template = ''' |
73 Subject: changeset in {webroot}: {desc|firstline|strip} | 73 Subject: changeset in {webroot}: {desc|firstline|strip} |
74 From: {author} | 74 From: {author} |
174 | 174 |
175 def send(self, ctx, count, data): | 175 def send(self, ctx, count, data): |
176 '''send message.''' | 176 '''send message.''' |
177 | 177 |
178 p = email.Parser.Parser() | 178 p = email.Parser.Parser() |
179 msg = p.parsestr(data) | 179 try: |
180 msg = p.parsestr(data) | |
181 except email.Errors.MessageParseError, inst: | |
182 raise util.Abort(inst) | |
180 | 183 |
181 # store sender and subject | 184 # store sender and subject |
182 sender, subject = msg['From'], msg['Subject'] | 185 sender, subject = msg['From'], msg['Subject'] |
183 del msg['From'], msg['Subject'] | 186 del msg['From'], msg['Subject'] |
184 # store remaining headers | 187 |
185 headers = msg.items() | 188 if not msg.is_multipart(): |
186 # create fresh mime message from msg body | 189 # create fresh mime message from scratch |
187 text = msg.get_payload() | 190 # (multipart templates must take care of this themselves) |
188 # for notification prefer readability over data precision | 191 headers = msg.items() |
189 msg = mail.mimeencode(self.ui, text, self.charsets, self.test) | 192 payload = msg.get_payload() |
190 # reinstate custom headers | 193 # for notification prefer readability over data precision |
191 for k, v in headers: | 194 msg = mail.mimeencode(self.ui, payload, self.charsets, self.test) |
192 msg[k] = v | 195 # reinstate custom headers |
196 for k, v in headers: | |
197 msg[k] = v | |
193 | 198 |
194 msg['Date'] = util.datestr(format="%a, %d %b %Y %H:%M:%S %1%2") | 199 msg['Date'] = util.datestr(format="%a, %d %b %Y %H:%M:%S %1%2") |
195 | 200 |
196 # try to make subject line exist and be useful | 201 # try to make subject line exist and be useful |
197 if not subject: | 202 if not subject: |