diff --git a/src/com/android/email/MessagingController.java b/src/com/android/email/MessagingController.java index bc9aff822..81a112ab8 100644 --- a/src/com/android/email/MessagingController.java +++ b/src/com/android/email/MessagingController.java @@ -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); } /** diff --git a/src/com/android/email/mail/store/Pop3Store.java b/src/com/android/email/mail/store/Pop3Store.java index 8104e859f..ea0976694 100644 --- a/src/com/android/email/mail/store/Pop3Store.java +++ b/src/com/android/email/mail/store/Pop3Store.java @@ -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; } diff --git a/tests/src/com/android/email/mail/store/Pop3StoreUnitTests.java b/tests/src/com/android/email/mail/store/Pop3StoreUnitTests.java index da8fe4381..a3469df0a 100644 --- a/tests/src/com/android/email/mail/store/Pop3StoreUnitTests.java +++ b/tests/src/com/android/email/mail/store/Pop3StoreUnitTests.java @@ -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