title: javamail store.isconnected() function bug
body: <p>I came across a very strange bug in javamail store isConnected() function. I am using it in my android application the reconnect to store if connection is dropped.</p>
  
  <pre><code>if (!store.isConnected()) store.connect(host, username, password);
  </code></pre>
  
  <p>But, when connection is dropped, this function returns <strong>true</strong> the first time it is called, and <strong>false</strong> the second time it is called. That means that the above code will not trigger store.connect if store is not connected, but this code:</p>
  
  <pre><code>if (!store.isConnected()) store.connect(host, username, password);
  else if (!store.isConnected()) store.connect(host, username, password);
  </code></pre>
  
  <p>will reconnect the store because of the second call to isConnected() function that return false.</p>
  
  <p>I don't know if I explained the bug good enought.
  I would like to know if this is a known behavior or not. Maybe, I am doing something wrong. Or, maybe there is a better way to reconnect store if it is disconnected.</p>
  
  <p>Thank you in advance!</p>
  
  <p><em>Edit:</em></p>
  
  <p>This code:</p>
  
  <pre><code>LOGGER.warning("START1");
  if (!store.isConnected()) {
      LOGGER.warning("START1 CONN");
      store.connect(host, username, password);
      LOGGER.warning("END1 CONN");
  }
  LOGGER.warning("END1");
  LOGGER.warning("START2");
  if (!store.isConnected()) {
      LOGGER.warning("START2 CONN");
      store.connect(host, username, password);
      LOGGER.warning("END2 CONN");
  }
  LOGGER.warning("END2");
  </code></pre>
  
  <p>outputs this in javamail debug:</p>
  
  <pre><code>03-29 15:52:13.162: W/ShowMailbox(2063): START1
  03-29 15:52:15.238: I/System.out(2063): IMAP DEBUG: IMAPProtocol noop
  03-29 15:52:15.238: I/System.out(2063): A57 NOOP
  03-29 15:52:15.242: I/System.out(2063): DEBUG: IMAPStore connection dead
  03-29 15:52:15.242: I/System.out(2063): DEBUG: IMAPStore cleanup, force true
  03-29 15:52:15.242: I/System.out(2063): DEBUG: IMAPStore cleanup done
  03-29 15:52:22.810: W/ShowMailbox(2063): END1
  03-29 15:52:24.762: W/ShowMailbox(2063): START2
  03-29 15:52:34.033: W/ShowMailbox(2063): START2 CONN
  03-29 15:52:36.369: I/System.out(2063): * OK [CAPABILITY IMAP4rev1 UIDPLUS CHILDREN NAMESPACE THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT QUOTA IDLE STARTTLS] Courier-IMAP ready. Copyright 1998-2008 Double Precision, Inc.  See COPYING for distribution information.
  03-29 15:52:36.369: I/System.out(2063): A0 CAPABILITY
  ...
  03-29 15:52:37.857: I/System.out(2063): A3 OK LOGIN Ok.
  03-29 15:52:38.053: I/System.out(2063): IMAP DEBUG: AUTH: PLAIN
  03-29 15:52:39.297: W/ShowMailbox(2063): END2 CONN
  03-29 15:52:40.885: W/ShowMailbox(2063): END2
  </code></pre>
  
  <p>It looks like the first call to isConnected() is executed but returning true even if store is not connected and second isConnected() is not executed at all!? But it executes connect() function!?</p>
  
  <p>I am really confused. And a little scared... :)</p>