I would like to use the net/imap library in ruby behind a authenticated proxy, I was starting to dig in and I'm wondering if there is a way to do this already or if I need to make my own version of the net/imap library that supports a proxy?
A:
The easiest way to hack libraries that don't support proxy information is to replace Net::HTTP
with an instance of Net::HTTP::Proxy
:
# somewhere before you load net/imap
proxy = Net::HTTP::Proxy(address, host)
Net.class_eval do
remove_const :HTTP
HTTP = proxy
end
James A. Rosen
2010-02-24 18:03:02
Doesn't that mean it would need to run through HTTP? I will try tomorrow just in case.
Jeff Beck
2010-02-25 06:15:05
Rats. I assumed the Net/IMAP library used the Net::HTTP library for building the socket, but it does not. (I have *no clue* why I thought that, by the way. It wouldn't make much sense.)
James A. Rosen
2010-02-26 18:59:09
Thanks any direction to make proxy support at the socket level, I'm looking and it seems like it may be messy. I may have to follow the pattern they used for the Net::HTTP::Proxy
Jeff Beck
2010-02-26 21:45:16
I'm surprised your organization proxies IMAP. Most proxies only do HTTP, HTTPS, FTP, and possibly SOCKS. An alternate solution might be to use WebDAV instead of IMAP if that's available. Then you'd be using the HTTP proxy, which is easy to do.
James A. Rosen
2010-02-27 16:06:42
All internet traffic that I can tell need to go through the authenticated proxy. We are trying to reach out to google to use it's IMAP.
Jeff Beck
2010-02-27 22:55:47
Are you sure that the proxy server in your organization supports the IMAP protocol. Most commercial proxy servers support HTTP / HTTPS / FTP only. You have two options, either convince your IT guys to install something like this http://wiki.dovecot.org/HowTo/ImapProxy or get a server outside of your firewall that would wrap IMAP traffic into HTTP.
Vlad
2010-03-05 13:03:31
Good point I will try thunderbird from inside to see if I can get out.
Jeff Beck
2010-03-05 16:50:59
+1
A:
It is possible to tunnel any socket connection through a HTTPS proxy server.
To do this:
- open a socket to your proxy server
- send "CONNECT hostname : portnumber HTTP/1.0\n\r\n\r\n"
- read from the socket until you see the end of the HTTP headers (2 blank lines)
- your socket is now connected
Here is a ruby example of such a tunnel.
Reasons this will fail:
- most network admins will only allow CONNECT to port 443
- proxy server has proxy authentication
Lachlan Roche
2010-03-08 08:37:51
This server does have proxy authentication. But your example has socket methods for that case. I think I should be able to use that socket to rewrite the net/imap into something I can use. Thanks
Jeff Beck
2010-03-08 12:25:28