[Twisted-Python] [twisted.mail][newbie] return tempfail (4xx) after eomReceived()

Hello list, I'm trying to code an SMTP server that stores received messages in a queue (es. RabbitMQ or Redis). I'm figuring out how to do it with Twisted, and so far I managed to print to console the messages the way I want. I'm trying to understand now how to return a tempfail code (4xx) from within eomReceived(), so to simulate (and, in the future, handle) temporary unavailabilities of the queuing system, and thus to delegate to the client the handling/retrying of the delivery (there will be postfix in front of my smtp server, so it will keep the message in its spool). I ended up digging in the code until I found the _messageHandled callback of the SMTP class, that's added to the deferred returned by eomReceived. I admit I'm not very accustomed to deferreds yet, but I can only see 250 and 550 response code inside it. I suspect that I should return the 4xx code in one of the deferred's callbacks/errbacks *before* _messageHandled, but I really can't imagine how. Would you please give me some hints about how to accomplish the task? Am I looking to the right direction at all? Thanks a lot, Fabio

On 10:36 am, sangiovanni@nweb.it wrote:
Hello list,
I'm trying to code an SMTP server that stores received messages in a queue (es. RabbitMQ or Redis). I'm figuring out how to do it with Twisted, and so far I managed to print to console the messages the way I want. I'm trying to understand now how to return a tempfail code (4xx) from within eomReceived(), so to simulate (and, in the future, handle) temporary unavailabilities of the queuing system, and thus to delegate to the client the handling/retrying of the delivery (there will be postfix in front of my smtp server, so it will keep the message in its spool). I ended up digging in the code until I found the _messageHandled callback of the SMTP class, that's added to the deferred returned by eomReceived. I admit I'm not very accustomed to deferreds yet, but I can only see 250 and 550 response code inside it. I suspect that I should return the 4xx code in one of the deferred's callbacks/errbacks *before* _messageHandled, but I really can't imagine how. Would you please give me some hints about how to accomplish the task? Am I looking to the right direction at all?
See https://twistedmatrix.com/trac/ticket/4904 Jean-Paul

Hi, thanks for your anwser, and forgive my late follow up. So, I understand that this feature is currently missing in twisted. I suppose that the only thing to do in my case is to override the _messageHandled method, and implement all the logic needed to my purpose. Is this correct? Are you aware of some technique other people adopted? Thanks a lot, Fabio On 23/11/13 13:08, exarkun@twistedmatrix.com wrote:
On 10:36 am, sangiovanni@nweb.it wrote:
Hello list,
I'm trying to code an SMTP server that stores received messages in a queue (es. RabbitMQ or Redis). I'm figuring out how to do it with Twisted, and so far I managed to print to console the messages the way I want. I'm trying to understand now how to return a tempfail code (4xx) from within eomReceived(), so to simulate (and, in the future, handle) temporary unavailabilities of the queuing system, and thus to delegate to the client the handling/retrying of the delivery (there will be postfix in front of my smtp server, so it will keep the message in its spool). I ended up digging in the code until I found the _messageHandled callback of the SMTP class, that's added to the deferred returned by eomReceived. I admit I'm not very accustomed to deferreds yet, but I can only see 250 and 550 response code inside it. I suspect that I should return the 4xx code in one of the deferred's callbacks/errbacks *before* _messageHandled, but I really can't imagine how. Would you please give me some hints about how to accomplish the task? Am I looking to the right direction at all?
See https://twistedmatrix.com/trac/ticket/4904
Jean-Paul
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python

On 10:06 am, sangiovanni@nweb.it wrote:
Hi,
thanks for your anwser, and forgive my late follow up. So, I understand that this feature is currently missing in twisted. I suppose that the only thing to do in my case is to override the _messageHandled method, and implement all the logic needed to my purpose. Is this correct? Are you aware of some technique other people adopted?
Names that start with "_" are private and subject to change in any new Twisted release. In other words, there are no compatibility guarantees for such names. If you're comfortable with future Twisted releases breaking this feature of your software then yes, this sounds like a workable approach. Another approach would be to contribute to Twisted - help resolve the ticket I linked to by introducing a new public API for controling the response code. Jean-Paul
participants (2)
-
exarkun@twistedmatrix.com
-
Fabio Sangiovanni