private boolean existsNonDeletedMessageInRange(int startIndex, int endIndex, String dateSearchString) throws MessagingException, IOException { String command = String.format(Locale.US, "SEARCH %d:%d%s NOT DELETED", startIndex, endIndex, dateSearchString); List<ImapResponse> imapResponses = executeSimpleCommand(command); SearchResponse response = SearchResponse.parse(imapResponses); return response.getNumbers().size() > 0; }
@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(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; }
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); } }
return executeSimpleCommand(Commands.NOOP); } catch (IOException ioe) { String escapedFolderName = ImapUtility.encodeString(encodedFolderName); String command = String.format("%s %s", openCommand, escapedFolderName); List<ImapResponse> responses = executeSimpleCommand(command);
List<ImapResponse> imapResponses = executeSimpleCommand(searchCommand); SearchResponse searchResponse = SearchResponse.parse(imapResponses); return getMessages(searchResponse, null);