# Still having problems with exceptions in IMAP module

**URL:** <https://rubytalk.org/t/still-having-problems-with-exceptions-in-imap-module/24329>\
**Category:** ruby-talk\
**Created:** [25 January 2006 02:11 UTC](https://rubytalk.org/t/still-having-problems-with-exceptions-in-imap-module/24329 "2006-01-25T02:11:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Russell\_Fulton](https://avatars.discourse-cdn.com/v4/letter/r/85f322/32.png) [@Russell\_Fulton](https://rubytalk.org/u/Russell_Fulton)\
**Post date:** [25 January 2006 02:11 UTC](https://rubytalk.org/t/still-having-problems-with-exceptions-in-imap-module/24329/1 "2006-01-25T02:11:59Z")

</div>

I have this method defined in a program I use for checking access to  
IMAP accounts.

def tryIMAP (host, usessl, user, pass)  
&nbsp;&nbsp;&nbsp;retryc = false  
&nbsp;&nbsp;&nbsp;proto = usessl ? "IMAPS" : "IMAP"  
&nbsp;&nbsp;&nbsp;begin  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;imap = Net::IMAP.new(host, usessl ? 993 : 143, usessl)  
&nbsp;&nbsp;&nbsp;rescue Net::IMAP::ByeResponseError =\> e  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;imap.disconnect if imap  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;STDERR.print "#{host} #{proto} #{e.to\_s}\n";  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;retryc = true  
&nbsp;&nbsp;&nbsp;rescue =\> e  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;imap.disconnect if imap  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;STDERR.print "#{host} #{proto} #{e.to\_s}\n";  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return 'aborted'  
&nbsp;&nbsp;&nbsp;end while retryc  
&nbsp;&nbsp;&nbsp;begin  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;imap.login( user, pass)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;imap.logout  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;imap.disconnect  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'success'  
&nbsp;&nbsp;&nbsp;rescue Net::IMAP::NoResponseError  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'failure'  
&nbsp;&nbsp;&nbsp;end  
end

As you can see I explicitly have a rescue clause for  
Net::IMAP::ByeResponseError but I still get the error raised at runtime  
☹

(Net::IMAP::ByeResponseError)948:in `receive\_responses': \* BYE  
Autologout; idle for too long  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /usr/lib/ruby/1.8/net/imap.rb:932:in `synchronize'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /usr/lib/ruby/1.8/net/imap.rb:932:in `receive\_responses'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /usr/lib/ruby/1.8/net/imap.rb:917:in `initialize'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /usr/lib/ruby/1.8/net/imap.rb:916:in `start'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /usr/lib/ruby/1.8/net/imap.rb:916:in `initialize'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from test.rb:11:in `new'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from test.rb:11:in `tryIMAP'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from test.rb:149  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from test.rb:105:in `each'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from test.rb:105  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from test.rb:94:in `each'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from test.rb:94  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from test.rb:93:in `open'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from test.rb:93

I am testing several thousand accounts and this error happens at random  
places in the list on different runs.

Can anyone suggest where I go from here. I suspect this is a bug  
somewhere in imap.rb but I can't reproduce this reliably. Sigh...

Russell

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
