Mercurial > hg
changeset 5948:597d8402087d
Merge after backout
author | Bryan O'Sullivan <bos@serpentine.com> |
---|---|
date | Fri, 25 Jan 2008 16:04:46 -0800 |
parents | 528c986f0162 (diff) ee0dc0f3804b (current diff) |
children | 4b8d568c65dd 92eb0a019bf2 |
files | hgext/patchbomb.py templates/raw/header.tmpl |
diffstat | 2 files changed, 25 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/patchbomb.py Tue Jan 22 13:12:43 2008 +0100 +++ b/hgext/patchbomb.py Fri Jan 25 16:04:46 2008 -0800 @@ -381,7 +381,6 @@ parent = None sender_addr = email.Utils.parseaddr(sender)[1] - sendmail = None for m in msgs: try: m['Message-Id'] = genmsgid(m['X-Mercurial-Node']) @@ -426,12 +425,10 @@ fp.write('\n\n') fp.close() else: - if not sendmail: - sendmail = mail.connect(ui) ui.status('Sending ', m['Subject'], ' ...\n') # Exim does not remove the Bcc field del m['Bcc'] - sendmail(ui, sender, to + bcc + cc, m.as_string(0)) + mail.sendmail(ui, sender, to + bcc + cc, m.as_string(0)) cmdtable = { "email":
--- a/mercurial/mail.py Tue Jan 22 13:12:43 2008 +0100 +++ b/mercurial/mail.py Fri Jan 25 16:04:46 2008 -0800 @@ -38,43 +38,39 @@ s.login(username, password) return s -def _sendmail(ui, sender, recipients, msg): +class _sendmail(object): '''send mail using sendmail.''' - program = ui.config('email', 'method') - cmdline = '%s -f %s %s' % (program, templater.email(sender), - ' '.join(map(templater.email, recipients))) - ui.note(_('sending mail: %s\n') % cmdline) - fp = os.popen(cmdline, 'w') - fp.write(msg) - ret = fp.close() - if ret: - raise util.Abort('%s %s' % ( - os.path.basename(program.split(None, 1)[0]), - util.explain_exit(ret)[0])) + + def __init__(self, ui, program): + self.ui = ui + self.program = program + + def sendmail(self, sender, recipients, msg): + cmdline = '%s -f %s %s' % ( + self.program, templater.email(sender), + ' '.join(map(templater.email, recipients))) + self.ui.note(_('sending mail: %s\n') % cmdline) + fp = os.popen(cmdline, 'w') + fp.write(msg) + ret = fp.close() + if ret: + raise util.Abort('%s %s' % ( + os.path.basename(self.program.split(None, 1)[0]), + util.explain_exit(ret)[0])) def connect(ui): - '''make a mail connection. return a function to send mail. + '''make a mail connection. object returned has one method, sendmail. call as sendmail(sender, list-of-recipients, msg).''' - func = _sendmail - if ui.config('email', 'method', 'smtp') == 'smtp': - func = _smtp(ui) + method = ui.config('email', 'method', 'smtp') + if method == 'smtp': + return _smtp(ui) - def send(ui, sender, recipients, msg): - try: - return func.sendmail(sender, recipients, msg) - except smtplib.SMTPRecipientsRefused, inst: - recipients = [r[1] for r in inst.recipients.values()] - raise util.Abort('\n' + '\n'.join(recipients)) - except smtplib.SMTPException, inst: - raise util.Abort(inst) - - return send + return _sendmail(ui, method) def sendmail(ui, sender, recipients, msg): try: - send = connect(ui) - return send(sender, recipients, msg) + return connect(ui).sendmail(sender, recipients, msg) except smtplib.SMTPRecipientsRefused, inst: recipients = [r[1] for r in inst.recipients.values()] raise util.Abort('\n' + '\n'.join(recipients))