From d1dc346475d94fd80e9967b4b09a2c9fcfc4608e Mon Sep 17 00:00:00 2001 From: ashley willis Date: Mon, 9 Jan 2012 04:45:11 -0600 Subject: [PATCH] Local pop3 folders -- woot! Create folder, move or copy a message anywhere. Deleting folders not implemented yet. Issues 2189 and 2969. --- src/com/fsck/k9/activity/ChooseFolder.java | 5 ++++- src/com/fsck/k9/activity/FolderList.java | 5 ++++- .../k9/controller/MessagingController.java | 18 ++++++++++++++---- src/com/fsck/k9/mail/store/LocalStore.java | 5 +++++ src/com/fsck/k9/mail/store/Pop3Store.java | 11 +++++++++++ 5 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/com/fsck/k9/activity/ChooseFolder.java b/src/com/fsck/k9/activity/ChooseFolder.java index 958f776d0..c4fbccbfb 100644 --- a/src/com/fsck/k9/activity/ChooseFolder.java +++ b/src/com/fsck/k9/activity/ChooseFolder.java @@ -310,8 +310,11 @@ public class ChooseFolder extends K9ListActivity { String toastText = "Creating WebDav Folders not currently implemented."; Toast.makeText(getApplication(), toastText, Toast.LENGTH_LONG).show(); } else if (store instanceof Pop3Store) { - String toastText = "Creating Local Folders not currently implemented."; + boolean result = mAccount.getLocalStore().createFolder(folderName); + String toastText = "Creation of folder \"" + folderName + + ((result) ? "\" succeeded." : "\" failed."); Toast.makeText(getApplication(), toastText, Toast.LENGTH_LONG).show(); + onRefresh(false); } else { Log.d(K9.LOG_TAG, "Unhandled store type " + store.getClass()); } diff --git a/src/com/fsck/k9/activity/FolderList.java b/src/com/fsck/k9/activity/FolderList.java index f8cabb500..84204ef7a 100644 --- a/src/com/fsck/k9/activity/FolderList.java +++ b/src/com/fsck/k9/activity/FolderList.java @@ -499,8 +499,11 @@ public class FolderList extends K9ListActivity { String toastText = "Creating WebDav Folders not currently implemented."; Toast.makeText(getApplication(), toastText, Toast.LENGTH_LONG).show(); } else if (store instanceof Pop3Store) { - String toastText = "Creating Local Folders not currently implemented."; + boolean result = mAccount.getLocalStore().createFolder(folderName); + String toastText = "Creation of folder \"" + folderName + + ((result) ? "\" succeeded." : "\" failed."); Toast.makeText(getApplication(), toastText, Toast.LENGTH_LONG).show(); + onRefresh(false); } else { Log.d(K9.LOG_TAG, "Unhandled store type " + store.getClass()); } diff --git a/src/com/fsck/k9/controller/MessagingController.java b/src/com/fsck/k9/controller/MessagingController.java index 2eedc119e..1070ecd87 100644 --- a/src/com/fsck/k9/controller/MessagingController.java +++ b/src/com/fsck/k9/controller/MessagingController.java @@ -64,7 +64,7 @@ import com.fsck.k9.mail.store.UnavailableStorageException; import com.fsck.k9.mail.store.LocalStore.LocalFolder; import com.fsck.k9.mail.store.LocalStore.LocalMessage; import com.fsck.k9.mail.store.LocalStore.PendingCommand; - +import com.fsck.k9.mail.store.Pop3Store; /** * Starts a long running (application) Thread that will run through commands @@ -3168,7 +3168,13 @@ public class MessagingController implements Runnable { public boolean isMoveCapable(Message message) { - return !message.getUid().startsWith(K9.LOCAL_UID_PREFIX); + boolean isPop3Store = false; + try { + isPop3Store = message.getFolder().getAccount().getRemoteStore() instanceof Pop3Store; + } catch (com.fsck.k9.mail.MessagingException me) { + Log.e(K9.LOG_TAG, "MessagingException trying to get remote store of message: " + me); + } + return (!message.getUid().startsWith(K9.LOCAL_UID_PREFIX) || isPop3Store); } public boolean isCopyCapable(Message message) { return isMoveCapable(message); @@ -3229,6 +3235,7 @@ public class MessagingController implements Runnable { private void moveOrCopyMessageSynchronous(final Account account, final String srcFolder, final Message[] inMessages, final String destFolder, final boolean isCopy, MessagingListener listener) { + try { Store localStore = account.getLocalStore(); Store remoteStore = account.getRemoteStore(); @@ -3245,7 +3252,7 @@ public class MessagingController implements Runnable { List uids = new LinkedList(); for (Message message : inMessages) { String uid = message.getUid(); - if (!uid.startsWith(K9.LOCAL_UID_PREFIX)) { + if (!uid.startsWith(K9.LOCAL_UID_PREFIX) || remoteStore instanceof Pop3Store) { uids.add(uid); } } @@ -3280,7 +3287,10 @@ public class MessagingController implements Runnable { } } - queueMoveOrCopy(account, srcFolder, destFolder, isCopy, origUidMap.keySet().toArray(EMPTY_STRING_ARRAY)); + if (!(remoteStore instanceof Pop3Store)) { // don't sync pop3 + queueMoveOrCopy(account, srcFolder, destFolder, isCopy, + origUidMap.keySet().toArray(EMPTY_STRING_ARRAY)); + } } processPendingCommands(account); diff --git a/src/com/fsck/k9/mail/store/LocalStore.java b/src/com/fsck/k9/mail/store/LocalStore.java index fbcfafa21..ecb9d5bd7 100644 --- a/src/com/fsck/k9/mail/store/LocalStore.java +++ b/src/com/fsck/k9/mail/store/LocalStore.java @@ -1045,6 +1045,11 @@ public class LocalStore extends Store implements Serializable { public String type; } + public boolean createFolder(String name) throws com.fsck.k9.mail.MessagingException { + LocalFolder folder = new LocalFolder(name); + return folder.create(null); + } + public void createFolders(final List foldersToCreate, final int visibleLimit) throws UnavailableStorageException { database.execute(true, new DbCallback() { @Override diff --git a/src/com/fsck/k9/mail/store/Pop3Store.java b/src/com/fsck/k9/mail/store/Pop3Store.java index 56d9b5fd8..2ed3bfb07 100644 --- a/src/com/fsck/k9/mail/store/Pop3Store.java +++ b/src/com/fsck/k9/mail/store/Pop3Store.java @@ -288,6 +288,17 @@ public class Pop3Store extends Store { folder.close(); } + @Override + public boolean isMoveCapable() { + return true; + } + + @Override + public boolean isCopyCapable() { + return true; + } + + class Pop3Folder extends Folder { private Socket mSocket; private InputStream mIn;