use of com.icegreen.greenmail.store.SimpleStoredMessage in project alfresco-repository by Alfresco.
the class ImapServiceImpl method getMessage.
// ---------------------- Service Methods --------------------------------
public SimpleStoredMessage getMessage(FileInfo mesInfo) throws MessagingException {
NodeRef nodeRef = mesInfo.getNodeRef();
Date modified = (Date) nodeService.getProperty(nodeRef, ContentModel.PROP_MODIFIED);
if (modified != null) {
CacheItem cached = messageCache.get(nodeRef);
if (cached != null) {
if (cached.getModified().equals(modified)) {
return cached.getMessage();
}
}
SimpleStoredMessage message = createImapMessage(mesInfo, true);
messageCache.put(nodeRef, new CacheItem(modified, message));
return message;
} else {
SimpleStoredMessage message = createImapMessage(mesInfo, true);
return message;
}
}
use of com.icegreen.greenmail.store.SimpleStoredMessage in project alfresco-repository by Alfresco.
the class AlfrescoImapFolder method searchInternal.
@Override
protected long[] searchInternal(SearchTerm searchTerm) {
List<SimpleStoredMessage> messages = getMessages();
long[] result = new long[messages.size()];
int i = 0;
for (SimpleStoredMessage message : messages) {
if (searchTerm.match(message.getMimeMessage())) {
result[i] = message.getUid();
i++;
}
}
return Arrays.copyOfRange(result, 0, i);
}
use of com.icegreen.greenmail.store.SimpleStoredMessage in project alfresco-repository by Alfresco.
the class ImapServiceImplCacheTest method testRepoBehaviourWithFoldersCache.
public void testRepoBehaviourWithFoldersCache() throws Exception {
AlfrescoImapUser localUser = new AlfrescoImapUser(USER_NAME + "@alfresco.com", USER_NAME, USER_PASSWORD);
String folderName = "ALF9361";
String mailbox = "Alfresco IMAP" + AlfrescoImapConst.HIERARCHY_DELIMITER + TEST_IMAP_FOLDER_NAME + AlfrescoImapConst.HIERARCHY_DELIMITER + folderName;
int contentItemsCount = 3;
// Create a tree like ALF9361/ALF9361_0/sub_0
// Mailbox path with default mount point should be like 'Alfresco IMAP/aaa/ALF9361/ALF9361_0/sub_0
FileInfo localRootFolder = fileFolderService.create(testImapFolderNodeRef, folderName, ContentModel.TYPE_FOLDER);
List<FileInfo> subFolders = new ArrayList<FileInfo>(10);
for (int i = 0; i < 3; i++) {
String childMailbox = folderName + "_" + i;
FileInfo subFolder = fileFolderService.create(localRootFolder.getNodeRef(), childMailbox, ContentModel.TYPE_FOLDER);
for (int j = 0; j < 3; j++) {
String subChildMailbox = "sub_" + j;
fileFolderService.create(subFolder.getNodeRef(), subChildMailbox, ContentModel.TYPE_FOLDER);
}
subFolders.add(subFolder);
}
// Create content within 'Alfresco IMAP/aaa/ALF9361'
createTestContent(localRootFolder, contentItemsCount);
// Load the cache
imapService.listMailboxes(localUser, "*", false);
imapService.listMailboxes(localUser, "*", true);
// Get the folder to examine
AlfrescoImapFolder folder = imapService.getOrCreateMailbox(localUser, mailbox, true, false);
// Check the folder exist via IMAP
assertNotNull("Folder wasn't successfully gotten from IMAP", folder);
assertEquals(contentItemsCount, folder.getMessageCount());
// Check UIDVALIDITY
long uidValidityBefore = folder.getUidValidity();
// Move in an old file with a smaller UID
fileFolderService.move(oldFile.getNodeRef(), folder.getFolderInfo().getNodeRef(), folder.getName());
// Get the folder once more and check it was changed since an old child was moved in
folder = imapService.getOrCreateMailbox(localUser, mailbox, true, false);
// Content count should be increased
assertEquals(++contentItemsCount, folder.getMessageCount());
long uidValidity = folder.getUidValidity();
assertTrue("UIDVALIDITY wasn't incremented", (uidValidity - uidValidityBefore) > 0);
// Delete first childMailbox 'ALF9361/ALF9361_0'
// System.out.println(" --------------------- DELETE FOLDER --------------------");
// System.out.println(" Parent " + localRootFolder.getNodeRef());
fileFolderService.delete(subFolders.get(0).getNodeRef());
uidValidityBefore = uidValidity;
// Try to get deleted child
try {
String subFolderName = mailbox + AlfrescoImapConst.HIERARCHY_DELIMITER + folderName + "_0";
folder = imapService.getOrCreateMailbox(localUser, subFolderName, true, false);
fail("The folder still in the cache");
} catch (RuntimeException e) {
// expected
}
// ArsenyKo: I think we should avoid repo API invocation like isStale...
try {
String subSubFolderName = mailbox + AlfrescoImapConst.HIERARCHY_DELIMITER + mailbox + "_0" + AlfrescoImapConst.HIERARCHY_DELIMITER + "sub_0";
folder = imapService.getOrCreateMailbox(localUser, subSubFolderName, true, false);
fail("The folder still in the cache");
} catch (RuntimeException e) {
// expected
}
// Do manipulations with a content in the folder to check the cache behaviour
folder = imapService.getOrCreateMailbox(localUser, mailbox, true, false);
SimpleStoredMessage message = folder.getMessages().get(0);
AbstractMimeMessage alfrescoMessage = (AbstractMimeMessage) message.getMimeMessage();
long uid = message.getUid();
// System.out.println(" --------------------- DELETE FILE --------------------");
// System.out.println(" Parent " + folder.getFolderInfo().getNodeRef());
// Delete a content
fileFolderService.delete(alfrescoMessage.getMessageInfo().getNodeRef());
// Get a folder once again. We expect that the folder would be retrieved from the repo,
// since its' cache should be invalidated
folder = imapService.getOrCreateMailbox(localUser, mailbox, true, false);
// Additional check whether messages cache is valid. Messages cache should be recreated
// with the new inctance of AlfrescoImapMessage
assertTrue("Messages cache is stale", contentItemsCount > folder.getMessageCount());
long[] uids = folder.getMessageUids();
Arrays.sort(uids);
assertFalse("Messages msn cache is stale", Arrays.binarySearch(uids, uid) > 0);
assertNull("Message is still in the messages cache", folder.getMessage(uid));
// System.out.println(" --------------------- THE END --------------------");
fileFolderService.delete(localRootFolder.getNodeRef());
}
use of com.icegreen.greenmail.store.SimpleStoredMessage in project alfresco-repository by Alfresco.
the class ImapServiceImplTest method testMoveViaAppendAndDelete.
/**
* 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));
}
use of com.icegreen.greenmail.store.SimpleStoredMessage in project alfresco-repository by Alfresco.
the class ImapServiceImplTest method testMoveViaDeleteAndAppend.
/**
* Test for MNT-12259
* There is a 5s gap to run the test, see {@link ImapServiceImpl#hideAndDelete}
*
* @throws Exception
*/
public void testMoveViaDeleteAndAppend() 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.setAdminUserAsFullyAuthenticatedUser();
// 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);
// Save the message and ensure the message id is set
SimpleStoredMessage origMessage = imapService.getMessage(origFile);
origMessage.getMimeMessage().saveChanges();
imapService.setFlag(origFile, Flags.Flag.DELETED, true);
// Delete the node
imapService.expungeMessage(origFile);
// Append the message to destination
AlfrescoImapFolder destinationMailbox = imapService.getOrCreateMailbox(poweredUser, destinationPath, true, false);
destinationMailbox.appendMessage(origMessage.getMimeMessage(), flags, null);
// original message should be deleted or about to
assertTrue(!nodeService.exists(origFile.getNodeRef()) || imapService.getFlags(origFile).contains(Flags.Flag.DELETED));
// new file should be in destination
assertEquals("There should be only one node in the destination folder", 1, nodeService.getChildAssocs(destinationNode.getNodeRef()).size());
NodeRef newNodeRef = nodeService.getChildAssocs(destinationNode.getNodeRef()).get(0).getChildRef();
FileInfo newNodeFileInfo = fileFolderService.getFileInfo(newNodeRef);
assertEquals("The file name should not change.", fileName, newNodeFileInfo.getName());
ContentReader reader = contentService.getReader(newNodeRef, ContentModel.PROP_CONTENT);
String contentString = reader.getContentString();
// new file content should be the same as original one
assertEquals(contentString, nodeContent);
}
Aggregations