Search in sources :

Example 1 with GroupedIds

use of com.fsck.k9.mail.store.imap.IdGrouper.GroupedIds in project k-9 by k9mail.

the class RealImapConnection method executeCommandWithIdSet.

@Override
@NotNull
public synchronized List<ImapResponse> executeCommandWithIdSet(@NotNull String commandPrefix, @NotNull String commandSuffix, @NotNull Set<Long> ids) throws IOException, MessagingException {
    GroupedIds groupedIds = IdGrouper.groupIds(ids);
    List<String> splitCommands = ImapCommandSplitter.splitCommand(commandPrefix, commandSuffix, groupedIds, getLineLengthLimit());
    List<ImapResponse> responses = new ArrayList<>();
    for (String splitCommand : splitCommands) {
        responses.addAll(executeSimpleCommand(splitCommand));
    }
    return responses;
}
Also used : GroupedIds(com.fsck.k9.mail.store.imap.IdGrouper.GroupedIds) ArrayList(java.util.ArrayList) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with GroupedIds

use of com.fsck.k9.mail.store.imap.IdGrouper.GroupedIds in project k-9 by k9mail.

the class ImapCommandSplitterTest method splitCommand_withManyNonContiguousIds_shouldSplitCommand.

@Test
public void splitCommand_withManyNonContiguousIds_shouldSplitCommand() throws Exception {
    Set<Long> ids = createNonContiguousIdSet(10000, 10500, 2);
    GroupedIds groupedIds = new GroupedIds(ids, Collections.<IdGrouper.ContiguousIdGroup>emptyList());
    List<String> commands = ImapCommandSplitter.splitCommand(COMMAND_PREFIX, COMMAND_SUFFIX, groupedIds, 980);
    assertEquals(commands.size(), 2);
    assertCommandLengthLimit(commands, 980);
    verifyCommandString(commands.get(0), createNonContiguousIdSet(10000, 10316, 2));
    verifyCommandString(commands.get(1), createNonContiguousIdSet(10318, 10500, 2));
}
Also used : GroupedIds(com.fsck.k9.mail.store.imap.IdGrouper.GroupedIds) Test(org.junit.Test)

Example 3 with GroupedIds

use of com.fsck.k9.mail.store.imap.IdGrouper.GroupedIds in project k-9 by k9mail.

the class ImapCommandSplitterTest method splitCommand_withContiguousAndNonContiguousIds_shouldGroupIdsAndSplitCommand.

@Test
public void splitCommand_withContiguousAndNonContiguousIds_shouldGroupIdsAndSplitCommand() throws Exception {
    Set<Long> idSet = Sets.union(createNonContiguousIdSet(10000, 10298, 2), createNonContiguousIdSet(10402, 10500, 2));
    List<IdGrouper.ContiguousIdGroup> idGroups = singletonList(new IdGrouper.ContiguousIdGroup(10300L, 10400L));
    GroupedIds groupedIds = new GroupedIds(idSet, idGroups);
    List<String> commands = ImapCommandSplitter.splitCommand(COMMAND_PREFIX, COMMAND_SUFFIX, groupedIds, 980);
    assertEquals(commands.size(), 2);
    assertCommandLengthLimit(commands, 980);
    verifyCommandString(commands.get(0), Sets.union(createNonContiguousIdSet(10000, 10298, 2), createNonContiguousIdSet(10402, 10418, 2)));
    verifyCommandString(commands.get(1), createNonContiguousIdSet(10420, 10500, 2), "10300:10400");
}
Also used : GroupedIds(com.fsck.k9.mail.store.imap.IdGrouper.GroupedIds) Test(org.junit.Test)

Example 4 with GroupedIds

use of com.fsck.k9.mail.store.imap.IdGrouper.GroupedIds in project k-9 by k9mail.

the class ImapCommandSplitterTest method splitCommand_withEmptySuffix_shouldCreateCommandWithoutTrailingSpace.

@Test
public void splitCommand_withEmptySuffix_shouldCreateCommandWithoutTrailingSpace() throws Exception {
    Set<Long> ids = createNonContiguousIdSet(1, 2, 1);
    GroupedIds groupedIds = new GroupedIds(ids, Collections.<IdGrouper.ContiguousIdGroup>emptyList());
    List<String> commands = ImapCommandSplitter.splitCommand("UID SEARCH UID", "", groupedIds, 980);
    assertEquals(commands.size(), 1);
    assertEquals("UID SEARCH UID 1,2", commands.get(0));
}
Also used : GroupedIds(com.fsck.k9.mail.store.imap.IdGrouper.GroupedIds) Test(org.junit.Test)

Aggregations

GroupedIds (com.fsck.k9.mail.store.imap.IdGrouper.GroupedIds)4 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1