diff --git a/src/java/davmail/Settings.java b/src/java/davmail/Settings.java index dd71ba7dd..b18cc4a39 100644 --- a/src/java/davmail/Settings.java +++ b/src/java/davmail/Settings.java @@ -550,6 +550,11 @@ public static synchronized boolean getBooleanProperty(String property, boolean d return value; } + public static synchronized String[] getListProperty(String property) { + String propertyValue = SETTINGS.getProperty(property); + return propertyValue.split(","); + } + public static synchronized String loadRefreshToken(String username) { String tokenFilePath = Settings.getProperty("davmail.oauth.tokenFilePath"); if (isEmpty(tokenFilePath)) { diff --git a/src/java/davmail/exchange/ExchangeSession.java b/src/java/davmail/exchange/ExchangeSession.java index 8914e7b84..db64130ab 100644 --- a/src/java/davmail/exchange/ExchangeSession.java +++ b/src/java/davmail/exchange/ExchangeSession.java @@ -79,8 +79,9 @@ public abstract class ExchangeSession { protected static final String TRASH = "Trash"; protected static final String JUNK = "Junk"; protected static final String UNSENT = "Unsent Messages"; + protected static final String ARCHIVE = "Archive"; - protected static final List SPECIAL = Arrays.asList(SENT, DRAFTS, TRASH, JUNK); + protected static final List SPECIAL = Arrays.asList(SENT, DRAFTS, TRASH, JUNK, ARCHIVE); static { // Adjust Mime decoder settings diff --git a/src/java/davmail/imap/ImapConnection.java b/src/java/davmail/imap/ImapConnection.java index c8e3cb581..5f00c4f1f 100644 --- a/src/java/davmail/imap/ImapConnection.java +++ b/src/java/davmail/imap/ImapConnection.java @@ -181,11 +181,12 @@ public void run() { String folderQuery = folderContext + decodeFolderPath(tokens.nextToken()); String returnOption = getReturnOption(tokens); boolean specialOnly = "SPECIAL-USE".equalsIgnoreCase(returnOption); + String[] ignoreFolders = Settings.getListProperty("davmail.imapIgnoreFolders"); if (folderQuery.endsWith("%/%") && !"/%/%".equals(folderQuery)) { List 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, false, specialOnly); + sendSubFolders(command, folder.folderPath, false, false, specialOnly, ignoreFolders); } sendClient(commandId + " OK " + command + " completed"); } else if (folderQuery.endsWith("%") || folderQuery.endsWith("*")) { @@ -201,7 +202,8 @@ public void run() { } boolean wildcard = folderQuery.endsWith("%") && !folderQuery.contains("/") && !folderQuery.equals("%"); boolean recursive = folderQuery.endsWith("*"); - sendSubFolders(command, folderQuery.substring(0, folderQuery.length() - 1), recursive, wildcard, specialOnly); + specialOnly = specialOnly && !folderQuery.equals("%"); + sendSubFolders(command, folderQuery.substring(0, folderQuery.length() - 1), recursive, wildcard, specialOnly, ignoreFolders); sendClient(commandId + " OK " + command + " completed"); } else { ExchangeSession.Folder folder = null; @@ -1412,11 +1414,12 @@ protected void appendBodyStructureValue(StringBuilder buffer, int value) { } } - protected void sendSubFolders(String command, String folderPath, boolean recursive, boolean wildcard, boolean specialOnly) throws IOException { + protected void sendSubFolders(String command, String folderPath, boolean recursive, boolean wildcard, boolean specialOnly, String[] ignore) throws IOException { try { + List ignoredList = Arrays.asList(ignore); List folders = session.getSubFolders(folderPath, recursive, wildcard); for (ExchangeSession.Folder folder : folders) { - if (!specialOnly || folder.isSpecial()) { + if ((!specialOnly || folder.isSpecial()) && (!ignoredList.contains(folder.folderPath))) { sendClient("* " + command + " (" + folder.getFlags() + ") \"/\" \"" + encodeFolderPath(folder.folderPath) + '\"'); } }