[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Net::imap exceptions

Russell Fulton

1/24/2006 3:56:00 AM

Hi,
I have a program that I am using to do password auditing on various
IMAP servers. It defines this method:

def tryIMAP (host, usessl, user, pass)

proto = usessl ? "IMAPS" : "IMAP"
begin
imap = Net::IMAP.new(host, usessl ? 993 : 143, usessl)
rescue => e
imap.disconnect if imap
STDERR.print "#{host} #{proto} #{e.to_s}\n";
raise RuntimeError, "#{proto} failed"
end
begin
imap.login( user, pass)
imap.logout
imap.disconnect
'success'
rescue Net::IMAP::NoResponseError
'failure'
end

end

But the rescue clause does not catch all errors:

(Net::IMAP::ByeResponseError)948:in `receive_responses': * BYE
Autologout; idle for too long
from /usr/lib/ruby/1.8/net/imap.rb:932:in `synchronize'
from /usr/lib/ruby/1.8/net/imap.rb:932:in `receive_responses'
from /usr/lib/ruby/1.8/net/imap.rb:917:in `initialize'
from /usr/lib/ruby/1.8/net/imap.rb:916:in `start'
from /usr/lib/ruby/1.8/net/imap.rb:916:in `initialize'
from test.rb:11:in `new'
from test.rb:11:in `tryIMAP'
from test.rb:143
from test.rb:100:in `each'
from test.rb:100
from test.rb:89:in `each'
from test.rb:89
from test.rb:88:in `open'
from test.rb:88

How can I catch these errors?

--
Posted via http://www.ruby-....


7 Answers

Stefan Mahlitz

1/24/2006 7:10:00 AM

0

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Russell Fulton wrote:
> Hi,
> I have a program that I am using to do password auditing on various
> IMAP servers. It defines this method:
>
> def tryIMAP (host, usessl, user, pass)
>
> proto = usessl ? "IMAPS" : "IMAP"
> begin
> imap = Net::IMAP.new(host, usessl ? 993 : 143, usessl)
> rescue => e
> imap.disconnect if imap
> STDERR.print "#{host} #{proto} #{e.to_s}\n";
> raise RuntimeError, "#{proto} failed"
> end
> begin
> imap.login( user, pass)
> imap.logout
> imap.disconnect
> 'success'
> rescue Net::IMAP::NoResponseError
> 'failure'
> end
>
> end
>
> But the rescue clause does not catch all errors:
>
> (Net::IMAP::ByeResponseError)948:in `receive_responses': * BYE
> Autologout; idle for too long

[snip]

>
> How can I catch these errors?

Change the rescue-line to:

> rescue Net::IMAP::NoResponseError, Net::IMAP::ByeResponseError, Net::IMAP::BadResponseError

and so on. Maybe it helps to rescue Net::IMAP::Error only, but can't
have a look at the implementation of the other exceptions at the moment.

HTH

Stefan
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (MingW32)

iD8DBQFD1dLM9S2Eui6zfdQRAiiRAJ9CMxchp2129sP5srKNpFHhEUIIgQCfU+ov
4bEy3i+wvmei5HvOR8RYDKk=
=Y0JS
-----END PGP SIGNATURE-----


Russell Fulton

1/24/2006 7:05:00 PM

0

Stefan Mahlitz wrote:

Thanks for your response Stefan!

>>
>> How can I catch these errors?
>
> Change the rescue-line to:
>
>> rescue Net::IMAP::NoResponseError, Net::IMAP::ByeResponseError, Net::IMAP::BadResponseError

That was going to be my next try. Hmmm.... last time I tried putting
more than one exception on a rescue statement I got a syntax error??
I'll try again -- must have been some other issue.

>
> and so on. Maybe it helps to rescue Net::IMAP::Error only, but can't
> have a look at the implementation of the other exceptions at the moment.
>

Just a check on my understanding of how things *should* work:

I thought that an unadorned "rescue" *should* catch *all* exceptions.
Is this correct? Should I file a bug report? Where to?

Russell

--
Posted via http://www.ruby-....


Russell Fulton

1/24/2006 11:53:00 PM

0

Russell Fulton wrote:
> Stefan Mahlitz wrote:
>
> Thanks for your response Stefan!
>
>>>
>>> How can I catch these errors?
>>
>> Change the rescue-line to:
>>
>>> rescue Net::IMAP::NoResponseError, Net::IMAP::ByeResponseError, Net::IMAP::BadResponseError
>
> That was going to be my next try.

I have now tried this and it still throws the exception with an explicit
rescue for that error.

Russell

--
Posted via http://www.ruby-....


Stefan Mahlitz

1/26/2006 7:41:00 PM

0

Russell Fulton wrote:
> Stefan Mahlitz wrote:
>
> Thanks for your response Stefan!
>
>>> How can I catch these errors?
>> Change the rescue-line to:
>>
>>> rescue Net::IMAP::NoResponseError, Net::IMAP::ByeResponseError, Net::IMAP::BadResponseError
>
> That was going to be my next try. Hmmm.... last time I tried putting
> more than one exception on a rescue statement I got a syntax error??
> I'll try again -- must have been some other issue.
>
>> and so on. Maybe it helps to rescue Net::IMAP::Error only, but can't
>> have a look at the implementation of the other exceptions at the moment.
>>
>
> Just a check on my understanding of how things *should* work:
>
> I thought that an unadorned "rescue" *should* catch *all* exceptions.
> Is this correct? Should I file a bug report? Where to?

No, it will only catch all Exceptions that are derived from
StandardError (as I read Pickaxe II, page 108).

Figure 8.1 on page 109 could be helpful.

The exception gets thrown in

> imap = Net::IMAP.new(host, usessl ? 993 : 143, usessl)

as the backtrace tells:

> ...
> from /usr/lib/ruby/1.8/net/imap.rb:916:in `initialize'
> from test.rb:11:in `new'
> from test.rb:11:in `tryIMAP'
> ...

and on line 12 is only the standard rescue

> rescue => e

If you add the IMAP-Exceptions there it should work (and raise a
RuntimeException).


Russell Fulton

1/26/2006 8:35:00 PM

0

Stefan Mahlitz wrote:
>
> No, it will only catch all Exceptions that are derived from
> StandardError (as I read Pickaxe II, page 108).
>
Ah! missed that, my bad!

Thanks Stefan!

--
Posted via http://www.ruby-....


The Peeler

6/28/2013 1:11:00 PM

0

On Fri, 28 Jun 2013 12:17:55 +0200, The Peeler
<finishingoff@themoronicRevd.invalid> wrote:

>On Thu, 27 Jun 2013 15:58:56 -0700, The Rectum, the resident psychopath of
>sci and scj, FAKING his time zone again and IMPERSONATING his master, The
>Peeler, wrote:
>
>>> >> >> >>Let's review these 11 points.
>>> >> >> >
>>> >> >> > Let's, not anus! <GGGGGGGG>
>>> >> >>
>>> >> >> Why, The Rectum? <BG>
>>> >> >
>>> >> > Why, not The Grik anus? <GB>
>>> >>
>>> >> So, why not, The Rectum? <BG>
>>> >
>>> > So, why The Grik anus? <GB>
>>>
>>> I might learn something, as a Grik idiot! <BG>
>>
>> You, MIGHT The Grik anus! <GB>
>
>Remember, I AM the official Grik village idiot here! ;-)

INNIT Grik anus! :---------------)

The Peeler

6/28/2013 3:56:00 PM

0

On Fri, 28 Jun 2013 06:11:11 -0700, The Rectum, the resident psychopath of
sci and scj, FAKING his time zone again and IMPERSONATING his master, The
Peeler, wrote:

>> >> You might learn something, idiot! <BG>
>> >
>> > You, MIGHT The Grik anus! <GB>
>>
>> Remember, YOU are the official village idiot here! ;-)
>
> INNIT Grik anus! :---------------)

You ARE!!! ;-))))

--
happy zombie addressing The Rectum:
"you are fluent in talking complete shite."
MID: <k5vur815aik81ki65l4r4t1dov70a0c88e@4ax.com>