Never create remote folders automatically
This commit is contained in:
parent
7b0c78803b
commit
130efa2991
6 changed files with 29 additions and 95 deletions
|
@ -0,0 +1,6 @@
|
|||
package com.fsck.k9.mail.store.imap
|
||||
|
||||
import com.fsck.k9.mail.MessagingException
|
||||
|
||||
class FolderNotFoundException(val folderServerId: String)
|
||||
: MessagingException("Folder not found: $folderServerId")
|
|
@ -356,15 +356,14 @@ class ImapFolder extends Folder<ImapMessage> {
|
|||
String encodedDestinationFolderName = folderNameCodec.encode(imapFolder.getPrefixedName());
|
||||
String escapedDestinationFolderName = ImapUtility.encodeString(encodedDestinationFolderName);
|
||||
|
||||
//TODO: Try to copy/move the messages first and only create the folder if the
|
||||
// operation fails. This will save a roundtrip if the folder already exists.
|
||||
//TODO: Just perform the operation and only check for existence of the folder if the operation fails.
|
||||
if (!exists(escapedDestinationFolderName)) {
|
||||
if (K9MailLib.isDebug()) {
|
||||
Timber.i("ImapFolder.copyMessages: attempting to create remote folder '%s' for %s",
|
||||
Timber.i("ImapFolder.copyMessages: couldn't find remote folder '%s' for %s",
|
||||
escapedDestinationFolderName, getLogId());
|
||||
}
|
||||
|
||||
imapFolder.create(FolderType.HOLDS_MESSAGES);
|
||||
throw new FolderNotFoundException(imapFolder.getServerId());
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -406,23 +405,18 @@ class ImapFolder extends Folder<ImapMessage> {
|
|||
|
||||
if (!exists(escapedTrashFolderName)) {
|
||||
if (K9MailLib.isDebug()) {
|
||||
Timber.i("IMAPMessage.delete: attempting to create remote '%s' folder for %s",
|
||||
Timber.i("ImapFolder.delete: couldn't find remote trash folder '%s' for %s",
|
||||
trashFolder, getLogId());
|
||||
}
|
||||
remoteTrashFolder.create(FolderType.HOLDS_MESSAGES);
|
||||
throw new FolderNotFoundException(remoteTrashFolder.getServerId());
|
||||
}
|
||||
|
||||
if (exists(escapedTrashFolderName)) {
|
||||
if (K9MailLib.isDebug()) {
|
||||
Timber.d("IMAPMessage.delete: copying remote %d messages to '%s' for %s",
|
||||
messages.size(), trashFolder, getLogId());
|
||||
}
|
||||
|
||||
moveMessages(messages, remoteTrashFolder);
|
||||
} else {
|
||||
throw new MessagingException("IMAPMessage.delete: remote Trash folder " + trashFolder +
|
||||
" does not exist and could not be created for " + getLogId(), true);
|
||||
if (K9MailLib.isDebug()) {
|
||||
Timber.d("IMAPMessage.delete: copying remote %d messages to '%s' for %s",
|
||||
messages.size(), trashFolder, getLogId());
|
||||
}
|
||||
|
||||
moveMessages(messages, remoteTrashFolder);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -418,7 +418,7 @@ public class ImapFolderTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void delete_withoutTrashFolderExisting_shouldCreateTrashFolder() throws Exception {
|
||||
public void delete_withoutTrashFolderExisting_shouldThrow() throws Exception {
|
||||
ImapFolder folder = createFolder("Folder");
|
||||
prepareImapFolderForOpen(OPEN_MODE_RW);
|
||||
ImapFolder trashFolder = createFolder("Trash");
|
||||
|
@ -432,9 +432,12 @@ public class ImapFolderTest {
|
|||
doThrow(NegativeImapResponseException.class).doReturn(Collections.emptyList())
|
||||
.when(imapConnection).executeSimpleCommand("STATUS \"Trash\" (RECENT)");
|
||||
|
||||
folder.delete(messages, "Trash");
|
||||
|
||||
verify(imapConnection).executeSimpleCommand("CREATE \"Trash\"");
|
||||
try {
|
||||
folder.delete(messages, "Trash");
|
||||
fail("Expected exception");
|
||||
} catch (FolderNotFoundException e) {
|
||||
assertEquals("Trash", e.getFolderServerId());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -795,11 +795,6 @@ public class MessagingController {
|
|||
Timber.v("SYNC: About to get remote folder %s", folder);
|
||||
remoteFolder = remoteStore.getFolder(folder);
|
||||
|
||||
if (!verifyOrCreateRemoteSpecialFolder(account, folder, remoteFolder, listener)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Synchronization process:
|
||||
*
|
||||
|
@ -1020,32 +1015,6 @@ public class MessagingController {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* If the folder is a "special" folder we need to see if it exists
|
||||
* on the remote server. It if does not exist we'll try to create it. If we
|
||||
* can't create we'll abort. This will happen on every single Pop3 folder as
|
||||
* designed and on Imap folders during error conditions. This allows us
|
||||
* to treat Pop3 and Imap the same in this code.
|
||||
*/
|
||||
private boolean verifyOrCreateRemoteSpecialFolder(Account account, String folder, Folder remoteFolder,
|
||||
MessagingListener listener) throws MessagingException {
|
||||
if (folder.equals(account.getTrashFolder()) ||
|
||||
folder.equals(account.getSentFolder()) ||
|
||||
folder.equals(account.getDraftsFolder())) {
|
||||
if (!remoteFolder.exists()) {
|
||||
if (!remoteFolder.create(FolderType.HOLDS_MESSAGES)) {
|
||||
for (MessagingListener l : getListeners(listener)) {
|
||||
l.synchronizeMailboxFinished(account, folder, 0, 0);
|
||||
}
|
||||
|
||||
Timber.i("Done synchronizing folder %s", folder);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the messages described by inputMessages from the remote store and writes them to
|
||||
* local storage.
|
||||
|
@ -1715,9 +1684,8 @@ public class MessagingController {
|
|||
RemoteStore remoteStore = account.getRemoteStore();
|
||||
remoteFolder = remoteStore.getFolder(folder);
|
||||
if (!remoteFolder.exists()) {
|
||||
if (!remoteFolder.create(FolderType.HOLDS_MESSAGES)) {
|
||||
return;
|
||||
}
|
||||
Timber.w("Remote folder doesn't exist: %s", folder);
|
||||
return;
|
||||
}
|
||||
remoteFolder.open(Folder.OPEN_MODE_RW);
|
||||
if (remoteFolder.getMode() != Folder.OPEN_MODE_RW) {
|
||||
|
@ -3221,16 +3189,9 @@ public class MessagingController {
|
|||
localFolder.setFlags(syncedMessages, Collections.singleton(Flag.DELETED), true);
|
||||
}
|
||||
} else {
|
||||
Timber.d("Deleting messages in normal folder, moving");
|
||||
localTrashFolder = localStore.getFolder(account.getTrashFolder());
|
||||
if (!localTrashFolder.exists()) {
|
||||
localTrashFolder.create(Folder.FolderType.HOLDS_MESSAGES);
|
||||
}
|
||||
if (localTrashFolder.exists()) {
|
||||
Timber.d("Deleting messages in normal folder, moving");
|
||||
|
||||
uidMap = localFolder.moveMessages(messages, localTrashFolder);
|
||||
|
||||
}
|
||||
uidMap = localFolder.moveMessages(messages, localTrashFolder);
|
||||
}
|
||||
|
||||
for (MessagingListener l : getListeners()) {
|
||||
|
|
|
@ -114,11 +114,6 @@ class ImapSync {
|
|||
Timber.v("SYNC: About to get remote folder %s", folder);
|
||||
remoteFolder = remoteStore.getFolder(folder);
|
||||
|
||||
if (!verifyOrCreateRemoteSpecialFolder(account, folder, remoteFolder, listener)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Synchronization process:
|
||||
*
|
||||
|
@ -325,30 +320,6 @@ class ImapSync {
|
|||
|
||||
}
|
||||
|
||||
/*
|
||||
* If the folder is a "special" folder we need to see if it exists
|
||||
* on the remote server. It if does not exist we'll try to create it. If we
|
||||
* can't create we'll abort.
|
||||
*/
|
||||
private boolean verifyOrCreateRemoteSpecialFolder(Account account, String folder, Folder remoteFolder,
|
||||
MessagingListener listener) throws MessagingException {
|
||||
if (folder.equals(account.getTrashFolder()) ||
|
||||
folder.equals(account.getSentFolder()) ||
|
||||
folder.equals(account.getDraftsFolder())) {
|
||||
if (!remoteFolder.exists()) {
|
||||
if (!remoteFolder.create(FolderType.HOLDS_MESSAGES)) {
|
||||
for (MessagingListener l : getListeners(listener)) {
|
||||
l.synchronizeMailboxFinished(account, folder, 0, 0);
|
||||
}
|
||||
|
||||
Timber.i("Done synchronizing folder %s", folder);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the messages described by inputMessages from the remote store and writes them to
|
||||
* local storage.
|
||||
|
|
|
@ -167,9 +167,8 @@ public class LocalFolder extends Folder<LocalMessage> {
|
|||
open(cursor);
|
||||
}
|
||||
} else {
|
||||
Timber.w("Creating folder %s with existing id %d", getServerId(), getDatabaseId());
|
||||
create(FolderType.HOLDS_MESSAGES);
|
||||
open(mode);
|
||||
throw new MessagingException("LocalFolder.open(): Folder not found: " +
|
||||
serverId + " (" + databaseId + ")");
|
||||
}
|
||||
} catch (MessagingException e) {
|
||||
throw new WrappedException(e);
|
||||
|
|
Loading…
Reference in a new issue