Fixes Issue 1116

Fixes Issue 1278
Fixes Issue 119
Fixes Issue 1077
Fixes Issue 1238

Worked performed by danapple0 and cketti in
https://k9mail.googlecode.com/svn/k9mail/branches/issue1116

Add support for most batch ops (except move and copy) in search
results.  Add support for batch move and copy on real folders.

Increase efficiency of bulk IMAP moves and copies by doing as multiple
UID operations.

Eliminated serialization of Account objects.

Provide up-references in useful places to make all future code cleaner
and more efficient.

Fixed a bunch of draft handling

Merged from issue1116 branch, except for Account.java, which was
copied wholesale.  Account.java was manually merged in issue1116
branch at r1489

svn merge -r 1459:1489 https://k9mail.googlecode.com/svn/k9mail/branches/issue1116 .
cp ../issue1116/src/com/fsck/k9/Account.java src/com/fsck/k9/Account.java
This commit is contained in:
Daniel Applebaum 2010-03-04 04:00:30 +00:00
parent 9e855c9ebd
commit c0e4220b82
32 changed files with 1822 additions and 1561 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,68 @@
package com.fsck.k9;
import java.io.Serializable;
public class Identity implements Serializable
{
private String mDescription;
private String mName;
private String mEmail;
private String mSignature;
private boolean mSignatureUse;
public synchronized String getName()
{
return mName;
}
public synchronized void setName(String name)
{
mName = name;
}
public synchronized String getEmail()
{
return mEmail;
}
public synchronized void setEmail(String email)
{
mEmail = email;
}
public synchronized boolean getSignatureUse()
{
return mSignatureUse;
}
public synchronized void setSignatureUse(boolean signatureUse)
{
mSignatureUse = signatureUse;
}
public synchronized String getSignature()
{
return mSignature;
}
public synchronized void setSignature(String signature)
{
mSignature = signature;
}
public synchronized String getDescription()
{
return mDescription;
}
public synchronized void setDescription(String description)
{
mDescription = description;
}
@Override
public synchronized String toString()
{
return "Account.Identity(description=" + mDescription + ", name=" + mName + ", email=" + mEmail + ", signature=" + mSignature;
}
}

View File

