Add FolderType support to WebDavStore + WebDavBackend
This commit is contained in:
parent
cea3c41269
commit
aecdbf5a6a
3 changed files with 37 additions and 49 deletions
|
@ -3,7 +3,6 @@ package com.fsck.k9.backend.webdav
|
|||
|
||||
import com.fsck.k9.backend.api.BackendStorage
|
||||
import com.fsck.k9.backend.api.FolderInfo
|
||||
import com.fsck.k9.mail.Folder.FolderType
|
||||
import com.fsck.k9.mail.store.webdav.WebDavStore
|
||||
|
||||
|
||||
|
@ -17,11 +16,10 @@ internal class CommandRefreshFolderList(
|
|||
|
||||
val foldersToCreate = mutableListOf<FolderInfo>()
|
||||
for (folder in foldersOnServer) {
|
||||
//FIXME: Use correct folder type
|
||||
if (folder.serverId !in oldFolderServerIds) {
|
||||
foldersToCreate.add(FolderInfo(folder.serverId, folder.name, FolderType.REGULAR))
|
||||
foldersToCreate.add(FolderInfo(folder.serverId, folder.name, folder.type))
|
||||
} else {
|
||||
backendStorage.changeFolder(folder.serverId, folder.name, FolderType.REGULAR)
|
||||
backendStorage.changeFolder(folder.serverId, folder.name, folder.type)
|
||||
}
|
||||
}
|
||||
backendStorage.createFolders(foldersToCreate)
|
||||
|
|
|
@ -19,6 +19,7 @@ import java.util.Map;
|
|||
import com.fsck.k9.mail.CertificateValidationException;
|
||||
import com.fsck.k9.mail.ConnectionSecurity;
|
||||
import com.fsck.k9.mail.Folder;
|
||||
import com.fsck.k9.mail.Folder.FolderType;
|
||||
import com.fsck.k9.mail.K9MailLib;
|
||||
import com.fsck.k9.mail.Message;
|
||||
import com.fsck.k9.mail.MessagingException;
|
||||
|
@ -167,8 +168,7 @@ public class WebDavStore extends RemoteStore {
|
|||
getHttpClient();
|
||||
|
||||
/*
|
||||
* Firstly we get the "special" folders list (inbox, outbox, etc)
|
||||
* and setup the account accordingly
|
||||
* First we get the "special" folders list (inbox, outbox, etc)
|
||||
*/
|
||||
Map<String, String> headers = new HashMap<>();
|
||||
headers.put("Depth", "0");
|
||||
|
@ -176,38 +176,6 @@ public class WebDavStore extends RemoteStore {
|
|||
DataSet dataset = processRequest(this.baseUrl, "PROPFIND", getSpecialFoldersList(), headers);
|
||||
|
||||
Map<String, String> specialFoldersMap = dataset.getSpecialFolderToUrl();
|
||||
String folderName = getFolderName(specialFoldersMap.get(WebDavConstants.DAV_MAIL_INBOX_FOLDER));
|
||||
if (folderName != null) {
|
||||
mStoreConfig.setAutoExpandFolder(folderName);
|
||||
mStoreConfig.setInboxFolder(folderName);
|
||||
}
|
||||
|
||||
folderName = getFolderName(specialFoldersMap.get(WebDavConstants.DAV_MAIL_DRAFTS_FOLDER));
|
||||
if (folderName != null) {
|
||||
mStoreConfig.setDraftsFolder(folderName);
|
||||
}
|
||||
|
||||
folderName = getFolderName(specialFoldersMap.get(WebDavConstants.DAV_MAIL_TRASH_FOLDER));
|
||||
if (folderName != null) {
|
||||
mStoreConfig.setTrashFolder(folderName);
|
||||
}
|
||||
|
||||
folderName = getFolderName(specialFoldersMap.get(WebDavConstants.DAV_MAIL_SPAM_FOLDER));
|
||||
if (folderName != null) {
|
||||
mStoreConfig.setSpamFolder(folderName);
|
||||
}
|
||||
|
||||
// K-9 Mail's outbox is a special local folder and different from Exchange/WebDAV's outbox.
|
||||
/*
|
||||
folderName = getFolderName(specialFoldersMap.get(DAV_MAIL_OUTBOX_FOLDER));
|
||||
if (folderName != null)
|
||||
mAccount.setOutboxFolderName(folderName);
|
||||
*/
|
||||
|
||||
folderName = getFolderName(specialFoldersMap.get(WebDavConstants.DAV_MAIL_SENT_FOLDER));
|
||||
if (folderName != null) {
|
||||
mStoreConfig.setSentFolder(folderName);
|
||||
}
|
||||
|
||||
/*
|
||||
* Next we get all the folders (including "special" ones)
|
||||
|
@ -218,7 +186,7 @@ public class WebDavStore extends RemoteStore {
|
|||
String[] folderUrls = dataset.getHrefs();
|
||||
|
||||
for (String tempUrl : folderUrls) {
|
||||
WebDavFolder folder = createFolder(tempUrl);
|
||||
WebDavFolder folder = createFolder(tempUrl, specialFoldersMap);
|
||||
if (folder != null) {
|
||||
folderList.add(folder);
|
||||
}
|
||||
|
@ -228,15 +196,10 @@ public class WebDavStore extends RemoteStore {
|
|||
}
|
||||
|
||||
/**
|
||||
* Creates a folder using the URL passed as parameter (only if it has not been
|
||||
* already created) and adds this to our store folder map.
|
||||
*
|
||||
* @param folderUrl
|
||||
* URL
|
||||
*
|
||||
* @return WebDAV remote folder
|
||||
* Creates a folder using the URL passed as parameter (only if it has not been already created) and adds this to
|
||||
* our store folder map.
|
||||
*/
|
||||
private WebDavFolder createFolder(String folderUrl) {
|
||||
private WebDavFolder createFolder(String folderUrl, Map<String, String> specialFoldersMap) {
|
||||
if (folderUrl == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -247,6 +210,8 @@ public class WebDavStore extends RemoteStore {
|
|||
wdFolder = getFolder(folderName);
|
||||
if (wdFolder != null) {
|
||||
wdFolder.setUrl(folderUrl);
|
||||
FolderType type = getFolderType(folderName, specialFoldersMap);
|
||||
wdFolder.setType(type);
|
||||
}
|
||||
}
|
||||
// else: Unknown URL format => NO Folder created
|
||||
|
@ -254,6 +219,22 @@ public class WebDavStore extends RemoteStore {
|
|||
return wdFolder;
|
||||
}
|
||||
|
||||
private FolderType getFolderType(String folderName, Map<String, String> specialFoldersMap) {
|
||||
if (folderName.equals(getFolderName(specialFoldersMap.get(WebDavConstants.DAV_MAIL_INBOX_FOLDER)))) {
|
||||
return FolderType.INBOX;
|
||||
} else if (folderName.equals(getFolderName(specialFoldersMap.get(WebDavConstants.DAV_MAIL_DRAFTS_FOLDER)))) {
|
||||
return FolderType.DRAFTS;
|
||||
} else if (folderName.equals(getFolderName(specialFoldersMap.get(WebDavConstants.DAV_MAIL_TRASH_FOLDER)))) {
|
||||
return FolderType.TRASH;
|
||||
} else if (folderName.equals(getFolderName(specialFoldersMap.get(WebDavConstants.DAV_MAIL_SPAM_FOLDER)))) {
|
||||
return FolderType.SPAM;
|
||||
} else if (folderName.equals(getFolderName(specialFoldersMap.get(WebDavConstants.DAV_MAIL_SENT_FOLDER)))) {
|
||||
return FolderType.SENT;
|
||||
} else {
|
||||
return FolderType.REGULAR;
|
||||
}
|
||||
}
|
||||
|
||||
private String getFolderName(String folderUrl) {
|
||||
if (folderUrl == null) {
|
||||
return null;
|
||||
|
|
|
@ -4,12 +4,15 @@ package com.fsck.k9.mail.store.webdav;
|
|||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.fsck.k9.mail.AuthType;
|
||||
import com.fsck.k9.mail.CertificateValidationException;
|
||||
import com.fsck.k9.mail.ConnectionSecurity;
|
||||
import com.fsck.k9.mail.Folder;
|
||||
import com.fsck.k9.mail.Folder.FolderType;
|
||||
import com.fsck.k9.mail.K9LibRobolectricTestRunner;
|
||||
import com.fsck.k9.mail.MessagingException;
|
||||
import com.fsck.k9.mail.filter.Base64;
|
||||
|
@ -223,9 +226,15 @@ public class WebDavStoreTest {
|
|||
configureHttpResponses(UNAUTHORIZED_401_RESPONSE, OK_200_RESPONSE, createOkPropfindResponse(),
|
||||
createOkSearchResponse());
|
||||
|
||||
webDavStore.getPersonalNamespaces();
|
||||
List<? extends Folder> folders = webDavStore.getPersonalNamespaces();
|
||||
|
||||
verify(storeConfig).setInboxFolder("Inbox");
|
||||
Map<String, FolderType> folderNameToTypeMap = new HashMap<>();
|
||||
for (Folder folder : folders) {
|
||||
folderNameToTypeMap.put(folder.getName(), folder.getType());
|
||||
}
|
||||
assertEquals(FolderType.INBOX, folderNameToTypeMap.get("Inbox"));
|
||||
assertEquals(FolderType.REGULAR, folderNameToTypeMap.get("Drafts"));
|
||||
assertEquals(FolderType.REGULAR, folderNameToTypeMap.get("Folder2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in a new issue