[Twisted-Python] [PATCH] SMTP cleanup, do not hide error messages
Tommi Virtanen
tv at twistedmatrix.com
Sat Aug 2 08:22:16 MDT 2003
Hi. Here's a patch that does two things to twisted.protocol.smtp:
1) use sendLine instead of self.transport.write, for prettiness
and also to make debug printing in sendLine be actually useful.
2) use the code and error message from SMTPBadSender and
SMTPBadRcpt exceptions trapped, not a hardcoded "550 I'm
not telling you what want wrong." Helps debugging scalemail
a _lot_.
You have at most a few days to protest, or I will
commit. Explicitly saying "looks good" appreciated.
Index: twisted/protocols/smtp.py
===================================================================
RCS file: /cvs/Twisted/twisted/protocols/smtp.py,v
retrieving revision 1.69
diff -u -u -r1.69 smtp.py
--- twisted/protocols/smtp.py 23 Jul 2003 23:10:54 -0000 1.69
+++ twisted/protocols/smtp.py 2 Aug 2003 14:46:49 -0000
@@ -444,9 +444,9 @@
lines = message.splitlines()
lastline = lines[-1:]
for line in lines[:-1]:
- self.transport.write('%3.3d-%s\r\n' % (code, line))
- self.transport.write('%3.3d %s\r\n' % (code,
- lastline and lastline[0] or ''))
+ self.sendLine('%3.3d-%s' % (code, line))
+ self.sendLine('%3.3d %s' % (code,
+ lastline and lastline[0] or ''))
def lineReceived(self, line):
self.resetTimeout()
@@ -558,7 +558,9 @@
def _ebFromValidate(self, failure):
if failure.check(SMTPBadSender):
- self.sendCode(550, 'Cannot receive for specified address')
+ self.sendCode(failure.value.code,
+ 'Cannot receive for specified address %s: %s'
+ % (repr(str(failure.value.addr)), failure.value.resp))
elif failure.check(SMTPServerError):
self.sendCode(failure.value.code, failure.value.resp)
else:
@@ -632,7 +634,7 @@
def _ebToValidate(self, failure):
if failure.check(SMTPBadRcpt):
- self.sendCode(550, 'Cannot receive for specified address')
+ self.sendCode(failure.value.code, failure.value.resp)
elif failure.check(SMTPServerError):
self.sendCode(failure.value.code, failure.value.resp)
else:
--
:(){ :|:&};:
More information about the Twisted-Python
mailing list