mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-07 18:25:23 +00:00
Merged HEAD-BUG-FIX (5.1/Cloud) to HEAD (5.0/Cloud)
85565: Merged V4.2-BUG-FIX (4.2.4) to HEAD-BUG-FIX (5.0/Cloud) 85433: Merged DEV to V4.2-BUG-FIX (4.1.4) with unit test 84722: MNT-12420: Outlook 2011 (MacOS) implements an IMAP move as an APPEND leading to the creation of an EML file - Perform copy instead of create on APPEND request when existing node with provided message-id or X-Alfresco-NodeRef-ID can be found - Add Unit test. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@94502 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
parent
5716fe7cfa
commit
f3928a21cd
@ -317,7 +317,11 @@ public class AlfrescoImapFolder extends AbstractImapFolder implements Serializab
|
|||||||
NodeRef sourceNodeRef = extractNodeRef(message);
|
NodeRef sourceNodeRef = extractNodeRef(message);
|
||||||
if (isMoveOperation(sourceNodeRef))
|
if (isMoveOperation(sourceNodeRef))
|
||||||
{
|
{
|
||||||
uid = moveNode(this.folderInfo, message, flags, sourceNodeRef);
|
uid = copyOrmoveNode(this.folderInfo, message, flags, sourceNodeRef, true);
|
||||||
|
}
|
||||||
|
else if (sourceNodeRef != null)
|
||||||
|
{
|
||||||
|
uid = copyOrmoveNode(this.folderInfo, message, flags, sourceNodeRef, false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -341,13 +345,21 @@ public class AlfrescoImapFolder extends AbstractImapFolder implements Serializab
|
|||||||
* @throws FileNotFoundException
|
* @throws FileNotFoundException
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
private long moveNode(FileInfo folderInfo, MimeMessage message, Flags flags, NodeRef sourceNodeRef)
|
private long copyOrmoveNode(FileInfo folderInfo, MimeMessage message, Flags flags, NodeRef sourceNodeRef, boolean move)
|
||||||
throws FileExistsException, FileNotFoundException
|
throws FileExistsException, FileNotFoundException
|
||||||
{
|
{
|
||||||
FileFolderService fileFolderService = serviceRegistry.getFileFolderService();
|
FileFolderService fileFolderService = serviceRegistry.getFileFolderService();
|
||||||
FileFilterMode.setClient(FileFilterMode.Client.imap);
|
FileFilterMode.setClient(FileFilterMode.Client.imap);
|
||||||
fileFolderService.setHidden(sourceNodeRef, false);
|
fileFolderService.setHidden(sourceNodeRef, false);
|
||||||
FileInfo messageFile = fileFolderService.move(sourceNodeRef, folderInfo.getNodeRef(), null);
|
FileInfo messageFile = null;
|
||||||
|
if (move)
|
||||||
|
{
|
||||||
|
messageFile = fileFolderService.move(sourceNodeRef, folderInfo.getNodeRef(), null);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
messageFile = fileFolderService.copy(sourceNodeRef, folderInfo.getNodeRef(), null);
|
||||||
|
}
|
||||||
final long newMessageUid = (Long) messageFile.getProperties().get(ContentModel.PROP_NODE_DBID);
|
final long newMessageUid = (Long) messageFile.getProperties().get(ContentModel.PROP_NODE_DBID);
|
||||||
imapService.setFlag(messageFile, Flag.RECENT, true);
|
imapService.setFlag(messageFile, Flag.RECENT, true);
|
||||||
imapService.setFlag(messageFile, Flag.DELETED, false);
|
imapService.setFlag(messageFile, Flag.DELETED, false);
|
||||||
@ -367,6 +379,7 @@ public class AlfrescoImapFolder extends AbstractImapFolder implements Serializab
|
|||||||
String uuid = null;
|
String uuid = null;
|
||||||
String messageId = null;
|
String messageId = null;
|
||||||
NodeRef result = null;
|
NodeRef result = null;
|
||||||
|
NodeService nodeService = serviceRegistry.getNodeService();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
messageId = message.getMessageID();
|
messageId = message.getMessageID();
|
||||||
@ -391,6 +404,28 @@ public class AlfrescoImapFolder extends AbstractImapFolder implements Serializab
|
|||||||
uuid = messageId;
|
uuid = messageId;
|
||||||
}
|
}
|
||||||
result = new NodeRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore", uuid);
|
result = new NodeRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore", uuid);
|
||||||
|
if (nodeService.exists(result) == false)
|
||||||
|
{
|
||||||
|
result = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(result == null)
|
||||||
|
{
|
||||||
|
//check X-Alfresco-NodeRef-ID header
|
||||||
|
try
|
||||||
|
{
|
||||||
|
uuid = message.getHeader(AlfrescoImapConst.X_ALF_NODEREF_ID)[0];
|
||||||
|
result = new NodeRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore", uuid);
|
||||||
|
if (nodeService.exists(result) == false)
|
||||||
|
{
|
||||||
|
result = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (MessagingException e)
|
||||||
|
{
|
||||||
|
//Do nothing
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -921,6 +921,56 @@ public class ImapServiceImplTest extends TestCase
|
|||||||
assertEquals("There should be only one node in the destination folder", 1, nodeService.getChildAssocs(destinationNode.getNodeRef()).size());
|
assertEquals("There should be only one node in the destination folder", 1, nodeService.getChildAssocs(destinationNode.getNodeRef()).size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test for MNT-12420
|
||||||
|
*
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public void testMoveViaAppendAndDelete() throws Exception
|
||||||
|
{
|
||||||
|
AlfrescoImapUser poweredUser = new AlfrescoImapUser((USER_NAME + "@alfresco.com"), USER_NAME, USER_PASSWORD);
|
||||||
|
String fileName = "testfile" + GUID.generate();
|
||||||
|
String destinationName = "testFolder" + GUID.generate();
|
||||||
|
String destinationPath = IMAP_ROOT + AlfrescoImapConst.HIERARCHY_DELIMITER + destinationName;
|
||||||
|
String nodeContent = "test content";
|
||||||
|
NodeRef root = findCompanyHomeNodeRef();
|
||||||
|
AuthenticationUtil.setRunAsUserSystem();
|
||||||
|
|
||||||
|
// Create node and destination folder
|
||||||
|
FileInfo origFile = fileFolderService.create(root, fileName, ContentModel.TYPE_CONTENT);
|
||||||
|
ContentWriter contentWriter = contentService.getWriter(origFile.getNodeRef(), ContentModel.PROP_CONTENT, true);
|
||||||
|
contentWriter.setMimetype("text/plain");
|
||||||
|
contentWriter.setEncoding("UTF-8");
|
||||||
|
contentWriter.putContent(nodeContent);
|
||||||
|
|
||||||
|
FileInfo destinationNode = fileFolderService.create(root, destinationName, ContentModel.TYPE_FOLDER);
|
||||||
|
nodeService.addAspect(origFile.getNodeRef(), ImapModel.ASPECT_IMAP_CONTENT, null);
|
||||||
|
nodeService.addAspect(origFile.getNodeRef(), ContentModel.ASPECT_TAGGABLE, null);
|
||||||
|
|
||||||
|
// Save the message and set X-Alfresco-NodeRef-ID header
|
||||||
|
SimpleStoredMessage origMessage = imapService.getMessage(origFile);
|
||||||
|
origMessage.getMimeMessage().addHeader(AlfrescoImapConst.X_ALF_NODEREF_ID, origFile.getNodeRef().getId());
|
||||||
|
origMessage.getMimeMessage().saveChanges();
|
||||||
|
|
||||||
|
// Append the message to destination
|
||||||
|
AlfrescoImapFolder destinationMailbox = imapService.getOrCreateMailbox(poweredUser, destinationPath, true, false);
|
||||||
|
long uuid = destinationMailbox.appendMessage(origMessage.getMimeMessage(), flags, null);
|
||||||
|
|
||||||
|
// Delete the node
|
||||||
|
imapService.setFlag(origFile, Flags.Flag.DELETED, true);
|
||||||
|
imapService.expungeMessage(origFile);
|
||||||
|
|
||||||
|
// Check the destination has copy of original file and only this file
|
||||||
|
FileInfo copiedNode = fileFolderService.getFileInfo(nodeService.getNodeRef(uuid));
|
||||||
|
assertNotNull("The file should exist.", copiedNode);
|
||||||
|
assertEquals("The file name should not change.", fileName, copiedNode.getName());
|
||||||
|
NodeRef copiedParentNodeRef = nodeService.getPrimaryParent(copiedNode.getNodeRef()).getParentRef();
|
||||||
|
assertEquals("The parent should change to destination.", destinationNode.getNodeRef(), copiedParentNodeRef);
|
||||||
|
assertEquals("There should be only one node in the destination folder", 1, nodeService.getChildAssocs(destinationNode.getNodeRef()).size());
|
||||||
|
assertTrue("New node should have original node aspects", nodeService.hasAspect(copiedNode.getNodeRef(), ContentModel.ASPECT_TAGGABLE));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param mailbox - {@link AlfrescoImapFolder} instance which should be checked
|
* @param mailbox - {@link AlfrescoImapFolder} instance which should be checked
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user