title: java mail Store.connect hangs - doesn't timeout
body: <p>I'm using plain old java mail (mail-1.4.1.jar - JVM 1.6.0_03-b05) to connect to an IMAP store:</p>
  
  <pre><code>Session mailSession = Session.getInstance(new Properties(), null);
  Store store = mailSession.getStore("imap");
  store.connect(host, user, pwd); // Hangs here
  folder = store.getFolder("INBOX");
  folder.open(Folder.READ_WRITE);
  ...
  </code></pre>
  
  <p>Problem is, occasionally the thread hands at <code>store.connect</code> and never returns.</p>
  
  <pre><code>"MyThread" daemon prio=10 tid=0x0a9c3000 nid=0x2095 runnable [0x9ccd3000..0x9ccd4130]
     java.lang.Thread.State: RUNNABLE
          at java.net.SocketInputStream.socketRead0(Native Method)
          at java.net.SocketInputStream.read(SocketInputStream.java:129)
          at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:110)
          at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
          at java.io.BufferedInputStream.read(BufferedInputStream.java:237)
          - locked &lt;0xc09003e8&gt; (a java.io.BufferedInputStream)
          at com.sun.mail.iap.ResponseInputStream.readResponse(ResponseInputStream.java:97)
          at com.sun.mail.iap.Response.&lt;init&gt;(Response.java:96)
          at com.sun.mail.imap.protocol.IMAPResponse.&lt;init&gt;(IMAPResponse.java:61)
          at com.sun.mail.imap.protocol.IMAPResponse.readResponse(IMAPResponse.java:135)
          at com.sun.mail.imap.protocol.IMAPProtocol.readResponse(IMAPProtocol.java:261)
          at com.sun.mail.iap.Protocol.&lt;init&gt;(Protocol.java:114)
          at com.sun.mail.imap.protocol.IMAPProtocol.&lt;init&gt;(IMAPProtocol.java:104)
          at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:538)
          - locked &lt;0xc04c73d0&gt; (a com.sun.mail.imap.IMAPStore)
          at javax.mail.Service.connect(Service.java:288)
          - locked &lt;0xc04c73d0&gt; (a com.sun.mail.imap.IMAPStore)
          at javax.mail.Service.connect(Service.java:169)
          at package.MyClass.checkInbox(MyClass.java:116)
  </code></pre>
  
  <p>There is no mention of timeout settings in the <a href="http://java.sun.com/products/javamail/JavaMail-1.2.pdf" rel="nofollow">javamail spec</a> and I cannot find any suitable 'setter' methods on either <code>Session</code> or <code>Store</code>.</p>
  
  <p>Any suggestions welcome.</p>