summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorklm1998-07-23 22:42:13 +0000
committerklm1998-07-23 22:42:13 +0000
commit609b29fb75b795fb78aef99cf4d793d767f1f276 (patch)
tree82b95291ce87c7c0e7955b86a0e5049240399b4d
parentfa46111f32ab0b192ba2febb6aa72c28803cfef2 (diff)
downloadmailman-609b29fb75b795fb78aef99cf4d793d767f1f276.tar.gz
mailman-609b29fb75b795fb78aef99cf4d793d767f1f276.tar.zst
mailman-609b29fb75b795fb78aef99cf4d793d767f1f276.zip
SmtpConnection.send(): More provision for when a local address is
recognized as bad and refused immediately (rather than being queued up, as happens for any offsite recipients). In particular, had to detect whether all recipients in the batch failed, and then just return - otherwise the DATA command would fail (no valid recipients), and raise a disruptive exception. It's worth noting that no bounce is generated for invalid local recipients, which means now way to disable or even notice that they're bad. This should be rectified at some point, but offhand i'm not sure the right way, other than by special casing local deliveries. Anyway, i left an XXX note to sorta this effect in the code. And finally - it looks like the "official" python smtplib already does the right kinds of thing regarding bad recipients, which makes me feel good about merging with it.
-rw-r--r--Mailman/smtplib.py34
1 files changed, 27 insertions, 7 deletions
diff --git a/Mailman/smtplib.py b/Mailman/smtplib.py
index abe719743..64380997a 100644
--- a/Mailman/smtplib.py
+++ b/Mailman/smtplib.py
@@ -69,13 +69,26 @@ class SmtpConnection:
lines = string.split(text, '\n')
self._sock.send('MAIL FROM: <%s>\r\n' % frm)
self.getresp()
+ valid_recipients = []
if type(to) == types.StringType:
self._sock.send('RCPT TO: <%s>\r\n' % to)
self.getresp()
+ valid_recipients.append(to)
else:
for item in to:
self._sock.send('RCPT TO: <%s>\r\n' % item)
- self.getresp(impunity=1)
+ lastresp = self.getresp(impunity=1)
+ if not lastresp:
+ # XXX klm 07/23/1998 Invalid recipients on local host
+ # are a special problem, since they are recognized
+ # and refused immediately by, eg, sendmail, rather than
+ # being queued. So we do not get the benefit of a
+ # bounce message for, eg, disabling the recipient, and
+ # it would knock out delivery to other recipients if we
+ # didn't take this precaution.
+ valid_recipients.append(item)
+ if not valid_recipients:
+ return
self._sock.send('DATA\r\n')
self.getresp()
if headers:
@@ -113,15 +126,22 @@ class SmtpConnection:
return line
def getresp(self, impunity=0):
+ """Get response, raising suitable exception for errors.
+
+ If option 'impunity' is set, on failure the exception and message
+ that would have been raised are instead returned."""
resp = self.getmultiline()
self.lastresp = resp[:3]
- if impunity:
- return resp
c = resp[:1]
+ bad = None
if c == '4':
- raise error_temp, resp
+ bad = error_temp
if c == '5':
- raise error_perm, resp
+ bad = error_perm
if c not in '123':
- raise error_proto, resp
- return resp
+ bad = error_proto
+ if bad:
+ if impunity:
+ return bad, resp
+ else:
+ raise bad, resp