Mercurial > hg
comparison hgext/notify.py @ 9316:23cf7b52785a
merge with crew-stable
author | Dirkjan Ochtman <dirkjan@ochtman.nl> |
---|---|
date | Wed, 05 Aug 2009 17:21:29 +0200 |
parents | 0efb3360bdb3 8736b1c853ff |
children | 9a69ab6d7cf7 |
comparison
equal
deleted
inserted
replaced
9312:c5f0825c1dbb | 9316:23cf7b52785a |
---|---|
68 can push changes to, they can manage their own subscriptions. | 68 can push changes to, they can manage their own subscriptions. |
69 ''' | 69 ''' |
70 | 70 |
71 from mercurial.i18n import _ | 71 from mercurial.i18n import _ |
72 from mercurial import patch, cmdutil, templater, util, mail | 72 from mercurial import patch, cmdutil, templater, util, mail |
73 import email.Parser, fnmatch, socket, time | 73 import email.Parser, email.Errors, fnmatch, socket, time |
74 | 74 |
75 # template for single changeset can include email headers. | 75 # template for single changeset can include email headers. |
76 single_template = ''' | 76 single_template = ''' |
77 Subject: changeset in {webroot}: {desc|firstline|strip} | 77 Subject: changeset in {webroot}: {desc|firstline|strip} |
78 From: {author} | 78 From: {author} |
178 | 178 |
179 def send(self, ctx, count, data): | 179 def send(self, ctx, count, data): |
180 '''send message.''' | 180 '''send message.''' |
181 | 181 |
182 p = email.Parser.Parser() | 182 p = email.Parser.Parser() |
183 msg = p.parsestr(data) | 183 try: |
184 msg = p.parsestr(data) | |
185 except email.Errors.MessageParseError, inst: | |
186 raise util.Abort(inst) | |
184 | 187 |
185 # store sender and subject | 188 # store sender and subject |
186 sender, subject = msg['From'], msg['Subject'] | 189 sender, subject = msg['From'], msg['Subject'] |
187 del msg['From'], msg['Subject'] | 190 del msg['From'], msg['Subject'] |
188 # store remaining headers | 191 |
189 headers = msg.items() | 192 if not msg.is_multipart(): |
190 # create fresh mime message from msg body | 193 # create fresh mime message from scratch |
191 text = msg.get_payload() | 194 # (multipart templates must take care of this themselves) |
192 # for notification prefer readability over data precision | 195 headers = msg.items() |
193 msg = mail.mimeencode(self.ui, text, self.charsets, self.test) | 196 payload = msg.get_payload() |
194 # reinstate custom headers | 197 # for notification prefer readability over data precision |
195 for k, v in headers: | 198 msg = mail.mimeencode(self.ui, payload, self.charsets, self.test) |
196 msg[k] = v | 199 # reinstate custom headers |
200 for k, v in headers: | |
201 msg[k] = v | |
197 | 202 |
198 msg['Date'] = util.datestr(format="%a, %d %b %Y %H:%M:%S %1%2") | 203 msg['Date'] = util.datestr(format="%a, %d %b %Y %H:%M:%S %1%2") |
199 | 204 |
200 # try to make subject line exist and be useful | 205 # try to make subject line exist and be useful |
201 if not subject: | 206 if not subject: |