2008-11-01 17:32:06 -04:00
|
|
|
|
2009-12-14 21:50:53 -05:00
|
|
|
package com.fsck.k9.mail;
|
2008-11-01 17:32:06 -04:00
|
|
|
|
|
|
|
import android.app.Application;
|
2010-11-13 16:40:56 -05:00
|
|
|
import android.content.Context;
|
2010-03-03 23:00:30 -05:00
|
|
|
|
|
|
|
import com.fsck.k9.Account;
|
2009-12-14 21:50:53 -05:00
|
|
|
import com.fsck.k9.mail.store.ImapStore;
|
|
|
|
import com.fsck.k9.mail.store.LocalStore;
|
|
|
|
import com.fsck.k9.mail.store.Pop3Store;
|
|
|
|
import com.fsck.k9.mail.store.WebDavStore;
|
2010-11-13 16:40:56 -05:00
|
|
|
import com.fsck.k9.mail.store.StorageManager.StorageProvider;
|
2008-11-01 17:32:06 -04:00
|
|
|
|
2009-12-09 22:16:42 -05:00
|
|
|
import java.util.HashMap;
|
2010-04-21 22:20:35 -04:00
|
|
|
import java.util.List;
|
2009-12-09 22:16:42 -05:00
|
|
|
|
2008-11-01 17:32:06 -04:00
|
|
|
/**
|
|
|
|
* Store is the access point for an email message store. It's location can be
|
|
|
|
* local or remote and no specific protocol is defined. Store is intended to
|
|
|
|
* loosely model in combination the JavaMail classes javax.mail.Store and
|
|
|
|
* javax.mail.Folder along with some additional functionality to improve
|
|
|
|
* performance on mobile devices. Implementations of this class should focus on
|
|
|
|
* making as few network connections as possible.
|
|
|
|
*/
|
2011-02-06 17:09:48 -05:00
|
|
|
public abstract class Store {
|
2010-04-05 22:54:48 -04:00
|
|
|
protected static final int SOCKET_CONNECT_TIMEOUT = 30000;
|
2008-11-01 17:32:06 -04:00
|
|
|
protected static final int SOCKET_READ_TIMEOUT = 60000;
|
|
|
|
|
2010-11-13 16:40:56 -05:00
|
|
|
/**
|
|
|
|
* Remote stores indexed by Uri.
|
|
|
|
*/
|
2008-11-01 17:32:06 -04:00
|
|
|
private static HashMap<String, Store> mStores = new HashMap<String, Store>();
|
2010-11-13 16:40:56 -05:00
|
|
|
/**
|
|
|
|
* Local stores indexed by UUid because the Uri may change due to migration to/from SD-card.
|
|
|
|
*/
|
|
|
|
private static HashMap<String, Store> mLocalStores = new HashMap<String, Store>();
|
2008-11-01 17:32:06 -04:00
|
|
|
|
2010-03-03 23:00:30 -05:00
|
|
|
protected final Account mAccount;
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
protected Store(Account account) {
|
2010-03-03 23:00:30 -05:00
|
|
|
mAccount = account;
|
|
|
|
}
|
|
|
|
|
2008-11-01 17:32:06 -04:00
|
|
|
/**
|
2010-03-03 23:00:30 -05:00
|
|
|
* Get an instance of a remote mail store.
|
2008-11-01 17:32:06 -04:00
|
|
|
*/
|
2011-02-06 17:09:48 -05:00
|
|
|
public synchronized static Store getRemoteInstance(Account account) throws MessagingException {
|
2010-03-03 23:00:30 -05:00
|
|
|
String uri = account.getStoreUri();
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
if (uri.startsWith("local")) {
|
2010-03-03 23:00:30 -05:00
|
|
|
throw new RuntimeException("Asked to get non-local Store object but given LocalStore URI");
|
|
|
|
}
|
|
|
|
|
2008-11-01 17:32:06 -04:00
|
|
|
Store store = mStores.get(uri);
|
2011-02-06 17:09:48 -05:00
|
|
|
if (store == null) {
|
|
|
|
if (uri.startsWith("imap")) {
|
2010-03-03 23:00:30 -05:00
|
|
|
store = new ImapStore(account);
|
2011-02-06 17:09:48 -05:00
|
|
|
} else if (uri.startsWith("pop3")) {
|
2010-03-03 23:00:30 -05:00
|
|
|
store = new Pop3Store(account);
|
2011-02-06 17:09:48 -05:00
|
|
|
} else if (uri.startsWith("webdav")) {
|
2010-03-03 23:00:30 -05:00
|
|
|
store = new WebDavStore(account);
|
2009-11-24 19:40:29 -05:00
|
|
|
}
|
2010-03-03 23:00:30 -05:00
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
if (store != null) {
|
2010-03-03 23:00:30 -05:00
|
|
|
mStores.put(uri, store);
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
2010-03-03 23:00:30 -05:00
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
if (store == null) {
|
2010-03-03 23:00:30 -05:00
|
|
|
throw new MessagingException("Unable to locate an applicable Store for " + uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
return store;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get an instance of a local mail store.
|
2010-11-13 16:40:56 -05:00
|
|
|
* @throws UnavailableStorageException if not {@link StorageProvider#isReady(Context)}
|
2010-03-03 23:00:30 -05:00
|
|
|
*/
|
2011-02-06 17:09:48 -05:00
|
|
|
public synchronized static LocalStore getLocalInstance(Account account, Application application) throws MessagingException {
|
2010-11-13 16:40:56 -05:00
|
|
|
Store store = mLocalStores.get(account.getUuid());
|
2011-02-06 17:09:48 -05:00
|
|
|
if (store == null) {
|
2010-03-03 23:00:30 -05:00
|
|
|
store = new LocalStore(account, application);
|
2010-11-13 16:40:56 -05:00
|
|
|
mLocalStores.put(account.getUuid(), store);
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
|
|
|
|
2010-11-13 16:40:56 -05:00
|
|
|
return (LocalStore) store;
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
|
|
|
|
2010-11-30 22:02:13 -05:00
|
|
|
public abstract Folder getFolder(String name);
|
2008-11-01 17:32:06 -04:00
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public abstract List <? extends Folder > getPersonalNamespaces(boolean forceListAll) throws MessagingException;
|
2008-11-01 17:32:06 -04:00
|
|
|
|
|
|
|
public abstract void checkSettings() throws MessagingException;
|
2009-11-24 19:40:29 -05:00
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public boolean isCopyCapable() {
|
2009-11-24 19:40:29 -05:00
|
|
|
return false;
|
2009-03-05 02:32:45 -05:00
|
|
|
}
|
2011-02-06 17:09:48 -05:00
|
|
|
public boolean isMoveCapable() {
|
2009-11-24 19:40:29 -05:00
|
|
|
return false;
|
2009-03-05 02:32:45 -05:00
|
|
|
}
|
2011-02-06 17:09:48 -05:00
|
|
|
public boolean isPushCapable() {
|
2009-10-21 20:41:06 -04:00
|
|
|
return false;
|
|
|
|
}
|
2011-02-06 17:09:48 -05:00
|
|
|
public boolean isSendCapable() {
|
2009-10-24 22:58:26 -04:00
|
|
|
return false;
|
|
|
|
}
|
2011-02-06 17:09:48 -05:00
|
|
|
public boolean isExpungeCapable() {
|
Implementation of complete IMAP two-phase "delete/expunge" behavior.
On each IMAP account, the expunge behavior can be set to expunge
messages in a folder as soon as a move or delete is performed on the
folder ("immediately"), each time the folder is polled, or only when
executed manually.
In the Message List, there is now an Expunge action in the option
menu.
In the Folder List, there is now an Expunge action in the context
menu (long-press on the folder).
For IMAP accounts, it is also possible to disable the copying of deleted messages to the
Trash folder, by setting the Trash folder to -NONE-.
Fixes Issue 536.
Separately, in WebDAV accounts, the user can now choose the
server-side equivalents of the special folders, just like for IMAP.
2009-12-20 18:13:49 -05:00
|
|
|
return false;
|
|
|
|
}
|
2010-01-02 20:50:51 -05:00
|
|
|
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public void sendMessages(Message[] messages) throws MessagingException {
|
2009-10-24 22:58:26 -04:00
|
|
|
}
|
2009-10-21 20:41:06 -04:00
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public Pusher getPusher(PushReceiver receiver) {
|
2009-10-21 20:41:06 -04:00
|
|
|
return null;
|
|
|
|
}
|
2009-03-05 02:32:45 -05:00
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public Account getAccount() {
|
2010-03-03 23:00:30 -05:00
|
|
|
return mAccount;
|
|
|
|
}
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|