AI 148230: Allow stores to indicate if they support server-side copying of sent

mail into the "Sent" folder, thus eliminating the need to perform a 2nd
  upload into the server's Sent folder.  IMAP and POP3 do not support
  this (although IMAP could when it recognizes Gmail IMAP servers.)
  BUG=1807499

Automated import of CL 148230
This commit is contained in:
Andy Stadler 2009-05-01 16:36:34 -07:00 committed by The Android Open Source Project
parent 9197f42894
commit c9f151d4fe
6 changed files with 77 additions and 19 deletions

View File

@ -1502,9 +1502,9 @@ public class MessagingController implements Runnable {
*/
public void sendPendingMessagesSynchronous(final Account account) {
try {
Store localStore = Store.getInstance(account.getLocalStoreUri(), mContext, null);
Folder localFolder = localStore.getFolder(
account.getOutboxFolderName());
LocalStore localStore = (LocalStore) Store.getInstance(
account.getLocalStoreUri(), mContext, null);
Folder localFolder = localStore.getFolder(account.getOutboxFolderName());
if (!localFolder.exists()) {
return;
}
@ -1521,29 +1521,36 @@ public class MessagingController implements Runnable {
fp.add(FetchProfile.Item.BODY);
LocalFolder localSentFolder =
(LocalFolder) localStore.getFolder(
account.getSentFolderName());
(LocalFolder) localStore.getFolder(account.getSentFolderName());
// Determine if upload to "sent" folder is necessary
Store remoteStore = Store.getInstance(
account.getStoreUri(), mContext, localStore.getPersistentCallbacks());
boolean requireCopyMessageToSentFolder = remoteStore.requireCopyMessageToSentFolder();
Sender sender = Sender.getInstance(account.getSenderUri(), mContext);
for (Message message : localMessages) {
try {
localFolder.fetch(new Message[] { message }, fp, null);
try {
// Send message using Sender
message.setFlag(Flag.X_SEND_IN_PROGRESS, true);
sender.sendMessage(message);
message.setFlag(Flag.X_SEND_IN_PROGRESS, false);
localFolder.copyMessages(
new Message[] { message },
localSentFolder, null);
PendingCommand command = new PendingCommand();
command.command = PENDING_COMMAND_APPEND;
command.arguments =
new String[] {
localSentFolder.getName(),
message.getUid() };
queuePendingCommand(account, command);
processPendingCommands(account);
// Upload to "sent" folder if not supported server-side
if (requireCopyMessageToSentFolder) {
localFolder.copyMessages(
new Message[] { message },localSentFolder, null);
PendingCommand command = new PendingCommand();
command.command = PENDING_COMMAND_APPEND;
command.arguments =
new String[] { localSentFolder.getName(), message.getUid() };
queuePendingCommand(account, command);
processPendingCommands(account);
}
// And delete from outbox
message.setFlag(Flag.X_DESTROYED, true);
}
catch (Exception e) {

View File

@ -214,6 +214,17 @@ public abstract class Store {
return false;
}
/**
* Some protocols require that a sent message be copied (uploaded) into the Sent folder
* while others can take care of it automatically (ideally, on the server). This function
* allows a given store to indicate which mode(s) it supports.
* @return true if the store requires an upload into "sent", false if this happens automatically
* for any sent message.
*/
public boolean requireCopyMessageToSentFolder() {
return true;
}
public abstract Folder getFolder(String name) throws MessagingException;
public abstract Folder[] getPersonalNamespaces() throws MessagingException;

View File

@ -174,5 +174,15 @@ public class ExchangeStoreExample extends Store {
public boolean requireStructurePrefetch() {
return true;
}
/**
* Inform MessagingController that messages sent via EAS will be placed in the Sent folder
* automatically (server-side) and don't need to be uploaded.
* @return always false for EAS (assuming server-side copy is supported)
*/
@Override
public boolean requireCopyMessageToSentFolder() {
return false;
}
}

View File

@ -74,8 +74,8 @@ public class StoreTests extends AndroidTestCase {
assertNotNull("scheme null", info.mScheme);
assertNotNull("classname null", info.mClassName);
assertTrue(info.mPushSupported);
assertEquals(1, info.mVisibleLimitDefault);
assertEquals(1, info.mVisibleLimitIncrement);
assertEquals(-1, info.mVisibleLimitDefault);
assertEquals(-1, info.mVisibleLimitIncrement);
// This will throw MessagingException if the result would have been null
Store store = Store.getInstance(storeUri, getContext(), null);

View File

@ -120,11 +120,27 @@ public class ImapStoreUnitTests extends AndroidTestCase {
* Lightweight test to confirm that IMAP hasn't implemented any folder roles yet.
*
* TODO: Test this with multiple folders provided by mock server
* TODO: Implement XLIST and then support this
*/
public void testNoFolderRolesYet() {
assertEquals(Folder.FolderRole.UNKNOWN, mFolder.getRole());
}
/**
* Lightweight test to confirm that IMAP isn't requesting structure prefetch.
*/
public void testNoStructurePrefetch() {
assertFalse(mStore.requireStructurePrefetch());
}
/**
* Lightweight test to confirm that IMAP is requesting sent-message-upload.
* TODO: Implement Gmail-specific cases and handle this server-side
*/
public void testSentUploadRequested() {
assertTrue(mStore.requireCopyMessageToSentFolder());
}
/**
* TODO: Test the process of opening and indexing a mailbox with one unread message in it.
*/

View File

@ -258,6 +258,20 @@ public class Pop3StoreUnitTests extends AndroidTestCase {
}
}
/**
* Lightweight test to confirm that POP3 isn't requesting structure prefetch.
*/
public void testNoStructurePrefetch() {
assertFalse(mStore.requireStructurePrefetch());
}
/**
* Lightweight test to confirm that POP3 is requesting sent-message-upload.
*/
public void testSentUploadRequested() {
assertTrue(mStore.requireCopyMessageToSentFolder());
}
/**
* Test the process of opening and indexing a mailbox with one unread message in it.
*