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