Combine responses in ImapConnection.executeSelectedStateCommand()
This commit is contained in:
parent
aa7e00263f
commit
590b6c6cc0
12 changed files with 86 additions and 179 deletions
|
@ -64,7 +64,7 @@ abstract class FolderSelectedStateCommand<R extends SelectedStateResponse> {
|
||||||
return commands;
|
return commands;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract R parseResponses(List<List<ImapResponse>> unparsedResponses);
|
public abstract R parseResponses(List<ImapResponse> unparsedResponses);
|
||||||
|
|
||||||
Set<Long> getIdSet() {
|
Set<Long> getIdSet() {
|
||||||
return idSet;
|
return idSet;
|
||||||
|
|
|
@ -743,9 +743,9 @@ class ImapConnection {
|
||||||
throws IOException, MessagingException {
|
throws IOException, MessagingException {
|
||||||
|
|
||||||
List<String> splitCommands = command.optimizeAndSplit(isCondstoreCapable());
|
List<String> splitCommands = command.optimizeAndSplit(isCondstoreCapable());
|
||||||
List<List<ImapResponse>> responses = new ArrayList<>(splitCommands.size());
|
List<ImapResponse> responses = new ArrayList<>();
|
||||||
for (String splitCommand : splitCommands) {
|
for (String splitCommand : splitCommands) {
|
||||||
responses.add(executeSimpleCommand(splitCommand));
|
responses.addAll(executeSimpleCommand(splitCommand));
|
||||||
}
|
}
|
||||||
|
|
||||||
return command.parseResponses(responses);
|
return command.parseResponses(responses);
|
||||||
|
|
|
@ -19,7 +19,7 @@ public class UidCopyCommand extends FolderSelectedStateCommand<UidCopyResponse>
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UidCopyResponse parseResponses(List<List<ImapResponse>> unparsedResponses) {
|
public UidCopyResponse parseResponses(List<ImapResponse> unparsedResponses) {
|
||||||
return UidCopyResponse.parse(unparsedResponses);
|
return UidCopyResponse.parse(unparsedResponses);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,20 +16,9 @@ class UidCopyResponse extends SelectedStateResponse {
|
||||||
super(imapResponse);
|
super(imapResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UidCopyResponse parse(List<List<ImapResponse>> imapResponses) {
|
public static UidCopyResponse parse(List<ImapResponse> imapResponses) {
|
||||||
UidCopyResponse combinedResponse = null;
|
UidCopyResponse response = new UidCopyResponse(imapResponses);
|
||||||
for (List<ImapResponse> imapResponse : imapResponses) {
|
return response.uidMapping == null ? null : response;
|
||||||
UidCopyResponse copyUidResponse = new UidCopyResponse(imapResponse);
|
|
||||||
if (copyUidResponse.uidMapping == null) {
|
|
||||||
copyUidResponse = null;
|
|
||||||
}
|
|
||||||
if (combinedResponse == null) {
|
|
||||||
combinedResponse = copyUidResponse;
|
|
||||||
} else {
|
|
||||||
combinedResponse.combine(copyUidResponse);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return combinedResponse;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -40,7 +40,7 @@ public class UidSearchCommand extends FolderSelectedStateCommand<UidSearchRespon
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public UidSearchResponse parseResponses(List<List<ImapResponse>> unparsedResponses) {
|
public UidSearchResponse parseResponses(List<ImapResponse> unparsedResponses) {
|
||||||
return UidSearchResponse.parse(unparsedResponses);
|
return UidSearchResponse.parse(unparsedResponses);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,17 +14,8 @@ class UidSearchResponse extends SelectedStateResponse {
|
||||||
super(imapResponse);
|
super(imapResponse);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static UidSearchResponse parse(List<List<ImapResponse>> imapResponses) {
|
public static UidSearchResponse parse(List<ImapResponse> imapResponses) {
|
||||||
UidSearchResponse combinedResponse = null;
|
return new UidSearchResponse(imapResponses);
|
||||||
for (List<ImapResponse> imapResponse : imapResponses) {
|
|
||||||
UidSearchResponse searchResponse = new UidSearchResponse(imapResponse);
|
|
||||||
if (combinedResponse == null) {
|
|
||||||
combinedResponse = searchResponse;
|
|
||||||
} else {
|
|
||||||
combinedResponse.combine(searchResponse);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return combinedResponse;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -28,7 +28,7 @@ class UidStoreCommand extends FolderSelectedStateCommand<SelectedStateResponse>
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SelectedStateResponse parseResponses(List<List<ImapResponse>> unparsedResponses) {
|
public SelectedStateResponse parseResponses(List<ImapResponse> unparsedResponses) {
|
||||||
//These results are not important, because of the FLAGS.SILENT option
|
//These results are not important, because of the FLAGS.SILENT option
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -510,7 +510,7 @@ public class ImapFolderTest {
|
||||||
public void getHighestUid() throws Exception {
|
public void getHighestUid() throws Exception {
|
||||||
ImapFolder folder = createFolder("Folder");
|
ImapFolder folder = createFolder("Folder");
|
||||||
prepareImapFolderForOpen(OPEN_MODE_RW);
|
prepareImapFolderForOpen(OPEN_MODE_RW);
|
||||||
setupSearchResponse("* SEARCH 42");
|
setupSearchResponses("* SEARCH 42");
|
||||||
folder.open(OPEN_MODE_RW);
|
folder.open(OPEN_MODE_RW);
|
||||||
|
|
||||||
long highestUid = folder.getHighestUid();
|
long highestUid = folder.getHighestUid();
|
||||||
|
@ -550,7 +550,7 @@ public class ImapFolderTest {
|
||||||
public void getMessages_withoutDateConstraint() throws Exception {
|
public void getMessages_withoutDateConstraint() throws Exception {
|
||||||
ImapFolder folder = createFolder("Folder");
|
ImapFolder folder = createFolder("Folder");
|
||||||
prepareImapFolderForOpen(OPEN_MODE_RW);
|
prepareImapFolderForOpen(OPEN_MODE_RW);
|
||||||
setupSearchResponse("* SEARCH 3", "* SEARCH 5", "* SEARCH 6");
|
setupSearchResponses("* SEARCH 3", "* SEARCH 5", "* SEARCH 6");
|
||||||
folder.open(OPEN_MODE_RW);
|
folder.open(OPEN_MODE_RW);
|
||||||
|
|
||||||
List<ImapMessage> messages = folder.getMessages(1, 10, null, null);
|
List<ImapMessage> messages = folder.getMessages(1, 10, null, null);
|
||||||
|
@ -564,7 +564,7 @@ public class ImapFolderTest {
|
||||||
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
|
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
|
||||||
ImapFolder folder = createFolder("Folder");
|
ImapFolder folder = createFolder("Folder");
|
||||||
prepareImapFolderForOpen(OPEN_MODE_RW);
|
prepareImapFolderForOpen(OPEN_MODE_RW);
|
||||||
setupSearchResponse("* SEARCH 47", "* SEARCH 18");
|
setupSearchResponses("* SEARCH 47", "* SEARCH 18");
|
||||||
folder.open(OPEN_MODE_RW);
|
folder.open(OPEN_MODE_RW);
|
||||||
|
|
||||||
List<ImapMessage> messages = folder.getMessages(1, 10, new Date(1454719826000L), null);
|
List<ImapMessage> messages = folder.getMessages(1, 10, new Date(1454719826000L), null);
|
||||||
|
@ -577,7 +577,7 @@ public class ImapFolderTest {
|
||||||
public void getMessages_withListener_shouldCallListener() throws Exception {
|
public void getMessages_withListener_shouldCallListener() throws Exception {
|
||||||
ImapFolder folder = createFolder("Folder");
|
ImapFolder folder = createFolder("Folder");
|
||||||
prepareImapFolderForOpen(OPEN_MODE_RW);
|
prepareImapFolderForOpen(OPEN_MODE_RW);
|
||||||
setupSearchResponse("* SEARCH 99");
|
setupSearchResponses("* SEARCH 99");
|
||||||
folder.open(OPEN_MODE_RW);
|
folder.open(OPEN_MODE_RW);
|
||||||
MessageRetrievalListener<ImapMessage> listener = createMessageRetrievalListener();
|
MessageRetrievalListener<ImapMessage> listener = createMessageRetrievalListener();
|
||||||
|
|
||||||
|
@ -655,7 +655,7 @@ public class ImapFolderTest {
|
||||||
public void getMessages_sequenceNumbers() throws Exception {
|
public void getMessages_sequenceNumbers() throws Exception {
|
||||||
ImapFolder folder = createFolder("Folder");
|
ImapFolder folder = createFolder("Folder");
|
||||||
prepareImapFolderForOpen(OPEN_MODE_RW);
|
prepareImapFolderForOpen(OPEN_MODE_RW);
|
||||||
setupSearchResponse("* SEARCH 17", "* SEARCH 18", "* SEARCH 49");
|
setupSearchResponses("* SEARCH 17", "* SEARCH 18", "* SEARCH 49");
|
||||||
folder.open(OPEN_MODE_RW);
|
folder.open(OPEN_MODE_RW);
|
||||||
|
|
||||||
List<ImapMessage> messages = folder.getMessages(newSet(1L, 2L, 5L), false, null);
|
List<ImapMessage> messages = folder.getMessages(newSet(1L, 2L, 5L), false, null);
|
||||||
|
@ -668,7 +668,7 @@ public class ImapFolderTest {
|
||||||
public void getMessages_sequenceNumbers_withListener_shouldCallListener() throws Exception {
|
public void getMessages_sequenceNumbers_withListener_shouldCallListener() throws Exception {
|
||||||
ImapFolder folder = createFolder("Folder");
|
ImapFolder folder = createFolder("Folder");
|
||||||
prepareImapFolderForOpen(OPEN_MODE_RW);
|
prepareImapFolderForOpen(OPEN_MODE_RW);
|
||||||
setupSearchResponse("* SEARCH 99");
|
setupSearchResponses("* SEARCH 99");
|
||||||
folder.open(OPEN_MODE_RW);
|
folder.open(OPEN_MODE_RW);
|
||||||
MessageRetrievalListener<ImapMessage> listener = createMessageRetrievalListener();
|
MessageRetrievalListener<ImapMessage> listener = createMessageRetrievalListener();
|
||||||
|
|
||||||
|
@ -697,7 +697,7 @@ public class ImapFolderTest {
|
||||||
public void getMessagesFromUids() throws Exception {
|
public void getMessagesFromUids() throws Exception {
|
||||||
ImapFolder folder = createFolder("Folder");
|
ImapFolder folder = createFolder("Folder");
|
||||||
prepareImapFolderForOpen(OPEN_MODE_RW);
|
prepareImapFolderForOpen(OPEN_MODE_RW);
|
||||||
setupSearchResponse("* SEARCH 11", "* SEARCH 22", "* SEARCH 25");
|
setupSearchResponses("* SEARCH 11", "* SEARCH 22", "* SEARCH 25");
|
||||||
folder.open(OPEN_MODE_RW);
|
folder.open(OPEN_MODE_RW);
|
||||||
|
|
||||||
List<ImapMessage> messages = folder.getMessagesFromUids(asList("11", "22", "25"));
|
List<ImapMessage> messages = folder.getMessagesFromUids(asList("11", "22", "25"));
|
||||||
|
@ -723,7 +723,7 @@ public class ImapFolderTest {
|
||||||
public void areMoreMessagesAvailable_withAdditionalMessages_shouldReturnTrue() throws Exception {
|
public void areMoreMessagesAvailable_withAdditionalMessages_shouldReturnTrue() throws Exception {
|
||||||
ImapFolder folder = createFolder("Folder");
|
ImapFolder folder = createFolder("Folder");
|
||||||
prepareImapFolderForOpen(OPEN_MODE_RW);
|
prepareImapFolderForOpen(OPEN_MODE_RW);
|
||||||
setupSearchResponse("* SEARCH 42");
|
setupSearchResponses("* SEARCH 42");
|
||||||
folder.open(OPEN_MODE_RW);
|
folder.open(OPEN_MODE_RW);
|
||||||
|
|
||||||
boolean areMoreMessagesAvailable = folder.areMoreMessagesAvailable(10, null);
|
boolean areMoreMessagesAvailable = folder.areMoreMessagesAvailable(10, null);
|
||||||
|
@ -735,7 +735,7 @@ public class ImapFolderTest {
|
||||||
public void areMoreMessagesAvailable_withoutAdditionalMessages_shouldReturnFalse() throws Exception {
|
public void areMoreMessagesAvailable_withoutAdditionalMessages_shouldReturnFalse() throws Exception {
|
||||||
ImapFolder folder = createFolder("Folder");
|
ImapFolder folder = createFolder("Folder");
|
||||||
prepareImapFolderForOpen(OPEN_MODE_RW);
|
prepareImapFolderForOpen(OPEN_MODE_RW);
|
||||||
setupSearchResponse("1 OK SEARCH completed");
|
setupSearchResponses("1 OK SEARCH completed");
|
||||||
folder.open(OPEN_MODE_RW);
|
folder.open(OPEN_MODE_RW);
|
||||||
|
|
||||||
boolean areMoreMessagesAvailable = folder.areMoreMessagesAvailable(600, null);
|
boolean areMoreMessagesAvailable = folder.areMoreMessagesAvailable(600, null);
|
||||||
|
@ -761,7 +761,7 @@ public class ImapFolderTest {
|
||||||
throws Exception {
|
throws Exception {
|
||||||
ImapFolder folder = createFolder("Folder");
|
ImapFolder folder = createFolder("Folder");
|
||||||
prepareImapFolderForOpen(OPEN_MODE_RW);
|
prepareImapFolderForOpen(OPEN_MODE_RW);
|
||||||
setupSearchResponse("1 OK SEARCH Completed");
|
setupSearchResponses("1 OK SEARCH Completed");
|
||||||
folder.open(OPEN_MODE_RW);
|
folder.open(OPEN_MODE_RW);
|
||||||
|
|
||||||
folder.areMoreMessagesAvailable(600, null);
|
folder.areMoreMessagesAvailable(600, null);
|
||||||
|
@ -974,7 +974,7 @@ public class ImapFolderTest {
|
||||||
folder.open(OPEN_MODE_RW);
|
folder.open(OPEN_MODE_RW);
|
||||||
ImapMessage message = createImapMessage("2");
|
ImapMessage message = createImapMessage("2");
|
||||||
when(message.getHeader("Message-ID")).thenReturn(new String[] { "<00000000.0000000@example.org>" });
|
when(message.getHeader("Message-ID")).thenReturn(new String[] { "<00000000.0000000@example.org>" });
|
||||||
setupSearchResponse("1 OK SEARCH Completed");
|
setupSearchResponses("1 OK SEARCH Completed");
|
||||||
|
|
||||||
folder.getUidFromMessageId(message);
|
folder.getUidFromMessageId(message);
|
||||||
|
|
||||||
|
@ -988,7 +988,7 @@ public class ImapFolderTest {
|
||||||
folder.open(OPEN_MODE_RW);
|
folder.open(OPEN_MODE_RW);
|
||||||
ImapMessage message = createImapMessage("2");
|
ImapMessage message = createImapMessage("2");
|
||||||
when(message.getHeader("Message-ID")).thenReturn(new String[] { "<00000000.0000000@example.org>" });
|
when(message.getHeader("Message-ID")).thenReturn(new String[] { "<00000000.0000000@example.org>" });
|
||||||
setupSearchResponse("* SEARCH 23");
|
setupSearchResponses("* SEARCH 23");
|
||||||
|
|
||||||
String uid = folder.getUidFromMessageId(message);
|
String uid = folder.getUidFromMessageId(message);
|
||||||
|
|
||||||
|
@ -1043,7 +1043,7 @@ public class ImapFolderTest {
|
||||||
prepareImapFolderForOpen(OPEN_MODE_RO);
|
prepareImapFolderForOpen(OPEN_MODE_RO);
|
||||||
when(storeConfig.allowRemoteSearch()).thenReturn(true);
|
when(storeConfig.allowRemoteSearch()).thenReturn(true);
|
||||||
when(storeConfig.isRemoteSearchFullText()).thenReturn(true);
|
when(storeConfig.isRemoteSearchFullText()).thenReturn(true);
|
||||||
setupSearchResponse("1 OK SEARCH completed");
|
setupSearchResponses("1 OK SEARCH completed");
|
||||||
|
|
||||||
folder.search("query", newSet(Flag.SEEN), Collections.<Flag>emptySet());
|
folder.search("query", newSet(Flag.SEEN), Collections.<Flag>emptySet());
|
||||||
|
|
||||||
|
@ -1056,7 +1056,7 @@ public class ImapFolderTest {
|
||||||
prepareImapFolderForOpen(OPEN_MODE_RO);
|
prepareImapFolderForOpen(OPEN_MODE_RO);
|
||||||
when(storeConfig.allowRemoteSearch()).thenReturn(true);
|
when(storeConfig.allowRemoteSearch()).thenReturn(true);
|
||||||
when(storeConfig.isRemoteSearchFullText()).thenReturn(false);
|
when(storeConfig.isRemoteSearchFullText()).thenReturn(false);
|
||||||
setupSearchResponse("1 OK SEARCH completed");
|
setupSearchResponses("1 OK SEARCH completed");
|
||||||
|
|
||||||
folder.search("query", Collections.<Flag>emptySet(), Collections.<Flag>emptySet());
|
folder.search("query", Collections.<Flag>emptySet(), Collections.<Flag>emptySet());
|
||||||
|
|
||||||
|
@ -1223,20 +1223,18 @@ public class ImapFolderTest {
|
||||||
assertEquals(stringCommands.contains(command), true);
|
assertEquals(stringCommands.contains(command), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupSearchResponse(String... responses) throws MessagingException, IOException {
|
private void setupSearchResponses(String... responses) throws MessagingException, IOException {
|
||||||
List<ImapResponse> imapResponses = new ArrayList<>(responses.length);
|
List<ImapResponse> imapResponses = new ArrayList<>(responses.length);
|
||||||
for (String response : responses) {
|
for (String response : responses) {
|
||||||
imapResponses.add(createImapResponse(response));
|
imapResponses.add(createImapResponse(response));
|
||||||
}
|
}
|
||||||
UidSearchResponse searchResponse = UidSearchResponse.parse(singletonList(imapResponses));
|
UidSearchResponse searchResponse = UidSearchResponse.parse(imapResponses);
|
||||||
when(imapConnection.executeSelectedStateCommand(any(UidSearchCommand.class)))
|
when(imapConnection.executeSelectedStateCommand(any(UidSearchCommand.class))).thenReturn(searchResponse);
|
||||||
.thenReturn(searchResponse);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupCopyResponse(String response) throws MessagingException, IOException {
|
private void setupCopyResponse(String response) throws MessagingException, IOException {
|
||||||
List<ImapResponse> imapResponse = singletonList(createImapResponse(response));
|
List<ImapResponse> imapResponses = singletonList(createImapResponse(response));
|
||||||
UidCopyResponse uidCopyResponse = UidCopyResponse.parse(singletonList(imapResponse));
|
UidCopyResponse uidCopyResponse = UidCopyResponse.parse(imapResponses);
|
||||||
when(imapConnection.executeSelectedStateCommand(any(UidCopyCommand.class)))
|
when(imapConnection.executeSelectedStateCommand(any(UidCopyCommand.class))).thenReturn(uidCopyResponse);
|
||||||
.thenReturn(uidCopyResponse);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,17 +12,7 @@ import com.fsck.k9.mail.filter.PeekableInputStream;
|
||||||
|
|
||||||
|
|
||||||
public class ImapResponseHelper {
|
public class ImapResponseHelper {
|
||||||
|
public static List<ImapResponse> createImapResponseList(String... responses) throws IOException {
|
||||||
@SafeVarargs
|
|
||||||
public static List<List<ImapResponse>> createMultipleImapResponses(List<String>... responses) throws IOException {
|
|
||||||
List<List<ImapResponse>> imapResponses = new ArrayList<>();
|
|
||||||
for (List<String> response : responses) {
|
|
||||||
imapResponses.add(createImapResponseList(response));
|
|
||||||
}
|
|
||||||
return imapResponses;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static List<ImapResponse> createImapResponseList(List<String> responses) throws IOException {
|
|
||||||
List<ImapResponse> imapResponses = new ArrayList<>();
|
List<ImapResponse> imapResponses = new ArrayList<>();
|
||||||
for (String response : responses) {
|
for (String response : responses) {
|
||||||
imapResponses.add(createImapResponse(response));
|
imapResponses.add(createImapResponse(response));
|
||||||
|
|
|
@ -17,7 +17,7 @@ class TestCommand extends FolderSelectedStateCommand<SelectedStateResponse> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SelectedStateResponse parseResponses(List unparsedResponses) {
|
public SelectedStateResponse parseResponses(List<ImapResponse> unparsedResponses) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,19 +1,15 @@
|
||||||
package com.fsck.k9.mail.store.imap;
|
package com.fsck.k9.mail.store.imap;
|
||||||
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import com.fsck.k9.mail.K9LibRobolectricTestRunner;
|
import com.fsck.k9.mail.K9LibRobolectricTestRunner;
|
||||||
import com.fsck.k9.mail.store.imap.ImapResponse;
|
|
||||||
import com.fsck.k9.mail.store.imap.UidCopyResponse;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
import static com.fsck.k9.mail.store.imap.ImapResponseHelper.createMultipleImapResponses;
|
import static com.fsck.k9.mail.store.imap.ImapResponseHelper.createImapResponseList;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
|
@ -23,9 +19,9 @@ import static org.junit.Assert.assertNull;
|
||||||
public class UidCopyResponseTest {
|
public class UidCopyResponseTest {
|
||||||
@Test
|
@Test
|
||||||
public void parse_withCopyUidResponse_shouldCreateUidMapping() throws Exception {
|
public void parse_withCopyUidResponse_shouldCreateUidMapping() throws Exception {
|
||||||
List<List<ImapResponse>> imapResponse = createImapResponse("x OK [COPYUID 1 1,3:5 7:10] Success");
|
List<ImapResponse> imapResponses = createImapResponseList("x OK [COPYUID 1 1,3:5 7:10] Success");
|
||||||
|
|
||||||
UidCopyResponse result = UidCopyResponse.parse(imapResponse);
|
UidCopyResponse result = UidCopyResponse.parse(imapResponses);
|
||||||
|
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
assertEquals(createUidMapping("1=7", "3=8", "4=9", "5=10"), result.getUidMapping());
|
assertEquals(createUidMapping("1=7", "3=8", "4=9", "5=10"), result.getUidMapping());
|
||||||
|
@ -33,7 +29,7 @@ public class UidCopyResponseTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parse_withUntaggedResponse_shouldReturnNull() throws Exception {
|
public void parse_withUntaggedResponse_shouldReturnNull() throws Exception {
|
||||||
List<List<ImapResponse>> imapResponse = createImapResponse("* OK [COPYUID 1 1,3:5 7:10] Success");
|
List<ImapResponse> imapResponse = createImapResponseList("* OK [COPYUID 1 1,3:5 7:10] Success");
|
||||||
|
|
||||||
UidCopyResponse result = UidCopyResponse.parse(imapResponse);
|
UidCopyResponse result = UidCopyResponse.parse(imapResponse);
|
||||||
|
|
||||||
|
@ -42,97 +38,94 @@ public class UidCopyResponseTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parse_withTooShortResponse_shouldReturnNull() throws Exception {
|
public void parse_withTooShortResponse_shouldReturnNull() throws Exception {
|
||||||
List<List<ImapResponse>> imapResponse = createImapResponse("x OK");
|
List<ImapResponse> imapResponses = createImapResponseList("x OK");
|
||||||
|
|
||||||
UidCopyResponse result = UidCopyResponse.parse(imapResponse);
|
UidCopyResponse result = UidCopyResponse.parse(imapResponses);
|
||||||
|
|
||||||
assertNull(result);
|
assertNull(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parse_withoutOkResponse_shouldReturnNull() throws Exception {
|
public void parse_withoutOkResponse_shouldReturnNull() throws Exception {
|
||||||
List<List<ImapResponse>> imapResponse = createImapResponse("x BYE Logout");
|
List<ImapResponse> imapResponses = createImapResponseList("x BYE Logout");
|
||||||
|
|
||||||
UidCopyResponse result = UidCopyResponse.parse(imapResponse);
|
UidCopyResponse result = UidCopyResponse.parse(imapResponses);
|
||||||
|
|
||||||
assertNull(result);
|
assertNull(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parse_withoutResponseTextList_shouldReturnNull() throws Exception {
|
public void parse_withoutResponseTextList_shouldReturnNull() throws Exception {
|
||||||
List<List<ImapResponse>> imapResponse = createImapResponse("x OK Success");
|
List<ImapResponse> imapResponses = createImapResponseList("x OK Success");
|
||||||
|
|
||||||
UidCopyResponse result = UidCopyResponse.parse(imapResponse);
|
UidCopyResponse result = UidCopyResponse.parse(imapResponses);
|
||||||
|
|
||||||
assertNull(result);
|
assertNull(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parse_withResponseTextListTooShort_shouldReturnNull() throws Exception {
|
public void parse_withResponseTextListTooShort_shouldReturnNull() throws Exception {
|
||||||
List<List<ImapResponse>> imapResponse = createImapResponse("x OK [A B C] Success");
|
List<ImapResponse> imapResponses = createImapResponseList("x OK [A B C] Success");
|
||||||
|
|
||||||
UidCopyResponse result = UidCopyResponse.parse(imapResponse);
|
UidCopyResponse result = UidCopyResponse.parse(imapResponses);
|
||||||
|
|
||||||
assertNull(result);
|
assertNull(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parse_withoutCopyUidResponse_shouldReturnNull() throws Exception {
|
public void parse_withoutCopyUidResponse_shouldReturnNull() throws Exception {
|
||||||
List<List<ImapResponse>> imapResponse = createImapResponse("x OK [A B C D] Success");
|
List<ImapResponse> imapResponses = createImapResponseList("x OK [A B C D] Success");
|
||||||
|
|
||||||
UidCopyResponse result = UidCopyResponse.parse(imapResponse);
|
UidCopyResponse result = UidCopyResponse.parse(imapResponses);
|
||||||
|
|
||||||
assertNull(result);
|
assertNull(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parse_withNonStringCopyUidArgumentOne_shouldReturnNull() throws Exception {
|
public void parse_withNonStringCopyUidArgumentOne_shouldReturnNull() throws Exception {
|
||||||
List<List<ImapResponse>> imapResponse = createImapResponse("x OK [COPYUID () C D] Success");
|
List<ImapResponse> imapResponses = createImapResponseList("x OK [COPYUID () C D] Success");
|
||||||
|
|
||||||
UidCopyResponse result = UidCopyResponse.parse(imapResponse);
|
UidCopyResponse result = UidCopyResponse.parse(imapResponses);
|
||||||
|
|
||||||
assertNull(result);
|
assertNull(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parse_withNonStringCopyUidArgumentTwo_shouldReturnNull() throws Exception {
|
public void parse_withNonStringCopyUidArgumentTwo_shouldReturnNull() throws Exception {
|
||||||
List<List<ImapResponse>> imapResponse = createImapResponse("x OK [COPYUID B () D] Success");
|
List<ImapResponse> imapResponses = createImapResponseList("x OK [COPYUID B () D] Success");
|
||||||
|
|
||||||
UidCopyResponse result = UidCopyResponse.parse(imapResponse);
|
UidCopyResponse result = UidCopyResponse.parse(imapResponses);
|
||||||
|
|
||||||
assertNull(result);
|
assertNull(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parse_withNonStringCopyUidArgumentThree_shouldReturnNull() throws Exception {
|
public void parse_withNonStringCopyUidArgumentThree_shouldReturnNull() throws Exception {
|
||||||
List<List<ImapResponse>> imapResponse = createImapResponse("x OK [COPYUID B C ()] Success");
|
List<ImapResponse> imapResponses = createImapResponseList("x OK [COPYUID B C ()] Success");
|
||||||
|
|
||||||
UidCopyResponse result = UidCopyResponse.parse(imapResponse);
|
UidCopyResponse result = UidCopyResponse.parse(imapResponses);
|
||||||
|
|
||||||
assertNull(result);
|
assertNull(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parse_withNonNumberCopyUidArguments_shouldReturnNull() throws Exception {
|
public void parse_withNonNumberCopyUidArguments_shouldReturnNull() throws Exception {
|
||||||
List<List<ImapResponse>> imapResponse = createImapResponse("x OK [COPYUID B C D] Success");
|
List<ImapResponse> imapResponses = createImapResponseList("x OK [COPYUID B C D] Success");
|
||||||
|
|
||||||
UidCopyResponse result = UidCopyResponse.parse(imapResponse);
|
UidCopyResponse result = UidCopyResponse.parse(imapResponses);
|
||||||
|
|
||||||
assertNull(result);
|
assertNull(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parse_withUnbalancedCopyUidArguments_shouldReturnNull() throws Exception {
|
public void parse_withUnbalancedCopyUidArguments_shouldReturnNull() throws Exception {
|
||||||
List<List<ImapResponse>> imapResponse = createImapResponse("x OK [COPYUID B 1 1,2] Success");
|
List<ImapResponse> imapResponses = createImapResponseList("x OK [COPYUID B 1 1,2] Success");
|
||||||
|
|
||||||
UidCopyResponse result = UidCopyResponse.parse(imapResponse);
|
UidCopyResponse result = UidCopyResponse.parse(imapResponses);
|
||||||
|
|
||||||
assertNull(result);
|
assertNull(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<List<ImapResponse>> createImapResponse(String response) throws IOException {
|
|
||||||
return createMultipleImapResponses(Collections.singletonList(response));
|
|
||||||
}
|
|
||||||
|
|
||||||
private Map<String, String> createUidMapping(String... values) {
|
private Map<String, String> createUidMapping(String... values) {
|
||||||
Map<String, String> mapping = new HashMap<>(values.length);
|
Map<String, String> mapping = new HashMap<>(values.length);
|
||||||
|
|
|
@ -4,140 +4,86 @@ package com.fsck.k9.mail.store.imap;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.fsck.k9.mail.store.imap.ImapResponse;
|
|
||||||
import com.fsck.k9.mail.store.imap.UidSearchResponse;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static com.fsck.k9.mail.store.imap.ImapResponseHelper.createImapResponse;
|
import static com.fsck.k9.mail.store.imap.ImapResponseHelper.createImapResponseList;
|
||||||
import static com.fsck.k9.mail.store.imap.ImapResponseHelper.createMultipleImapResponses;
|
|
||||||
import static java.util.Arrays.asList;
|
import static java.util.Arrays.asList;
|
||||||
import static java.util.Collections.singletonList;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
|
|
||||||
public class UidSearchResponseTest {
|
public class UidSearchResponseTest {
|
||||||
|
|
||||||
private static final List<String> SEARCH_RESPONSE_1 = asList("* SEARCH 1 2 3",
|
|
||||||
"* 23 EXISTS",
|
|
||||||
"* SEARCH 4");
|
|
||||||
private static final List<String> SEARCH_RESPONSE_2 = asList("* SEARCH 5 6",
|
|
||||||
"* 19 EXPUNGED",
|
|
||||||
"* SEARCH 7");
|
|
||||||
private static final List<String> SEARCH_RESPONSE_3 = singletonList("* SEARCH 8");
|
|
||||||
private static final List<String> SEARCH_RESPONSE_TAGGED = singletonList("x SEARCH 7 8 9");
|
|
||||||
private static final List<String> SEARCH_RESPONSE_SHORT = singletonList("* SEARCH");
|
|
||||||
private static final List<String> SEARCH_RESPONSE_NONE = singletonList("* 23 EXPUNGE");
|
|
||||||
private static final List<String> SEARCH_RESPONSE_INVALID = singletonList("* SEARCH A");
|
|
||||||
|
|
||||||
private static final List<Long> SEARCH_RESPONSE_1_NUMBERS = asList(1L, 2L, 3L, 4L);
|
|
||||||
private static final List<Long> SEARCH_RESPONSE_123_NUMBERS = asList(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L);
|
|
||||||
private static final List<Long> SEARCH_RESPONSE_12_NUMBERS = asList(1L, 2L, 3L, 4L, 5L, 6L, 7L);
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parse_withSingleSearchResponse_shouldExtractNumbers() throws Exception {
|
public void parse_withSingleSearchResponse_shouldExtractNumbers() throws Exception {
|
||||||
List<List<ImapResponse>> responses = createMultipleImapResponses(SEARCH_RESPONSE_1);
|
List<ImapResponse> imapResponses = createImapResponseList(
|
||||||
|
"* SEARCH 1 2 3",
|
||||||
|
"* 23 EXISTS",
|
||||||
|
"* SEARCH 4",
|
||||||
|
"1 OK SEARCH completed");
|
||||||
|
|
||||||
UidSearchResponse result = UidSearchResponse.parse(responses);
|
UidSearchResponse result = UidSearchResponse.parse(imapResponses);
|
||||||
|
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
assertEquals(SEARCH_RESPONSE_1_NUMBERS, result.getNumbers());
|
assertEquals(asList(1L, 2L, 3L, 4L), result.getNumbers());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parse_withMultipleSearchResponses_shouldExtractNumbers() throws Exception {
|
public void parse_withMultipleSearchResponses_shouldExtractNumbers() throws Exception {
|
||||||
List<List<ImapResponse>> responses = createMultipleImapResponses(SEARCH_RESPONSE_1, SEARCH_RESPONSE_2,
|
List<ImapResponse> imapResponses = createImapResponseList(
|
||||||
SEARCH_RESPONSE_3);
|
"* SEARCH 1 2 3",
|
||||||
|
"* 23 EXISTS",
|
||||||
|
"* SEARCH 4",
|
||||||
|
"1 OK SEARCH completed",
|
||||||
|
"* SEARCH 5 6",
|
||||||
|
"* 19 EXPUNGED",
|
||||||
|
"* SEARCH 7",
|
||||||
|
"2 OK SEARCH completed",
|
||||||
|
"* SEARCH 8",
|
||||||
|
"3 OK SEARCH completed");
|
||||||
|
|
||||||
UidSearchResponse result = UidSearchResponse.parse(responses);
|
UidSearchResponse result = UidSearchResponse.parse(imapResponses);
|
||||||
|
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
assertEquals(SEARCH_RESPONSE_123_NUMBERS, result.getNumbers());
|
assertEquals(asList(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L), result.getNumbers());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parse_withSingleTaggedSearchResponse_shouldReturnEmptyList() throws Exception {
|
public void parse_withSingleTaggedSearchResponse_shouldReturnEmptyList() throws Exception {
|
||||||
List<List<ImapResponse>> responses = createMultipleImapResponses(SEARCH_RESPONSE_TAGGED);
|
List<ImapResponse> imapResponses = createImapResponseList("x SEARCH 7 8 9");
|
||||||
|
|
||||||
UidSearchResponse result = UidSearchResponse.parse(responses);
|
UidSearchResponse result = UidSearchResponse.parse(imapResponses);
|
||||||
|
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
assertEquals(Collections.emptyList(), result.getNumbers());
|
assertEquals(Collections.emptyList(), result.getNumbers());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void parse_withMultipleSearchResponsesAndSingleTaggedSearchResponse_shouldExtractNumbers() throws Exception {
|
|
||||||
List<List<ImapResponse>> responses = createMultipleImapResponses(SEARCH_RESPONSE_1, SEARCH_RESPONSE_2,
|
|
||||||
SEARCH_RESPONSE_TAGGED);
|
|
||||||
|
|
||||||
UidSearchResponse result = UidSearchResponse.parse(responses);
|
|
||||||
|
|
||||||
assertNotNull(result);
|
|
||||||
assertEquals(SEARCH_RESPONSE_12_NUMBERS, result.getNumbers());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parse_withSingleTooShortResponse_shouldReturnEmptyList() throws Exception {
|
public void parse_withSingleTooShortResponse_shouldReturnEmptyList() throws Exception {
|
||||||
List<List<ImapResponse>> responses = createMultipleImapResponses(SEARCH_RESPONSE_SHORT);
|
List<ImapResponse> imapResponses = createImapResponseList("* SEARCH");
|
||||||
|
|
||||||
UidSearchResponse result = UidSearchResponse.parse(responses);
|
UidSearchResponse result = UidSearchResponse.parse(imapResponses);
|
||||||
|
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
assertEquals(Collections.emptyList(), result.getNumbers());
|
assertEquals(Collections.emptyList(), result.getNumbers());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void parse_withMultipleSearchResponsesAndSingleTooShortResponse_shouldExtractNumbers() throws Exception {
|
|
||||||
List<List<ImapResponse>> responses = createMultipleImapResponses(SEARCH_RESPONSE_1, SEARCH_RESPONSE_2,
|
|
||||||
SEARCH_RESPONSE_SHORT);
|
|
||||||
|
|
||||||
UidSearchResponse result = UidSearchResponse.parse(responses);
|
|
||||||
|
|
||||||
assertNotNull(result);
|
|
||||||
assertEquals(SEARCH_RESPONSE_12_NUMBERS, result.getNumbers());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parse_withSingleNoSearchResponse_shouldReturnEmptyList() throws Exception {
|
public void parse_withSingleNoSearchResponse_shouldReturnEmptyList() throws Exception {
|
||||||
List<List<ImapResponse>> responses = createMultipleImapResponses(SEARCH_RESPONSE_NONE);
|
List<ImapResponse> imapResponses = createImapResponseList("* 23 EXPUNGE");
|
||||||
|
|
||||||
UidSearchResponse result = UidSearchResponse.parse(responses);
|
UidSearchResponse result = UidSearchResponse.parse(imapResponses);
|
||||||
|
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
assertEquals(Collections.emptyList(), result.getNumbers());
|
assertEquals(Collections.emptyList(), result.getNumbers());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void parse_withMultipleSearchResponsesAndSingleNoSearchResponse_shouldExtractNumbers() throws Exception {
|
|
||||||
List<List<ImapResponse>> responses = createMultipleImapResponses(SEARCH_RESPONSE_1, SEARCH_RESPONSE_2,
|
|
||||||
SEARCH_RESPONSE_NONE);
|
|
||||||
|
|
||||||
UidSearchResponse result = UidSearchResponse.parse(responses);
|
|
||||||
|
|
||||||
assertNotNull(result);
|
|
||||||
assertEquals(SEARCH_RESPONSE_12_NUMBERS, result.getNumbers());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void parse_withSingleSearchResponseContainingInvalidNumber_shouldReturnEmptyList() throws Exception {
|
public void parse_withSingleSearchResponseContainingInvalidNumber_shouldReturnEmptyList() throws Exception {
|
||||||
List<List<ImapResponse>> responses = singletonList(singletonList(createImapResponse("* SEARCH A")));
|
List<ImapResponse> imapResponses = createImapResponseList("* SEARCH A");
|
||||||
|
|
||||||
UidSearchResponse result = UidSearchResponse.parse(responses);
|
UidSearchResponse result = UidSearchResponse.parse(imapResponses);
|
||||||
|
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
assertEquals(Collections.emptyList(), result.getNumbers());
|
assertEquals(Collections.emptyList(), result.getNumbers());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void parse_withMultipleSearchResponsesAndSingleSearchResponseContainingInvalidNumber_shouldExtractNumbers()
|
|
||||||
throws Exception {
|
|
||||||
List<List<ImapResponse>> responses = createMultipleImapResponses(SEARCH_RESPONSE_1, SEARCH_RESPONSE_2,
|
|
||||||
SEARCH_RESPONSE_INVALID);
|
|
||||||
|
|
||||||
UidSearchResponse result = UidSearchResponse.parse(responses);
|
|
||||||
|
|
||||||
assertNotNull(result);
|
|
||||||
assertEquals(SEARCH_RESPONSE_12_NUMBERS, result.getNumbers());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue