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-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;
|
2008-11-01 17:32:06 -04:00
|
|
|
|
2009-12-09 22:16:42 -05:00
|
|
|
import java.util.HashMap;
|
|
|
|
|
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.
|
|
|
|
*/
|
2009-11-24 19:40:29 -05:00
|
|
|
public abstract class Store
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
/**
|
|
|
|
* A global suggestion to Store implementors on how much of the body
|
|
|
|
* should be returned on FetchProfile.Item.BODY_SANE requests.
|
|
|
|
*/
|
2009-05-20 00:27:51 -04:00
|
|
|
//Matching MessagingController.MAX_SMALL_MESSAGE_SIZE
|
2009-05-21 14:49:39 -04:00
|
|
|
public static final int FETCH_BODY_SANE_SUGGESTED_SIZE = (50 * 1024);
|
2008-11-01 17:32:06 -04:00
|
|
|
|
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;
|
|
|
|
|
|
|
|
private static HashMap<String, Store> mStores = new HashMap<String, Store>();
|
|
|
|
|
2010-03-03 23:00:30 -05:00
|
|
|
protected final Account mAccount;
|
|
|
|
|
|
|
|
protected Store(Account account)
|
|
|
|
{
|
|
|
|
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
|
|
|
*/
|
2010-03-03 23:00:30 -05:00
|
|
|
public synchronized static Store getRemoteInstance(Account account) throws MessagingException
|
2009-11-24 19:40:29 -05:00
|
|
|
{
|
2010-03-03 23:00:30 -05:00
|
|
|
String uri = account.getStoreUri();
|
|
|
|
|
|
|
|
if (uri.startsWith("local"))
|
|
|
|
{
|
|
|
|
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);
|
2009-11-24 19:40:29 -05:00
|
|
|
if (store == null)
|
|
|
|
{
|
|
|
|
if (uri.startsWith("imap"))
|
|
|
|
{
|
2010-03-03 23:00:30 -05:00
|
|
|
store = new ImapStore(account);
|
2009-11-24 19:40:29 -05:00
|
|
|
}
|
|
|
|
else if (uri.startsWith("pop3"))
|
|
|
|
{
|
2010-03-03 23:00:30 -05:00
|
|
|
store = new Pop3Store(account);
|
2009-11-24 19:40:29 -05:00
|
|
|
}
|
2010-03-03 23:00:30 -05:00
|
|
|
else if (uri.startsWith("webdav"))
|
2009-11-24 19:40:29 -05:00
|
|
|
{
|
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
|
|
|
|
|
|
|
if (store != null)
|
2009-11-24 19:40:29 -05:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
if (store == null)
|
|
|
|
{
|
|
|
|
throw new MessagingException("Unable to locate an applicable Store for " + uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
return store;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get an instance of a local mail store.
|
|
|
|
*/
|
|
|
|
public synchronized static LocalStore getLocalInstance(Account account, Application application) throws MessagingException
|
|
|
|
{
|
|
|
|
String uri = account.getLocalStoreUri();
|
2008-11-01 17:32:06 -04:00
|
|
|
|
2010-03-03 23:00:30 -05:00
|
|
|
if (!uri.startsWith("local"))
|
|
|
|
{
|
|
|
|
throw new RuntimeException("LocalStore URI doesn't start with 'local'");
|
|
|
|
}
|
|
|
|
|
|
|
|
Store store = mStores.get(uri);
|
|
|
|
if (store == null)
|
|
|
|
{
|
|
|
|
store = new LocalStore(account, application);
|
2008-12-06 19:29:11 -05:00
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
if (store != null)
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
mStores.put(uri, store);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-24 19:40:29 -05:00
|
|
|
if (store == null)
|
|
|
|
{
|
2008-11-01 17:32:06 -04:00
|
|
|
throw new MessagingException("Unable to locate an applicable Store for " + uri);
|
|
|
|
}
|
|
|
|
|
2010-03-03 23:00:30 -05:00
|
|
|
return (LocalStore)store;
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
public abstract Folder getFolder(String name) throws MessagingException;
|
|
|
|
|
|
|
|
public abstract Folder[] getPersonalNamespaces() throws MessagingException;
|
|
|
|
|
|
|
|
public abstract void checkSettings() throws MessagingException;
|
2009-11-24 19:40:29 -05:00
|
|
|
|
|
|
|
public boolean isCopyCapable()
|
|
|
|
{
|
|
|
|
return false;
|
2009-03-05 02:32:45 -05:00
|
|
|
}
|
2009-11-24 19:40:29 -05:00
|
|
|
public boolean isMoveCapable()
|
|
|
|
{
|
|
|
|
return false;
|
2009-03-05 02:32:45 -05:00
|
|
|
}
|
2009-11-24 19:40:29 -05:00
|
|
|
public boolean isPushCapable()
|
|
|
|
{
|
2009-10-21 20:41:06 -04:00
|
|
|
return false;
|
|
|
|
}
|
2009-10-24 22:58:26 -04:00
|
|
|
public boolean isSendCapable()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
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
|
|
|
public boolean isExpungeCapable()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2010-01-02 20:50:51 -05:00
|
|
|
|
|
|
|
|
2009-10-24 22:58:26 -04:00
|
|
|
public void sendMessages(Message[] messages) throws MessagingException
|
|
|
|
{
|
|
|
|
}
|
2009-10-21 20:41:06 -04:00
|
|
|
|
2009-11-28 09:51:44 -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
|
|
|
|
2010-03-03 23:00:30 -05:00
|
|
|
public Account getAccount()
|
|
|
|
{
|
|
|
|
return mAccount;
|
|
|
|
}
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|