@ -23,7 +23,6 @@ import java.util.concurrent.Executors;
import java.util.concurrent.PriorityBlockingQueue;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import android.app.Application;
import android.app.Notification;
import android.app.NotificationManager;
@ -36,7 +35,6 @@ import android.os.Process;
import android.os.PowerManager.WakeLock;
import android.text.TextUtils;
import android.util.Log;
import com.fsck.k9.activity.FolderList;
import com.fsck.k9.activity.MessageList;
import com.fsck.k9.mail.Address;
@ -62,6 +60,7 @@ import com.fsck.k9.mail.store.LocalStore.LocalFolder;
import com.fsck.k9.mail.store.LocalStore.LocalMessage;
import com.fsck.k9.mail.store.LocalStore.PendingCommand;
/**
* Starts a long running (application) Thread that will run through commands
* that require remote mailbox access. This class is used to serialize and
@ -422,7 +421,7 @@ public class MessagingController implements Runnable
Folder[] localFolders = null;
try
{
Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication);
Store localStore = account.getLocalStore();
localFolders = localStore.getPersonalNamespaces();
if (refreshRemote || localFolders == null || localFolders.length == 0)
@ -487,11 +486,11 @@ public class MessagingController implements Runnable
Folder[] localFolders = null;
try
{
Store store = Store.getInstance(account.getStoreUri(), mApplication);
Store store = account.getRemoteStore();
Folder[] remoteFolders = store.getPersonalNamespaces();
LocalStore localStore = (LocalStore)Store.getInstance(account.getLocalStoreUri(), mApplication);
LocalStore localStore = account.getLocalStore();
HashSet<String> remoteFolderNames = new HashSet<String>();
for (int i = 0, count = remoteFolders.length; i < count; i++)
{
@ -664,7 +663,7 @@ public class MessagingController implements Runnable
try
{
Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication);
Store localStore = account.getLocalStore();
localFolder = localStore.getFolder(folder);
localFolder.open(OpenMode.READ_WRITE);
@ -756,8 +755,7 @@ public class MessagingController implements Runnable
try
{
LocalStore localStore = (LocalStore)Store.getInstance(account.getLocalStoreUri(), mApplication);
LocalStore localStore = account.getLocalStore();
localStore.searchForMessages(retrievalListener, query);
}
catch (Exception e)
@ -778,8 +776,8 @@ public class MessagingController implements Runnable
{
try
{
LocalStore localStore = (LocalStore) Store.getInstance(account.getLocalStoreUri(), mApplication);
LocalFolder localFolder = (LocalFolder) localStore.getFolder(folder);
LocalStore localStore = account.getLocalStore();
LocalFolder localFolder = localStore.getFolder(folder);
localFolder.setVisibleLimit(localFolder.getVisibleLimit() + account.getDisplayCount());
synchronizeMailbox(account, folder, listener);
}
@ -797,8 +795,7 @@ public class MessagingController implements Runnable
{
try
{
LocalStore localStore =
(LocalStore) Store.getInstance(account.getLocalStoreUri(), mApplication);
LocalStore localStore = account.getLocalStore();
localStore.resetVisibleLimits(account.getDisplayCount());
}
catch (MessagingException e)
@ -885,8 +882,8 @@ public class MessagingController implements Runnable
if (K9.DEBUG)
Log.v(K9.LOG_TAG, "SYNC: About to get local folder " + folder);
final LocalStore localStore = (LocalStore) Store.getInstance(account.getLocalStoreUri(), mApplication);
tLocalFolder = (LocalFolder) localStore.getFolder(folder);
final LocalStore localStore = account.getLocalStore();
tLocalFolder = localStore.getFolder(folder);
final LocalFolder localFolder = tLocalFolder;
localFolder.open(OpenMode.READ_WRITE);
Message[] localMessages = localFolder.getMessages(null);
@ -899,7 +896,7 @@ public class MessagingController implements Runnable
if (K9.DEBUG)
Log.v(K9.LOG_TAG, "SYNC: About to get remote store for " + folder);
Store remoteStore = Store.getInstance(account.getStoreUri(), mApplication);
Store remoteStore = account.getRemoteStore();
if (K9.DEBUG)
Log.v(K9.LOG_TAG, "SYNC: About to get remote folder " + folder);
@ -1667,9 +1664,7 @@ public class MessagingController implements Runnable
{
try
{
LocalStore localStore = (LocalStore) Store.getInstance(
account.getLocalStoreUri(),
mApplication);
LocalStore localStore = account.getLocalStore();
localStore.addPendingCommand(command);
}
catch (Exception e)
@ -1707,9 +1702,7 @@ public class MessagingController implements Runnable
private void processPendingCommandsSynchronous(Account account) throws MessagingException
{
LocalStore localStore = (LocalStore) Store.getInstance(
account.getLocalStoreUri(),
mApplication);
LocalStore localStore = account.getLocalStore();
ArrayList<PendingCommand> commands = localStore.getPendingCommands();
int progress = 0;
@ -1850,10 +1843,8 @@ public class MessagingController implements Runnable
return;
}
LocalStore localStore = (LocalStore) Store.getInstance(
account.getLocalStoreUri(),
mApplication);
localFolder = (LocalFolder) localStore.getFolder(folder);
LocalStore localStore = account.getLocalStore();
localFolder = localStore.getFolder(folder);
LocalMessage localMessage = (LocalMessage) localFolder.getMessage(uid);
if (localMessage == null)
@ -1861,7 +1852,7 @@ public class MessagingController implements Runnable
return;
}
Store remoteStore = Store.getInstance(account.getStoreUri(), mApplication);
Store remoteStore = account.getRemoteStore();
remoteFolder = remoteStore.getFolder(folder);
if (!remoteFolder.exists())
{
@ -2033,7 +2024,7 @@ public class MessagingController implements Runnable
}
String destFolder = command.arguments[1];
String isCopyS = command.arguments[2];
Store remoteStore = Store.getInstance(account.getStoreUri(), mApplication);
Store remoteStore = account.getRemoteStore();
remoteSrcFolder = remoteStore.getFolder(srcFolder);
List<Message> messages = new ArrayList<Message>();
@ -2156,7 +2147,7 @@ public class MessagingController implements Runnable
Flag flag = Flag.valueOf(command.arguments[2]);
Store remoteStore = Store.getInstance(account.getStoreUri(), mApplication);
Store remoteStore = account.getRemoteStore();
Folder remoteFolder = remoteStore.getFolder(folder);
try
{
@ -2215,7 +2206,7 @@ public class MessagingController implements Runnable
Folder remoteFolder = null;
try
{
Store remoteStore = Store.getInstance(account.getStoreUri(), mApplication);
Store remoteStore = account.getRemoteStore();
remoteFolder = remoteStore.getFolder(folder);
if (!remoteFolder.exists())
{
@ -2274,7 +2265,7 @@ public class MessagingController implements Runnable
if (K9.DEBUG)
Log.d(K9.LOG_TAG, "processPendingExpunge: folder = " + folder);
Store remoteStore = Store.getInstance(account.getStoreUri(), mApplication);
Store remoteStore = account.getRemoteStore();
Folder remoteFolder = remoteStore.getFolder(folder);
try
{
@ -2322,7 +2313,7 @@ public class MessagingController implements Runnable
return;
}
Store remoteStore = Store.getInstance(account.getStoreUri(), mApplication);
Store remoteStore = account.getRemoteStore();
Folder remoteSrcFolder = remoteStore.getFolder(srcFolder);
Folder remoteDestFolder = remoteStore.getFolder(destFolder);
@ -2385,7 +2376,7 @@ public class MessagingController implements Runnable
LocalFolder localFolder = null;
try
{
Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication);
Store localStore = account.getLocalStore();
localFolder = (LocalFolder) localStore.getFolder(folder);
localFolder.open(OpenMode.READ_WRITE);
Message[] messages = localFolder.getMessages(null, false);
@ -2412,7 +2403,7 @@ public class MessagingController implements Runnable
return;
}
Store remoteStore = Store.getInstance(account.getStoreUri(), mApplication);
Store remoteStore = account.getRemoteStore();
remoteFolder = remoteStore.getFolder(folder);
if (!remoteFolder.exists())
@ -2467,7 +2458,7 @@ public class MessagingController implements Runnable
String rootCauseMessage = getRootCauseMessage(t);
Log.e(K9.LOG_TAG, "Error " + "'" + rootCauseMessage + "'", t);
Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication);
Store localStore = account.getLocalStore();
LocalFolder localFolder = (LocalFolder)localStore.getFolder(account.getErrorFolderName());
Message[] messages = new Message[1];
MimeMessage message = new MimeMessage();
@ -2523,7 +2514,7 @@ public class MessagingController implements Runnable
return;
}
Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication);
Store localStore = account.getLocalStore();
LocalFolder localFolder = (LocalFolder)localStore.getFolder(account.getErrorFolderName());
Message[] messages = new Message[1];
MimeMessage message = new MimeMessage();
@ -2572,18 +2563,26 @@ public class MessagingController implements Runnable
}
public void setFlag(
final Account account,
final String folderName,
final Message[] messages,
final Flag flag,
final boolean newState)
{
String[] uids = new String[messages.length];
for (int i = 0; i < messages.length; i++)
actOnMessages(messages, new MessageActor()
{
uids[i] = messages[i].getUid();
}
setFlag(account, folderName, uids, flag, newState);
@Override
public void act(final Account account, final Folder folder,
final List<Message> messages)
{
String[] uids = new String[messages.size()];
for (int i = 0; i < messages.size(); i++)
{
uids[i] = messages.get(i).getUid();
}
setFlag(account, folder.getName(), uids, flag, newState);
}
});
}
public void setFlag(
@ -2598,7 +2597,7 @@ public class MessagingController implements Runnable
Folder localFolder = null;
try
{
Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication);
Store localStore = account.getLocalStore();
localFolder = localStore.getFolder(folderName);
localFolder.open(OpenMode.READ_WRITE);
ArrayList<Message> messages = new ArrayList<Message>();
@ -2655,7 +2654,7 @@ public class MessagingController implements Runnable
try
{
Log.w(K9.LOG_TAG, "Clearing pending commands!");
LocalStore localStore = (LocalStore)Store.getInstance(account.getLocalStoreUri(), mApplication);
LocalStore localStore = account.getLocalStore();
localStore.removePendingCommands();
}
catch (MessagingException me)
@ -2676,8 +2675,8 @@ public class MessagingController implements Runnable
LocalFolder localFolder = null;
try
{
Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication);
localFolder = (LocalFolder) localStore.getFolder(folder);
LocalStore localStore = account.getLocalStore();
localFolder = localStore.getFolder(folder);
localFolder.open(OpenMode.READ_WRITE);
Message message = localFolder.getMessage(uid);
@ -2700,7 +2699,7 @@ public class MessagingController implements Runnable
* fully if possible.
*/
Store remoteStore = Store.getInstance(account.getStoreUri(), mApplication);
Store remoteStore = account.getRemoteStore();
remoteFolder = remoteStore.getFolder(folder);
remoteFolder.open(OpenMode.READ_WRITE);
@ -2722,7 +2721,7 @@ public class MessagingController implements Runnable
// This is a view message request, so mark it read
if (!message.isSet(Flag.SEEN))
{
setFlag(account, localFolder.getName(), new Message[] { message }, Flag.SEEN, true);
setFlag(new Message[] { message }, Flag.SEEN, true);
}
if (listener != null && !getListeners().contains(listener))
@ -2789,8 +2788,8 @@ public class MessagingController implements Runnable
try
{
Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication);
LocalFolder localFolder = (LocalFolder) localStore.getFolder(folder);
LocalStore localStore = account.getLocalStore();
LocalFolder localFolder = localStore.getFolder(folder);
localFolder.open(OpenMode.READ_WRITE);
LocalMessage message = (LocalMessage)localFolder.getMessage(uid);
@ -2829,7 +2828,7 @@ public class MessagingController implements Runnable
localFolder.close();
if (!message.isSet(Flag.SEEN))
{
setFlag(account, localFolder.getName(), new Message[] { message }, Flag.SEEN, true);
setFlag(new Message[] { message }, Flag.SEEN, true);
}
for (MessagingListener l : getListeners())
@ -2936,8 +2935,8 @@ public class MessagingController implements Runnable
LocalFolder localFolder = null;
try
{
LocalStore localStore =
(LocalStore) Store.getInstance(account.getLocalStoreUri(), mApplication);
LocalStore localStore = account.getLocalStore();
/*
* We clear out any attachments already cached in the entire store and then
* we update the passed in message to reflect that there are no cached
@ -2952,9 +2951,8 @@ public class MessagingController implements Runnable
{
attachment.setBody(null);
}
Store remoteStore = Store.getInstance(account.getStoreUri(), mApplication);
localFolder =
(LocalFolder) localStore.getFolder(message.getFolder().getName());
Store remoteStore = account.getRemoteStore();
localFolder = localStore.getFolder(message.getFolder().getName());
remoteFolder = remoteStore.getFolder(message.getFolder().getName());
remoteFolder.open(OpenMode.READ_WRITE);
@ -3015,9 +3013,8 @@ public class MessagingController implements Runnable
{
try
{
Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication);
LocalFolder localFolder =
(LocalFolder) localStore.getFolder(account.getOutboxFolderName());
LocalStore localStore = account.getLocalStore();
LocalFolder localFolder = localStore.getFolder(account.getOutboxFolderName());
localFolder.open(OpenMode.READ_WRITE);
localFolder.appendMessages(new Message[]
{
@ -3062,9 +3059,7 @@ public class MessagingController implements Runnable
Folder localFolder = null;
try
{
Store localStore = Store.getInstance(
account.getLocalStoreUri(),
mApplication);
Store localStore = account.getLocalStore();
localFolder = localStore.getFolder(
account.getOutboxFolderName());
if (!localFolder.exists())
@ -3104,9 +3099,7 @@ public class MessagingController implements Runnable
Folder localFolder = null;
try
{
Store localStore = Store.getInstance(
account.getLocalStoreUri(),
mApplication);
Store localStore = account.getLocalStore();
localFolder = localStore.getFolder(
account.getOutboxFolderName());
if (!localFolder.exists())
@ -3138,7 +3131,7 @@ public class MessagingController implements Runnable
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "Scanning folder '" + account.getOutboxFolderName() + "' (" + ((LocalFolder)localFolder).getId() + ") for messages to send");
Transport transport = Transport.getInstance(account.getTransportUri());
Transport transport = Transport.getInstance(account);
for (Message message : localMessages)
{
if (message.isSet(Flag.DELETED))
@ -3333,7 +3326,7 @@ public class MessagingController implements Runnable
int unreadMessageCount = 0;
try
{
unreadMessageCount = account.getUnreadMessageCount(context, mApplication);
unreadMessageCount = account.getUnreadMessageCount(context);
}
catch (MessagingException me)
{
@ -3359,7 +3352,7 @@ public class MessagingController implements Runnable
int unreadMessageCount = 0;
try
{
Folder localFolder = (Folder) Store.getInstance(account.getLocalStoreUri(), mApplication).getFolder(folderName);
Folder localFolder = account.getLocalStore().getFolder(folderName);
unreadMessageCount = localFolder.getUnreadMessageCount();
}
catch (MessagingException me)
@ -3375,41 +3368,7 @@ public class MessagingController implements Runnable
}
public int moveMessages(final Account account, final String srcFolder, final Message[] messages, final String destFolder,
final MessagingListener listener)
{
int messagesMoved = 0;
for (Message message : messages)
{
if (moveMessage(account, srcFolder, message, destFolder, listener))
{
messagesMoved++;
}
}
return messagesMoved;
}
public boolean moveMessage(final Account account, final String srcFolder, final Message message, final String destFolder,
final MessagingListener listener)
{
if (!message.getUid().startsWith(K9.LOCAL_UID_PREFIX))
{
suppressMessage(account, srcFolder, message);
putBackground("moveMessage", null, new Runnable()
{
public void run()
{
moveOrCopyMessageSynchronous(account, srcFolder, message, destFolder, false, listener);
}
});
return true;
}
else
{
return false;
}
}
public boolean isMoveCapable(Message message)
{
if (!message.getUid().startsWith(K9.LOCAL_UID_PREFIX))
@ -3430,8 +3389,8 @@ public class MessagingController implements Runnable
{
try
{
Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication);
Store remoteStore = Store.getInstance(account.getStoreUri(), mApplication);
Store localStore = account.getLocalStore();
Store remoteStore = account.getRemoteStore();
return localStore.isMoveCapable() && remoteStore.isMoveCapable();
}
catch (MessagingException me)
@ -3445,8 +3404,8 @@ public class MessagingController implements Runnable
{
try
{
Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication);
Store remoteStore = Store.getInstance(account.getStoreUri(), mApplication);
Store localStore = account.getLocalStore();
Store remoteStore = account.getRemoteStore();
return localStore.isCopyCapable() && remoteStore.isCopyCapable();
}
catch (MessagingException me)
@ -3455,47 +3414,52 @@ public class MessagingController implements Runnable
return false;
}
}
public int copyMessages(final Account account, final String srcFolder, final Message[] messages, final String destFolder,
final MessagingListener listener)
public void moveMessages(final Account account, final String srcFolder, final Message[] messages, final String destFolder,
final MessagingListener listener)
{
int messagesCopied = 0;
for (Message message : messages)
{
if (copyMessage(account, srcFolder, message, destFolder, listener))
suppressMessage(account, srcFolder, message);
}
putBackground("moveMessages", null, new Runnable()
{
public void run()
{
messagesCopied++;
moveOrCopyMessageSynchronous(account, srcFolder, messages, destFolder, false, listener);
}
}
return messagesCopied;
}
public boolean copyMessage(final Account account, final String srcFolder, final Message message, final String destFolder,
final MessagingListener listener)
{
if (!message.getUid().startsWith(K9.LOCAL_UID_PREFIX))
{
putBackground("copyMessage", null, new Runnable()
{
public void run()
{
moveOrCopyMessageSynchronous(account, srcFolder, message, destFolder, true, listener);
}
});
return true;
}
else
{
return false;
}
});
}
private void moveOrCopyMessageSynchronous(final Account account, final String srcFolder, final Message message,
public void moveMessage(final Account account, final String srcFolder, final Message message, final String destFolder,
final MessagingListener listener)
{
moveMessages(account, srcFolder, new Message[] { message }, destFolder, listener);
}
public void copyMessages(final Account account, final String srcFolder, final Message[] messages, final String destFolder,
final MessagingListener listener)
{
putBackground("copyMessages", null, new Runnable()
{
public void run()
{
moveOrCopyMessageSynchronous(account, srcFolder, messages, destFolder, true, listener);
}
});
}
public void copyMessage(final Account account, final String srcFolder, final Message message, final String destFolder,
final MessagingListener listener)
{
copyMessages(account, srcFolder, new Message[] { message }, destFolder, listener);
}
private void moveOrCopyMessageSynchronous(final Account account, final String srcFolder, final Message[] inMessages,
final String destFolder, final boolean isCopy, MessagingListener listener)
{
try
{
Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication);
Store remoteStore = Store.getInstance(account.getStoreUri(), mApplication);
Store localStore = account.getLocalStore();
Store remoteStore = account.getRemoteStore();
if (isCopy == false && (remoteStore.isMoveCapable() == false || localStore.isMoveCapable() == false))
{
return;
@ -3507,33 +3471,54 @@ public class MessagingController implements Runnable
Folder localSrcFolder = localStore.getFolder(srcFolder);
Folder localDestFolder = localStore.getFolder(destFolder);
Message lMessage = localSrcFolder.getMessage(message.getUid());
String origUid = message.getUid();
if (lMessage != null)
List<String> uids = new LinkedList<String>();
for (Message message : inMessages)
{
String uid = message.getUid();
if (!uid.startsWith(K9.LOCAL_UID_PREFIX))
{
uids.add(uid);
}
}
Message[] messages = localSrcFolder.getMessages(uids.toArray(new String[0]), null);
if (messages.length > 0)
{
Map<String, Message> origUidMap = new HashMap<String, Message>();
for (Message message : messages)
{
origUidMap.put(message.getUid(), message);
}
if (K9.DEBUG)
Log.i(K9.LOG_TAG, "moveOrCopyMessageSynchronous: source folder = " + srcFolder
+ ", uid = " + origUid + ", destination folder = " + destFolder + ", isCopy = " + isCopy);
+ ", " + messages.length + " messages, " + ", destination folder = " + destFolder + ", isCopy = " + isCopy);
if (isCopy)
{
FetchProfile fp = new FetchProfile();
fp.add(FetchProfile.Item.ENVELOPE);
fp.add(FetchProfile.Item.BODY);
localSrcFolder.fetch(new Message[] { message }, fp, null);
localSrcFolder.copyMessages(new Message[] { message }, localDestFolder);
localSrcFolder.fetch(messages, fp, null);
localSrcFolder.copyMessages(messages, localDestFolder);
}
else
{
localSrcFolder.moveMessages(new Message[] { message }, localDestFolder);
for (MessagingListener l : getListeners())
localSrcFolder.moveMessages(messages, localDestFolder);
for (String origUid : origUidMap.keySet())
{
l.messageUidChanged(account, srcFolder, origUid, message.getUid());
for (MessagingListener l : getListeners())
{
l.messageUidChanged(account, srcFolder, origUid, origUidMap.get(origUid).getUid());
}
unsuppressMessage(account, srcFolder, origUid);
}
unsuppressMessage(account, srcFolder, origUid);
}
queueMoveOrCopy(account, srcFolder, destFolder, isCopy, origUidMap.keySet().toArray(new String[0]));
}
queueMoveOrCopy(account, srcFolder, destFolder, isCopy, new String[] { origUid });
processPendingCommands(account);
}
@ -3555,22 +3540,56 @@ public class MessagingController implements Runnable
}
});
}
public void deleteMessages(final Account account, final String folder, final Message[] messages,
final MessagingListener listener)
public void deleteDraft(final Account account, String uid)
{
for (Message message : messages)
LocalFolder localFolder = null;
try
{
suppressMessage(account, folder, message);
LocalStore localStore = account.getLocalStore();
localFolder = localStore.getFolder(account.getDraftsFolderName());
localFolder.open(OpenMode.READ_WRITE);
Message message = localFolder.getMessage(uid);
deleteMessages(new Message[] { message }, null);
}
putBackground("deleteMessages", null, new Runnable()
catch (MessagingException me)
{
public void run()
addErrorMessage(account, me);
}
finally
{
if (localFolder != null)
{
deleteMessagesSynchronous(account, folder, messages, listener);
localFolder.close();
}
}
}
public void deleteMessages(final Message[] messages, final MessagingListener listener)
{
actOnMessages(messages, new MessageActor()
{
@Override
public void act(final Account account, final Folder folder,
final List<Message> messages)
{
for (Message message : messages)
{
suppressMessage(account, folder.getName(), message);
}
putBackground("deleteMessages", null, new Runnable()
{
public void run()
{
deleteMessagesSynchronous(account, folder.getName(), messages.toArray(new Message[0]), listener);
}
});
}
});
}
private void deleteMessagesSynchronous(final Account account, final String folder, final Message[] messages,
@ -3585,7 +3604,6 @@ public class MessagingController implements Runnable
//as messages get a new UID after being moved
for (Message message : messages)
{
unsuppressMessage(account, folder, message);
if (listener != null)
{
listener.messageDeleted(account, folder, message);
@ -3595,7 +3613,7 @@ public class MessagingController implements Runnable
l.messageDeleted(account, folder, message);
}
}
Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication);
Store localStore = account.getLocalStore();
localFolder = localStore.getFolder(folder);
if (folder.equals(account.getTrashFolderName()) || K9.FOLDER_NONE.equals(account.getTrashFolderName()))
{
@ -3671,6 +3689,10 @@ public class MessagingController implements Runnable
if (K9.DEBUG)
Log.d(K9.LOG_TAG, "Delete policy " + account.getDeletePolicy() + " prevents delete from server");
}
for (String uid : uids)
{
unsuppressMessage(account, folder, uid);
}
}
catch (MessagingException me)
{
@ -3680,6 +3702,7 @@ public class MessagingController implements Runnable
}
finally
{
if (localFolder != null)
{
localFolder.close();
@ -3703,7 +3726,7 @@ public class MessagingController implements Runnable
private void processPendingEmptyTrash(PendingCommand command, Account account) throws MessagingException
{
Store remoteStore = Store.getInstance(account.getStoreUri(), mApplication);
Store remoteStore = account.getRemoteStore();
Folder remoteFolder = remoteStore.getFolder(account.getTrashFolderName());
try
@ -3736,7 +3759,7 @@ public class MessagingController implements Runnable
Folder localFolder = null;
try
{
Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication);
Store localStore = account.getLocalStore();
localFolder = localStore.getFolder(account.getTrashFolderName());
localFolder.open(OpenMode.READ_WRITE);
localFolder.setFlags(new Flag[] { Flag.DELETED }, true);
@ -3932,7 +3955,7 @@ public class MessagingController implements Runnable
Account.FolderMode aDisplayMode = account.getFolderDisplayMode();
Account.FolderMode aSyncMode = account.getFolderSyncMode();
Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication);
Store localStore = account.getLocalStore();
for (final Folder folder : localStore.getPersonalNamespaces())
{
@ -3985,9 +4008,8 @@ public class MessagingController implements Runnable
{
// In case multiple Commands get enqueued, don't run more than
// once
final LocalStore localStore =
(LocalStore) Store.getInstance(account.getLocalStoreUri(), mApplication);
tLocalFolder = (LocalFolder) localStore.getFolder(folder.getName());
final LocalStore localStore = account.getLocalStore();
tLocalFolder = localStore.getFolder(folder.getName());
tLocalFolder.open(Folder.OpenMode.READ_WRITE);
if (ignoreLastCheckedTime == false && tLocalFolder.getLastChecked() >
@ -4095,7 +4117,7 @@ public class MessagingController implements Runnable
{
try
{
LocalStore localStore = (LocalStore)Store.getInstance(account.getLocalStoreUri(), mApplication);
LocalStore localStore = account.getLocalStore();
long oldSize = localStore.getSize();
localStore.compact();
long newSize = localStore.getSize();
@ -4124,7 +4146,7 @@ public class MessagingController implements Runnable
{
try
{
LocalStore localStore = (LocalStore)Store.getInstance(account.getLocalStoreUri(), mApplication);
LocalStore localStore = account.getLocalStore();
long oldSize = localStore.getSize();
localStore.clear();
localStore.resetVisibleLimits(account.getDisplayCount());
@ -4206,7 +4228,7 @@ public class MessagingController implements Runnable
int unreadMessageCount = 0;
try
{
unreadMessageCount = account.getUnreadMessageCount(context, mApplication);
unreadMessageCount = account.getUnreadMessageCount(context);
}
catch (MessagingException e)
{
@ -4253,19 +4275,19 @@ public class MessagingController implements Runnable
}
public void saveDraft(final Account account, final Message message)
public Message saveDraft(final Account account, final Message message)
{
Message localMessage = null;
try
{
Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication);
LocalFolder localFolder =
(LocalFolder) localStore.getFolder(account.getDraftsFolderName());
LocalStore localStore = account.getLocalStore();
LocalFolder localFolder = localStore.getFolder(account.getDraftsFolderName());
localFolder.open(OpenMode.READ_WRITE);
localFolder.appendMessages(new Message[]
{
message
});
Message localMessage = localFolder.getMessage(message.getUid());
localMessage = localFolder.getMessage(message.getUid());
localMessage.setFlag(Flag.X_DOWNLOADED_FULL, true);
PendingCommand command = new PendingCommand();
@ -4277,12 +4299,14 @@ public class MessagingController implements Runnable
};
queuePendingCommand(account, command);
processPendingCommands(account);
}
catch (MessagingException e)
{
Log.e(K9.LOG_TAG, "Unable to save message as draft.", e);
addErrorMessage(account, e);
}
return localMessage;
}
public boolean modeMismatch(Account.FolderMode aMode, Folder.FolderClass fMode)
@ -4403,7 +4427,7 @@ public class MessagingController implements Runnable
List<String> names = new ArrayList<String>();
Store localStore = Store.getInstance(account.getLocalStoreUri(), mApplication);
Store localStore = account.getLocalStore();
for (final Folder folder : localStore.getPersonalNamespaces())
{
if (folder.getName().equals(account.getErrorFolderName())
@ -4462,7 +4486,7 @@ public class MessagingController implements Runnable
try
{
Store store = Store.getInstance(account.getStoreUri(), mApplication);
Store store = account.getRemoteStore();
if (store.isPushCapable() == false)
{
if (K9.DEBUG)
@ -4537,8 +4561,8 @@ public class MessagingController implements Runnable
LocalFolder localFolder = null;
try
{
LocalStore localStore = (LocalStore) Store.getInstance(account.getLocalStoreUri(), mApplication);
localFolder= (LocalFolder) localStore.getFolder(remoteFolder.getName());
LocalStore localStore = account.getLocalStore();
localFolder= localStore.getFolder(remoteFolder.getName());
localFolder.open(OpenMode.READ_WRITE);
int newCount = downloadMessages(account, remoteFolder, localFolder, messages, flagSyncOnly);
@ -4849,23 +4873,47 @@ public class MessagingController implements Runnable
}
private Map<String, List<Message>> binMessages(Message[] messages)
private void actOnMessages(Message[] messages, MessageActor actor)
{
Map<String, List<Message>> bins = new HashMap<String, List<Message>>();
Map<Account, Map<Folder, List<Message>>> accountMap = new HashMap<Account, Map<Folder, List<Message>>>();
for (Message message : messages)
{
String folderName = message.getFolder().getName();
List<Message> bin = bins.get(folderName);
if (bin == null)
Folder folder = message.getFolder();
Account account = folder.getAccount();
Map<Folder, List<Message>> folderMap = accountMap.get(account);
if (folderMap == null)
{
bin = new LinkedList<Message>();
bins.put(folderName, bin);
folderMap = new HashMap<Folder, List<Message>>();
accountMap.put(account, folderMap);
}
List<Message> messageList = folderMap.get(folder);
if (messageList == null)
{
messageList = new LinkedList<Message>();
folderMap.put(folder, messageList);
}
messageList.add(message);
}
for (Map.Entry<Account, Map<Folder, List<Message>>> entry : accountMap.entrySet())
{
Account account = entry.getKey();
//account.refresh(Preferences.getPreferences(K9.app));
Map<Folder, List<Message>> folderMap = entry.getValue();
for (Map.Entry<Folder, List<Message>> folderEntry : folderMap.entrySet())
{
Folder folder = folderEntry.getKey();
List<Message> messageList = folderEntry.getValue();
actor.act(account, folder, messageList);
}
bin.add(message);
}
return bins;
}
interface MessageActor
{
public void act(final Account account, final Folder folder, final List<Message> messages);
}
}

View File

@ -103,8 +103,8 @@ public class MessagingControllerPushReceiver implements PushReceiver
LocalFolder localFolder = null;
try
{
LocalStore localStore = (LocalStore) Store.getInstance(account.getLocalStoreUri(), mApplication);
localFolder= (LocalFolder) localStore.getFolder(folderName);
LocalStore localStore = account.getLocalStore();
localFolder = localStore.getFolder(folderName);
localFolder.open(OpenMode.READ_WRITE);
return localFolder.getPushState();
}

View File

@ -1,9 +1,10 @@
package com.fsck.k9;
import java.util.ArrayList;
import java.util.List;
import android.content.Context;
import android.content.SharedPreferences;
import android.net.Uri;
import android.util.Config;
import android.util.Log;
import com.fsck.k9.preferences.Editor;
@ -13,7 +14,24 @@ public class Preferences
{
private static Preferences preferences;
/**
* TODO need to think about what happens if this gets GCed along with the
* Activity that initialized it. Do we lose ability to read Preferences in
* further Activities? Maybe this should be stored in the Application
* context.
*/
public static synchronized Preferences getPreferences(Context context)
{
if (preferences == null)
{
preferences = new Preferences(context);
}
return preferences;
}
private Storage mStorage;
private List<Account> accounts;
private Preferences(Context context)
{
@ -27,77 +45,83 @@ public class Preferences
}
}
/**
* TODO need to think about what happens if this gets GCed along with the
* Activity that initialized it. Do we lose ability to read Preferences in
* further Activities? Maybe this should be stored in the Application
* context.
*
* @return
*/
public static synchronized Preferences getPreferences(Context context)
private synchronized void loadAccounts()
{
if (preferences == null)
String accountUuids = getPreferences().getString("accountUuids", null);
if ((accountUuids != null) && (accountUuids.length() != 0))
{
preferences = new Preferences(context);
String[] uuids = accountUuids.split(",");
accounts = new ArrayList<Account>(uuids.length);
for (int i = 0, length = uuids.length; i < length; i++)
{
accounts.add(new Account(this, uuids[i]));
}
}
else
{
accounts = new ArrayList<Account>();
}
return preferences;
}
/**
* Returns an array of the accounts on the system. If no accounts are
* registered the method returns an empty array.
*
* @return
*/
public Account[] getAccounts()
public synchronized Account[] getAccounts()
{
String accountUuids = getPreferences().getString("accountUuids", null);
if (accountUuids == null || accountUuids.length() == 0)
if (accounts == null)
{
return new Account[] {};
loadAccounts();
}
String[] uuids = accountUuids.split(",");
Account[] accounts = new Account[uuids.length];
for (int i = 0, length = uuids.length; i < length; i++)
{
accounts[i] = new Account(this, uuids[i]);
}
return accounts;
return accounts.toArray(new Account[0]);
}
public Account getAccountByContentUri(Uri uri)
public synchronized Account getAccount(String uuid)
{
return new Account(this, uri.getPath().substring(1));
if (accounts == null)
{
loadAccounts();
}
for (Account account : accounts)
{
if (account.getUuid().equals(uuid))
{
return account;
}
}
return null;
}
public synchronized Account newAccount()
{
Account account = new Account(K9.app);
accounts.add(account);
return account;
}
public synchronized void deleteAccount(Account account)
{
accounts.remove(account);
account.delete(this);
}
/**
* Returns the Account marked as default. If no account is marked as default
* the first account in the list is marked as default and then returned. If
* there are no accounts on the system the method returns null.
*
* @return
*/
public Account getDefaultAccount()
{
String defaultAccountUuid = getPreferences().getString("defaultAccountUuid", null);
Account defaultAccount = null;
Account[] accounts = getAccounts();
if (defaultAccountUuid != null)
{
for (Account account : accounts)
{
if (account.getUuid().equals(defaultAccountUuid))
{
defaultAccount = account;
break;
}
}
}
Account defaultAccount = getAccount(defaultAccountUuid);
if (defaultAccount == null)
{
Account[] accounts = getAccounts();
if (accounts.length > 0)
{
defaultAccount = accounts[0];

View File

@ -21,9 +21,6 @@ import com.fsck.k9.*;
import com.fsck.k9.activity.setup.AccountSettings;
import com.fsck.k9.activity.setup.AccountSetupBasics;
import com.fsck.k9.activity.setup.Prefs;
import com.fsck.k9.mail.Store;
import com.fsck.k9.mail.store.LocalStore;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@ -297,7 +294,8 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
if (icicle != null && icicle.containsKey(SELECTED_CONTEXT_ACCOUNT))
{
mSelectedContextAccount = (Account) icicle.getSerializable("selectedContextAccount");
String accountUuid = icicle.getString("selectedContextAccount");
mSelectedContextAccount = Preferences.getPreferences(this).getAccount(accountUuid);
}
if (icicle != null)
@ -317,7 +315,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
super.onSaveInstanceState(outState);
if (mSelectedContextAccount != null)
{
outState.putSerializable(SELECTED_CONTEXT_ACCOUNT, mSelectedContextAccount);
outState.putString(SELECTED_CONTEXT_ACCOUNT, mSelectedContextAccount.getUuid());
}
outState.putSerializable(UNREAD_MESSAGE_COUNTS, unreadMessageCounts);
}
@ -473,13 +471,13 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
dismissDialog(DIALOG_REMOVE_ACCOUNT);
try
{
((LocalStore)Store.getInstance(mSelectedContextAccount.getLocalStoreUri(), getApplication())).delete();
mSelectedContextAccount.getLocalStore().delete();
}
catch (Exception e)
{
// Ignore
}
mSelectedContextAccount.delete(Preferences.getPreferences(Accounts.this));
Preferences.getPreferences(Accounts.this).deleteAccount(mSelectedContextAccount);
K9.setServicesEnabled(Accounts.this);
refresh();
}
@ -730,5 +728,3 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
}
}
}

