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