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 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); } }
private void setupCopyResponse(String response) throws MessagingException, IOException { List<ImapResponse> imapResponses = singletonList(createImapResponse(response)); when(imapConnection.executeCommandWithIdSet(eq(Commands.UID_COPY), anyString(), anySetOf(Long.class))) .thenReturn(imapResponses); } }
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); } }
@SuppressWarnings("unchecked") private void assertCommandWithIdsIssued(String expectedCommand) throws MessagingException, IOException { ArgumentCaptor<String> commandPrefixCaptor = ArgumentCaptor.forClass(String.class); ArgumentCaptor<String> commandSuffixCaptor = ArgumentCaptor.forClass(String.class); ArgumentCaptor<Set> commandUidsCaptor = ArgumentCaptor.forClass(Set.class); verify(imapConnection, atLeastOnce()).executeCommandWithIdSet( commandPrefixCaptor.capture(), commandSuffixCaptor.capture(), commandUidsCaptor.capture()); List<String> commandPrefixes = commandPrefixCaptor.getAllValues(); List<String> commandSuffixes = commandSuffixCaptor.getAllValues(); List<Set> commandUids = commandUidsCaptor.getAllValues(); for (int i = 0, end = commandPrefixes.size(); i < end; i++) { String command = commandPrefixes.get(i) + " " + ImapUtility.join(",", commandUids.get(i)) + ((commandSuffixes.get(i).length() == 0) ? "" : " " + commandSuffixes.get(i)); if (command.equals(expectedCommand)) { return; } } fail("Expected IMAP command not issued: " + expectedCommand); }
private void setupUidSearchResponses(String... responses) throws MessagingException, IOException { List<ImapResponse> imapResponses = new ArrayList<>(responses.length); for (String response : responses) { imapResponses.add(createImapResponse(response)); } when(imapConnection.executeSimpleCommand(startsWith("UID SEARCH"))).thenReturn(imapResponses); when(imapConnection.executeCommandWithIdSet(startsWith("UID SEARCH"), anyString(), anySetOf(Long.class))) .thenReturn(imapResponses); }
List<ImapResponse> imapResponses = connection.executeCommandWithIdSet(Commands.UID_COPY, escapedDestinationFolderName, uids);