@Override public boolean create(FolderType type) throws MessagingException { /* * This method needs to operate in the unselected mode as well as the selected mode * so we must get the connection ourselves if it's not there. We are specifically * not calling checkOpen() since we don't care if the folder is open. */ ImapConnection connection = null; synchronized (this) { if (mConnection == null) { connection = mStore.getConnection(); } else { connection = mConnection; } } try { connection.executeSimpleCommand( String.format( ImapConstants.CREATE + " \"%s\"", ImapStore.encodeFolderName(mName, mStore.mPathPrefix))); return true; } catch (MessagingException me) { return false; } catch (IOException ioe) { throw ioExceptionHandler(connection, ioe); } finally { connection.destroyResponses(); if (mConnection == null) { mStore.poolConnection(connection); } } }
@Override public void open(OpenMode mode) throws MessagingException { try { if (isOpen()) { if (mMode == mode) { // Make sure the connection is valid. // If it's not we'll close it down and continue on to get a new one. try { mConnection.executeSimpleCommand(ImapConstants.NOOP); return; } catch (IOException ioe) { ioExceptionHandler(mConnection, ioe); } finally { destroyResponses(); } } else { // Return the connection to the pool, if exists. close(false); } } synchronized (this) { mConnection = mStore.getConnection(); } // * FLAGS (\Answered \Flagged \Deleted \Seen \Draft NonJunk // $MDNSent) // * OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft // NonJunk $MDNSent \*)] Flags permitted. // * 23 EXISTS // * 0 RECENT // * OK [UIDVALIDITY 1125022061] UIDs valid // * OK [UIDNEXT 57576] Predicted next UID // 2 OK [READ-WRITE] Select completed. try { doSelect(); } catch (IOException ioe) { throw ioExceptionHandler(mConnection, ioe); } finally { destroyResponses(); } } catch (AuthenticationFailedException e) { // Don't cache this connection, so we're forced to try connecting/login again mConnection = null; close(false); throw e; } catch (MessagingException e) { mExists = false; close(false); throw e; } }
@Override public boolean exists() throws MessagingException { if (mExists) { return true; } /* * This method needs to operate in the unselected mode as well as the selected mode * so we must get the connection ourselves if it's not there. We are specifically * not calling checkOpen() since we don't care if the folder is open. */ ImapConnection connection = null; synchronized (this) { if (mConnection == null) { connection = mStore.getConnection(); } else { connection = mConnection; } } try { connection.executeSimpleCommand( String.format( ImapConstants.STATUS + " \"%s\" (" + ImapConstants.UIDVALIDITY + ")", ImapStore.encodeFolderName(mName, mStore.mPathPrefix))); mExists = true; return true; } catch (MessagingException me) { // Treat IOERROR messaging exception as IOException if (me.getExceptionType() == MessagingException.IOERROR) { throw me; } return false; } catch (IOException ioe) { throw ioExceptionHandler(connection, ioe); } finally { connection.destroyResponses(); if (mConnection == null) { mStore.poolConnection(connection); } } }