@Test public void copyMessages() throws Exception { ImapFolder sourceFolder = createFolder("Folder"); prepareImapFolderForOpen(OPEN_MODE_RW); ImapFolder destinationFolder = createFolder("Destination"); List<ImapMessage> messages = singletonList(createImapMessage("1")); List<ImapResponse> copyResponses = singletonList( createImapResponse("x OK [COPYUID 23 1 101] Success") ); when(imapConnection.executeSimpleCommand("UID COPY 1 \"Destination\"")).thenReturn(copyResponses); sourceFolder.open(OPEN_MODE_RW); Map<String, String> uidMapping = sourceFolder.copyMessages(messages, destinationFolder); assertNotNull(uidMapping); assertEquals("101", uidMapping.get("1")); }
@Override public Map<String, String> copyMessages(List<? extends Message> messages, Folder folder) throws MessagingException { if (!(folder instanceof ImapFolder)) { throw new MessagingException("ImapFolder.copyMessages passed non-ImapFolder"); } if (messages.isEmpty()) { return null; } ImapFolder imapFolder = (ImapFolder) folder; checkOpen(); String[] uids = new String[messages.size()]; for (int i = 0, count = messages.size(); i < count; i++) { uids[i] = messages.get(i).getUid(); } try { String encodedDestinationFolderName = folderNameCodec.encode(imapFolder.getPrefixedId()); String escapedDestinationFolderName = ImapUtility.encodeString(encodedDestinationFolderName); if (!exists(escapedDestinationFolderName)) { if (K9MailLib.isDebug()) { Timber.i("ImapFolder.copyMessages: attempting to create remote folder '%s' for %s", escapedDestinationFolderName, getLogId()); } imapFolder.create(FolderType.HOLDS_MESSAGES); } List<ImapResponse> responses = executeSimpleCommand(String.format("UID COPY %s %s", combine(uids, ','), escapedDestinationFolderName)); ImapResponse response = getLastResponse(responses); CopyUidResponse copyUidResponse = CopyUidResponse.parse(response); if (copyUidResponse == null) { return null; } return copyUidResponse.getUidMapping(); } catch (IOException ioe) { throw ioExceptionHandler(connection, ioe); } }
ImapFolder extends Folder<ImapMessage> { @Override public Map<String, String> copyMessages(List<? extends Message> messages, Folder folder) throws MessagingException { if (!(folder instanceof ImapFolder)) { throw new MessagingException("ImapFolder.copyMessages passed non-ImapFolder"); } if (messages.isEmpty()) { return null; } ImapFolder imapFolder = (ImapFolder) folder; checkOpen(); String[] uids = new String[messages.size()]; for (int i = 0, count = messages.size(); i < count; i++) { uids[i] = messages.get(i).getUid(); } try { String encodedDestinationFolderName = folderNameCodec.encode(imapFolder.getPrefixedId()); String escapedDestinationFolderName = ImapUtility.encodeString(encodedDestinationFolderName); if (!exists(escapedDestinationFolderName)) { if (K9MailLib.isDebug()) { Timber.i("ImapFolder.copyMessages: attempting to create remote folder '%s' for %s", escapedDestinationFolderName, getLogId()); } imapFolder.create(FolderType.HOLDS_MESSAGES); } List<ImapResponse> responses = executeSimpleCommand(String.format("UID COPY %s %s", combine(uids, ','), escapedDestinationFolderName)); ImapResponse response = getLastResponse(responses); CopyUidResponse copyUidResponse = CopyUidResponse.parse(response); if (copyUidResponse == null) { return null; } return copyUidResponse.getUidMapping(); } catch (IOException ioe) { throw ioExceptionHandler(connection, ioe); } } }
ImapFolder extends Folder<ImapMessage> { @Override public Map<String, String> copyMessages(List<? extends Message> messages, Folder folder) throws MessagingException { if (!(folder instanceof ImapFolder)) { throw new MessagingException("ImapFolder.copyMessages passed non-ImapFolder"); } if (messages.isEmpty()) { return null; } ImapFolder imapFolder = (ImapFolder) folder; checkOpen(); String[] uids = new String[messages.size()]; for (int i = 0, count = messages.size(); i < count; i++) { uids[i] = messages.get(i).getUid(); } try { String encodedDestinationFolderName = folderNameCodec.encode(imapFolder.getPrefixedId()); String escapedDestinationFolderName = ImapUtility.encodeString(encodedDestinationFolderName); if (!exists(escapedDestinationFolderName)) { if (K9MailLib.isDebug()) { Timber.i("ImapFolder.copyMessages: attempting to create remote folder '%s' for %s", escapedDestinationFolderName, getLogId()); } imapFolder.create(FolderType.HOLDS_MESSAGES); } List<ImapResponse> responses = executeSimpleCommand(String.format("UID COPY %s %s", combine(uids, ','), escapedDestinationFolderName)); ImapResponse response = getLastResponse(responses); CopyUidResponse copyUidResponse = CopyUidResponse.parse(response); if (copyUidResponse == null) { return null; } return copyUidResponse.getUidMapping(); } catch (IOException ioe) { throw ioExceptionHandler(connection, ioe); } } ImapFolder(ImapStore store, String id);   ImapFolder(ImapStore store, String id, FolderNameCodec folderNameCodec); }
ImapFolder extends Folder<ImapMessage> { @Override public Map<String, String> copyMessages(List<? extends Message> messages, Folder folder) throws MessagingException { if (!(folder instanceof ImapFolder)) { throw new MessagingException("ImapFolder.copyMessages passed non-ImapFolder"); } if (messages.isEmpty()) { return null; } ImapFolder imapFolder = (ImapFolder) folder; checkOpen(); String[] uids = new String[messages.size()]; for (int i = 0, count = messages.size(); i < count; i++) { uids[i] = messages.get(i).getUid(); } try { String encodedDestinationFolderName = folderNameCodec.encode(imapFolder.getPrefixedId()); String escapedDestinationFolderName = ImapUtility.encodeString(encodedDestinationFolderName); if (!exists(escapedDestinationFolderName)) { if (K9MailLib.isDebug()) { Timber.i("ImapFolder.copyMessages: attempting to create remote folder '%s' for %s", escapedDestinationFolderName, getLogId()); } imapFolder.create(FolderType.HOLDS_MESSAGES); } List<ImapResponse> responses = executeSimpleCommand(String.format("UID COPY %s %s", combine(uids, ','), escapedDestinationFolderName)); ImapResponse response = getLastResponse(responses); CopyUidResponse copyUidResponse = CopyUidResponse.parse(response); if (copyUidResponse == null) { return null; } return copyUidResponse.getUidMapping(); } catch (IOException ioe) { throw ioExceptionHandler(connection, ioe); } } ImapFolder(ImapStore store, String id);   ImapFolder(ImapStore store, String id, FolderNameCodec folderNameCodec); @Override void open(int mode); @Override boolean isOpen(); @Override int getMode(); @Override void close(); @Override String getId(); @Override String getParentId(); @Override String getName(); @Override boolean exists(); @Override boolean canHaveSubFolders(); @Override boolean create(FolderType type); @Override Map<String, String> copyMessages(List<? extends Message> messages, Folder folder); @Override Map<String, String> moveMessages(List<? extends Message> messages, Folder folder); @Override void delete(List<? extends Message> messages, String trashFolderName); @Override int getMessageCount(); @Override int getUnreadMessageCount(); @Override int getFlaggedMessageCount(); @Override void delete(boolean recurse); @Override ImapMessage getMessage(String uid); @Override List<ImapMessage> getMessages(int start, int end, Date earliestDate,
            MessageRetrievalListener<ImapMessage> listener); @Override boolean areMoreMessagesAvailable(int indexOfOldestMessage, Date earliestDate); @Override void fetch(List<ImapMessage> messages, FetchProfile fetchProfile,
            MessageRetrievalListener<ImapMessage> listener); @Override void fetchPart(Message message, Part part, MessageRetrievalListener<Message> listener,
            BodyFactory bodyFactory); @Override Map<String, String> appendMessages(List<? extends Message> messages); @Override String getUidFromMessageId(Message message); @Override void expunge(); @Override void setFlags(Set<Flag> flags, boolean value); @Override String getNewPushState(String oldSerializedPushState, Message message); @Override void setFlags(List<? extends Message> messages, final Set<Flag> flags, boolean value); @Override boolean equals(Object other); @Override int hashCode(); @Override List<ImapMessage> search(final String queryString, final Set<Flag> requiredFlags,
            final Set<Flag> forbiddenFlags); }
ImapFolder extends Folder<ImapMessage> { @Override public Map<String, String> copyMessages(List<? extends Message> messages, Folder folder) throws MessagingException { if (!(folder instanceof ImapFolder)) { throw new MessagingException("ImapFolder.copyMessages passed non-ImapFolder"); } if (messages.isEmpty()) { return null; } ImapFolder imapFolder = (ImapFolder) folder; checkOpen(); String[] uids = new String[messages.size()]; for (int i = 0, count = messages.size(); i < count; i++) { uids[i] = messages.get(i).getUid(); } try { String encodedDestinationFolderName = folderNameCodec.encode(imapFolder.getPrefixedId()); String escapedDestinationFolderName = ImapUtility.encodeString(encodedDestinationFolderName); if (!exists(escapedDestinationFolderName)) { if (K9MailLib.isDebug()) { Timber.i("ImapFolder.copyMessages: attempting to create remote folder '%s' for %s", escapedDestinationFolderName, getLogId()); } imapFolder.create(FolderType.HOLDS_MESSAGES); } List<ImapResponse> responses = executeSimpleCommand(String.format("UID COPY %s %s", combine(uids, ','), escapedDestinationFolderName)); ImapResponse response = getLastResponse(responses); CopyUidResponse copyUidResponse = CopyUidResponse.parse(response); if (copyUidResponse == null) { return null; } return copyUidResponse.getUidMapping(); } catch (IOException ioe) { throw ioExceptionHandler(connection, ioe); } } ImapFolder(ImapStore store, String id);   ImapFolder(ImapStore store, String id, FolderNameCodec folderNameCodec); @Override void open(int mode); @Override boolean isOpen(); @Override int getMode(); @Override void close(); @Override String getId(); @Override String getParentId(); @Override String getName(); @Override boolean exists(); @Override boolean canHaveSubFolders(); @Override boolean create(FolderType type); @Override Map<String, String> copyMessages(List<? extends Message> messages, Folder folder); @Override Map<String, String> moveMessages(List<? extends Message> messages, Folder folder); @Override void delete(List<? extends Message> messages, String trashFolderName); @Override int getMessageCount(); @Override int getUnreadMessageCount(); @Override int getFlaggedMessageCount(); @Override void delete(boolean recurse); @Override ImapMessage getMessage(String uid); @Override List<ImapMessage> getMessages(int start, int end, Date earliestDate,
            MessageRetrievalListener<ImapMessage> listener); @Override boolean areMoreMessagesAvailable(int indexOfOldestMessage, Date earliestDate); @Override void fetch(List<ImapMessage> messages, FetchProfile fetchProfile,
            MessageRetrievalListener<ImapMessage> listener); @Override void fetchPart(Message message, Part part, MessageRetrievalListener<Message> listener,
            BodyFactory bodyFactory); @Override Map<String, String> appendMessages(List<? extends Message> messages); @Override String getUidFromMessageId(Message message); @Override void expunge(); @Override void setFlags(Set<Flag> flags, boolean value); @Override String getNewPushState(String oldSerializedPushState, Message message); @Override void setFlags(List<? extends Message> messages, final Set<Flag> flags, boolean value); @Override boolean equals(Object other); @Override int hashCode(); @Override List<ImapMessage> search(final String queryString, final Set<Flag> requiredFlags,
            final Set<Flag> forbiddenFlags);  }