Commit 9da18912 authored by Francisco Cunha's avatar Francisco Cunha Committed by Hussein

P4A-816 - Remove prefix (path) before special folders set

parent 0952b545
......@@ -16,6 +16,8 @@ import java.util.Set;
import android.net.ConnectivityManager;
import androidx.annotation.Nullable;
import com.fsck.k9.mail.AuthType;
import com.fsck.k9.mail.ConnectionSecurity;
import com.fsck.k9.mail.Flag;
......@@ -175,8 +177,6 @@ public class ImapStore extends RemoteStore {
Set<String> folderNames = new HashSet<>(listResponses.size());
for (ListResponse listResponse : listResponses) {
boolean includeFolder = true;
String decodedFolderName;
try {
decodedFolderName = folderNameCodec.decode(listResponse.getName());
......@@ -208,24 +208,12 @@ public class ImapStore extends RemoteStore {
* we simply ignore the folder on the server.
*/
continue;
} else {
int prefixLength = getCombinedPrefix().length();
if (prefixLength > 0) {
// Strip prefix from the folder name
if (folder.length() >= prefixLength) {
folder = folder.substring(prefixLength);
}
if (!decodedFolderName.equalsIgnoreCase(getCombinedPrefix() + folder)) {
includeFolder = false;
}
}
}
if (listResponse.hasAttribute("\\NoSelect")) {
includeFolder = false;
} else if (listResponse.hasAttribute("\\NoSelect")) {
continue;
}
if (includeFolder) {
folder = removePrefixFromFolderName(folder);
if (folder != null) {
folderNames.add(folder);
}
}
......@@ -268,6 +256,11 @@ public class ImapStore extends RemoteStore {
combinedPrefix = null;
}
decodedFolderName = removePrefixFromFolderName(decodedFolderName);
if (decodedFolderName == null) {
continue;
}
if (listResponse.hasAttribute("\\Archive") || listResponse.hasAttribute("\\All")) {
mStoreConfig.setArchiveFolderName(decodedFolderName);
if (K9MailLib.isDebug()) {
......@@ -297,6 +290,23 @@ public class ImapStore extends RemoteStore {
}
}
@Nullable
private String removePrefixFromFolderName(String folderName) {
String prefix = getCombinedPrefix();
int prefixLength = prefix.length();
if (prefixLength == 0) {
return folderName;
}
if (!folderName.startsWith(prefix)) {
// Folder name doesn't start with our configured prefix. But right now when building commands we prefix all
// folders except the INBOX with the prefix. So we won't be able to use this folder.
return null;
}
return folderName.substring(prefixLength);
}
@Override
public void checkSettings() throws MessagingException {
try {
......
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