View File

@ -14,7 +14,6 @@ import android.widget.TextView;
import com.fsck.k9.*;
import com.fsck.k9.mail.Folder;
import com.fsck.k9.mail.MessagingException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
@ -50,7 +49,8 @@ public class ChooseFolder extends K9ListActivity
getListView().setItemsCanFocus(false);
getListView().setChoiceMode(ListView.CHOICE_MODE_NONE);
Intent intent = getIntent();
mAccount = (Account) intent.getSerializableExtra(EXTRA_ACCOUNT);
String accountUuid = intent.getStringExtra(EXTRA_ACCOUNT);
mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
mUID = intent.getStringExtra(EXTRA_MESSAGE_UID);
mFolder = intent.getStringExtra(EXTRA_CUR_FOLDER);
if (intent.getStringExtra(EXTRA_SHOW_CURRENT) != null)

View File

@ -11,9 +11,10 @@ import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import com.fsck.k9.Account;
import com.fsck.k9.Identity;
import com.fsck.k9.K9ListActivity;
import com.fsck.k9.Preferences;
import com.fsck.k9.R;
import java.util.List;
public class ChooseIdentity extends K9ListActivity
@ -26,7 +27,7 @@ public class ChooseIdentity extends K9ListActivity
public static final String EXTRA_ACCOUNT = "com.fsck.k9.ChooseIdentity_account";
public static final String EXTRA_IDENTITY = "com.fsck.k9.ChooseIdentity_identity";
protected List<Account.Identity> identities = null;
protected List<Identity> identities = null;
@Override
public void onCreate(Bundle savedInstanceState)
@ -39,7 +40,8 @@ public class ChooseIdentity extends K9ListActivity
getListView().setItemsCanFocus(false);
getListView().setChoiceMode(ListView.CHOICE_MODE_NONE);
Intent intent = getIntent();
mAccount = (Account) intent.getSerializableExtra(EXTRA_ACCOUNT);
String accountUuid = intent.getStringExtra(EXTRA_ACCOUNT);
mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1);
@ -61,7 +63,7 @@ public class ChooseIdentity extends K9ListActivity
adapter.clear();
identities = mAccount.getIdentities();
for (Account.Identity identity : identities)
for (Identity identity : identities)
{
String email = identity.getEmail();
String description = identity.getDescription();
@ -80,7 +82,7 @@ public class ChooseIdentity extends K9ListActivity
{
public void onItemClick(AdapterView adapterview, View view, int i, long l)
{
Account.Identity identity = mAccount.getIdentity(i);
Identity identity = mAccount.getIdentity(i);
String email = identity.getEmail();
if (email != null && email.trim().equals("") == false)
{

View File

@ -7,12 +7,11 @@ import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.LinearLayout;
import com.fsck.k9.Account;
import com.fsck.k9.Identity;
import com.fsck.k9.K9Activity;
import com.fsck.k9.Preferences;
import com.fsck.k9.R;
import java.util.List;
public class EditIdentity extends K9Activity
@ -23,7 +22,7 @@ public class EditIdentity extends K9Activity
public static final String EXTRA_ACCOUNT = "com.fsck.k9.EditIdentity_account";
private Account mAccount;
private Account.Identity mIdentity;
private Identity mIdentity;
private int mIdentityIndex;
private EditText mDescriptionView;
private CheckBox mSignatureUse;
@ -38,13 +37,14 @@ public class EditIdentity extends K9Activity
{
super.onCreate(savedInstanceState);
mIdentity = (Account.Identity)getIntent().getSerializableExtra(EXTRA_IDENTITY);
mIdentity = (Identity)getIntent().getSerializableExtra(EXTRA_IDENTITY);
mIdentityIndex = getIntent().getIntExtra(EXTRA_IDENTITY_INDEX, -1);
mAccount = (Account) getIntent().getSerializableExtra(EXTRA_ACCOUNT);
String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
if (mIdentityIndex == -1)
{
mIdentity = mAccount.new Identity();
mIdentity = new Identity();
}
setContentView(R.layout.edit_identity);
@ -55,7 +55,7 @@ public class EditIdentity extends K9Activity
*/
if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_IDENTITY))
{
mIdentity = (Account.Identity)savedInstanceState.getSerializable(EXTRA_IDENTITY);
mIdentity = (Identity)savedInstanceState.getSerializable(EXTRA_IDENTITY);
}
mDescriptionView = (EditText)findViewById(R.id.description);
@ -115,7 +115,7 @@ public class EditIdentity extends K9Activity
mIdentity.setSignatureUse(mSignatureUse.isChecked());
mIdentity.setSignature(mSignatureView.getText().toString());
List<Account.Identity> identities = mAccount.getIdentities();
List<Identity> identities = mAccount.getIdentities();
if (mIdentityIndex == -1)
{
identities.add(mIdentity);

View File

@ -25,9 +25,7 @@ import com.fsck.k9.activity.setup.FolderSettings;
import com.fsck.k9.mail.Folder;
import com.fsck.k9.mail.Message;
import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mail.Store;
import com.fsck.k9.service.MailService;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
@ -46,7 +44,7 @@ public class FolderList extends K9ListActivity
private static final String EXTRA_INITIAL_FOLDER = "initialFolder";
private static final String STATE_CURRENT_FOLDER = "com.fsck.k9.activity.folderlist_folder";
//private static final String STATE_CURRENT_FOLDER = "com.fsck.k9.activity.folderlist_folder";
private static final String EXTRA_CLEAR_NOTIFICATION = "clearNotification";
@ -205,7 +203,7 @@ public class FolderList extends K9ListActivity
private static void actionHandleAccount(Context context, Account account, String initialFolder)
{
Intent intent = new Intent(context, FolderList.class);
intent.putExtra(EXTRA_ACCOUNT, account);
intent.putExtra(EXTRA_ACCOUNT, account.getUuid());
if (initialFolder != null)
{
@ -228,7 +226,7 @@ public class FolderList extends K9ListActivity
context,
FolderList.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(EXTRA_ACCOUNT, account);
intent.putExtra(EXTRA_ACCOUNT, account.getUuid());
intent.putExtra(EXTRA_CLEAR_NOTIFICATION, true);
if (initialFolder != null)
@ -278,7 +276,8 @@ public class FolderList extends K9ListActivity
String initialFolder;
mUnreadMessageCount = 0;
mAccount = (Account)intent.getSerializableExtra(EXTRA_ACCOUNT);
String accountUuid = intent.getStringExtra(EXTRA_ACCOUNT);
mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
initialFolder = intent.getStringExtra(EXTRA_INITIAL_FOLDER);
if (
@ -338,7 +337,7 @@ public class FolderList extends K9ListActivity
initializeActivityView();
MessagingController.getInstance(getApplication()).addListener(mAdapter.mListener);
mAccount.refresh(Preferences.getPreferences(this));
//mAccount.refresh(Preferences.getPreferences(this));
MessagingController.getInstance(getApplication()).getAccountUnreadCount(this, mAccount, mAdapter.mListener);
onRefresh(!REFRESH_REMOTE);
@ -922,7 +921,7 @@ public class FolderList extends K9ListActivity
{
if (account != null && folderName != null)
{
localFolder = (Folder) Store.getInstance(account.getLocalStoreUri(), getApplication()).getFolder(folderName);
localFolder = account.getLocalStore().getFolder(folderName);
int unreadMessageCount = localFolder.getUnreadMessageCount();
if (localFolder != null)
{

View File

@ -7,7 +7,7 @@ import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.ListView;
import android.widget.Toast;
import com.fsck.k9.Account;
import com.fsck.k9.Identity;
import com.fsck.k9.Preferences;
import com.fsck.k9.R;
@ -34,8 +34,7 @@ public class ManageIdentities extends ChooseIdentity
private void editItem(int i)
{
Intent intent = new Intent(ManageIdentities.this, EditIdentity.class);
intent.putExtra(EditIdentity.EXTRA_ACCOUNT, mAccount);
intent.putExtra(EditIdentity.EXTRA_ACCOUNT, mAccount.getUuid());
intent.putExtra(EditIdentity.EXTRA_IDENTITY, mAccount.getIdentity(i));
intent.putExtra(EditIdentity.EXTRA_IDENTITY_INDEX, i);
startActivityForResult(intent, ACTIVITY_EDIT_IDENTITY);
@ -56,8 +55,7 @@ public class ManageIdentities extends ChooseIdentity
{
case R.id.new_identity:
Intent intent = new Intent(ManageIdentities.this, EditIdentity.class);
intent.putExtra(EditIdentity.EXTRA_ACCOUNT, mAccount);
intent.putExtra(EditIdentity.EXTRA_ACCOUNT, mAccount.getUuid());
startActivityForResult(intent, ACTIVITY_EDIT_IDENTITY);
break;
default:
@ -85,7 +83,7 @@ public class ManageIdentities extends ChooseIdentity
case R.id.up:
if (menuInfo.position > 0)
{
Account.Identity identity = identities.remove(menuInfo.position);
Identity identity = identities.remove(menuInfo.position);
identities.add(menuInfo.position - 1, identity);
mIdentitiesChanged = true;
refreshView();
@ -95,14 +93,14 @@ public class ManageIdentities extends ChooseIdentity
case R.id.down:
if (menuInfo.position < identities.size() - 1)
{
Account.Identity identity = identities.remove(menuInfo.position);
Identity identity = identities.remove(menuInfo.position);
identities.add(menuInfo.position + 1, identity);
mIdentitiesChanged = true;
refreshView();
}
break;
case R.id.top:
Account.Identity identity = identities.remove(menuInfo.position);
Identity identity = identities.remove(menuInfo.position);
identities.add(0, identity);
mIdentitiesChanged = true;
refreshView();
@ -129,7 +127,7 @@ public class ManageIdentities extends ChooseIdentity
public void onResume()
{
super.onResume();
mAccount.refresh(Preferences.getPreferences(getApplication().getApplicationContext()));
//mAccount.refresh(Preferences.getPreferences(getApplication().getApplicationContext()));
refreshView();
}

View File

@ -28,7 +28,6 @@ import com.fsck.k9.mail.Message.RecipientType;
import com.fsck.k9.mail.internet.*;
import com.fsck.k9.mail.store.LocalStore;
import com.fsck.k9.mail.store.LocalStore.LocalAttachmentBody;
import java.io.File;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
@ -78,7 +77,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
private static final int ACTIVITY_CHOOSE_IDENTITY = 2;
private Account mAccount;
private Account.Identity mIdentity;
private Identity mIdentity;
private boolean mIdentityChanged = false;
private boolean mSignatureChanged = false;
private String mFolder;
@ -178,7 +177,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
public static void actionCompose(Context context, Account account)
{
Intent i = new Intent(context, MessageCompose.class);
i.putExtra(EXTRA_ACCOUNT, account);
i.putExtra(EXTRA_ACCOUNT, account.getUuid());
context.startActivity(i);
}
@ -197,7 +196,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
boolean replyAll)
{
Intent i = new Intent(context, MessageCompose.class);
i.putExtra(EXTRA_ACCOUNT, account);
i.putExtra(EXTRA_ACCOUNT, account.getUuid());
i.putExtra(EXTRA_FOLDER, message.getFolder().getName());
i.putExtra(EXTRA_MESSAGE, message.getUid());
if (replyAll)
@ -220,7 +219,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
public static void actionForward(Context context, Account account, Message message)
{
Intent i = new Intent(context, MessageCompose.class);
i.putExtra(EXTRA_ACCOUNT, account);
i.putExtra(EXTRA_ACCOUNT, account.getUuid());
i.putExtra(EXTRA_FOLDER, message.getFolder().getName());
i.putExtra(EXTRA_MESSAGE, message.getUid());
i.setAction(ACTION_FORWARD);
@ -240,7 +239,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
public static void actionEditDraft(Context context, Account account, Message message)
{
Intent i = new Intent(context, MessageCompose.class);
i.putExtra(EXTRA_ACCOUNT, account);
i.putExtra(EXTRA_ACCOUNT, account.getUuid());
i.putExtra(EXTRA_FOLDER, message.getFolder().getName());
i.putExtra(EXTRA_MESSAGE, message.getUid());
i.setAction(ACTION_EDIT_DRAFT);
@ -257,7 +256,8 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
setContentView(R.layout.message_compose);
Intent intent = getIntent();
mAccount = (Account) intent.getSerializableExtra(EXTRA_ACCOUNT);
String accountUuid = intent.getStringExtra(EXTRA_ACCOUNT);
mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
if (mAccount == null)
{
@ -632,7 +632,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
mQuotedTextBar.setVisibility(savedInstanceState.getBoolean(STATE_KEY_QUOTED_TEXT_SHOWN) ? View.VISIBLE : View.GONE);
mQuotedText.setVisibility(savedInstanceState.getBoolean(STATE_KEY_QUOTED_TEXT_SHOWN) ? View.VISIBLE : View.GONE);
mDraftUid = savedInstanceState.getString(STATE_KEY_DRAFT_UID);
mIdentity = (Account.Identity)savedInstanceState.getSerializable(STATE_IDENTITY);
mIdentity = (Identity)savedInstanceState.getSerializable(STATE_IDENTITY);
mIdentityChanged = savedInstanceState.getBoolean(STATE_IDENTITY_CHANGED);
updateFrom();
updateSignature();
@ -820,7 +820,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
if (mIdentityChanged || mSignatureChanged)
{
String signature = mSignatureView.getText().toString();
k9identity += ":" + Utility.base64Encode(signature) ;
k9identity += ":" + Utility.base64Encode(signature);
if (mIdentityChanged)
{
@ -835,8 +835,8 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
Log.d(K9.LOG_TAG, "Saving identity: " + k9identity);
message.addHeader(K9.K9MAIL_IDENTITY, k9identity);
MessagingController.getInstance(getApplication()).saveDraft(mAccount, message);
mDraftUid = message.getUid();
Message draftMessage = MessagingController.getInstance(getApplication()).saveDraft(mAccount, message);
mDraftUid = draftMessage.getUid();
// Don't display the toast if the user is just changing the orientation
if ((getChangingConfigurations() & ActivityInfo.CONFIG_ORIENTATION) == 0)
@ -846,28 +846,12 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
}
else
{
/*
* Send the message
* TODO Is it possible for us to be editing a draft with a null source message? Don't
* think so. Could probably remove below check.
*/
if (ACTION_EDIT_DRAFT.equals(getIntent().getAction()) && mSourceMessageUid != null)
{
/*
* We're sending a previously saved draft, so delete the old draft first.
*/
MessagingController.getInstance(getApplication()).deleteMessages(mAccount, mFolder, new Message[] { mSourceMessage }, null);
}
MessagingController.getInstance(getApplication()).sendMessage(mAccount, message, null);
if (mDraftUid != null)
{
/*
* Message was auto-saved (screen rotation) so delete that draft before sending
*/
Message draftMessage = new MimeMessage();
draftMessage.setUid(mDraftUid);
MessagingController.getInstance(getApplication()).deleteMessages(mAccount, mAccount.getDraftsFolderName(), new Message[] { draftMessage }, null);
MessagingController.getInstance(getApplication()).deleteDraft(mAccount, mDraftUid);
mDraftUid = null;
}
MessagingController.getInstance(getApplication()).sendMessage(mAccount, message, null);
}
}
@ -896,17 +880,10 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
private void onDiscard()
{
if (mSourceMessageUid != null)
{
if (ACTION_EDIT_DRAFT.equals(getIntent().getAction()) && mSourceMessageUid != null)
{
MessagingController.getInstance(getApplication()).deleteMessages(mAccount, mFolder, new Message[] { mSourceMessage }, null);
}
}
if (mDraftUid != null)
{
Message draftMessage = new MimeMessage();
MessagingController.getInstance(getApplication()).deleteMessages(mAccount, mAccount.getDraftsFolderName(), new Message[] { draftMessage }, null);
MessagingController.getInstance(getApplication()).deleteDraft(mAccount, mDraftUid);
mDraftUid = null;
}
mHandler.sendEmptyMessage(MSG_DISCARDED_DRAFT);
mDraftNeedsSaving = false;
@ -1045,10 +1022,10 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
private void onIdentityChosen(Intent intent)
{
Bundle bundle = intent.getExtras();;
switchToIdentity((Account.Identity)bundle.getSerializable(ChooseIdentity.EXTRA_IDENTITY));
switchToIdentity((Identity)bundle.getSerializable(ChooseIdentity.EXTRA_IDENTITY));
}
private void switchToIdentity(Account.Identity identity)
private void switchToIdentity(Identity identity)
{
mIdentity = identity;
mIdentityChanged = true;
@ -1133,7 +1110,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
if (mAccount.getIdentities().size() > 1)
{
Intent intent = new Intent(this, ChooseIdentity.class);
intent.putExtra(ChooseIdentity.EXTRA_ACCOUNT, mAccount);
intent.putExtra(ChooseIdentity.EXTRA_ACCOUNT, mAccount.getUuid());
startActivityForResult(intent, ACTIVITY_CHOOSE_IDENTITY);
}
else
@ -1273,10 +1250,10 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
if (ACTION_REPLY_ALL.equals(action) || ACTION_REPLY.equals(action))
{
Account.Identity useIdentity = null;
Identity useIdentity = null;
for (Address address : message.getRecipients(RecipientType.TO))
{
Account.Identity identity = mAccount.findIdentity(address);
Identity identity = mAccount.findIdentity(address);
if (identity != null)
{
useIdentity = identity;
@ -1289,7 +1266,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
{
for (Address address : message.getRecipients(RecipientType.CC))
{
Account.Identity identity = mAccount.findIdentity(address);
Identity identity = mAccount.findIdentity(address);
if (identity != null)
{
useIdentity = identity;
@ -1300,7 +1277,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
}
if (useIdentity != null)
{
Account.Identity defaultIdentity = mAccount.getIdentity(0);
Identity defaultIdentity = mAccount.getIdentity(0);
if (useIdentity != defaultIdentity)
{
switchToIdentity(useIdentity);
@ -1312,7 +1289,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
{
for (Address address : message.getRecipients(RecipientType.TO))
{
Account.Identity identity = mAccount.findIdentity(address);
Identity identity = mAccount.findIdentity(address);
if (!mAccount.isAnIdentity(address))
{
addAddress(mToView, address);
@ -1398,6 +1375,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
{
try
{
mDraftUid = message.getUid();
mSubjectView.setText(message.getSubject());
addAddresses(mToView, message.getRecipients(RecipientType.TO));
if (message.getRecipients(RecipientType.CC).length > 0)
@ -1431,6 +1409,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
String name = null;
String email = null;
String signature = null;
boolean signatureUse = message.getFolder().getAccount().getSignatureUse();
if (tokens.hasMoreTokens())
{
bodyLengthS = Utility.base64Decode(tokens.nextToken());
@ -1445,6 +1424,7 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
}
if (tokens.hasMoreTokens())
{
signatureUse = true;
signature = Utility.base64Decode(tokens.nextToken());
}
if (tokens.hasMoreTokens())
@ -1456,7 +1436,8 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
email = Utility.base64Decode(tokens.nextToken());
}
Account.Identity newIdentity= mAccount.new Identity();
Identity newIdentity = new Identity();
newIdentity.setSignatureUse(signatureUse);
if (signature != null)
{
newIdentity.setSignature(signature);
@ -1584,12 +1565,16 @@ public class MessageCompose extends K9Activity implements OnClickListener, OnFoc
@Override
public void messageUidChanged(Account account, String folder, String oldUid, String newUid)
{
if (account.equals(mAccount) && (folder.equals(mFolder) || (mFolder == null && folder.equals(mAccount.getDraftsFolderName()))))
if (account.equals(mAccount) && folder.equals(mAccount.getDraftsFolderName()))
{
if (oldUid.equals(mDraftUid))
{
mDraftUid = newUid;
}
}
if (account.equals(mAccount) && (folder.equals(mFolder)))
{
if (oldUid.equals(mSourceMessageUid))
{
mSourceMessageUid = newUid;

View File

@ -22,7 +22,6 @@ import android.view.*;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View.OnClickListener;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.widget.*;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.CompoundButton.OnCheckedChangeListener;
@ -35,7 +34,6 @@ import com.fsck.k9.mail.Message.RecipientType;
import com.fsck.k9.mail.store.LocalStore;
import com.fsck.k9.mail.store.LocalStore.LocalFolder;
import com.fsck.k9.mail.store.LocalStore.LocalMessage;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
@ -61,19 +59,14 @@ public class MessageList
private static final int ACTIVITY_CHOOSE_FOLDER_MOVE = 1;
private static final int ACTIVITY_CHOOSE_FOLDER_COPY = 2;
private static final int ACTIVITY_CHOOSE_FOLDER_MOVE_BATCH = 3;
private static final int ACTIVITY_CHOOSE_FOLDER_COPY_BATCH = 4;
private static final String EXTRA_ACCOUNT = "account";
private static final String EXTRA_FOLDER = "folder";
private static final String EXTRA_QUERY = "query";
private static final String STATE_KEY_LIST = "com.fsck.k9.activity.messagelist_state";
private static final String STATE_CURRENT_FOLDER = "com.fsck.k9.activity.messagelist_folder";
private static final String STATE_QUERY = "com.fsck.k9.activity.query";
private static final String STATE_CURRENT_ITEM = "com.fsck.k9.activity.messagelist_selection";
private static final String STATE_KEY_SELECTED_COUNT = "com.fsck.k9.activity.messagelist_selected_count";
private ListView mListView;
private boolean mTouchView = true;
@ -291,7 +284,7 @@ public class MessageList
public static Intent actionHandleFolderIntent(Context context, Account account, String folder)
{
Intent intent = new Intent(context, MessageList.class);
intent.putExtra(EXTRA_ACCOUNT, account);
intent.putExtra(EXTRA_ACCOUNT, account.getUuid());
if (folder != null)
{
@ -338,7 +331,8 @@ public class MessageList
public void onNewIntent(Intent intent)
{
setIntent(intent); // onNewIntent doesn't autoset our "internal" intent
mAccount = (Account)intent.getSerializableExtra(EXTRA_ACCOUNT);
String accountUuid = intent.getStringExtra(EXTRA_ACCOUNT);
mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
mFolderName = intent.getStringExtra(EXTRA_FOLDER);
mQueryString = intent.getStringExtra(EXTRA_QUERY);
@ -749,7 +743,7 @@ public class MessageList
private void onDelete(MessageInfoHolder holder, int position)
{
mAdapter.removeMessage(holder);
mController.deleteMessages(holder.account, holder.message.getFolder().getName(), new Message[] { holder.message }, null);
mController.deleteMessages(new Message[] { holder.message }, null);
}
@ -768,8 +762,7 @@ public class MessageList
}
Intent intent = new Intent(this, ChooseFolder.class);
intent.putExtra(ChooseFolder.EXTRA_ACCOUNT, holder.account);
intent.putExtra(ChooseFolder.EXTRA_ACCOUNT, holder.account.getUuid());
intent.putExtra(ChooseFolder.EXTRA_CUR_FOLDER, holder.folder.name);
intent.putExtra(ChooseFolder.EXTRA_MESSAGE_UID, holder.message.getUid());
startActivityForResult(intent, ACTIVITY_CHOOSE_FOLDER_MOVE);
@ -790,8 +783,7 @@ public class MessageList
}
Intent intent = new Intent(this, ChooseFolder.class);
intent.putExtra(ChooseFolder.EXTRA_ACCOUNT, holder.account);
intent.putExtra(ChooseFolder.EXTRA_ACCOUNT, holder.account.getUuid());
intent.putExtra(ChooseFolder.EXTRA_CUR_FOLDER, holder.folder.name);
intent.putExtra(ChooseFolder.EXTRA_MESSAGE_UID, holder.message.getUid());
startActivityForResult(intent, ACTIVITY_CHOOSE_FOLDER_COPY);
@ -807,6 +799,7 @@ public class MessageList
{
case ACTIVITY_CHOOSE_FOLDER_MOVE:
case ACTIVITY_CHOOSE_FOLDER_COPY:
{
if (data == null)
return;
@ -814,7 +807,6 @@ public class MessageList
String uid = data.getStringExtra(ChooseFolder.EXTRA_MESSAGE_UID);
MessageInfoHolder m = mAdapter.getMessage(uid);
if (destFolderName != null && m != null)
{
@ -822,15 +814,27 @@ public class MessageList
{
case ACTIVITY_CHOOSE_FOLDER_MOVE:
onMoveChosen(m, destFolderName);
break;
case ACTIVITY_CHOOSE_FOLDER_COPY:
onCopyChosen(m, destFolderName);
break;
}
}
break;
}
case ACTIVITY_CHOOSE_FOLDER_MOVE_BATCH:
{
String destFolderName = data.getStringExtra(ChooseFolder.EXTRA_NEW_FOLDER);
onMoveChosenBatch(destFolderName);
break;
}
case ACTIVITY_CHOOSE_FOLDER_COPY_BATCH:
{
String destFolderName = data.getStringExtra(ChooseFolder.EXTRA_NEW_FOLDER);
onCopyChosenBatch(destFolderName);
break;
}
}
}
@ -987,16 +991,7 @@ public class MessageList
int itemId = item.getItemId();
switch (itemId)
{
case R.id.check_mail:
if (mFolderName != null)
{
checkMail(mAccount, mFolderName);
}
return true;
case R.id.send_messages:
sendMail(mAccount);
return true;
case R.id.compose:
onCompose();
@ -1037,38 +1032,6 @@ public class MessageList
return true;
case R.id.list_folders:
onShowFolderList();
return true;
}
if (mQueryString != null)
{
return false; // none of the options after this point are "safe" for search results
}
switch (itemId)
{
case R.id.mark_all_as_read:
if (mFolderName != null)
{
onMarkAllAsRead(mAccount, mFolderName);
}
return true;
case R.id.folder_settings:
if (mFolderName != null)
{
FolderSettings.actionSettings(this, mAccount, mFolderName);
}
return true;
case R.id.account_settings:
onEditAccount();
return true;
case R.id.batch_select_all:
setAllSelected(true);
toggleBatchButtons();
@ -1078,15 +1041,7 @@ public class MessageList
setAllSelected(false);
toggleBatchButtons();
return true;
case R.id.batch_copy_op:
moveOrCopySelected(false);
return true;
case R.id.batch_move_op:
moveOrCopySelected(true);
return true;
case R.id.batch_delete_op:
deleteSelected();
return true;
@ -1107,6 +1062,58 @@ public class MessageList
flagSelected(Flag.FLAGGED, false);
return true;
}
if (mQueryString != null)
{
return false; // none of the options after this point are "safe" for search results
}
switch (itemId)
{
case R.id.check_mail:
if (mFolderName != null)
{
checkMail(mAccount, mFolderName);
}
return true;
case R.id.send_messages:
sendMail(mAccount);
return true;
case R.id.list_folders:
onShowFolderList();
return true;
case R.id.mark_all_as_read:
if (mFolderName != null)
{
onMarkAllAsRead(mAccount, mFolderName);
}
return true;
case R.id.folder_settings:
if (mFolderName != null)
{
FolderSettings.actionSettings(this, mAccount, mFolderName);
}
return true;
case R.id.account_settings:
onEditAccount();
return true;
case R.id.batch_copy_op:
onCopyBatch();
return true;
case R.id.batch_move_op:
onMoveBatch();
return true;
case R.id.expunge:
if (mCurrentFolder != null)
{
@ -1138,19 +1145,37 @@ public class MessageList
@Override
public boolean onPrepareOptionsMenu(Menu menu)
{
boolean anySelected = anySelected();
setOpsState(menu, true, anySelected);
if (mQueryString != null)
{
menu.findItem(R.id.batch_ops).setVisible(false);
menu.findItem(R.id.mark_all_as_read).setVisible(false);
menu.findItem(R.id.folder_settings).setVisible(false);
menu.findItem(R.id.account_settings).setVisible(false);
menu.findItem(R.id.list_folders).setVisible(false);
menu.findItem(R.id.expunge).setVisible(false);
menu.findItem(R.id.batch_move_op).setVisible(false);
menu.findItem(R.id.batch_copy_op).setVisible(false);
menu.findItem(R.id.check_mail).setVisible(false);
menu.findItem(R.id.send_messages).setVisible(false);
}
else
{
if (mCurrentFolder != null && mCurrentFolder.outbox)
{
menu.findItem(R.id.check_mail).setVisible(false);
}
else
{
menu.findItem(R.id.send_messages).setVisible(false);
}
boolean anySelected = anySelected();
setOpsState(menu, true, anySelected);
if (mCurrentFolder != null && K9.ERROR_FOLDER_NAME.equals(mCurrentFolder.name))
{
menu.findItem(R.id.expunge).setVisible(false);
}
}
boolean newFlagState = computeBatchDirection(true);
boolean newReadState = computeBatchDirection(false);
@ -1160,24 +1185,7 @@ public class MessageList
menu.findItem(R.id.batch_mark_unread_op).setVisible(!newReadState);
menu.findItem(R.id.batch_deselect_all).setVisible(anySelected);
menu.findItem(R.id.batch_select_all).setEnabled(true);
// TODO: batch move and copy not yet implemented
menu.findItem(R.id.batch_move_op).setVisible(false);
menu.findItem(R.id.batch_copy_op).setVisible(false);
if (mCurrentFolder != null && mCurrentFolder.outbox)
{
menu.findItem(R.id.check_mail).setVisible(false);
}
else
{
menu.findItem(R.id.send_messages).setVisible(false);
}
if (mCurrentFolder != null && K9.ERROR_FOLDER_NAME.equals(mCurrentFolder.name))
{
menu.findItem(R.id.expunge).setVisible(false);
}
return true;
}
@ -1585,6 +1593,15 @@ public class MessageList
super.pendingCommandCompleted(account, commandTitle);
mHandler.refreshTitle();
}
public void messageUidChanged(Account account, String folder, String oldUid, String newUid)
{
if (updateForMe(account, folder))
{
MessageInfoHolder holder = getMessage(oldUid);
holder.uid = newUid;
holder.message.setUid(newUid);
}
}
};
@ -1699,7 +1716,7 @@ public class MessageList
LocalFolder local_folder = null;
try
{
LocalStore localStore = (LocalStore)Store.getInstance(account.getLocalStoreUri(), getApplication());
LocalStore localStore = account.getLocalStore();
local_folder = localStore.getFolder(folder);
return new FolderInfoHolder((Folder)local_folder, account);
}
@ -2467,14 +2484,13 @@ public class MessageList
{
if (v == mBatchDeleteButton)
{
mController.deleteMessages(mAccount, mCurrentFolder.name, messageList.toArray(new Message[0]), null);
mController.deleteMessages(messageList.toArray(new Message[0]), null);
mSelectedCount = 0;
toggleBatchButtons();
}
else
{
mController.setFlag(mAccount, mCurrentFolder.name, messageList.toArray(new Message[0]),
(v == mBatchReadButton ? Flag.SEEN : Flag.FLAGGED), newState);
mController.setFlag(messageList.toArray(new Message[0]), (v == mBatchReadButton ? Flag.SEEN : Flag.FLAGGED), newState);
}
}
else
@ -2529,8 +2545,7 @@ public class MessageList
}
}
}
mController.setFlag(mAccount, mCurrentFolder.name, messageList.toArray(new Message[0]),
flag , newState);
mController.setFlag(messageList.toArray(new Message[0]), flag, newState);
mHandler.sortMessages();
}
@ -2548,14 +2563,112 @@ public class MessageList
}
mAdapter.removeMessages(removeHolderList);
mController.deleteMessages(mAccount, mCurrentFolder.name, messageList.toArray(new Message[0]), null);
mController.deleteMessages(messageList.toArray(new Message[0]), null);
mSelectedCount = 0;
toggleBatchButtons();
}
private void moveOrCopySelected(boolean isMove)
private void onMoveBatch()
{
if (mController.isMoveCapable(mAccount) == false)
{
return;
}
for (MessageInfoHolder holder : mAdapter.messages)
{
if (holder.selected)
{
Message message = holder.message;
if (mController.isMoveCapable(message) == false)
{
Toast toast = Toast.makeText(this, R.string.move_copy_cannot_copy_unsynced_message, Toast.LENGTH_LONG);
toast.show();
return;
}
}
}
Intent intent = new Intent(this, ChooseFolder.class);
intent.putExtra(ChooseFolder.EXTRA_ACCOUNT, mAccount.getUuid());
intent.putExtra(ChooseFolder.EXTRA_CUR_FOLDER, mCurrentFolder.folder.getName());
startActivityForResult(intent, ACTIVITY_CHOOSE_FOLDER_MOVE_BATCH);
}
private void onMoveChosenBatch(String folderName)
{
if (mController.isMoveCapable(mAccount) == false)
{
return;
}
List<Message> messageList = new ArrayList<Message>();
List<MessageInfoHolder> removeHolderList = new ArrayList<MessageInfoHolder>();
for (MessageInfoHolder holder : mAdapter.messages)
{
if (holder.selected)
{
Message message = holder.message;
if (mController.isMoveCapable(message) == false)
{
Toast toast = Toast.makeText(this, R.string.move_copy_cannot_copy_unsynced_message, Toast.LENGTH_LONG);
toast.show();
return;
}
messageList.add(holder.message);
removeHolderList.add(holder);
}
}
mAdapter.removeMessages(removeHolderList);
mController.moveMessages(mAccount, mCurrentFolder.name, messageList.toArray(new Message[0]), folderName, null);
mSelectedCount = 0;
toggleBatchButtons();
}
private void onCopyBatch()
{
if (mController.isCopyCapable(mAccount) == false)
{
return;
}
for (MessageInfoHolder holder : mAdapter.messages)
{
if (holder.selected)
{
Message message = holder.message;
if (mController.isCopyCapable(message) == false)
{
Toast toast = Toast.makeText(this, R.string.move_copy_cannot_copy_unsynced_message, Toast.LENGTH_LONG);
toast.show();
return;
}
}
}
Intent intent = new Intent(this, ChooseFolder.class);
intent.putExtra(ChooseFolder.EXTRA_ACCOUNT, mAccount.getUuid());
intent.putExtra(ChooseFolder.EXTRA_CUR_FOLDER, mCurrentFolder.folder.getName());
startActivityForResult(intent, ACTIVITY_CHOOSE_FOLDER_COPY_BATCH);
}
private void onCopyChosenBatch(String folderName)
{
if (mController.isCopyCapable(mAccount) == false)
{
return;
}
List<Message> messageList = new ArrayList<Message>();
for (MessageInfoHolder holder : mAdapter.messages)
{
if (holder.selected)
{
Message message = holder.message;
if (mController.isCopyCapable(message) == false)
{
Toast toast = Toast.makeText(this, R.string.move_copy_cannot_copy_unsynced_message, Toast.LENGTH_LONG);
toast.show();
return;
}
messageList.add(holder.message);
}
}
mController.copyMessages(mAccount, mCurrentFolder.name, messageList.toArray(new Message[0]), folderName, null);
}
}

View File

@ -35,7 +35,6 @@ import com.fsck.k9.mail.store.LocalStore.LocalMessage;
import com.fsck.k9.mail.store.LocalStore.LocalTextBody;
import com.fsck.k9.provider.AttachmentProvider;
import org.apache.commons.io.IOUtils;
import java.io.*;
import java.net.HttpURLConnection;
import java.util.ArrayList;
@ -427,7 +426,7 @@ public class MessageView extends K9Activity
public static void actionView(Context context, Account account, String folder, String messageUid, ArrayList<String> folderUids, Bundle extras)
{
Intent i = new Intent(context, MessageView.class);
i.putExtra(EXTRA_ACCOUNT, account);
i.putExtra(EXTRA_ACCOUNT, account.getUuid());
i.putExtra(EXTRA_FOLDER, folder);
i.putExtra(EXTRA_MESSAGE, messageUid);
i.putExtra(EXTRA_MESSAGE_UIDS, folderUids);
@ -515,7 +514,8 @@ public class MessageView extends K9Activity
if (icicle!=null)
{
mAccount = (Account) icicle.getSerializable(EXTRA_ACCOUNT);
String accountUuid = icicle.getString(EXTRA_ACCOUNT);
mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
mFolder = icicle.getString(EXTRA_FOLDER);
mMessageUid = icicle.getString(EXTRA_MESSAGE);
mMessageUids = icicle.getStringArrayList(EXTRA_MESSAGE_UIDS);
@ -524,7 +524,8 @@ public class MessageView extends K9Activity
{
if (uri==null)
{
mAccount = (Account) intent.getSerializableExtra(EXTRA_ACCOUNT);
String accountUuid = intent.getStringExtra(EXTRA_ACCOUNT);
mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
mFolder = intent.getStringExtra(EXTRA_FOLDER);
mMessageUid = intent.getStringExtra(EXTRA_MESSAGE);
mMessageUids = intent.getStringArrayListExtra(EXTRA_MESSAGE_UIDS);
@ -613,7 +614,7 @@ public class MessageView extends K9Activity
@Override
protected void onSaveInstanceState(Bundle outState)
{
outState.putSerializable(EXTRA_ACCOUNT, mAccount);
outState.putString(EXTRA_ACCOUNT, mAccount.getUuid());
outState.putString(EXTRA_FOLDER, mFolder);
outState.putString(EXTRA_MESSAGE, mMessageUid);
outState.putStringArrayList(EXTRA_MESSAGE_UIDS, mMessageUids);
@ -702,8 +703,6 @@ public class MessageView extends K9Activity
if (mMessage != null)
{
Message messageToDelete = mMessage;
String folderForDelete = mFolder;
Account accountForDelete = mAccount;
findSurroundingMessagesUid();
@ -711,8 +710,6 @@ public class MessageView extends K9Activity
mMessageUids.remove(messageToDelete.getUid());
MessagingController.getInstance(getApplication()).deleteMessages(
accountForDelete,
folderForDelete,
new Message[] { messageToDelete },
null);
@ -836,7 +833,7 @@ public class MessageView extends K9Activity
return;
}
Intent intent = new Intent(this, ChooseFolder.class);
intent.putExtra(ChooseFolder.EXTRA_ACCOUNT, mAccount);
intent.putExtra(ChooseFolder.EXTRA_ACCOUNT, mAccount.getUuid());
intent.putExtra(ChooseFolder.EXTRA_CUR_FOLDER, mFolder);
intent.putExtra(ChooseFolder.EXTRA_MESSAGE_UID, mMessageUid);
startActivityForResult(intent, ACTIVITY_CHOOSE_FOLDER_MOVE);
@ -855,8 +852,7 @@ public class MessageView extends K9Activity
return;
}
Intent intent = new Intent(this, ChooseFolder.class);
intent.putExtra(ChooseFolder.EXTRA_ACCOUNT, mAccount);
intent.putExtra(ChooseFolder.EXTRA_ACCOUNT, mAccount.getUuid());
intent.putExtra(ChooseFolder.EXTRA_CUR_FOLDER, mFolder);
intent.putExtra(ChooseFolder.EXTRA_MESSAGE_UID, mMessageUid);
startActivityForResult(intent, ACTIVITY_CHOOSE_FOLDER_COPY);

View File

@ -75,7 +75,7 @@ public class AccountSettings extends K9PreferenceActivity
public static void actionSettings(Context context, Account account)
{
Intent i = new Intent(context, AccountSettings.class);
i.putExtra(EXTRA_ACCOUNT, account);
i.putExtra(EXTRA_ACCOUNT, account.getUuid());
context.startActivity(i);
}
@ -84,15 +84,15 @@ public class AccountSettings extends K9PreferenceActivity
{
super.onCreate(savedInstanceState);
mAccount = (Account)getIntent().getSerializableExtra(EXTRA_ACCOUNT);
mAccount.refresh(Preferences.getPreferences(this));
String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
boolean isPushCapable = false;
boolean isExpungeCapable = false;
Store store = null;
try
{
store = Store.getInstance(mAccount.getStoreUri(), getApplication());
store = mAccount.getRemoteStore();
isPushCapable = store.isPushCapable();
isExpungeCapable = store.isExpungeCapable();
}
@ -360,7 +360,7 @@ public class AccountSettings extends K9PreferenceActivity
public void onResume()
{
super.onResume();
mAccount.refresh(Preferences.getPreferences(this));
//mAccount.refresh(Preferences.getPreferences(this));
}
private void saveSettings()
@ -457,7 +457,7 @@ public class AccountSettings extends K9PreferenceActivity
private void onManageIdentities()
{
Intent intent = new Intent(this, ManageIdentities.class);
intent.putExtra(ChooseIdentity.EXTRA_ACCOUNT, mAccount);
intent.putExtra(ChooseIdentity.EXTRA_ACCOUNT, mAccount.getUuid());
startActivityForResult(intent, ACTIVITY_MANAGE_IDENTITIES);
}
@ -474,7 +474,7 @@ public class AccountSettings extends K9PreferenceActivity
public void onChooseAutoExpandFolder()
{
Intent selectIntent = new Intent(this, ChooseFolder.class);
selectIntent.putExtra(ChooseFolder.EXTRA_ACCOUNT, mAccount);
selectIntent.putExtra(ChooseFolder.EXTRA_ACCOUNT, mAccount.getUuid());
selectIntent.putExtra(ChooseFolder.EXTRA_CUR_FOLDER, mAutoExpandFolder.getSummary());
selectIntent.putExtra(ChooseFolder.EXTRA_SHOW_CURRENT, "yes");

View File

@ -12,8 +12,8 @@ import android.widget.Toast;
import com.fsck.k9.Account;
import com.fsck.k9.K9;
import com.fsck.k9.K9Activity;
import com.fsck.k9.Preferences;
import com.fsck.k9.R;
import java.net.URI;
/**
@ -34,7 +34,7 @@ public class AccountSetupAccountType extends K9Activity implements OnClickListen
public static void actionSelectAccountType(Context context, Account account, boolean makeDefault)
{
Intent i = new Intent(context, AccountSetupAccountType.class);
i.putExtra(EXTRA_ACCOUNT, account);
i.putExtra(EXTRA_ACCOUNT, account.getUuid());
i.putExtra(EXTRA_MAKE_DEFAULT, makeDefault);
context.startActivity(i);
}
@ -48,7 +48,8 @@ public class AccountSetupAccountType extends K9Activity implements OnClickListen
((Button)findViewById(R.id.imap)).setOnClickListener(this);
((Button)findViewById(R.id.webdav)).setOnClickListener(this);
mAccount = (Account)getIntent().getSerializableExtra(EXTRA_ACCOUNT);
String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
mMakeDefault = (boolean)getIntent().getBooleanExtra(EXTRA_MAKE_DEFAULT, false);
}

View File

@ -21,15 +21,12 @@ import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import com.fsck.k9.*;
import java.io.Serializable;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URLEncoder;
import org.apache.http.client.utils.URLEncodedUtils;
/**
* Prompts the user for the email address and password. Also prompts for
* "Use this account as default" if this is the 2nd+ account being set up.
@ -88,7 +85,8 @@ public class AccountSetupBasics extends K9Activity
if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_ACCOUNT))
{
mAccount = (Account)savedInstanceState.getSerializable(EXTRA_ACCOUNT);
String accountUuid = savedInstanceState.getString(EXTRA_ACCOUNT);
mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
}
if (savedInstanceState != null && savedInstanceState.containsKey(STATE_KEY_PROVIDER))
@ -108,7 +106,7 @@ public class AccountSetupBasics extends K9Activity
public void onSaveInstanceState(Bundle outState)
{
super.onSaveInstanceState(outState);
outState.putSerializable(EXTRA_ACCOUNT, mAccount);
outState.putString(EXTRA_ACCOUNT, mAccount.getUuid());
if (mProvider != null)
{
outState.putSerializable(STATE_KEY_PROVIDER, mProvider);
@ -274,7 +272,7 @@ public class AccountSetupBasics extends K9Activity
return;
}
mAccount = new Account(this);
mAccount = Preferences.getPreferences(this).newAccount();
mAccount.setName(getOwnerName());
mAccount.setEmail(email);
mAccount.setStoreUri(incomingUri.toString());
@ -337,7 +335,7 @@ public class AccountSetupBasics extends K9Activity
String user = emailParts[0];
String domain = emailParts[1];
mAccount = new Account(this);
mAccount = Preferences.getPreferences(this).newAccount();
mAccount.setName(getOwnerName());
mAccount.setEmail(email);
try

View File

@ -20,7 +20,6 @@ import com.fsck.k9.mail.CertificateValidationException;
import com.fsck.k9.mail.Store;
import com.fsck.k9.mail.Transport;
import com.fsck.k9.mail.store.TrustManagerFactory;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
@ -62,7 +61,7 @@ public class AccountSetupCheckSettings extends K9Activity implements OnClickList
boolean checkIncoming, boolean checkOutgoing)
{
Intent i = new Intent(context, AccountSetupCheckSettings.class);
i.putExtra(EXTRA_ACCOUNT, account);
i.putExtra(EXTRA_ACCOUNT, account.getUuid());
i.putExtra(EXTRA_CHECK_INCOMING, checkIncoming);
i.putExtra(EXTRA_CHECK_OUTGOING, checkOutgoing);
context.startActivityForResult(i, ACTIVITY_REQUEST_CODE);
@ -80,7 +79,8 @@ public class AccountSetupCheckSettings extends K9Activity implements OnClickList
setMessage(R.string.account_setup_check_settings_retr_info_msg);
mProgressBar.setIndeterminate(true);
mAccount = (Account)getIntent().getSerializableExtra(EXTRA_ACCOUNT);
String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
mCheckIncoming = (boolean)getIntent().getBooleanExtra(EXTRA_CHECK_INCOMING, false);
mCheckOutgoing = (boolean)getIntent().getBooleanExtra(EXTRA_CHECK_OUTGOING, false);
@ -104,7 +104,7 @@ public class AccountSetupCheckSettings extends K9Activity implements OnClickList
if (mCheckIncoming)
{
setMessage(R.string.account_setup_check_settings_check_incoming_msg);
store = Store.getInstance(mAccount.getStoreUri(), getApplication());
store = mAccount.getRemoteStore();
store.checkSettings();
MessagingController.getInstance(getApplication()).listFolders(mAccount, true, null);
@ -123,7 +123,7 @@ public class AccountSetupCheckSettings extends K9Activity implements OnClickList
if (mCheckOutgoing)
{
setMessage(R.string.account_setup_check_settings_check_outgoing_msg);
Transport transport = Transport.getInstance(mAccount.getTransportUri());
Transport transport = Transport.getInstance(mAccount);
transport.close();
transport.open();
transport.close();

View File

@ -5,7 +5,6 @@ import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.CheckBox;
import android.widget.EditText;
@ -36,7 +35,7 @@ public class AccountSetupComposition extends K9Activity
{
Intent i = new Intent(context, AccountSetupComposition.class);
i.setAction(Intent.ACTION_EDIT);
i.putExtra(EXTRA_ACCOUNT, account);
i.putExtra(EXTRA_ACCOUNT, account.getUuid());
context.startActivity(i);
}
@ -46,7 +45,8 @@ public class AccountSetupComposition extends K9Activity
{
super.onCreate(savedInstanceState);
mAccount = (Account)getIntent().getSerializableExtra(EXTRA_ACCOUNT);
String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
setContentView(R.layout.account_setup_composition);
@ -56,7 +56,8 @@ public class AccountSetupComposition extends K9Activity
*/
if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_ACCOUNT))
{
mAccount = (Account)savedInstanceState.getSerializable(EXTRA_ACCOUNT);
accountUuid = savedInstanceState.getString(EXTRA_ACCOUNT);
mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
}
mAccountName = (EditText)findViewById(R.id.account_name);
@ -114,7 +115,7 @@ public class AccountSetupComposition extends K9Activity
public void onResume()
{
super.onResume();
mAccount.refresh(Preferences.getPreferences(this));
//mAccount.refresh(Preferences.getPreferences(this));
}
private void saveSettings()
@ -147,7 +148,7 @@ public class AccountSetupComposition extends K9Activity
public void onSaveInstanceState(Bundle outState)
{
super.onSaveInstanceState(outState);
outState.putSerializable(EXTRA_ACCOUNT, mAccount);
outState.putSerializable(EXTRA_ACCOUNT, mAccount.getUuid());
}
@Override

View File

@ -13,7 +13,6 @@ import android.view.View.OnClickListener;
import android.widget.*;
import com.fsck.k9.*;
import com.fsck.k9.activity.ChooseFolder;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
@ -28,7 +27,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
private static final int SELECT_DRAFT_FOLDER = 100;
private static final int SELECT_SENT_FOLDER = 101;
private static final int SELECT_TRASH_FOLDER = 102;
private static final int SELECT_OUTBOX_FOLDER = 103;
//private static final int SELECT_OUTBOX_FOLDER = 103;
private static final int popPorts[] =
{
@ -84,7 +83,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
public static void actionIncomingSettings(Activity context, Account account, boolean makeDefault)
{
Intent i = new Intent(context, AccountSetupIncoming.class);
i.putExtra(EXTRA_ACCOUNT, account);
i.putExtra(EXTRA_ACCOUNT, account.getUuid());
i.putExtra(EXTRA_MAKE_DEFAULT, makeDefault);
context.startActivity(i);
}
@ -93,7 +92,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
{
Intent i = new Intent(context, AccountSetupIncoming.class);
i.setAction(Intent.ACTION_EDIT);
i.putExtra(EXTRA_ACCOUNT, account);
i.putExtra(EXTRA_ACCOUNT, account.getUuid());
context.startActivity(i);
}
@ -199,7 +198,8 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
*/
mPortView.setKeyListener(DigitsKeyListener.getInstance("0123456789"));
mAccount = (Account)getIntent().getSerializableExtra(EXTRA_ACCOUNT);
String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
mMakeDefault = (boolean)getIntent().getBooleanExtra(EXTRA_MAKE_DEFAULT, false);
/*
@ -208,7 +208,8 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
*/
if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_ACCOUNT))
{
mAccount = (Account)savedInstanceState.getSerializable(EXTRA_ACCOUNT);
accountUuid = savedInstanceState.getString(EXTRA_ACCOUNT);
mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
}
try
@ -385,7 +386,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
public void onSaveInstanceState(Bundle outState)
{
super.onSaveInstanceState(outState);
outState.putSerializable(EXTRA_ACCOUNT, mAccount);
outState.putString(EXTRA_ACCOUNT, mAccount.getUuid());
}
private void validateFields()
@ -580,7 +581,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
{
selectIntent.putExtra(ChooseFolder.EXTRA_SHOW_FOLDER_NONE, "yes");
}
selectIntent.putExtra(ChooseFolder.EXTRA_ACCOUNT, mAccount);
selectIntent.putExtra(ChooseFolder.EXTRA_ACCOUNT, mAccount.getUuid());
selectIntent.putExtra(ChooseFolder.EXTRA_CUR_FOLDER, curFolder);
selectIntent.putExtra(ChooseFolder.EXTRA_SHOW_CURRENT, "yes");
startActivityForResult(selectIntent, activityCode);

View File

@ -13,7 +13,6 @@ import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import com.fsck.k9.*;
import com.fsck.k9.activity.FolderList;
public class AccountSetupNames extends K9Activity implements OnClickListener
{
@ -30,7 +29,7 @@ public class AccountSetupNames extends K9Activity implements OnClickListener
public static void actionSetNames(Context context, Account account)
{
Intent i = new Intent(context, AccountSetupNames.class);
i.putExtra(EXTRA_ACCOUNT, account);
i.putExtra(EXTRA_ACCOUNT, account.getUuid());
context.startActivity(i);
}
@ -63,7 +62,8 @@ public class AccountSetupNames extends K9Activity implements OnClickListener
mName.setKeyListener(TextKeyListener.getInstance(false, Capitalize.WORDS));
mAccount = (Account)getIntent().getSerializableExtra(EXTRA_ACCOUNT);
String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
/*
* Since this field is considered optional, we don't set this here. If

View File

@ -33,7 +33,7 @@ public class AccountSetupOptions extends K9Activity implements OnClickListener
public static void actionOptions(Context context, Account account, boolean makeDefault)
{
Intent i = new Intent(context, AccountSetupOptions.class);
i.putExtra(EXTRA_ACCOUNT, account);
i.putExtra(EXTRA_ACCOUNT, account.getUuid());
i.putExtra(EXTRA_MAKE_DEFAULT, makeDefault);
context.startActivity(i);
}
@ -103,7 +103,8 @@ public class AccountSetupOptions extends K9Activity implements OnClickListener
displayCountsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mDisplayCountView.setAdapter(displayCountsAdapter);
mAccount = (Account)getIntent().getSerializableExtra(EXTRA_ACCOUNT);
String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
mNotifyView.setChecked(mAccount.isNotifyNewMail());
mNotifySyncView.setChecked(mAccount.isShowOngoing());
@ -116,7 +117,7 @@ public class AccountSetupOptions extends K9Activity implements OnClickListener
boolean isPushCapable = false;
try
{
Store store = Store.getInstance(mAccount.getStoreUri(), getApplication());
Store store = mAccount.getRemoteStore();
isPushCapable = store.isPushCapable();
}
catch (Exception e)

View File

@ -14,7 +14,6 @@ import android.view.ViewGroup;
import android.widget.*;
import android.widget.CompoundButton.OnCheckedChangeListener;
import com.fsck.k9.*;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
@ -37,6 +36,7 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
{
"smtp", "smtp+ssl", "smtp+ssl+", "smtp+tls", "smtp+tls+"
};
/*
private static final int webdavPorts[] =
{
80, 443, 443, 443, 443
@ -45,6 +45,7 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
{
"webdav", "webdav+ssl", "webdav+ssl+", "webdav+tls", "webdav+tls+"
};
*/
private static final String authTypes[] =
{
@ -65,7 +66,7 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
public static void actionOutgoingSettings(Context context, Account account, boolean makeDefault)
{
Intent i = new Intent(context, AccountSetupOutgoing.class);
i.putExtra(EXTRA_ACCOUNT, account);
i.putExtra(EXTRA_ACCOUNT, account.getUuid());
i.putExtra(EXTRA_MAKE_DEFAULT, makeDefault);
context.startActivity(i);
}
@ -74,7 +75,7 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
{
Intent i = new Intent(context, AccountSetupOutgoing.class);
i.setAction(Intent.ACTION_EDIT);
i.putExtra(EXTRA_ACCOUNT, account);
i.putExtra(EXTRA_ACCOUNT, account.getUuid());
context.startActivity(i);
}
@ -84,7 +85,8 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
super.onCreate(savedInstanceState);
setContentView(R.layout.account_setup_outgoing);
mAccount = (Account)getIntent().getSerializableExtra(EXTRA_ACCOUNT);
String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
try
{
@ -190,7 +192,9 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
*/
mPortView.setKeyListener(DigitsKeyListener.getInstance("0123456789"));
mAccount = (Account)getIntent().getSerializableExtra(EXTRA_ACCOUNT);
//FIXME: get Account object again?
accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
mMakeDefault = (boolean)getIntent().getBooleanExtra(EXTRA_MAKE_DEFAULT, false);
/*
@ -199,7 +203,8 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
*/
if (savedInstanceState != null && savedInstanceState.containsKey(EXTRA_ACCOUNT))
{
mAccount = (Account)savedInstanceState.getSerializable(EXTRA_ACCOUNT);
accountUuid = savedInstanceState.getString(EXTRA_ACCOUNT);
mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
}
try
@ -284,7 +289,7 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
public void onSaveInstanceState(Bundle outState)
{
super.onSaveInstanceState(outState);
outState.putSerializable(EXTRA_ACCOUNT, mAccount);
outState.putString(EXTRA_ACCOUNT, mAccount.getUuid());
}
private void validateFields()

View File

@ -12,6 +12,7 @@ import com.fsck.k9.*;
import com.fsck.k9.mail.Folder.FolderClass;
import com.fsck.k9.mail.MessagingException;
import com.fsck.k9.mail.Store;
import com.fsck.k9.mail.store.LocalStore;
import com.fsck.k9.mail.store.LocalStore.LocalFolder;
import com.fsck.k9.service.MailService;
@ -36,7 +37,7 @@ public class FolderSettings extends K9PreferenceActivity
{
Intent i = new Intent(context, FolderSettings.class);
i.putExtra(EXTRA_FOLDER_NAME, folderName);
i.putExtra(EXTRA_ACCOUNT, account);
i.putExtra(EXTRA_ACCOUNT, account.getUuid());
context.startActivity(i);
}
@ -46,13 +47,13 @@ public class FolderSettings extends K9PreferenceActivity
super.onCreate(savedInstanceState);
String folderName = (String)getIntent().getSerializableExtra(EXTRA_FOLDER_NAME);
Account mAccount = (Account)getIntent().getSerializableExtra(EXTRA_ACCOUNT);
String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
Account mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
try
{
Store localStore = Store.getInstance(mAccount.getLocalStoreUri(),
getApplication());
mFolder = (LocalFolder) localStore.getFolder(folderName);
LocalStore localStore = mAccount.getLocalStore();
mFolder = localStore.getFolder(folderName);
mFolder.refresh(Preferences.getPreferences(this));
}
catch (MessagingException me)
@ -65,7 +66,7 @@ public class FolderSettings extends K9PreferenceActivity
Store store = null;
try
{
store = Store.getInstance(mAccount.getStoreUri(), getApplication());
store = mAccount.getRemoteStore();
isPushCapable = store.isPushCapable();
}
catch (Exception e)

View File

@ -1,10 +1,13 @@
package com.fsck.k9.mail;
import com.fsck.k9.Account;
import com.fsck.k9.Preferences;
public abstract class Folder
{
protected final Account mAccount;
private String status = null;
private long lastChecked = 0;
private long lastPush = 0;
@ -23,6 +26,11 @@ public abstract class Folder
HOLDS_FOLDERS, HOLDS_MESSAGES,
}
protected Folder(Account account)
{
mAccount = account;
}
/**
* Forces an open of the MailProvider. If the provider is already open this
* function returns without doing anything.
@ -205,5 +213,8 @@ public abstract class Folder
this.status = status;
}
public Account getAccount()
{
return mAccount;
}
}

View File

@ -2,6 +2,8 @@
package com.fsck.k9.mail;
import android.app.Application;
import com.fsck.k9.Account;
import com.fsck.k9.mail.store.ImapStore;
import com.fsck.k9.mail.store.LocalStore;
import com.fsck.k9.mail.store.Pop3Store;
@ -31,45 +33,41 @@ public abstract class Store
private static HashMap<String, Store> mStores = new HashMap<String, Store>();
/**
* Get an instance of a mail store. The URI is parsed as a standard URI and
* the scheme is used to determine which protocol will be used. The
* following schemes are currently recognized: imap - IMAP with no
* connection security. Ex: imap://username:password@host/ imap+tls - IMAP
* with TLS connection security, if the server supports it. Ex:
* imap+tls://username:password@host imap+tls+ - IMAP with required TLS
* connection security. Connection fails if TLS is not available. Ex:
* imap+tls+://username:password@host imap+ssl+ - IMAP with required SSL
* connection security. Connection fails if SSL is not available. Ex:
* imap+ssl+://username:password@host
*
* @param uri The URI of the store.
* @return
* @throws MessagingException
*/
public synchronized static Store getInstance(String uri, Application application) throws MessagingException
protected final Account mAccount;
protected Store(Account account)
{
mAccount = account;
}
/**
* Get an instance of a remote mail store.
*/
public synchronized static Store getRemoteInstance(Account account) throws MessagingException
{
String uri = account.getStoreUri();
if (uri.startsWith("local"))
{
throw new RuntimeException("Asked to get non-local Store object but given LocalStore URI");
}
Store store = mStores.get(uri);
if (store == null)
{
if (uri.startsWith("imap"))
{
store = new ImapStore(uri);
store = new ImapStore(account);
}
else if (uri.startsWith("pop3"))
{
store = new Pop3Store(uri);
}
else if (uri.startsWith("local"))
{
store = new LocalStore(uri, application);
store = new Pop3Store(account);
}
else if (uri.startsWith("webdav"))
{
store = new WebDavStore(uri);
store = new WebDavStore(account);
}
if (store != null)
{
mStores.put(uri, store);
@ -84,6 +82,37 @@ public abstract class Store
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();
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);
if (store != null)
{
mStores.put(uri, store);
}
}
if (store == null)
{
throw new MessagingException("Unable to locate an applicable Store for " + uri);
}
return (LocalStore)store;
}
public abstract Folder getFolder(String name) throws MessagingException;
public abstract Folder[] getPersonalNamespaces() throws MessagingException;
@ -121,4 +150,8 @@ public abstract class Store
return null;
}
public Account getAccount()
{
return mAccount;
}
}

View File

@ -1,6 +1,7 @@
package com.fsck.k9.mail;
import com.fsck.k9.Account;
import com.fsck.k9.mail.transport.SmtpTransport;
import com.fsck.k9.mail.transport.WebDavTransport;
@ -11,15 +12,16 @@ public abstract class Transport
// RFC 1047
protected static final int SOCKET_READ_TIMEOUT = 300000;
public synchronized static Transport getInstance(String uri) throws MessagingException
public synchronized static Transport getInstance(Account account) throws MessagingException
{
String uri = account.getTransportUri();
if (uri.startsWith("smtp"))
{
return new SmtpTransport(uri);
}
else if (uri.startsWith("webdav"))
{
return new WebDavTransport(uri);
return new WebDavTransport(account);
}
else
{

View File

@ -2,6 +2,8 @@
package com.fsck.k9.mail.store;
import android.util.Log;
import com.fsck.k9.Account;
import com.fsck.k9.K9;
import com.fsck.k9.PeekableInputStream;
import com.fsck.k9.Utility;
@ -98,15 +100,15 @@ public class ImapStore extends Store
* imap+tls+://auth:user:password@server:port CONNECTION_SECURITY_TLS_REQUIRED
* imap+ssl+://auth:user:password@server:port CONNECTION_SECURITY_SSL_REQUIRED
* imap+ssl://auth:user:password@server:port CONNECTION_SECURITY_SSL_OPTIONAL
*
* @param _uri
*/
public ImapStore(String _uri) throws MessagingException
public ImapStore(Account account) throws MessagingException
{
super(account);
URI uri;
try
{
uri = new URI(_uri);
uri = new URI(mAccount.getStoreUri());
}
catch (URISyntaxException use)
{
@ -438,6 +440,7 @@ public class ImapStore extends Store
public ImapFolder(ImapStore nStore, String name)
{
super(nStore.getAccount());
store = nStore;
this.mName = name;
}

View File

@ -10,6 +10,7 @@ import android.database.sqlite.SQLiteException;
import android.net.Uri;
import android.text.util.Regex;
import android.util.Log;
import com.fsck.k9.Account;
import com.fsck.k9.K9;
import com.fsck.k9.Preferences;
import com.fsck.k9.Utility;
@ -58,17 +59,17 @@ public class LocalStore extends Store implements Serializable
"subject, sender_list, date, uid, flags, id, to_list, cc_list, "
+ "bcc_list, reply_to_list, attachment_count, internal_date, message_id, folder_id, preview ";
/**
* @param uri local://localhost/path/to/database/uuid.db
* local://localhost/path/to/database/uuid.db
*/
public LocalStore(String _uri, Application application) throws MessagingException
public LocalStore(Account account, Application application) throws MessagingException
{
super(account);
mApplication = application;
URI uri = null;
try
{
uri = new URI(_uri);
uri = new URI(mAccount.getLocalStoreUri());
}
catch (Exception e)
{
@ -84,6 +85,7 @@ public class LocalStore extends Store implements Serializable
// We need to associate the localstore with the account. Since we don't have the account
// handy here, we'll take the filename from the DB and use the basename of the filename
// Folders probably should have references to their containing accounts
//TODO: We do have an account object now
File dbFile = new File(mPath);
String[] tokens = dbFile.getName().split("\\.");
uUid = tokens[0];
@ -108,7 +110,6 @@ public class LocalStore extends Store implements Serializable
}
private void doDbUpgrade(SQLiteDatabase mDb, Application application)
{
Log.i(K9.LOG_TAG, String.format("Upgrading database from version %d to version %d",
@ -676,6 +677,7 @@ public class LocalStore extends Store implements Serializable
public LocalFolder(String name)
{
super(LocalStore.this.mAccount);
this.mName = name;
if (K9.INBOX.equals(getName()))
@ -689,6 +691,7 @@ public class LocalStore extends Store implements Serializable
public LocalFolder(long id)
{
super(LocalStore.this.mAccount);
this.mFolderId = id;
}
@ -1376,7 +1379,11 @@ public class LocalStore extends Store implements Serializable
ArrayList<Message> messages = new ArrayList<Message>();
for (String uid : uids)
{
messages.add(getMessage(uid));
Message message = getMessage(uid);
if (message != null)
{
messages.add(message);
}
}
return messages.toArray(new Message[] {});
}
@ -1452,7 +1459,7 @@ public class LocalStore extends Store implements Serializable
* old message. It is implemented as a delete/insert. This functionality is used in saving
* of drafts and re-synchronization of updated server messages.
*/
public void appendMessages(Message[] messages, boolean copy) throws MessagingException
private void appendMessages(Message[] messages, boolean copy) throws MessagingException
{
open(OpenMode.READ_WRITE);
for (Message message : messages)
@ -1463,10 +1470,13 @@ public class LocalStore extends Store implements Serializable
}
String uid = message.getUid();
if (uid == null)
if (uid == null || copy)
{
uid = K9.LOCAL_UID_PREFIX + UUID.randomUUID().toString();
message.setUid(uid);
if (!copy)
{
message.setUid(uid);
}
}
else
{
@ -1903,6 +1913,12 @@ public class LocalStore extends Store implements Serializable
return super.equals(o);
}
@Override
public int hashCode()
{
return mName.hashCode();
}
@Override
public Flag[] getPermanentFlags() throws MessagingException
{

View File

@ -3,6 +3,8 @@ package com.fsck.k9.mail.store;
import android.util.Config;
import android.util.Log;
import com.fsck.k9.Account;
import com.fsck.k9.K9;
import com.fsck.k9.Utility;
import com.fsck.k9.mail.*;
@ -69,15 +71,15 @@ public class Pop3Store extends Store
* pop3+tls+://user:password@server:port CONNECTION_SECURITY_TLS_REQUIRED
* pop3+ssl+://user:password@server:port CONNECTION_SECURITY_SSL_REQUIRED
* pop3+ssl://user:password@server:port CONNECTION_SECURITY_SSL_OPTIONAL
*
* @param _uri
*/
public Pop3Store(String _uri) throws MessagingException
public Pop3Store(Account account) throws MessagingException
{
super(account);
URI uri;
try
{
uri = new URI(_uri);
uri = new URI(mAccount.getStoreUri());
}
catch (URISyntaxException use)
{
@ -197,6 +199,7 @@ public class Pop3Store extends Store
public Pop3Folder(String name)
{
super(Pop3Store.this.mAccount);
this.mName = name;
if (mName.equalsIgnoreCase("INBOX"))
{

View File

@ -1,6 +1,8 @@
package com.fsck.k9.mail.store;
import android.util.Log;
import com.fsck.k9.Account;
import com.fsck.k9.K9;
import com.fsck.k9.Utility;
import com.fsck.k9.mail.*;
@ -99,14 +101,14 @@ public class WebDavStore extends Store
* webdav+tls+://user:password@server:port CONNECTION_SECURITY_TLS_REQUIRED
* webdav+ssl+://user:password@server:port CONNECTION_SECURITY_SSL_REQUIRED
* webdav+ssl://user:password@server:port CONNECTION_SECURITY_SSL_OPTIONAL
*
* @param _uri
*/
public WebDavStore(String _uri) throws MessagingException
public WebDavStore(Account account) throws MessagingException
{
super(account);
try
{
mUri = new URI(_uri);
mUri = new URI(mAccount.getStoreUri());
}
catch (URISyntaxException use)
{
@ -1160,6 +1162,7 @@ public class WebDavStore extends Store
public WebDavFolder(WebDavStore nStore, String name)
{
super(nStore.getAccount());
store = nStore;
this.mName = name;

View File

@ -2,6 +2,8 @@
package com.fsck.k9.mail.transport;
import android.util.Log;
import com.fsck.k9.Account;
import com.fsck.k9.K9;
import com.fsck.k9.PeekableInputStream;
import com.fsck.k9.mail.Message;
@ -42,9 +44,9 @@ public class WebDavTransport extends Transport
*
* @param _uri
*/
public WebDavTransport(String _uri) throws MessagingException
public WebDavTransport(Account account) throws MessagingException
{
store = new WebDavStore(_uri);
store = new WebDavStore(account);
if (K9.DEBUG)
Log.d(K9.LOG_TAG, ">>> New WebDavTransport creation complete");
}