Commit b309c8a5 authored by Mickaël Guessant's avatar Mickaël Guessant

IMAP: apply patch #41 IMAP wildcard LIST supportwith unit test

git-svn-id: https://svn.code.sf.net/p/davmail/code/trunk@2465 3d1905a2-6b24-0410-a738-b14d5a86fcbd
parent a5986b8c
......@@ -1226,10 +1226,14 @@ public abstract class ExchangeSession {
* @return list of folders
* @throws IOException on error
*/
public List<Folder> getSubFolders(String folderName, boolean recursive) throws IOException {
Condition folderCondition = null;
public List<Folder> getSubFolders(String folderName, boolean recursive, boolean wildcard) throws IOException {
MultiCondition folderCondition = and();
if (!Settings.getBooleanProperty("davmail.imapIncludeSpecialFolders", false)) {
folderCondition = or(isEqualTo("folderclass", "IPF.Note"), isNull("folderclass"));
folderCondition.add(or(isEqualTo("folderclass", "IPF.Note"), isNull("folderclass")));
}
if (wildcard) {
folderCondition.add(startsWith("displayname", folderName));
folderName = "";
}
List<Folder> results = getSubFolders(folderName, folderCondition,
recursive);
......
......@@ -164,10 +164,10 @@ public class ImapConnection extends AbstractConnection {
if (tokens.hasMoreTokens()) {
String folderQuery = folderContext + decodeFolderPath(tokens.nextToken());
if (folderQuery.endsWith("%/%") && !"/%/%".equals(folderQuery)) {
List<ExchangeSession.Folder> folders = session.getSubFolders(folderQuery.substring(0, folderQuery.length() - 3), false);
List<ExchangeSession.Folder> folders = session.getSubFolders(folderQuery.substring(0, folderQuery.length() - 3), false, false);
for (ExchangeSession.Folder folder : folders) {
sendClient("* " + command + " (" + folder.getFlags() + ") \"/\" \"" + encodeFolderPath(folder.folderPath) + '\"');
sendSubFolders(command, folder.folderPath, false);
sendSubFolders(command, folder.folderPath, false, false);
}
sendClient(commandId + " OK " + command + " completed");
} else if (folderQuery.endsWith("%") || folderQuery.endsWith("*")) {
......@@ -181,8 +181,9 @@ public class ImapConnection extends AbstractConnection {
if ("*%".equals(folderQuery)) {
folderQuery = "*";
}
boolean wildcard = folderQuery.endsWith("%") && !folderQuery.contains("/");
boolean recursive = folderQuery.endsWith("*") && !folderQuery.startsWith("/public");
sendSubFolders(command, folderQuery.substring(0, folderQuery.length() - 1), recursive);
sendSubFolders(command, folderQuery.substring(0, folderQuery.length() - 1), recursive, wildcard);
sendClient(commandId + " OK " + command + " completed");
} else {
ExchangeSession.Folder folder = null;
......@@ -1336,9 +1337,9 @@ public class ImapConnection extends AbstractConnection {
}
}
protected void sendSubFolders(String command, String folderPath, boolean recursive) throws IOException {
protected void sendSubFolders(String command, String folderPath, boolean recursive, boolean wildcard) throws IOException {
try {
List<ExchangeSession.Folder> folders = session.getSubFolders(folderPath, recursive);
List<ExchangeSession.Folder> folders = session.getSubFolders(folderPath, recursive, wildcard);
for (ExchangeSession.Folder folder : folders) {
sendClient("* " + command + " (" + folder.getFlags() + ") \"/\" \"" + encodeFolderPath(folder.folderPath) + '\"');
}
......
......@@ -87,16 +87,16 @@ public class TestExchangeAdapter extends TestCase {
}
public void testFindFolder() throws IOException {
List<ExchangeSession.Folder> davFolders = davSession.getSubFolders("", false);
List<ExchangeSession.Folder> davFolders = davSession.getSubFolders("", false, false);
Settings.setLoggingLevel("httpclient.wire", Level.DEBUG);
List<ExchangeSession.Folder> ewsFolders = ewsSession.getSubFolders("", false);
List<ExchangeSession.Folder> ewsFolders = ewsSession.getSubFolders("", false, false);
assertEquals(davFolders.size(), ewsFolders.size());
}
public void testFindPublicFolder() throws IOException {
List<ExchangeSession.Folder> davFolders = davSession.getSubFolders("/public", false);
List<ExchangeSession.Folder> davFolders = davSession.getSubFolders("/public", false, false);
Settings.setLoggingLevel("httpclient.wire", Level.DEBUG);
List<ExchangeSession.Folder> ewsFolders = ewsSession.getSubFolders("/public", false);
List<ExchangeSession.Folder> ewsFolders = ewsSession.getSubFolders("/public", false, false);
assertEquals(davFolders.size(), ewsFolders.size());
}
......
......@@ -65,4 +65,10 @@ public class TestImapFolders extends AbstractImapTestCase {
assertEquals(". OK UID FETCH completed", readFullAnswer("."));
}
public void testListWildcard() throws IOException {
writeLine(". LIST \"\" \"testfo%\"");
assertEquals("* LIST (\\HasNoChildren) \"/\" \"testfolder\"", readLine());
assertEquals(". OK LIST completed", readFullAnswer("."));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment