Return consistent tuple on error.

This commit is contained in:
Stuart Gathman
2005-06-15 19:45:47 +00:00
parent 9a969e8f60
commit 493741c81e
+8 -5
View File
@@ -95,7 +95,10 @@ Received-SPF: %(spf_result)s
"""
def send_dsn(mailfrom,receiver,msg=None):
"Send DSN. If msg is None, do callback verification."
"""Send DSN. If msg is None, do callback verification.
Mailfrom is original sender we are sending DSN or CBV to.
Receiver is the MTA sending the DSN.
Return None for success or (code,msg) for failure."""
user,domain = mailfrom.split('@')
q = spf.query(None,None,None)
mxlist = q.dns(domain,'MX')
@@ -112,7 +115,7 @@ def send_dsn(mailfrom,receiver,msg=None):
if resp.split()[0] == receiver:
return (553,'Fraudulent MX for %s' % domain)
if not (200 <= code <= 299):
raise SMTPHeloError(code, resp)
raise smtplib.SMTPHeloError(code, resp)
if msg:
try:
smtp.sendmail('<>',mailfrom,msg)
@@ -122,7 +125,7 @@ def send_dsn(mailfrom,receiver,msg=None):
else: # CBV
code,resp = smtp.docmd('MAIL FROM: <>')
if code != 250:
raise SMTPSenderRefused(code, resp, '<>')
raise smtplib.SMTPSenderRefused(code, resp, '<>')
code,resp = smtp.rcpt(mailfrom)
if code not in (250,251):
return (code,resp) # permanent error
@@ -131,9 +134,9 @@ def send_dsn(mailfrom,receiver,msg=None):
except smtplib.SMTPRecipientsRefused,x:
return x.recipients[mailfrom] # permanent error
except smtplib.SMTPSenderRefused,x:
return x # does not accept DSN
return x.args[:2] # does not accept DSN
except smtplib.SMTPDataError,x:
return x # permanent error
return x.args # permanent error
except smtplib.SMTPException:
pass # any other error, try next MX
except socket.error: