Commit 42682ae3 authored by cketti's avatar cketti

Merge branch 'GH-3301_backport' into 5.6-MAINT

parents 83fc4c8d 41d8fc96
......@@ -1844,14 +1844,24 @@ public class MessagingController {
}
void processPendingMoveOrCopy(PendingMoveOrCopy command, Account account) throws MessagingException {
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 {
String srcFolder = command.srcFolder;
String destFolder = command.destFolder;
boolean isCopy = command.isCopy;
try {
Store remoteStore = account.getRemoteStore();
remoteSrcFolder = remoteStore.getFolder(srcFolder);
......@@ -1859,13 +1869,17 @@ public class MessagingController {
localDestFolder = (LocalFolder) 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));
}
}
if (messages.isEmpty()) {
Timber.i("processingPendingMoveOrCopy: no remote messages to move, skipping");
return;
}
if (!remoteSrcFolder.exists()) {
throw new MessagingException(
"processingPendingMoveOrCopy: remoteFolder " + srcFolder + " does not exist", true);
......@@ -1911,11 +1925,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;
}
......
......@@ -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;
......@@ -65,6 +67,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;
......@@ -825,6 +828,20 @@ public class MessagingControllerTest {
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.getName(), 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.getOutboxFolderName()).thenReturn(FOLDER_NAME);
when(account.hasSentFolder()).thenReturn(true);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment