public static List<ImapResponse> createImapResponseList(String... responses) throws IOException { List<ImapResponse> imapResponses = new ArrayList<>(); for (String response : responses) { imapResponses.add(createImapResponse(response)); } return imapResponses; }
@Test public void parse_withTooShortResponse_shouldReturnNull() throws Exception { List<ImapResponse> imapResponses = createImapResponseList("x OK"); UidCopyResponse result = UidCopyResponse.parse(imapResponses); assertNull(result); }
@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"); }
private void prepareImapFolderForOpen(int openMode) throws MessagingException, IOException { when(imapStore.getConnection()).thenReturn(imapConnection); List<ImapResponse> imapResponses = asList( createImapResponse("* FLAGS (\\Answered \\Flagged \\Deleted \\Seen \\Draft NonJunk $MDNSent)"), createImapResponse("* OK [PERMANENTFLAGS (\\Answered \\Flagged \\Deleted \\Seen \\Draft NonJunk " + "$MDNSent \\*)] Flags permitted."), createImapResponse("* 23 EXISTS"), createImapResponse("* 0 RECENT"), createImapResponse("* OK [UIDVALIDITY 1125022061] UIDs valid"), createImapResponse("* OK [UIDNEXT 57576] Predicted next UID"), (openMode == OPEN_MODE_RW) ? createImapResponse("2 OK [READ-WRITE] Select completed.") : createImapResponse("2 OK [READ-ONLY] Examine completed.") ); if (openMode == OPEN_MODE_RW) { when(imapConnection.executeSimpleCommand("SELECT \"Folder\"")).thenReturn(imapResponses); } else { when(imapConnection.executeSimpleCommand("EXAMINE \"Folder\"")).thenReturn(imapResponses); } }
@Test public void parse_withNonNumberCopyUidArguments_shouldReturnNull() throws Exception { List<ImapResponse> imapResponses = createImapResponseList("x OK [COPYUID B C D] Success"); UidCopyResponse result = UidCopyResponse.parse(imapResponses); assertNull(result); }
@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)); }
private NamespaceResponse parse(String response) throws IOException { ImapResponse imapResponse = createImapResponse(response); return NamespaceResponse.parse(imapResponse); } }
@Test public void parse_withUntaggedResponse_shouldReturnNull() throws Exception { List<ImapResponse> imapResponse = createImapResponseList("* OK [COPYUID 1 1,3:5 7:10] Success"); UidCopyResponse result = UidCopyResponse.parse(imapResponse); assertNull(result); }
@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)); }
private CapabilityResponse parse(String responseText) throws IOException { ImapResponse response = createImapResponse(responseText); List<ImapResponse> responses = Collections.singletonList(response); return CapabilityResponse.parse(responses); } }
@Test public void parse_withoutOkResponse_shouldReturnNull() throws Exception { List<ImapResponse> imapResponses = createImapResponseList("x BYE Logout"); UidCopyResponse result = UidCopyResponse.parse(imapResponses); assertNull(result); }
private List<ListResponse> parseSingle(String response) throws IOException { List<ImapResponse> responses = singletonList(createImapResponse(response)); return ListResponse.parseList(responses); }
@Test public void parse_withNonStringCopyUidArgumentOne_shouldReturnNull() throws Exception { List<ImapResponse> imapResponses = createImapResponseList("x OK [COPYUID () C D] Success"); UidCopyResponse result = UidCopyResponse.parse(imapResponses); assertNull(result); }
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); } }
@Test public void parse_withNonStringCopyUidArgumentThree_shouldReturnNull() throws Exception { List<ImapResponse> imapResponses = createImapResponseList("x OK [COPYUID B C ()] Success"); UidCopyResponse result = UidCopyResponse.parse(imapResponses); assertNull(result); }
private void setupSearchResponses(String... responses) throws MessagingException, IOException { List<ImapResponse> imapResponses = new ArrayList<>(responses.length); for (String response : responses) { imapResponses.add(createImapResponse(response)); } when(imapConnection.executeSimpleCommand(startsWith("SEARCH"))).thenReturn(imapResponses); }
@Test public void parse_withUnbalancedCopyUidArguments_shouldReturnNull() throws Exception { List<ImapResponse> imapResponses = createImapResponseList("x OK [COPYUID B 1 1,2] Success"); UidCopyResponse result = UidCopyResponse.parse(imapResponses); assertNull(result); }
@Test public void parseList_withValidResponses_shouldReturnListResponses() throws Exception { List<ImapResponse> responses = asList( createImapResponse("* LIST () \"/\" blurdybloop"), createImapResponse("* LIST (\\Noselect) \"/\" foo"), createImapResponse("* LIST () \"/\" foo/bar"), createImapResponse("* LIST (\\NoInferiors) NIL INBOX"), createImapResponse("X OK LIST completed") ); List<ListResponse> result = ListResponse.parseList(responses); assertEquals(4, result.size()); assertListResponseEquals(noAttributes(), "/", "blurdybloop", result.get(0)); assertListResponseEquals(singletonList("\\Noselect"), "/", "foo", result.get(1)); assertListResponseEquals(noAttributes(), "/", "foo/bar", result.get(2)); assertListResponseEquals(singletonList("\\NoInferiors"), null, "INBOX", result.get(3)); }
@Test public void parse_withoutResponseTextList_shouldReturnNull() throws Exception { List<ImapResponse> imapResponses = createImapResponseList("x OK Success"); UidCopyResponse result = UidCopyResponse.parse(imapResponses); assertNull(result); }
@Test public void getPersonalNamespaces_withoutException_shouldLeaveImapConnectionOpen() throws Exception { ImapConnection imapConnection = mock(ImapConnection.class); List<ImapResponse> imapResponses = Collections.singletonList(createImapResponse("5 OK Success")); when(imapConnection.executeSimpleCommand(anyString())).thenReturn(imapResponses); imapStore.enqueueImapConnection(imapConnection); imapStore.getPersonalNamespaces(); verify(imapConnection, never()).close(); }