Loading k9mail/src/main/java/com/fsck/k9/controller/MessagingController.java +18 −8 Original line number Diff line number Diff line Loading @@ -1810,14 +1810,24 @@ public class MessagingController { } void processPendingMoveOrCopy(PendingMoveOrCopy command, Account account) throws MessagingException { Folder remoteSrcFolder = null; Folder remoteDestFolder = null; LocalFolder localDestFolder; try { String srcFolder = command.srcFolder; String destFolder = command.destFolder; boolean isCopy = command.isCopy; Map<String, String> newUidMap = command.newUidMap; Collection<String> uids = newUidMap != null ? newUidMap.keySet() : command.uids; processPendingMoveOrCopy(account, srcFolder, destFolder, uids, isCopy, newUidMap); } @VisibleForTesting void processPendingMoveOrCopy(Account account, String srcFolder, String destFolder, Collection<String> uids, boolean isCopy, Map<String, String> newUidMap) throws MessagingException { Folder remoteSrcFolder = null; Folder remoteDestFolder = null; LocalFolder localDestFolder; try { RemoteStore remoteStore = account.getRemoteStore(); remoteSrcFolder = remoteStore.getFolder(srcFolder); Loading @@ -1825,7 +1835,6 @@ public class MessagingController { localDestFolder = localStore.getFolder(destFolder); List<Message> messages = new ArrayList<>(); Collection<String> uids = command.newUidMap != null ? command.newUidMap.keySet() : command.uids; for (String uid : uids) { if (!uid.startsWith(K9.LOCAL_UID_PREFIX)) { messages.add(remoteSrcFolder.getMessage(uid)); Loading Loading @@ -1882,11 +1891,12 @@ public class MessagingController { * This next part is used to bring the local UIDs of the local destination folder * upto speed with the remote UIDs of remote destination folder. */ if (command.newUidMap != null && remoteUidMap != null && !remoteUidMap.isEmpty()) { for (Map.Entry<String, String> entry : remoteUidMap.entrySet()) { if (newUidMap != null && remoteUidMap != null && !remoteUidMap.isEmpty()) { Timber.i("processingPendingMoveOrCopy: changing local uids of %d messages", remoteUidMap.size()); for (Entry<String, String> entry : remoteUidMap.entrySet()) { String remoteSrcUid = entry.getKey(); String newUid = entry.getValue(); String localDestUid = command.newUidMap.get(remoteSrcUid); String localDestUid = newUidMap.get(remoteSrcUid); if (localDestUid == null) { continue; } Loading k9mail/src/test/java/com/fsck/k9/controller/MessagingControllerTest.java +17 −0 Original line number Diff line number Diff line Loading @@ -3,6 +3,8 @@ package com.fsck.k9.controller; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.List; Loading Loading @@ -67,6 +69,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; Loading Loading @@ -841,6 +844,20 @@ public class MessagingControllerTest extends K9RobolectricTest { assertEquals(FetchProfile.Item.BODY_SANE, fetchProfileCaptor.getAllValues().get(3).get(0)); } @Test public void processPendingMoveOrCopy_withOnlyLocalMessages() throws Exception { configureRemoteStoreWithFolder(); Collection<String> uids = Arrays.asList(K9.LOCAL_UID_PREFIX + "msg1", K9.LOCAL_UID_PREFIX + "msg2"); controller.processPendingMoveOrCopy( account, localFolder.getServerId(), FOLDER_NAME, uids, false, null); verify(account).getRemoteStore(); verify(remoteStore).getFolder(FOLDER_NAME); verify(remoteFolder).close(); verifyNoMoreInteractions(remoteFolder); } private void setupAccountWithMessageToSend() throws MessagingException { when(account.getOutboxFolder()).thenReturn(FOLDER_NAME); when(account.hasSentFolder()).thenReturn(true); Loading Loading
k9mail/src/main/java/com/fsck/k9/controller/MessagingController.java +18 −8 Original line number Diff line number Diff line Loading @@ -1810,14 +1810,24 @@ public class MessagingController { } void processPendingMoveOrCopy(PendingMoveOrCopy command, Account account) throws MessagingException { Folder remoteSrcFolder = null; Folder remoteDestFolder = null; LocalFolder localDestFolder; try { String srcFolder = command.srcFolder; String destFolder = command.destFolder; boolean isCopy = command.isCopy; Map<String, String> newUidMap = command.newUidMap; Collection<String> uids = newUidMap != null ? newUidMap.keySet() : command.uids; processPendingMoveOrCopy(account, srcFolder, destFolder, uids, isCopy, newUidMap); } @VisibleForTesting void processPendingMoveOrCopy(Account account, String srcFolder, String destFolder, Collection<String> uids, boolean isCopy, Map<String, String> newUidMap) throws MessagingException { Folder remoteSrcFolder = null; Folder remoteDestFolder = null; LocalFolder localDestFolder; try { RemoteStore remoteStore = account.getRemoteStore(); remoteSrcFolder = remoteStore.getFolder(srcFolder); Loading @@ -1825,7 +1835,6 @@ public class MessagingController { localDestFolder = localStore.getFolder(destFolder); List<Message> messages = new ArrayList<>(); Collection<String> uids = command.newUidMap != null ? command.newUidMap.keySet() : command.uids; for (String uid : uids) { if (!uid.startsWith(K9.LOCAL_UID_PREFIX)) { messages.add(remoteSrcFolder.getMessage(uid)); Loading Loading @@ -1882,11 +1891,12 @@ public class MessagingController { * This next part is used to bring the local UIDs of the local destination folder * upto speed with the remote UIDs of remote destination folder. */ if (command.newUidMap != null && remoteUidMap != null && !remoteUidMap.isEmpty()) { for (Map.Entry<String, String> entry : remoteUidMap.entrySet()) { if (newUidMap != null && remoteUidMap != null && !remoteUidMap.isEmpty()) { Timber.i("processingPendingMoveOrCopy: changing local uids of %d messages", remoteUidMap.size()); for (Entry<String, String> entry : remoteUidMap.entrySet()) { String remoteSrcUid = entry.getKey(); String newUid = entry.getValue(); String localDestUid = command.newUidMap.get(remoteSrcUid); String localDestUid = newUidMap.get(remoteSrcUid); if (localDestUid == null) { continue; } Loading
k9mail/src/test/java/com/fsck/k9/controller/MessagingControllerTest.java +17 −0 Original line number Diff line number Diff line Loading @@ -3,6 +3,8 @@ package com.fsck.k9.controller; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.List; Loading Loading @@ -67,6 +69,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyZeroInteractions; import static org.mockito.Mockito.when; Loading Loading @@ -841,6 +844,20 @@ public class MessagingControllerTest extends K9RobolectricTest { assertEquals(FetchProfile.Item.BODY_SANE, fetchProfileCaptor.getAllValues().get(3).get(0)); } @Test public void processPendingMoveOrCopy_withOnlyLocalMessages() throws Exception { configureRemoteStoreWithFolder(); Collection<String> uids = Arrays.asList(K9.LOCAL_UID_PREFIX + "msg1", K9.LOCAL_UID_PREFIX + "msg2"); controller.processPendingMoveOrCopy( account, localFolder.getServerId(), FOLDER_NAME, uids, false, null); verify(account).getRemoteStore(); verify(remoteStore).getFolder(FOLDER_NAME); verify(remoteFolder).close(); verifyNoMoreInteractions(remoteFolder); } private void setupAccountWithMessageToSend() throws MessagingException { when(account.getOutboxFolder()).thenReturn(FOLDER_NAME); when(account.hasSentFolder()).thenReturn(true); Loading