IMAP Proxy

Alex Verstraeten alex at quad.com.ar
Fri Jun 10 16:23:22 EDT 2005


Tarek Ziadé wrote:

>Hi,
>
>I want to write a small TCP Server in Python to make an IMAP Proxy for
>post-processing client requests.
>
>It is not long either complicated but needs to be very robust so...
>maybe someone here has already done such a thing I can use or know where
>i can get it ?
>
>Cheers,
>
>Tarek
>  
>
I wrote one with twisted.. it's quite easy and minimal..
you can start hooking stuff to it, I only use "dataReceived"
as I only need to watch what cmds are imap client sending.

from twisted.protocols.portforward import ProxyFactory
from twisted.protocols.portforward import ProxyClientFactory
from twisted.protocols.portforward import ProxyClient
from twisted.protocols.portforward import ProxyServer
from twisted.internet import reactor

class PS(ProxyServer):
    def dataReceived(self, data):
        print "PS->dataReceived(%s)" %repr(data)
        ProxyServer.dataReceived(self, data)
         
pfactory = ProxyFactory('192.168.1.1',143)
pfactory.protocol = PS

reactor.listenTCP(143, pfactory)
reactor.run()

this will bind to port 143 and proxy all requests to the real imap 
server at 192.168.1.1, while printing the commands being sent to stdout.
Here, my proxy runs on different box than imap server... if you need to 
put both of them on same box you'll need to change the port number of , 
either imap server, or imap proxy.

well..
hope it helps


Alex



More information about the Python-list mailing list