Show More
@@ -381,7 +381,6 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 |
|
|||
385 | for m in msgs: |
|
384 | for m in msgs: | |
386 | try: |
|
385 | try: | |
387 | m['Message-Id'] = genmsgid(m['X-Mercurial-Node']) |
|
386 | m['Message-Id'] = genmsgid(m['X-Mercurial-Node']) | |
@@ -427,12 +426,10 b' def patchbomb(ui, repo, *revs, **opts):' | |||||
427 | fp.write('\n\n') |
|
426 | fp.write('\n\n') | |
428 | fp.close() |
|
427 | fp.close() | |
429 | else: |
|
428 | else: | |
430 | if not sendmail: |
|
|||
431 | sendmail = mail.connect(ui) |
|
|||
432 | ui.status('Sending ', m['Subject'], ' ...\n') |
|
429 | ui.status('Sending ', m['Subject'], ' ...\n') | |
433 | # Exim does not remove the Bcc field |
|
430 | # Exim does not remove the Bcc field | |
434 | del m['Bcc'] |
|
431 | del m['Bcc'] | |
435 | sendmail(ui, sender, to + bcc + cc, m.as_string(0)) |
|
432 | mail.sendmail(ui, sender, to + bcc + cc, m.as_string(0)) | |
436 |
|
433 | |||
437 | cmdtable = { |
|
434 | cmdtable = { | |
438 | "email": |
|
435 | "email": |
@@ -38,43 +38,39 b' def _smtp(ui):' | |||||
38 | s.login(username, password) |
|
38 | s.login(username, password) | |
39 | return s |
|
39 | return s | |
40 |
|
40 | |||
41 | def _sendmail(ui, sender, recipients, msg): |
|
41 | class _sendmail(object): | |
42 | '''send mail using sendmail.''' |
|
42 | '''send mail using sendmail.''' | |
43 | program = ui.config('email', 'method') |
|
43 | ||
44 | cmdline = '%s -f %s %s' % (program, templater.email(sender), |
|
44 | def __init__(self, ui, program): | |
45 | ' '.join(map(templater.email, recipients))) |
|
45 | self.ui = ui | |
46 | ui.note(_('sending mail: %s\n') % cmdline) |
|
46 | self.program = program | |
47 | fp = os.popen(cmdline, 'w') |
|
47 | ||
48 | fp.write(msg) |
|
48 | def sendmail(self, sender, recipients, msg): | |
49 | ret = fp.close() |
|
49 | cmdline = '%s -f %s %s' % ( | |
50 | if ret: |
|
50 | self.program, templater.email(sender), | |
51 | raise util.Abort('%s %s' % ( |
|
51 | ' '.join(map(templater.email, recipients))) | |
52 | os.path.basename(program.split(None, 1)[0]), |
|
52 | self.ui.note(_('sending mail: %s\n') % cmdline) | |
53 | util.explain_exit(ret)[0])) |
|
53 | fp = os.popen(cmdline, 'w') | |
|
54 | fp.write(msg) | |||
|
55 | ret = fp.close() | |||
|
56 | if ret: | |||
|
57 | raise util.Abort('%s %s' % ( | |||
|
58 | os.path.basename(self.program.split(None, 1)[0]), | |||
|
59 | util.explain_exit(ret)[0])) | |||
54 |
|
60 | |||
55 | def connect(ui): |
|
61 | def connect(ui): | |
56 |
'''make a mail connection. return a |
|
62 | '''make a mail connection. object returned has one method, sendmail. | |
57 | call as sendmail(sender, list-of-recipients, msg).''' |
|
63 | call as sendmail(sender, list-of-recipients, msg).''' | |
58 |
|
64 | |||
59 | func = _sendmail |
|
65 | method = ui.config('email', 'method', 'smtp') | |
60 |
if |
|
66 | if method == 'smtp': | |
61 |
|
|
67 | return _smtp(ui) | |
62 |
|
68 | |||
63 | def send(ui, sender, recipients, msg): |
|
69 | return _sendmail(ui, method) | |
64 | try: |
|
|||
65 | return func.sendmail(sender, recipients, msg) |
|
|||
66 | except smtplib.SMTPRecipientsRefused, inst: |
|
|||
67 | recipients = [r[1] for r in inst.recipients.values()] |
|
|||
68 | raise util.Abort('\n' + '\n'.join(recipients)) |
|
|||
69 | except smtplib.SMTPException, inst: |
|
|||
70 | raise util.Abort(inst) |
|
|||
71 |
|
||||
72 | return send |
|
|||
73 |
|
70 | |||
74 | def sendmail(ui, sender, recipients, msg): |
|
71 | def sendmail(ui, sender, recipients, msg): | |
75 | try: |
|
72 | try: | |
76 | send = connect(ui) |
|
73 | return connect(ui).sendmail(sender, recipients, msg) | |
77 | return send(sender, recipients, msg) |
|
|||
78 | except smtplib.SMTPRecipientsRefused, inst: |
|
74 | except smtplib.SMTPRecipientsRefused, inst: | |
79 | recipients = [r[1] for r in inst.recipients.values()] |
|
75 | recipients = [r[1] for r in inst.recipients.values()] | |
80 | raise util.Abort('\n' + '\n'.join(recipients)) |
|
76 | raise util.Abort('\n' + '\n'.join(recipients)) |
General Comments 0
You need to be logged in to leave comments.
Login now