Search code examples
delphiindyindy10

How to make TIdIMAP4 support socks 4/5 proxy?


The TidIMAP4 client of the Indy package does not support socks 4/5 proxies, what will be the possible approaches to add that support?


Solution

  • Indy already has a built-in framework for connecting any TCP client component through a proxy. You simply attach the desired proxy component to the client component, and then the client will automatically connect to the proxy and tell it where to connect to. And proxy components can be chained, if you need to connect through multiple proxies.

    Indy 10 provides two proxy components by default - TIdSocksInfo for SOCKS 4/4a/5 proxies, and TIdConnectThroughHttpProxy for HTTP proxies (using the HTTP CONNECT method). But the framework is generic enough that you can derive new classes if you need to implement other proxy protocols.

    In your case, before connecting to the server, assign a TIdIOHandlerStack component to the TIdIMAP4.IOHandler property, then assign a TIdSocksInfo component to the TIdIOHandlerStack.TransparentProxy property, and then configure the TIdSocksInfo as needed. All of this can be done at design-time or run-time.