Show More
@@ -381,6 +381,7 b' def patchbomb(ui, repo, *revs, **opts):' | |||||
381 | parent = None |
|
381 | parent = None | |
382 |
|
382 | |||
383 | sender_addr = email.Utils.parseaddr(sender)[1] |
|
383 | sender_addr = email.Utils.parseaddr(sender)[1] | |
|
384 | sendmail = None | |||
384 | for m in msgs: |
|
385 | for m in msgs: | |
385 | try: |
|
386 | try: | |
386 | m['Message-Id'] = genmsgid(m['X-Mercurial-Node']) |
|
387 | m['Message-Id'] = genmsgid(m['X-Mercurial-Node']) | |
@@ -425,10 +426,12 b' def patchbomb(ui, repo, *revs, **opts):' | |||||
425 | fp.write('\n\n') |
|
426 | fp.write('\n\n') | |
426 | fp.close() |
|
427 | fp.close() | |
427 | else: |
|
428 | else: | |
|
429 | if not sendmail: | |||
|
430 | sendmail = mail.connect(ui) | |||
428 | ui.status('Sending ', m['Subject'], ' ...\n') |
|
431 | ui.status('Sending ', m['Subject'], ' ...\n') | |
429 | # Exim does not remove the Bcc field |
|
432 | # Exim does not remove the Bcc field | |
430 | del m['Bcc'] |
|
433 | del m['Bcc'] | |
431 |
|
|
434 | sendmail(sender, to + bcc + cc, m.as_string(0)) | |
432 |
|
435 | |||
433 | cmdtable = { |
|
436 | cmdtable = { | |
434 | "email": |
|
437 | "email": |
@@ -9,8 +9,7 b' from i18n import _' | |||||
9 | import os, smtplib, templater, util, socket |
|
9 | import os, smtplib, templater, util, socket | |
10 |
|
10 | |||
11 | def _smtp(ui): |
|
11 | def _smtp(ui): | |
12 | '''send mail using smtp.''' |
|
12 | '''build an smtp connection and return a function to send mail''' | |
13 |
|
||||
14 | local_hostname = ui.config('smtp', 'local_hostname') |
|
13 | local_hostname = ui.config('smtp', 'local_hostname') | |
15 | s = smtplib.SMTP(local_hostname=local_hostname) |
|
14 | s = smtplib.SMTP(local_hostname=local_hostname) | |
16 | mailhost = ui.config('smtp', 'host') |
|
15 | mailhost = ui.config('smtp', 'host') | |
@@ -36,46 +35,42 b' def _smtp(ui):' | |||||
36 | ui.note(_('(authenticating to mail server as %s)\n') % |
|
35 | ui.note(_('(authenticating to mail server as %s)\n') % | |
37 | (username)) |
|
36 | (username)) | |
38 | s.login(username, password) |
|
37 | s.login(username, password) | |
39 | return s |
|
|||
40 |
|
38 | |||
41 | class _sendmail(object): |
|
39 | def send(sender, recipients, msg): | |
42 | '''send mail using sendmail.''' |
|
40 | try: | |
|
41 | return s.sendmail(sender, recipients, msg) | |||
|
42 | except smtplib.SMTPRecipientsRefused, inst: | |||
|
43 | recipients = [r[1] for r in inst.recipients.values()] | |||
|
44 | raise util.Abort('\n' + '\n'.join(recipients)) | |||
|
45 | except smtplib.SMTPException, inst: | |||
|
46 | raise util.Abort(inst) | |||
43 |
|
47 | |||
44 | def __init__(self, ui, program): |
|
48 | return send | |
45 | self.ui = ui |
|
|||
46 | self.program = program |
|
|||
47 |
|
49 | |||
48 |
|
|
50 | def _sendmail(ui, sender, recipients, msg): | |
49 | cmdline = '%s -f %s %s' % ( |
|
51 | '''send mail using sendmail.''' | |
50 | self.program, templater.email(sender), |
|
52 | program = ui.config('email', 'method') | |
51 | ' '.join(map(templater.email, recipients))) |
|
53 | cmdline = '%s -f %s %s' % (program, templater.email(sender), | |
52 | self.ui.note(_('sending mail: %s\n') % cmdline) |
|
54 | ' '.join(map(templater.email, recipients))) | |
53 | fp = os.popen(cmdline, 'w') |
|
55 | ui.note(_('sending mail: %s\n') % cmdline) | |
54 | fp.write(msg) |
|
56 | fp = os.popen(cmdline, 'w') | |
55 | ret = fp.close() |
|
57 | fp.write(msg) | |
56 | if ret: |
|
58 | ret = fp.close() | |
57 | raise util.Abort('%s %s' % ( |
|
59 | if ret: | |
58 | os.path.basename(self.program.split(None, 1)[0]), |
|
60 | raise util.Abort('%s %s' % ( | |
59 | util.explain_exit(ret)[0])) |
|
61 | os.path.basename(program.split(None, 1)[0]), | |
|
62 | util.explain_exit(ret)[0])) | |||
60 |
|
63 | |||
61 | def connect(ui): |
|
64 | def connect(ui): | |
62 |
'''make a mail connection. |
|
65 | '''make a mail connection. return a function to send mail. | |
63 | call as sendmail(sender, list-of-recipients, msg).''' |
|
66 | call as sendmail(sender, list-of-recipients, msg).''' | |
64 |
|
67 | if ui.config('email', 'method', 'smtp') == 'smtp': | ||
65 | method = ui.config('email', 'method', 'smtp') |
|
|||
66 | if method == 'smtp': |
|
|||
67 | return _smtp(ui) |
|
68 | return _smtp(ui) | |
68 |
|
69 | return lambda s, r, m: _sendmail(ui, s, r, m) | ||
69 | return _sendmail(ui, method) |
|
|||
70 |
|
70 | |||
71 | def sendmail(ui, sender, recipients, msg): |
|
71 | def sendmail(ui, sender, recipients, msg): | |
72 | try: |
|
72 | send = connect(ui) | |
73 |
|
|
73 | return send(sender, recipients, msg) | |
74 | except smtplib.SMTPRecipientsRefused, inst: |
|
|||
75 | recipients = [r[1] for r in inst.recipients.values()] |
|
|||
76 | raise util.Abort('\n' + '\n'.join(recipients)) |
|
|||
77 | except smtplib.SMTPException, inst: |
|
|||
78 | raise util.Abort(inst) |
|
|||
79 |
|
74 | |||
80 | def validateconfig(ui): |
|
75 | def validateconfig(ui): | |
81 | '''determine if we have enough config data to try sending email.''' |
|
76 | '''determine if we have enough config data to try sending email.''' |
General Comments 0
You need to be logged in to leave comments.
Login now