[PATCH] Catch smtp exceptions
Christian Ebert
blacktrash at gmx.net
Fri Oct 19 20:39:01 UTC 2007
* Matt Mackall on Friday, October 19, 2007 at 13:43:32 -0500
> On Fri, Sep 07, 2007 at 04:50:25PM +0200, Christian Ebert wrote:
>> --- a/hgext/patchbomb.py
>> +++ b/hgext/patchbomb.py
>> @@ -411,7 +411,8 @@ def patchbomb(ui, repo, *revs, **opts):
>> ui.status('Sending ', m['Subject'], ' ...\n')
>> # Exim does not remove the Bcc field
>> del m['Bcc']
>> - mailer.sendmail(sender, to + bcc + cc, m.as_string(0))
>> + mail.sendmail(ui, sender, to + bcc + cc, m.as_string(0),
>> + mailer=mailer)
>
> This change looks suspicious?
Perhaps I had to much respect for the existing structure of
patchbomb. Here's another version, simpler and cleaner imho:
# HG changeset patch
# User Christian Ebert <blacktrash at gmx.net>
# Date 1189176522 -7200
# Node ID 65b3553e7b8bd3705a3e96446a0491d11e8511dc
# Parent 18091102a6333d38c68fd6e590e6bfea0970b771
Catch smtp exceptions
diff --git a/hgext/patchbomb.py b/hgext/patchbomb.py
--- a/hgext/patchbomb.py
+++ b/hgext/patchbomb.py
@@ -224,9 +224,8 @@ def patchbomb(ui, repo, *revs, **opts):
pass
os.rmdir(tmpdir)
- really_sending = not (opts['test'] or opts['mbox'])
-
- if really_sending:
+ if not (opts['test'] or opts['mbox']):
+ # really sending
mail.validateconfig(ui)
if not (revs or opts.get('rev') or opts.get('outgoing')):
@@ -361,8 +360,6 @@ def patchbomb(ui, repo, *revs, **opts):
ui.write('\n')
- if really_sending:
- mailer = mail.connect(ui)
parent = None
sender_addr = email.Utils.parseaddr(sender)[1]
@@ -411,7 +408,7 @@ def patchbomb(ui, repo, *revs, **opts):
ui.status('Sending ', m['Subject'], ' ...\n')
# Exim does not remove the Bcc field
del m['Bcc']
- mailer.sendmail(sender, to + bcc + cc, m.as_string(0))
+ mail.sendmail(ui, sender, to + bcc + cc, m.as_string(0))
cmdtable = {
"email":
diff --git a/mercurial/mail.py b/mercurial/mail.py
--- a/mercurial/mail.py
+++ b/mercurial/mail.py
@@ -67,7 +67,13 @@ def connect(ui):
return _sendmail(ui, method)
def sendmail(ui, sender, recipients, msg):
- return connect(ui).sendmail(sender, recipients, msg)
+ try:
+ 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))
+ except smtplib.SMTPException, inst:
+ raise util.Abort(inst)
def validateconfig(ui):
'''determine if we have enough config data to try sending email.'''
More information about the Mercurial-devel
mailing list