Check for LIST-EXTENDED capability before issuing LIST with SPECIAL-USE

This commit is contained in:
cketti 2018-12-21 18:52:59 +01:00
parent b4f41eb91d
commit 2861d93a7f
3 changed files with 18 additions and 1 deletions

View file

@ -15,4 +15,5 @@ class Capabilities {
public static final String STARTTLS = "STARTTLS";
public static final String SPECIAL_USE = "SPECIAL-USE";
public static final String UID_PLUS = "UIDPLUS";
public static final String LIST_EXTENDED = "LIST-EXTENDED";
}

View file

@ -165,7 +165,8 @@ public class ImapStore extends RemoteStore {
String command;
if (subscribedOnly) {
command = "LSUB";
} else if (connection.hasCapability(Capabilities.SPECIAL_USE)) {
} else if (connection.hasCapability(Capabilities.SPECIAL_USE) &&
connection.hasCapability(Capabilities.LIST_EXTENDED)) {
command = "LIST (SPECIAL-USE)";
} else {
command = "LIST";

View file

@ -101,6 +101,7 @@ public class ImapStoreTest {
@Test
public void getPersonalNamespaces_withSpecialUseCapability_shouldReturnSpecialFolderInfo() throws Exception {
ImapConnection imapConnection = mock(ImapConnection.class);
when(imapConnection.hasCapability(Capabilities.LIST_EXTENDED)).thenReturn(true);
when(imapConnection.hasCapability(Capabilities.SPECIAL_USE)).thenReturn(true);
List<ImapResponse> imapResponses = Arrays.asList(
createImapResponse("* LIST (\\HasNoChildren) \"/\" \"INBOX\""),
@ -131,6 +132,7 @@ public class ImapStoreTest {
@Test
public void getPersonalNamespaces_withoutSpecialUseCapability_shouldUseSimpleListCommand() throws Exception {
ImapConnection imapConnection = mock(ImapConnection.class);
when(imapConnection.hasCapability(Capabilities.LIST_EXTENDED)).thenReturn(true);
when(imapConnection.hasCapability(Capabilities.SPECIAL_USE)).thenReturn(false);
imapStore.enqueueImapConnection(imapConnection);
@ -140,6 +142,19 @@ public class ImapStoreTest {
verify(imapConnection).executeSimpleCommand("LIST \"\" \"*\"");
}
@Test
public void getPersonalNamespaces_withoutListExtendedCapability_shouldUseSimpleListCommand() throws Exception {
ImapConnection imapConnection = mock(ImapConnection.class);
when(imapConnection.hasCapability(Capabilities.LIST_EXTENDED)).thenReturn(false);
when(imapConnection.hasCapability(Capabilities.SPECIAL_USE)).thenReturn(true);
imapStore.enqueueImapConnection(imapConnection);
imapStore.getPersonalNamespaces();
verify(imapConnection, never()).executeSimpleCommand("LIST (SPECIAL-USE) \"\" \"*\"");
verify(imapConnection).executeSimpleCommand("LIST \"\" \"*\"");
}
@Test
public void getPersonalNamespaces_withoutSubscribedFoldersOnly() throws Exception {
when(storeConfig.isSubscribedFoldersOnly()).thenReturn(false);