private boolean exists(String escapedFolderName) throws MessagingException { try { // Since we don't care about RECENT, we'll use that for the check, because we're checking // a folder other than ourself, and don't want any untagged responses to cause a change // in our own fields connection.executeSimpleCommand(String.format("STATUS %s (RECENT)", escapedFolderName)); return true; } catch (IOException ioe) { throw ioExceptionHandler(connection, ioe); } catch (NegativeImapResponseException e) { return false; } }
protected List<ImapMessage> getMessagesFromUids(final List<String> mesgUids) throws MessagingException { checkOpen(); Set<Long> uidSet = new HashSet<>(); for (String uid : mesgUids) { uidSet.add(Long.parseLong(uid)); } try { List<ImapResponse> imapResponses = connection.executeCommandWithIdSet("UID SEARCH UID", "", uidSet); SearchResponse searchResponse = SearchResponse.parse(imapResponses); return getMessages(searchResponse, null); } catch (IOException ioe) { throw ioExceptionHandler(connection, ioe); } }
@Override public void expungeUids(List<String> uids) throws MessagingException { if (uids == null || uids.isEmpty()) { throw new IllegalArgumentException("expungeUids() must be called with a non-empty set of UIDs"); } open(OPEN_MODE_RW); checkOpen(); try { if (connection.isUidPlusCapable()) { Set<Long> longUids = new HashSet<>(uids.size()); for (String uid : uids) { longUids.add(Long.parseLong(uid)); } connection.executeCommandWithIdSet(Commands.UID_EXPUNGE, "", longUids); } else { executeSimpleCommand("EXPUNGE"); } } catch (IOException ioe) { throw ioExceptionHandler(connection, ioe); } }
protected long getHighestUid() throws MessagingException { try { List<ImapResponse> responses = executeSimpleCommand("UID SEARCH *:*"); SearchResponse searchResponse = SearchResponse.parse(responses); return extractHighestUid(searchResponse); } catch (NegativeImapResponseException e) { return -1L; } catch (IOException ioe) { throw ioExceptionHandler(connection, ioe); } }
@Override public void expunge() throws MessagingException { open(OPEN_MODE_RW); checkOpen(); try { executeSimpleCommand("EXPUNGE"); } catch (IOException ioe) { throw ioExceptionHandler(connection, ioe); } }
@Override public void setFlags(List<? extends Message> messages, final Set<Flag> flags, boolean value) throws MessagingException { open(OPEN_MODE_RW); checkOpen(); Set<Long> uids = new HashSet<>(messages.size()); for (Message message : messages) { uids.add(Long.parseLong(message.getUid())); } boolean canCreateForwardedFlag = canCreateKeywords || store.getPermanentFlagsIndex().contains(Flag.FORWARDED); String combinedFlags = ImapUtility.combineFlags(flags, canCreateForwardedFlag); String commandSuffix = String.format("%sFLAGS.SILENT (%s)", value ? "+" : "-", combinedFlags); try { connection.executeCommandWithIdSet(Commands.UID_STORE, commandSuffix, uids); } catch (IOException ioe) { throw ioExceptionHandler(connection, ioe); } }
@Override public void setFlags(Set<Flag> flags, boolean value) throws MessagingException { open(OPEN_MODE_RW); checkOpen(); boolean canCreateForwardedFlag = canCreateKeywords || store.getPermanentFlagsIndex().contains(Flag.FORWARDED); try { String combinedFlags = ImapUtility.combineFlags(flags, canCreateForwardedFlag); String command = String.format("%s 1:* %sFLAGS.SILENT (%s)", Commands.UID_STORE, value ? "+" : "-", combinedFlags); executeSimpleCommand(command); } catch (IOException ioe) { throw ioExceptionHandler(connection, ioe); } }
@Override public String getUidFromMessageId(String messageId) throws MessagingException { if (K9MailLib.isDebug()) { Timber.d("Looking for UID for message with message-id %s for %s", messageId, getLogId()); } String command = String.format("UID SEARCH HEADER MESSAGE-ID %s", ImapUtility.encodeString(messageId)); List<ImapResponse> imapResponses; try { imapResponses = executeSimpleCommand(command); } catch (IOException ioe) { throw ioExceptionHandler(connection, ioe); } SearchResponse searchResponse = SearchResponse.parse(imapResponses); List<Long> uids = searchResponse.getNumbers(); if (uids.size() > 0) { return Long.toString(uids.get(0)); } return null; }
protected List<ImapMessage> getMessages(final Set<Long> mesgSeqs, final boolean includeDeleted, final MessageRetrievalListener<ImapMessage> listener) throws MessagingException { checkOpen(); try { String commandSuffix = includeDeleted ? "" : " NOT DELETED"; List<ImapResponse> imapResponses = connection.executeCommandWithIdSet(Commands.UID_SEARCH, commandSuffix, mesgSeqs); SearchResponse searchResponse = SearchResponse.parse(imapResponses); return getMessages(searchResponse, listener); } catch (IOException ioe) { throw ioExceptionHandler(connection, ioe); } }
private int getRemoteMessageCount(String criteria) throws MessagingException { checkOpen(); try { int count = 0; int start = 1; String command = String.format(Locale.US, "SEARCH %d:* %s", start, criteria); List<ImapResponse> responses = executeSimpleCommand(command); for (ImapResponse response : responses) { if (ImapResponseParser.equalsIgnoreCase(response.get(0), "SEARCH")) { count += response.size() - 1; } } return count; } catch (IOException ioe) { throw ioExceptionHandler(connection, ioe); } }
protected List<ImapMessage> getMessages(final int start, final int end, Date earliestDate, final boolean includeDeleted, final MessageRetrievalListener<ImapMessage> listener) throws MessagingException { if (start < 1 || end < 1 || end < start) { throw new MessagingException(String.format(Locale.US, "Invalid message set %d %d", start, end)); } checkOpen(); String dateSearchString = getDateSearchString(earliestDate); String command = String.format(Locale.US, "UID SEARCH %d:%d%s%s", start, end, dateSearchString, includeDeleted ? "" : " NOT DELETED"); try { List<ImapResponse> imapResponses = connection.executeSimpleCommand(command); SearchResponse searchResponse = SearchResponse.parse(imapResponses); return getMessages(searchResponse, listener); } catch (IOException ioe) { throw ioExceptionHandler(connection, ioe); } }
@Override public boolean create() 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; synchronized (this) { if (this.connection == null) { connection = store.getConnection(); } else { connection = this.connection; } } try { String encodedFolderName = folderNameCodec.encode(getPrefixedName()); String escapedFolderName = ImapUtility.encodeString(encodedFolderName); connection.executeSimpleCommand(String.format("CREATE %s", escapedFolderName)); return true; } catch (NegativeImapResponseException e) { return false; } catch (IOException ioe) { throw ioExceptionHandler(this.connection, ioe); } finally { if (this.connection == null) { store.releaseConnection(connection); } } }
return false; } catch (IOException ioe) { throw ioExceptionHandler(connection, ioe); } finally { if (this.connection == null) {
return response == null ? null : response.getUidMapping(); } catch (IOException ioe) { throw ioExceptionHandler(connection, ioe);
throw ioExceptionHandler(connection, ioe);
return executeSimpleCommand(Commands.NOOP); } catch (IOException ioe) { /* don't throw */ ioExceptionHandler(connection, ioe); throw ioExceptionHandler(connection, ioe); } catch (MessagingException me) { Timber.e(me, "Unable to open connection for %s", getLogId());
throw ioExceptionHandler(connection, ioe);
throw ioExceptionHandler(connection, ioe);
return getMessages(searchResponse, null); } catch (IOException ioe) { throw ioExceptionHandler(connection, ioe);