Skip to content

Commit

Permalink
Don't only list special folders when SPECIAL-USE capability is present
Browse files Browse the repository at this point in the history
  • Loading branch information
cketti committed Jan 7, 2019
1 parent 0422268 commit 2a4f1c4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -162,19 +162,18 @@ private List<FolderListItem> limitToSubscribedFolders(List<FolderListItem> folde
private List<FolderListItem> listFolders(ImapConnection connection, boolean subscribedOnly) throws IOException,
MessagingException {

String command;
String commandFormat;
if (subscribedOnly) {
command = "LSUB";
commandFormat = "LSUB \"\" %s";
} else if (connection.hasCapability(Capabilities.SPECIAL_USE) &&
connection.hasCapability(Capabilities.LIST_EXTENDED)) {
command = "LIST (SPECIAL-USE)";
commandFormat = "LIST \"\" %s RETURN (SPECIAL-USE)";
} else {
command = "LIST";
commandFormat = "LIST \"\" %s";
}

String encodedListPrefix = ImapUtility.encodeString(getCombinedPrefix() + "*");
List<ImapResponse> responses = connection.executeSimpleCommand(
String.format("%s \"\" %s", command, encodedListPrefix));
List<ImapResponse> responses = connection.executeSimpleCommand(String.format(commandFormat, encodedListPrefix));

List<ListResponse> listResponses = (subscribedOnly) ?
ListResponse.parseLsub(responses) :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void getPersonalNamespaces_withSpecialUseCapability_shouldReturnSpecialFo
createImapResponse("* LIST (\\HasNoChildren \\Trash) \"/\" \"[Gmail]/Trash\""),
createImapResponse("5 OK Success")
);
when(imapConnection.executeSimpleCommand("LIST (SPECIAL-USE) \"\" \"*\"")).thenReturn(imapResponses);
when(imapConnection.executeSimpleCommand("LIST \"\" \"*\" RETURN (SPECIAL-USE)")).thenReturn(imapResponses);
imapStore.enqueueImapConnection(imapConnection);

List<ImapFolder> folders = imapStore.getPersonalNamespaces();
Expand All @@ -138,7 +138,7 @@ public void getPersonalNamespaces_withoutSpecialUseCapability_shouldUseSimpleLis

imapStore.getPersonalNamespaces();

verify(imapConnection, never()).executeSimpleCommand("LIST (SPECIAL-USE) \"\" \"*\"");
verify(imapConnection, never()).executeSimpleCommand("LIST \"\" \"*\" RETURN (SPECIAL-USE)");
verify(imapConnection).executeSimpleCommand("LIST \"\" \"*\"");
}

Expand All @@ -151,7 +151,7 @@ public void getPersonalNamespaces_withoutListExtendedCapability_shouldUseSimpleL

imapStore.getPersonalNamespaces();

verify(imapConnection, never()).executeSimpleCommand("LIST (SPECIAL-USE) \"\" \"*\"");
verify(imapConnection, never()).executeSimpleCommand("LIST \"\" \"*\" RETURN (SPECIAL-USE)");
verify(imapConnection).executeSimpleCommand("LIST \"\" \"*\"");
}

Expand Down

0 comments on commit 2a4f1c4

Please sign in to comment.