IMAP disconnect method broken?

I’m using the standard Net::IMAP and OpenSSL libraries to connect to
an IMAP server.
I can connect, examine and manipulate my INBOX, but when call the
disconnect method of the imap instance it just hangs. The minimal
version is almost identical to
the example on page 701 of “Programming Ruby”. Should I be calling
some other method?

require ‘net/imap’
require ‘openssl’
server, login, password = ‘imap.server’,‘my_login’,‘my_password’
imap = Net::IMAP::new(server, 993, true)
imap.login(login,password)
imap.examine(‘INBOX’)
puts “Message count: #{ imap.responses[“EXISTS”]}”
imap.search([“To”, “Me”]).each do |message_id|
envelope = imap.fetch(message_id, “ENVELOPE”)[0].attr[“ENVELOPE”]
puts “#{envelope.from[0].name}: \t#{envelope.subject}”
end
imap.disconnect

Regards,

Bealach