@Override public boolean areMoreMessagesAvailable(int indexOfOldestMessage, Date earliestDate) throws IOException, MessagingException { checkOpen(); if (indexOfOldestMessage == 1) { return false; } int endIndex = indexOfOldestMessage - 1; String dateSearchString = getDateSearchString(earliestDate); while (endIndex > 0) { int startIndex = Math.max(0, endIndex - MORE_MESSAGES_WINDOW_SIZE) + 1; if (existsNonDeletedMessageInRange(startIndex, endIndex, dateSearchString)) { return true; } endIndex = endIndex - MORE_MESSAGES_WINDOW_SIZE; } 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); } }
@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); } }
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); } }
checkOpen(); //only need READ access
@Override public void fetchPart(Message message, Part part, MessageRetrievalListener<Message> listener, BodyFactory bodyFactory) throws MessagingException { checkOpen();
public Map<String, String> appendMessages(List<? extends Message> messages) throws MessagingException { open(OPEN_MODE_RW); checkOpen();