Search in sources :

Example 1 with SimpleStoredMessage

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;
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) SimpleStoredMessage(com.icegreen.greenmail.store.SimpleStoredMessage) Date(java.util.Date)

Example 2 with SimpleStoredMessage

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);
}
Also used : SimpleStoredMessage(com.icegreen.greenmail.store.SimpleStoredMessage)

Example 3 with SimpleStoredMessage

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());
}
Also used : FileInfo(org.alfresco.service.cmr.model.FileInfo) ArrayList(java.util.ArrayList) SimpleStoredMessage(com.icegreen.greenmail.store.SimpleStoredMessage)

Example 4 with SimpleStoredMessage

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));
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) FileInfo(org.alfresco.service.cmr.model.FileInfo) SimpleStoredMessage(com.icegreen.greenmail.store.SimpleStoredMessage)

Example 5 with SimpleStoredMessage

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);
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) ContentWriter(org.alfresco.service.cmr.repository.ContentWriter) FileInfo(org.alfresco.service.cmr.model.FileInfo) ContentReader(org.alfresco.service.cmr.repository.ContentReader) SimpleStoredMessage(com.icegreen.greenmail.store.SimpleStoredMessage)

Aggregations

SimpleStoredMessage (com.icegreen.greenmail.store.SimpleStoredMessage)7 NodeRef (org.alfresco.service.cmr.repository.NodeRef)4 FileInfo (org.alfresco.service.cmr.model.FileInfo)3 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 ContentWriter (org.alfresco.service.cmr.repository.ContentWriter)2 IOException (java.io.IOException)1 LinkedList (java.util.LinkedList)1 Flags (javax.mail.Flags)1 UserTransaction (javax.transaction.UserTransaction)1 ChildApplicationContextFactory (org.alfresco.repo.management.subsystems.ChildApplicationContextFactory)1 ServiceRegistry (org.alfresco.service.ServiceRegistry)1 FileFolderService (org.alfresco.service.cmr.model.FileFolderService)1 ContentReader (org.alfresco.service.cmr.repository.ContentReader)1 NodeService (org.alfresco.service.cmr.repository.NodeService)1 StoreRef (org.alfresco.service.cmr.repository.StoreRef)1 SearchService (org.alfresco.service.cmr.search.SearchService)1 PermissionService (org.alfresco.service.cmr.security.PermissionService)1 PersonService (org.alfresco.service.cmr.security.PersonService)1 NamespaceService (org.alfresco.service.namespace.NamespaceService)1