More on IMAP

I have been attempting to implement IMAP authentication in my organization--- it has been nothing but a nightmare. Take this simple function (It's quick and dirty for testing purposes... definitely a nasty recursive call in there)

def authenticate_user(u, p)   imap=Net::IMAP.new('imap.server.net', 993, true)   isvalid = imap.authenticate('LOGIN', u, p)   return isvalid rescue Errno::ECONNRESET   authenticate_user(u, p) rescue   false ensure   imap.disconnect end

On any platform in a flat .rb file: works 100% of the time On Mac OS X in a RoR instance: works 100% of the time On Ubuntu 8.10 (x64 & i386): works, but sometimes throws the Errno::ECONNRESET error which must be rescued On SuSE 10.2 (i386): will not rescue Errno::ECONNRESET error

What is going on?! Why do RoR instances on Linux hate Net/IMAP when everything functions fine within Ruby itself or within OS X. There is clearly some kind of issue with OpenSSL, but I've tried compiling from source and cross-compiling Ruby on top of it.

It should be noted that my OS X box is using 1.8.6 darwin version of Ruby, whereas my Linux servers are using 1.8.7 linux versions. Should I try downgrading Ruby?

Any suggestions would be greatly appreciated.

Here are more errors for your pleasure:

/usr/lib/ruby/1.8/openssl/buffering.rb:35:in `sysread' /usr/lib/ruby/1.8/openssl/buffering.rb:35:in `fill_rbuff' /usr/lib/ruby/1.8/openssl/buffering.rb:106:in `gets' /usr/lib/ruby/1.8/net/imap.rb:992:in `get_response' /usr/lib/ruby/1.8/net/imap.rb:930:in `receive_responses' /usr/lib/ruby/1.8/net/imap.rb:923:in `initialize' /usr/lib/ruby/1.8/net/imap.rb:922:in `start' /usr/lib/ruby/1.8/net/imap.rb:922:in `initialize' /home/me/monolith/app/controllers/user_sessions_controller.rb:17:in `new' /home/me/monolith/app/controllers/user_sessions_controller.rb:17:in `authenticate_user' /home/me/monolith/app/controllers/user_sessions_controller.rb:32:in `create'

Thanks!