# More on IMAP

**URL:** <https://www.ruby-forum.com/t/more-on-imap/167167>\
**Category:** Rails\
**Created:** [May 4, 2009, 11:58pm UTC](https://www.ruby-forum.com/t/more-on-imap/167167 "2009-05-04T23:58:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [May 4, 2009, 11:58pm UTC](https://www.ruby-forum.com/t/more-on-imap/167167/1 "2009-05-04T23:58:23Z")

</div>

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](http://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!
