# IMAP disconnect broken?

**URL:** <https://rubytalk.org/t/imap-disconnect-broken/26934>\
**Category:** ruby-talk\
**Created:** [25 April 2006 21:21 UTC](https://rubytalk.org/t/imap-disconnect-broken/26934 "2006-04-25T21:21:38Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bealach\_Na\_Bo](https://avatars.discourse-cdn.com/v4/letter/b/e19b73/32.png) [@Bealach\_Na\_Bo](https://rubytalk.org/u/Bealach_Na_Bo)\
**Post date:** [25 April 2006 21:21 UTC](https://rubytalk.org/t/imap-disconnect-broken/26934/1 "2006-04-25T21:21:38Z")

</div>

Hi folks,

New Ruby convert here 🙂

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

---

<div class="post-metadata">

**Author:** ![Eric\_Hodel1](https://avatars.discourse-cdn.com/v4/letter/e/a9adbd/32.png) [@Eric\_Hodel1](https://rubytalk.org/u/Eric_Hodel1)\
**Post date:** [28 April 2006 20:56 UTC](https://rubytalk.org/t/imap-disconnect-broken/26934/2 "2006-04-28T20:56:35Z")

</div>

I don't know, the disconnect method is suspect:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# Disconnects from the server.  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def disconnect  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@sock.shutdown unless @usessl  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@receiver\_thread.join  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@sock.close  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end

> **···**
>
> On Apr 25, 2006, at 2:21 PM, Bealach Na Bo wrote:
> 
> > Hi folks,
> > 
> > New Ruby convert here 🙂
> > 
> > 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?
> 
> --  
> Eric Hodel - drbrain@segment7.net - [http://blog.segment7.net](http://blog.segment7.net)  
> This implementation is HODEL-HASH-9600 compliant
> 
> [http://trackmap.robotcoop.com](http://trackmap.robotcoop.com)

---

<div class="post-metadata">

**Author:** ![Stuart\_Stegall](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@Stuart\_Stegall](https://rubytalk.org/u/Stuart_Stegall)\
**Post date:** [28 April 2006 21:58 UTC](https://rubytalk.org/t/imap-disconnect-broken/26934/3 "2006-04-28T21:58:33Z")

</div>

Eric Hodel wrote:

> > Hi folks,
> > 
> > New Ruby convert here 🙂
> > 
> > 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?
> 
> I don't know, the disconnect method is suspect:
> 
> &nbsp;&nbsp;&nbsp;&nbsp;# Disconnects from the server.  
> &nbsp;&nbsp;&nbsp;&nbsp;def disconnect  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@sock.shutdown unless @usessl  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@receiver\_thread.join  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@sock.close  
> &nbsp;&nbsp;&nbsp;&nbsp;end

I cannot replicate the problem with my imap4 server.

> **···**
>
> > On Apr 25, 2006, at 2:21 PM, Bealach Na Bo wrote:

---

<div class="post-metadata">

**Author:** ![Bealach\_Na\_Bo](https://avatars.discourse-cdn.com/v4/letter/b/e19b73/32.png) [@Bealach\_Na\_Bo](https://rubytalk.org/u/Bealach_Na_Bo)\
**Post date:** [28 April 2006 22:32 UTC](https://rubytalk.org/t/imap-disconnect-broken/26934/4 "2006-04-28T22:32:20Z")

</div>

I've not set up my own IMAP server to test this, but I just might.  
Sadly, that will not solve the problem for since I do not have admin  
access to the IMAP server I'm experiencing problems with  
(incidentally, that too is an IMAP 4 server).

Bealach

> **···**
>
> On 4/28/06, Stuart Stegall \<stuart@footworkmedia.com\> wrote:
> 
> > Eric Hodel wrote:  
> > \>  
> > \> On Apr 25, 2006, at 2:21 PM, Bealach Na Bo wrote:  
> > \>  
> > \>\> Hi folks,  
> > \>\>  
> > \>\> New Ruby convert here 🙂  
> > \>\>  
> > \>\> 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?  
> > \>  
> > \> I don't know, the disconnect method is suspect:  
> > \>  
> > \> # Disconnects from the server.  
> > \> def disconnect  
> > \> @sock.shutdown unless @usessl  
> > \> @receiver\_thread.join  
> > \> @sock.close  
> > \> end  
> > \>  
> > I cannot replicate the problem with my imap4 server.

---

<div class="post-metadata">

**Author:** ![Eric\_Hodel1](https://avatars.discourse-cdn.com/v4/letter/e/a9adbd/32.png) [@Eric\_Hodel1](https://rubytalk.org/u/Eric_Hodel1)\
**Post date:** [30 April 2006 19:37 UTC](https://rubytalk.org/t/imap-disconnect-broken/26934/5 "2006-04-30T19:37:10Z")

</div>

Did you use SSL?

I have Dovecot.

> **···**
>
> On Apr 28, 2006, at 2:58 PM, Stuart Stegall wrote:
> 
> > Eric Hodel wrote:
> > 
> > > On Apr 25, 2006, at 2:21 PM, Bealach Na Bo wrote:
> > > 
> > > > Hi folks,
> > > > 
> > > > New Ruby convert here 🙂
> > > > 
> > > > 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?
> > > 
> > > I don't know, the disconnect method is suspect:
> > > 
> > > &nbsp;&nbsp;&nbsp;&nbsp;# Disconnects from the server.  
> > > &nbsp;&nbsp;&nbsp;&nbsp;def disconnect  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@sock.shutdown unless @usessl  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@receiver\_thread.join  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@sock.close  
> > > &nbsp;&nbsp;&nbsp;&nbsp;end
> > 
> > I cannot replicate the problem with my imap4 server.
> 
> --  
> Eric Hodel - drbrain@segment7.net - [http://blog.segment7.net](http://blog.segment7.net)  
> This implementation is HODEL-HASH-9600 compliant
> 
> [http://trackmap.robotcoop.com](http://trackmap.robotcoop.com)

---

<div class="post-metadata">

**Author:** ![Stuart\_Stegall](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@Stuart\_Stegall](https://rubytalk.org/u/Stuart_Stegall)\
**Post date:** [30 April 2006 22:04 UTC](https://rubytalk.org/t/imap-disconnect-broken/26934/6 "2006-04-30T22:04:51Z")

</div>

Eric Hodel wrote:

> > Eric Hodel wrote:
> > 
> > > > Hi folks,
> > > > 
> > > > New Ruby convert here 🙂
> > > > 
> > > > 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?
> > > 
> > > I don't know, the disconnect method is suspect:
> > > 
> > > &nbsp;&nbsp;&nbsp;&nbsp;# Disconnects from the server.  
> > > &nbsp;&nbsp;&nbsp;&nbsp;def disconnect  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@sock.shutdown unless @usessl  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@receiver\_thread.join  
> > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@sock.close  
> > > &nbsp;&nbsp;&nbsp;&nbsp;end
> > 
> > I cannot replicate the problem with my imap4 server.
> 
> Did you use SSL?
> 
> I have Dovecot.

I used SSL and I tried it on Gentoo Linux and Windows. The Windows is all my own compiling as I am using the Intel C++ compiler to compile everything (which of course causes me problems with some gems/addons/libraries as they are precompiled for Windows and do not include nmake makefile or VS project files and then I have to TRY to manually make a makefile for them)

But I digress, on both platforms, I got the exact same lack of a problem.

> **···**
>
> > On Apr 28, 2006, at 2:58 PM, Stuart Stegall wrote:
> > 
> > > > On Apr 25, 2006, at 2:21 PM, Bealach Na Bo wrote:

---

<div class="post-metadata">

**Author:** ![Bealach\_Na\_Bo](https://avatars.discourse-cdn.com/v4/letter/b/e19b73/32.png) [@Bealach\_Na\_Bo](https://rubytalk.org/u/Bealach_Na_Bo)\
**Post date:** [30 April 2006 22:29 UTC](https://rubytalk.org/t/imap-disconnect-broken/26934/7 "2006-04-30T22:29:08Z")

</div>

Is your code anything like what I posted (quoting from "Programming  
Ruby")? I've tried that code in Debian, WinXP pro (SP2) and Win2003  
all with ruby 1.8.4 and all of them hang at exactly the same place.  
Can you post some example code if it's different to what I posted.

Regards,

Bealach

> **···**
>
> On 5/1/06, Stuart Stegall \<stuart@footworkmedia.com\> wrote:
> 
> > Eric Hodel wrote:  
> > \> On Apr 28, 2006, at 2:58 PM, Stuart Stegall wrote:  
> > \>  
> > \>\> Eric Hodel wrote:  
> > \>\>\>  
> > \>\>\> On Apr 25, 2006, at 2:21 PM, Bealach Na Bo wrote:  
> > \>\>\>  
> > \>\>\>\> Hi folks,  
> > \>\>\>\>  
> > \>\>\>\> New Ruby convert here 🙂  
> > \>\>\>\>  
> > \>\>\>\> 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?  
> > \>\>\>  
> > \>\>\> I don't know, the disconnect method is suspect:  
> > \>\>\>  
> > \>\>\> # Disconnects from the server.  
> > \>\>\> def disconnect  
> > \>\>\> @sock.shutdown unless @usessl  
> > \>\>\> @receiver\_thread.join  
> > \>\>\> @sock.close  
> > \>\>\> end  
> > \>\>\>  
> > \>\> I cannot replicate the problem with my imap4 server.  
> > \>  
> > \> Did you use SSL?  
> > \>  
> > \> I have Dovecot.  
> > \>  
> > I used SSL and I tried it on Gentoo Linux and Windows. The Windows is  
> > all my own compiling as I am using the Intel C++ compiler to compile  
> > everything (which of course causes me problems with some  
> > gems/addons/libraries as they are precompiled for Windows and do not  
> > include nmake makefile or VS project files and then I have to TRY to  
> > manually make a makefile for them)
> > 
> > But I digress, on both platforms, I got the exact same lack of a problem.

---

<div class="post-metadata">

**Author:** ![Eric\_Hodel1](https://avatars.discourse-cdn.com/v4/letter/e/a9adbd/32.png) [@Eric\_Hodel1](https://rubytalk.org/u/Eric_Hodel1)\
**Post date:** [1 May 2006 19:36 UTC](https://rubytalk.org/t/imap-disconnect-broken/26934/8 "2006-05-01T19:36:50Z")

</div>

> Eric Hodel wrote:
> 
> > > Eric Hodel wrote:
> > > 
> > > > I don't know, the disconnect method is suspect:
> > > > 
> > > > &nbsp;&nbsp;&nbsp;&nbsp;# Disconnects from the server.  
> > > > &nbsp;&nbsp;&nbsp;&nbsp;def disconnect  
> > > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@sock.shutdown unless @usessl  
> > > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@receiver\_thread.join  
> > > > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@sock.close  
> > > > &nbsp;&nbsp;&nbsp;&nbsp;end
> > > 
> > > I cannot replicate the problem with my imap4 server.
> > 
> > Did you use SSL?
> > 
> > I have Dovecot.
> 
> I used SSL and I tried it on Gentoo Linux and Windows. [...]

This problem has nothing to do with SSL on the client side.

> But I digress, on both platforms, I got the exact same lack of a problem.

What mail server are you using?

> **···**
>
> On Apr 30, 2006, at 3:04 PM, Stuart Stegall wrote:
> 
> > > On Apr 28, 2006, at 2:58 PM, Stuart Stegall wrote:
> 
> --  
> Eric Hodel - drbrain@segment7.net - [http://blog.segment7.net](http://blog.segment7.net)  
> This implementation is HODEL-HASH-9600 compliant
> 
> [http://trackmap.robotcoop.com](http://trackmap.robotcoop.com)

---

<div class="post-metadata">

**Author:** ![Stuart\_Stegall](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@Stuart\_Stegall](https://rubytalk.org/u/Stuart_Stegall)\
**Post date:** [2 May 2006 01:02 UTC](https://rubytalk.org/t/imap-disconnect-broken/26934/9 "2006-05-02T01:02:09Z")

</div>

[SNIP]

> > I used SSL and I tried it on Gentoo Linux and Windows. [...]
> 
> This problem has nothing to do with SSL on the client side.
> 
> > But I digress, on both platforms, I got the exact same lack of a problem.
> 
> What mail server are you using?
> 
> [SNIP

I am not sure what server it is. I teleneted to port 143 and 993 (I have a special perl SSL telnet program for testing SSL ports) and It just says IMAP4rev1

---

<div class="post-metadata">

**Author:** ![Stuart\_Stegall](https://avatars.discourse-cdn.com/v4/letter/s/7ea924/32.png) [@Stuart\_Stegall](https://rubytalk.org/u/Stuart_Stegall)\
**Post date:** [2 May 2006 01:03 UTC](https://rubytalk.org/t/imap-disconnect-broken/26934/10 "2006-05-02T01:03:19Z")

</div>

Bealach Na Bo wrote:

> **···**
>
> > On 5/1/06, Stuart Stegall \<stuart@footworkmedia.com\> wrote:
> > 
> > > Eric Hodel wrote:  
> > > \> On Apr 28, 2006, at 2:58 PM, Stuart Stegall wrote:  
> > > \>  
> > > \>\> Eric Hodel wrote:  
> > > \>\>\>  
> > > \>\>\> On Apr 25, 2006, at 2:21 PM, Bealach Na Bo wrote:  
> > > \>\>\>  
> > > \>\>\>\> Hi folks,  
> > > \>\>\>\>  
> > > \>\>\>\> New Ruby convert here 🙂  
> > > \>\>\>\>  
> > > \>\>\>\> 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?  
> > > \>\>\>  
> > > \>\>\> I don't know, the disconnect method is suspect:  
> > > \>\>\>  
> > > \>\>\> # Disconnects from the server.  
> > > \>\>\> def disconnect  
> > > \>\>\> @sock.shutdown unless @usessl  
> > > \>\>\> @receiver\_thread.join  
> > > \>\>\> @sock.close  
> > > \>\>\> end  
> > > \>\>\>  
> > > \>\> I cannot replicate the problem with my imap4 server.  
> > > \>  
> > > \> Did you use SSL?  
> > > \>  
> > > \> I have Dovecot.  
> > > \>  
> > > I used SSL and I tried it on Gentoo Linux and Windows. The Windows is  
> > > all my own compiling as I am using the Intel C++ compiler to compile  
> > > everything (which of course causes me problems with some  
> > > gems/addons/libraries as they are precompiled for Windows and do not  
> > > include nmake makefile or VS project files and then I have to TRY to  
> > > manually make a makefile for them)
> > > 
> > > But I digress, on both platforms, I got the exact same lack of a problem.
> > 
> > Is your code anything like what I posted (quoting from "Programming  
> > Ruby")? I've tried that code in Debian, WinXP pro (SP2) and Win2003  
> > all with ruby 1.8.4 and all of them hang at exactly the same place.  
> > Can you post some example code if it's different to what I posted.
> > 
> > Regards,
> > 
> > Bealach
> 
> I used the same code, but did you use the same IMAP server for all of your tests? (I did for mine, but of course it worked for me.)

---

<div class="post-metadata">

**Author:** ![Eric\_Hodel1](https://avatars.discourse-cdn.com/v4/letter/e/a9adbd/32.png) [@Eric\_Hodel1](https://rubytalk.org/u/Eric_Hodel1)\
**Post date:** [4 May 2006 05:48 UTC](https://rubytalk.org/t/imap-disconnect-broken/26934/11 "2006-05-04T05:48:51Z")

</div>

> [SNIP]
> 
> > > I used SSL and I tried it on Gentoo Linux and Windows. [...]
> > 
> > This problem has nothing to do with SSL on the client side.
> > 
> > > But I digress, on both platforms, I got the exact same lack of a problem.
> > 
> > What mail server are you using?
> > 
> > [SNIP
> 
> I am not sure what server it is.

Could you find out? It'll help track down where the bug really is.

> I teleneted to port 143 and 993 (I have a special perl SSL telnet program for testing SSL ports) and It just says IMAP4rev1

dovecot says:

$ openssl s\_client -connect mail.robotcoop.com:imaps  
CONNECTED(00000004)  
[openssl output]  
\* OK Dovecot ready.  
QUIT  
DONE  
$

> **···**
>
> On May 1, 2006, at 6:02 PM, Stuart Stegall wrote:
> 
> --  
> Eric Hodel - drbrain@segment7.net - [http://blog.segment7.net](http://blog.segment7.net)  
> This implementation is HODEL-HASH-9600 compliant
> 
> [http://trackmap.robotcoop.com](http://trackmap.robotcoop.com)

---

<div class="post-metadata">

**Author:** ![Eric\_Hodel1](https://avatars.discourse-cdn.com/v4/letter/e/a9adbd/32.png) [@Eric\_Hodel1](https://rubytalk.org/u/Eric_Hodel1)\
**Post date:** [4 May 2006 07:16 UTC](https://rubytalk.org/t/imap-disconnect-broken/26934/12 "2006-05-04T07:16:11Z")

</div>

UW IMAP has the same problem (host name removed, not my mail server).

$ openssl s\_client -connect mail.example.com:imaps  
CONNECTED(00000004)  
\* OK [CAPABILITY IMAP4REV1 LOGIN-REFERRALS AUTH=CRAM-MD5 AUTH=PLAIN AUTH=LOGIN] [w.x.y.z] IMAP4rev1 2002.332 at Wed, 3 May 2006 22:50:04 -0700 (PDT)  
QUIT  
DONE  
$ ruby -ropenssl -rnet/imap -e 'Net::IMAP.new("mail.example.com", 993, true).disconnect'  
^C/usr/local/lib/ruby/1.8/net/imap.rb:288:in `join': Interrupt  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /usr/local/lib/ruby/1.8/net/imap.rb:288:in `disconnect'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from -e:1

> **···**
>
> On May 1, 2006, at 6:02 PM, Stuart Stegall wrote:
> 
> > [SNIP]
> > 
> > > > I used SSL and I tried it on Gentoo Linux and Windows. [...]
> > > 
> > > This problem has nothing to do with SSL on the client side.
> > > 
> > > > But I digress, on both platforms, I got the exact same lack of a problem.
> > > 
> > > What mail server are you using?
> > > 
> > > [SNIP
> > 
> > I am not sure what server it is. I teleneted to port 143 and 993 (I have a special perl SSL telnet program for testing SSL ports) and It just says IMAP4rev1
> 
> --  
> Eric Hodel - drbrain@segment7.net - [http://blog.segment7.net](http://blog.segment7.net)  
> This implementation is HODEL-HASH-9600 compliant
> 
> [http://trackmap.robotcoop.com](http://trackmap.robotcoop.com)
