45 # to = recipient1, recipient2, ... |
49 # to = recipient1, recipient2, ... |
46 # cc = cc1, cc2, ... |
50 # cc = cc1, cc2, ... |
47 |
51 |
48 from email.MIMEMultipart import MIMEMultipart |
52 from email.MIMEMultipart import MIMEMultipart |
49 from email.MIMEText import MIMEText |
53 from email.MIMEText import MIMEText |
|
54 from email.Utils import parseaddr |
50 from mercurial import commands |
55 from mercurial import commands |
51 from mercurial import hg |
56 from mercurial import hg |
52 from mercurial import ui |
57 from mercurial import ui |
53 from mercurial.i18n import gettext as _ |
58 from mercurial.i18n import gettext as _ |
54 import os |
59 import os |
220 d = cdiffstat(_('Final summary:\n'), jumbo) |
225 d = cdiffstat(_('Final summary:\n'), jumbo) |
221 if d: msg.attach(MIMEText(d)) |
226 if d: msg.attach(MIMEText(d)) |
222 |
227 |
223 msgs.insert(0, msg) |
228 msgs.insert(0, msg) |
224 |
229 |
225 if not opts['test']: |
230 if not opts['test'] and not opts['mbox']: |
226 s = smtplib.SMTP() |
231 s = smtplib.SMTP() |
227 s.connect(host = ui.config('smtp', 'host', 'mail'), |
232 s.connect(host = ui.config('smtp', 'host', 'mail'), |
228 port = int(ui.config('smtp', 'port', 25))) |
233 port = int(ui.config('smtp', 'port', 25))) |
229 if ui.configbool('smtp', 'tls'): |
234 if ui.configbool('smtp', 'tls'): |
230 s.ehlo() |
235 s.ehlo() |
248 m['Date'] = time.strftime('%a, %e %b %Y %T ', time.localtime(start_time)) + tz |
254 m['Date'] = time.strftime('%a, %e %b %Y %T ', time.localtime(start_time)) + tz |
249 start_time += 1 |
255 start_time += 1 |
250 m['From'] = sender |
256 m['From'] = sender |
251 m['To'] = ', '.join(to) |
257 m['To'] = ', '.join(to) |
252 if cc: m['Cc'] = ', '.join(cc) |
258 if cc: m['Cc'] = ', '.join(cc) |
253 ui.status('Sending ', m['Subject'], ' ...\n') |
|
254 if opts['test']: |
259 if opts['test']: |
|
260 ui.status('Displaying ', m['Subject'], ' ...\n') |
255 fp = os.popen(os.getenv('PAGER', 'more'), 'w') |
261 fp = os.popen(os.getenv('PAGER', 'more'), 'w') |
256 fp.write(m.as_string(0)) |
262 fp.write(m.as_string(0)) |
257 fp.write('\n') |
263 fp.write('\n') |
258 fp.close() |
264 fp.close() |
|
265 elif opts['mbox']: |
|
266 ui.status('Writing ', m['Subject'], ' ...\n') |
|
267 fp = open(opts['mbox'], m.has_key('In-Reply-To') and 'ab+' or 'wb+') |
|
268 date = time.asctime(time.localtime(start_time)) |
|
269 fp.write('From %s %s\n' % (sender_addr, date)) |
|
270 fp.write(m.as_string(0)) |
|
271 fp.write('\n\n') |
|
272 fp.close() |
259 else: |
273 else: |
|
274 ui.status('Sending ', m['Subject'], ' ...\n') |
260 s.sendmail(sender, to + cc, m.as_string(0)) |
275 s.sendmail(sender, to + cc, m.as_string(0)) |
261 if not opts['test']: |
276 if not opts['test'] and not opts['mbox']: |
262 s.close() |
277 s.close() |
263 |
278 |
264 cmdtable = { |
279 cmdtable = { |
265 'email': |
280 'email': |
266 (patchbomb, |
281 (patchbomb, |
267 [('c', 'cc', [], 'email addresses of copy recipients'), |
282 [('c', 'cc', [], 'email addresses of copy recipients'), |
268 ('d', 'diffstat', None, 'add diffstat output to messages'), |
283 ('d', 'diffstat', None, 'add diffstat output to messages'), |
269 ('f', 'from', '', 'email address of sender'), |
284 ('f', 'from', '', 'email address of sender'), |
270 ('', 'plain', None, 'omit hg patch header'), |
285 ('', 'plain', None, 'omit hg patch header'), |
271 ('n', 'test', None, 'print messages that would be sent'), |
286 ('n', 'test', None, 'print messages that would be sent'), |
|
287 ('m', 'mbox', '', 'write messages to mbox file instead of sending them'), |
272 ('s', 'subject', '', 'subject of introductory message'), |
288 ('s', 'subject', '', 'subject of introductory message'), |
273 ('t', 'to', [], 'email addresses of recipients')], |
289 ('t', 'to', [], 'email addresses of recipients')], |
274 "hg email [OPTION]... [REV]...") |
290 "hg email [OPTION]... [REV]...") |
275 } |
291 } |