Fixed Pop3Store to be able to delete message in Inbox.

When delete policy is DELETE_POLICY_ON_DELETE, PENDING_COMMAND_TRASH
will be invoked. But in POP3 account, because of 1) Inbox is
OpenMode.READ_ONLY, 2) getMessage(uid) just after open() is not work
correctly, 3) remote Inbox folder is not closed after deleting message,
PENDING_COMMAND_TRASH does not work.  And also the fat that some POP3
server use UID with '-' prevents PENDING_COMMAND_TRASH to recognize
the message is remote message.

Internal Bug: 1651709
This commit is contained in:
Takaoka G. Tadashi 2009-06-25 15:53:32 +09:00
parent a492673609
commit 4f23ebd3dc
3 changed files with 51 additions and 8 deletions

View File

@ -1100,15 +1100,16 @@ public class MessagingController implements Runnable {
}
remoteFolder.open(OpenMode.READ_WRITE, localFolder.getPersistentCallbacks());
if (remoteFolder.getMode() != OpenMode.READ_WRITE) {
remoteFolder.close(false);
return;
}
Message remoteMessage = null;
if (!uid.startsWith("Local")
&& !uid.contains("-")) {
if (!uid.startsWith("Local")) {
remoteMessage = remoteFolder.getMessage(uid);
}
if (remoteMessage == null) {
remoteFolder.close(false);
return;
}
@ -1132,6 +1133,8 @@ public class MessagingController implements Runnable {
(LocalFolder) localStore.getFolder(account.getTrashFolderName());
remoteTrashFolder.open(OpenMode.READ_WRITE, localTrashFolder.getPersistentCallbacks());
if (remoteTrashFolder.getMode() != OpenMode.READ_WRITE) {
remoteFolder.close(false);
remoteTrashFolder.close(false);
return;
}
@ -1164,10 +1167,12 @@ public class MessagingController implements Runnable {
}
);
remoteTrashFolder.close(false);
}
remoteMessage.setFlag(Flag.DELETED, true);
remoteFolder.expunge();
remoteFolder.close(false);
}
/**

View File

@ -294,7 +294,7 @@ public class Pop3Store extends Store {
@Override
public OpenMode getMode() throws MessagingException {
return OpenMode.READ_ONLY;
return OpenMode.READ_WRITE;
}
/**
@ -342,10 +342,18 @@ public class Pop3Store extends Store {
@Override
public Message getMessage(String uid) throws MessagingException {
Pop3Message message = mUidToMsgMap.get(uid);
if (message == null) {
message = new Pop3Message(uid, this);
if (mUidToMsgNumMap.size() == 0) {
try {
indexMsgNums(1, mMessageCount);
} catch (IOException ioe) {
mTransport.close();
if (Email.DEBUG) {
Log.d(Email.LOG_TAG, "Unable to index during getMessage " + ioe);
}
throw new MessagingException("getMessages", ioe);
}
}
Pop3Message message = mUidToMsgMap.get(uid);
return message;
}

View File

@ -32,6 +32,7 @@ import com.android.email.mail.transport.MockTransport;
import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import android.util.Log;
/**
* This is a series of unit tests for the POP3 Store class. These tests must be locally
@ -234,8 +235,8 @@ public class Pop3StoreUnitTests extends AndroidTestCase {
*/
public void testSmallFolderFunctions() throws MessagingException {
// getMode() returns OpenMode.READ_ONLY
assertEquals(OpenMode.READ_ONLY, mFolder.getMode());
// getMode() returns OpenMode.READ_WRITE
assertEquals(OpenMode.READ_WRITE, mFolder.getMode());
// create() return false
assertFalse(mFolder.create(FolderType.HOLDS_FOLDERS));
@ -321,6 +322,35 @@ public class Pop3StoreUnitTests extends AndroidTestCase {
checkOneUnread(mockTransport);
}
/**
* Test the process of opening and getting message by uid.
*/
public void testGetMessageByUid() throws MessagingException {
MockTransport mockTransport = openAndInjectMockTransport();
setupOpenFolder(mockTransport, 2, null);
mFolder.open(OpenMode.READ_WRITE, null);
// check message count
assertEquals(2, mFolder.getMessageCount());
// setup 2 messages
setupUidlSequence(mockTransport, 2);
String uid1 = getSingleMessageUID(1);
String uid2 = getSingleMessageUID(2);
String uid3 = getSingleMessageUID(3);
Message msg1 = mFolder.getMessage(uid1);
assertTrue("message with uid1", msg1 != null);
// uid3 does not exist
Message msg3 = mFolder.getMessage(uid3);
assertTrue("message with uid3", msg3 == null);
Message msg2 = mFolder.getMessage(uid2);
assertTrue("message with uid2", msg2 != null);
}
/**
* Test the scenario where the transport is "open" but not really (e.g. server closed). Two
* things should happen: We should see an intermediate failure that makes sense, and the next