Remove namespace prefix from auto-configured special folder names
Fixes #701
This commit is contained in:
parent
a36254dbc0
commit
9d90c53050
2 changed files with 44 additions and 0 deletions
|
@ -267,6 +267,15 @@ public class ImapStore extends RemoteStore {
|
|||
combinedPrefix = null;
|
||||
}
|
||||
|
||||
String prefix = getCombinedPrefix();
|
||||
int prefixLength = prefix.length();
|
||||
if (prefixLength > 0 && decodedFolderName.startsWith(prefix)) {
|
||||
if (K9MailLib.isDebug()) {
|
||||
Timber.d("Folder auto-configuration stripping prefix (%s) from folder name: %s", prefix, decodedFolderName);
|
||||
}
|
||||
decodedFolderName = decodedFolderName.substring(prefixLength);
|
||||
}
|
||||
|
||||
if (listResponse.hasAttribute("\\Archive") || listResponse.hasAttribute("\\All")) {
|
||||
mStoreConfig.setArchiveFolderName(decodedFolderName);
|
||||
if (K9MailLib.isDebug()) {
|
||||
|
|
|
@ -131,6 +131,31 @@ public class ImapStoreTest {
|
|||
verifyNoMoreInteractions(imapConnection);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void autoconfigureFolders_removeNamespacePrefix() throws Exception {
|
||||
ImapConnection imapConnection = mock(ImapConnection.class);
|
||||
when(imapConnection.hasCapability(Capabilities.SPECIAL_USE)).thenReturn(true);
|
||||
List<ImapResponse> imapResponses = Arrays.asList(
|
||||
createImapResponse("* LIST (\\Drafts) \"/\" \"INBOX.Drafts\""),
|
||||
createImapResponse("* LIST (\\Sent) \"/\" \"INBOX.Sent\""),
|
||||
createImapResponse("* LIST (\\Junk) \"/\" \"INBOX.Spam\""),
|
||||
createImapResponse("* LIST (\\Trash) \"/\" \"INBOX.Trash\""),
|
||||
createImapResponse("* LIST (\\Archive) \"/\" \"INBOX.Archive\""),
|
||||
createImapResponse("5 OK Success")
|
||||
);
|
||||
when(imapConnection.executeSimpleCommand("LIST (SPECIAL-USE) \"\" \"INBOX.*\"")).thenReturn(imapResponses);
|
||||
|
||||
imapStore.setTestCombinedPrefix("INBOX.");
|
||||
imapStore.autoconfigureFolders(imapConnection);
|
||||
|
||||
assertEquals("INBOX.", imapStore.getCombinedPrefix());
|
||||
verify(storeConfig).setDraftsFolderName("Drafts");
|
||||
verify(storeConfig).setSentFolderName("Sent");
|
||||
verify(storeConfig).setSpamFolderName("Spam");
|
||||
verify(storeConfig).setTrashFolderName("Trash");
|
||||
verify(storeConfig).setArchiveFolderName("Archive");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPersonalNamespaces_withForceListAll() throws Exception {
|
||||
when(storeConfig.subscribedFoldersOnly()).thenReturn(true);
|
||||
|
@ -313,6 +338,7 @@ public class ImapStoreTest {
|
|||
|
||||
static class TestImapStore extends ImapStore {
|
||||
private Deque<ImapConnection> imapConnections = new ArrayDeque<>();
|
||||
private String testCombinedPrefix;
|
||||
|
||||
public TestImapStore(StoreConfig storeConfig, TrustedSocketFactory trustedSocketFactory,
|
||||
ConnectivityManager connectivityManager, OAuth2TokenProvider oauth2TokenProvider) throws MessagingException {
|
||||
|
@ -330,5 +356,14 @@ public class ImapStoreTest {
|
|||
public void enqueueImapConnection(ImapConnection imapConnection) {
|
||||
imapConnections.add(imapConnection);
|
||||
}
|
||||
|
||||
@Override
|
||||
String getCombinedPrefix() {
|
||||
return testCombinedPrefix != null ? testCombinedPrefix : super.getCombinedPrefix();
|
||||
}
|
||||
|
||||
void setTestCombinedPrefix(String prefix) {
|
||||
testCombinedPrefix = prefix;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue