mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Merged DEV/SWIFT to HEAD (FTP Tests, Tika and Poi)
26059: ALF-5900 - IMAP creates winmail.dat in attachment folder (Add support for Microsoft Transport Neutral Encapsulation Format.) - added attachment extraction for TNEF documents - goodbye winmail.dat ! 26063: javadoc for imap. 26088: ALF-7408 - addition of commons-net for ftp client library. First test of end to end ftp. Just a simple test of connection now, will be followed by more detailed tests. 26176: ALF-7408 - FTP tests + disabled failing test case for ALF-7618 26180: ALF-7618 - correction of unit test error. 26188: ALF-7618 - added a test of paths 26229: Added back simple '\~.*' pattern 26288: ALF-7676 - Test to stress different user rights. - FTPServerTest.testTwoUserUpdate added for the FTP server. 26304: Corrected spelling name in private class. 26408: addming minimal package infos. 26416: ALF-5082 / ALF-2183 / ALF-4448 - When guessing the mimetype for a file, add the option to supply a ContentReader to enhance the accuracy. Enable this for a few key places that do mimetype guessing, which should avoid issues for files with the wrong extension (either renamed accidently, or for .TMP) 26433: Re-order the mimetype guess step to ensure that the Content Reader is always valid 26440: Added another test for word 2003 save as. 26441: Test resource for ContentDiskDriver 26446: ALF-5082 - Back out a FileFolderService change to mimetype guessing, which had broken things, pending a better way to do it with ContentWriter 26490: Small change for ContentDiskDriverTes.fileExists. Leaky transaction causing problems in automated build. 26497: ContentDiskDriver - commented out two of the problematic leaky transaction tests. 26503: Add new interface methods + documentation for asking a ContentWriter to guess the mimetype and encoding for you. (Code will be migrated from places that currently do this themselves later) 26504: Add an extension interface in the DataModel project for some of the extra ContentReader methods that FileContentReader provides 26505: When ContentWriter.putContent(String) is called with no encoding specified, record what the system default encoding was that was used. (Prevents issues if the system default is ever changed) 26509: When calling Tika to do file detection, if we have a file based reader then give Tika the File rather than an InputStream 26522: More debug logging while debugging ALF-5260 26546: Have one copy of the Tika Config in spring, rather than several places fetching their own copy of the default one (either explicitly or implicitly). 26522: More debug logging while diagnosing ALF-5260 26548: Add another mimetype check - ensures that truncated/corrup container files which can't be fully processed can still get the container type without failure 26549: Implement the mimetype and encoding guessers on ContentWriter (either immediately or as a listener, as required), and update FileFolderServer to make use of this (+test this) 26553: Replace explicit mimetype and encoding guess calls with ContentWriter requests to have the work done 26554: Replace explicit mimetype and encoding guess calls with ContentWriter requests to have the work done 26579: Switch the transformer to use Tika git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@28224 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1065,100 +1065,11 @@ public class AlfrescoImapFolder extends AbstractImapFolder implements Serializab
|
||||
|
||||
if (extractAttachmentsEnabled)
|
||||
{
|
||||
extractAttachments(folderFileInfo, messageFile, message);
|
||||
imapService.extractAttachments(folderFileInfo.getNodeRef(), messageFile.getNodeRef(), message);
|
||||
}
|
||||
return new IncomingImapMessage(messageFile, serviceRegistry, message);
|
||||
}
|
||||
|
||||
private void extractAttachments(
|
||||
FileInfo parentFolder,
|
||||
FileInfo messageFile,
|
||||
MimeMessage originalMessage)
|
||||
throws IOException, MessagingException
|
||||
{
|
||||
NodeService nodeService = serviceRegistry.getNodeService();
|
||||
FileFolderService fileFolderService = serviceRegistry.getFileFolderService();
|
||||
|
||||
String messageName = (String)nodeService.getProperty(messageFile.getNodeRef(), ContentModel.PROP_NAME);
|
||||
String attachmentsFolderName = messageName + "-attachments";
|
||||
FileInfo attachmentsFolderFileInfo = null;
|
||||
Object content = originalMessage.getContent();
|
||||
if (content instanceof Multipart)
|
||||
{
|
||||
Multipart multipart = (Multipart) content;
|
||||
|
||||
for (int i = 0, n = multipart.getCount(); i < n; i++)
|
||||
{
|
||||
Part part = multipart.getBodyPart(i);
|
||||
if ("attachment".equalsIgnoreCase(part.getDisposition()))
|
||||
{
|
||||
if (attachmentsFolderFileInfo == null)
|
||||
{
|
||||
attachmentsFolderFileInfo = fileFolderService.create(
|
||||
parentFolder.getNodeRef(),
|
||||
attachmentsFolderName,
|
||||
ContentModel.TYPE_FOLDER);
|
||||
serviceRegistry.getNodeService().createAssociation(
|
||||
messageFile.getNodeRef(),
|
||||
attachmentsFolderFileInfo.getNodeRef(),
|
||||
ImapModel.ASSOC_IMAP_ATTACHMENTS_FOLDER);
|
||||
}
|
||||
createAttachment(messageFile, attachmentsFolderFileInfo, part);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void createAttachment(FileInfo messageFile, FileInfo attachmentsFolderFileInfo, Part part) throws MessagingException, IOException
|
||||
{
|
||||
String fileName = part.getFileName();
|
||||
try
|
||||
{
|
||||
fileName = MimeUtility.decodeText(fileName);
|
||||
}
|
||||
catch (UnsupportedEncodingException e)
|
||||
{
|
||||
if (logger.isWarnEnabled())
|
||||
{
|
||||
logger.warn("Cannot decode file name '" + fileName + "'", e);
|
||||
}
|
||||
}
|
||||
|
||||
ContentType contentType = new ContentType(part.getContentType());
|
||||
FileFolderService fileFolderService = serviceRegistry.getFileFolderService();
|
||||
List<FileInfo> result = fileFolderService.search(attachmentsFolderFileInfo.getNodeRef(), fileName, false);
|
||||
// The one possible behaviour
|
||||
/*
|
||||
if (result.size() > 0)
|
||||
{
|
||||
for (FileInfo fi : result)
|
||||
{
|
||||
fileFolderService.delete(fi.getNodeRef());
|
||||
}
|
||||
}
|
||||
*/
|
||||
// And another one behaviour which will overwrite the content of the existing file. It is performance preferable.
|
||||
FileInfo attachmentFile = null;
|
||||
if (result.size() == 0)
|
||||
{
|
||||
FileInfo createdFile = fileFolderService.create(
|
||||
attachmentsFolderFileInfo.getNodeRef(),
|
||||
fileName,
|
||||
ContentModel.TYPE_CONTENT);
|
||||
serviceRegistry.getNodeService().createAssociation(
|
||||
messageFile.getNodeRef(),
|
||||
createdFile.getNodeRef(),
|
||||
ImapModel.ASSOC_IMAP_ATTACHMENT);
|
||||
result.add(createdFile);
|
||||
}
|
||||
attachmentFile = result.get(0);
|
||||
ContentWriter writer = fileFolderService.getWriter(attachmentFile.getNodeRef());
|
||||
writer.setMimetype(contentType.getBaseType());
|
||||
OutputStream os = writer.getContentOutputStream();
|
||||
FileCopyUtils.copy(part.getInputStream(), os);
|
||||
}
|
||||
|
||||
|
||||
private void removeMessageFromCache(long uid)
|
||||
{
|
||||
messages.remove(uid);
|
||||
|
@@ -18,10 +18,13 @@
|
||||
*/
|
||||
package org.alfresco.repo.imap;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import javax.mail.Flags;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.Flags.Flag;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
|
||||
import org.alfresco.repo.imap.AlfrescoImapConst.ImapViewMode;
|
||||
import org.alfresco.service.cmr.model.FileInfo;
|
||||
@@ -261,4 +264,20 @@ public interface ImapService
|
||||
*/
|
||||
public boolean isNodeInSitesLibrary(NodeRef nodeRef);
|
||||
|
||||
|
||||
/**
|
||||
* Extract Attachments
|
||||
*
|
||||
* @param parentFolder
|
||||
* @param messageFile the node ref of the message.
|
||||
* @param originalMessage
|
||||
* @throws IOException
|
||||
* @throws MessagingException
|
||||
*/
|
||||
public NodeRef extractAttachments(
|
||||
NodeRef parentFolder,
|
||||
NodeRef messageFile,
|
||||
MimeMessage originalMessage)
|
||||
throws IOException, MessagingException;
|
||||
|
||||
}
|
||||
|
@@ -20,7 +20,11 @@ package org.alfresco.repo.imap;
|
||||
|
||||
import static org.alfresco.repo.imap.AlfrescoImapConst.DICTIONARY_TEMPLATE_PREFIX;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.io.Serializable;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
@@ -34,6 +38,12 @@ import java.util.Set;
|
||||
|
||||
import javax.mail.Flags;
|
||||
import javax.mail.Flags.Flag;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.Multipart;
|
||||
import javax.mail.Part;
|
||||
import javax.mail.internet.ContentType;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
import javax.mail.internet.MimeUtility;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
@@ -64,7 +74,9 @@ import org.alfresco.service.cmr.model.FileInfo;
|
||||
import org.alfresco.service.cmr.model.SubFolderFilter;
|
||||
import org.alfresco.service.cmr.preference.PreferenceService;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
|
||||
import org.alfresco.service.cmr.repository.MimetypeService;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
@@ -80,9 +92,11 @@ import org.alfresco.util.Utf7;
|
||||
import org.alfresco.util.config.RepositoryFolderConfigBean;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.poi.hmef.HMEFMessage;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
import org.springframework.extensions.surf.util.AbstractLifecycleBean;
|
||||
import org.springframework.extensions.surf.util.I18NUtil;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
/**
|
||||
* @author Dmitry Vaserin
|
||||
@@ -108,6 +122,7 @@ public class ImapServiceImpl implements ImapService, OnCreateChildAssociationPol
|
||||
private PermissionService permissionService;
|
||||
private ServiceRegistry serviceRegistry;
|
||||
private BehaviourFilter policyBehaviourFilter;
|
||||
private MimetypeService mimetypeService;
|
||||
|
||||
/**
|
||||
* Folders cache
|
||||
@@ -201,11 +216,6 @@ public class ImapServiceImpl implements ImapService, OnCreateChildAssociationPol
|
||||
this.foldersCache = foldersCache;
|
||||
}
|
||||
|
||||
public SimpleCache<Serializable, Object> getFoldersCache()
|
||||
{
|
||||
return foldersCache;
|
||||
}
|
||||
|
||||
public FileFolderService getFileFolderService()
|
||||
{
|
||||
return fileFolderService;
|
||||
@@ -216,9 +226,9 @@ public class ImapServiceImpl implements ImapService, OnCreateChildAssociationPol
|
||||
this.fileFolderService = fileFolderService;
|
||||
}
|
||||
|
||||
public NodeService getNodeService()
|
||||
public void setMimetypeService(MimetypeService mimetypeService)
|
||||
{
|
||||
return nodeService;
|
||||
this.mimetypeService = mimetypeService;
|
||||
}
|
||||
|
||||
public void setNodeService(NodeService nodeService)
|
||||
@@ -226,21 +236,11 @@ public class ImapServiceImpl implements ImapService, OnCreateChildAssociationPol
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
public PermissionService getPermissionService()
|
||||
{
|
||||
return permissionService;
|
||||
}
|
||||
|
||||
public void setPermissionService(PermissionService permissionService)
|
||||
{
|
||||
this.permissionService = permissionService;
|
||||
}
|
||||
|
||||
public ServiceRegistry getServiceRegistry()
|
||||
{
|
||||
return serviceRegistry;
|
||||
}
|
||||
|
||||
public void setServiceRegistry(ServiceRegistry serviceRegistry)
|
||||
{
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
@@ -320,6 +320,7 @@ public class ImapServiceImpl implements ImapService, OnCreateChildAssociationPol
|
||||
PropertyCheck.mandatory(this, "defaultFromAddress", defaultFromAddress);
|
||||
PropertyCheck.mandatory(this, "repositoryTemplatePath", repositoryTemplatePath);
|
||||
PropertyCheck.mandatory(this, "policyBehaviourFilter", policyBehaviourFilter);
|
||||
PropertyCheck.mandatory(this, "mimetypeService", mimetypeService);
|
||||
}
|
||||
|
||||
public void startup()
|
||||
@@ -900,7 +901,7 @@ public class ImapServiceImpl implements ImapService, OnCreateChildAssociationPol
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("[searchByPattern] Start. nodeRef=" + contextNodeRef + ", namePattern=" + namePattern);
|
||||
logger.debug("[searchByPattern] Start. nodeRef=" + contextNodeRef + ", viewMode=" + viewMode + " namePattern=" + namePattern);
|
||||
}
|
||||
|
||||
List<FileInfo> searchResult;
|
||||
@@ -913,13 +914,13 @@ public class ImapServiceImpl implements ImapService, OnCreateChildAssociationPol
|
||||
/**
|
||||
* This is a simple listing of all folders below contextNodeRef
|
||||
*/
|
||||
logger.debug("call file folder service to list folders");
|
||||
|
||||
searchResult = fileFolderService.listFolders(contextNodeRef);
|
||||
}
|
||||
else
|
||||
{
|
||||
// MER TODO I'm not sure we ever get here in real use of IMAP. But if we do then the use of this
|
||||
// deprecated method needs to be re-worked.
|
||||
// searchResult = fileFolderService.search(contextNodeRef, namePattern, false, true, false);
|
||||
logger.debug("call listDeepFolders");
|
||||
searchResult = fileFolderService.listDeepFolders(contextNodeRef, new ImapSubFolderFilter(viewMode, namePattern));
|
||||
}
|
||||
|
||||
@@ -1000,7 +1001,10 @@ public class ImapServiceImpl implements ImapService, OnCreateChildAssociationPol
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("[searchByPattern] End. namePattern=" + namePattern);
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("[searchByPattern] End. nodeRef=" + contextNodeRef + ", viewMode=" + viewMode + ", namePattern=" + namePattern + ", searchResult=" +searchResult.size());
|
||||
}
|
||||
}
|
||||
|
||||
return searchResult;
|
||||
@@ -1271,7 +1275,7 @@ public class ImapServiceImpl implements ImapService, OnCreateChildAssociationPol
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("List folder: mailboxPattern=" + mailboxPattern);
|
||||
logger.debug("expand folder: root:" + root + " user: " + user + " :mailboxPattern=" + mailboxPattern);
|
||||
}
|
||||
if (mailboxPattern == null)
|
||||
return null;
|
||||
@@ -2015,7 +2019,7 @@ public class ImapServiceImpl implements ImapService, OnCreateChildAssociationPol
|
||||
ImapSubFolderFilter(ImapViewMode imapViewMode)
|
||||
{
|
||||
this.imapViewMode = imapViewMode;
|
||||
this.typesToExclude = getServiceRegistry().getDictionaryService().getSubTypes(SiteModel.TYPE_SITE, true);
|
||||
this.typesToExclude = serviceRegistry.getDictionaryService().getSubTypes(SiteModel.TYPE_SITE, true);
|
||||
this.favs = getFavouriteSites(getCurrentUser());
|
||||
}
|
||||
|
||||
@@ -2192,5 +2196,173 @@ public class ImapServiceImpl implements ImapService, OnCreateChildAssociationPol
|
||||
{
|
||||
return nodeService.getType(parent).equals(SiteModel.TYPE_SITE) && isInDocLibrary;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract attachments from a MimeMessage
|
||||
*
|
||||
* Puts the attachments into a subfolder below the parent folder.
|
||||
*
|
||||
* @return the node ref of the folder containing the attachments or null if there are no
|
||||
* attachments.
|
||||
*/
|
||||
public NodeRef extractAttachments(
|
||||
NodeRef parentFolder,
|
||||
NodeRef messageFile,
|
||||
MimeMessage originalMessage)
|
||||
throws IOException, MessagingException
|
||||
{
|
||||
|
||||
String messageName = (String)nodeService.getProperty(messageFile, ContentModel.PROP_NAME);
|
||||
String attachmentsFolderName = messageName + "-attachments";
|
||||
FileInfo attachmentsFolderFileInfo = null;
|
||||
Object content = originalMessage.getContent();
|
||||
if (content instanceof Multipart)
|
||||
{
|
||||
Multipart multipart = (Multipart) content;
|
||||
|
||||
for (int i = 0, n = multipart.getCount(); i < n; i++)
|
||||
{
|
||||
Part part = multipart.getBodyPart(i);
|
||||
|
||||
if ("attachment".equalsIgnoreCase(part.getDisposition()))
|
||||
{
|
||||
if (attachmentsFolderFileInfo == null)
|
||||
{
|
||||
attachmentsFolderFileInfo = fileFolderService.create(
|
||||
parentFolder,
|
||||
attachmentsFolderName,
|
||||
ContentModel.TYPE_FOLDER);
|
||||
nodeService.createAssociation(
|
||||
messageFile,
|
||||
attachmentsFolderFileInfo.getNodeRef(),
|
||||
ImapModel.ASSOC_IMAP_ATTACHMENTS_FOLDER);
|
||||
}
|
||||
createAttachment(messageFile, attachmentsFolderFileInfo.getNodeRef(), part);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(attachmentsFolderFileInfo != null)
|
||||
{
|
||||
return attachmentsFolderFileInfo.getNodeRef();
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an attachment given a mime part
|
||||
*
|
||||
* @param messageFile the file containing the message
|
||||
* @param destinationFolder where to put the attachment
|
||||
* @param part the mime part
|
||||
*
|
||||
* @throws MessagingException
|
||||
* @throws IOException
|
||||
*/
|
||||
private void createAttachment(NodeRef messageFile, NodeRef destinationFolder, Part part) throws MessagingException, IOException
|
||||
{
|
||||
String fileName = part.getFileName();
|
||||
try
|
||||
{
|
||||
fileName = MimeUtility.decodeText(fileName);
|
||||
}
|
||||
catch (UnsupportedEncodingException e)
|
||||
{
|
||||
if (logger.isWarnEnabled())
|
||||
{
|
||||
logger.warn("Cannot decode file name '" + fileName + "'", e);
|
||||
}
|
||||
}
|
||||
|
||||
ContentType contentType = new ContentType(part.getContentType());
|
||||
|
||||
if(contentType.getBaseType().equalsIgnoreCase("application/ms-tnef"))
|
||||
{
|
||||
// The content is TNEF
|
||||
HMEFMessage hmef = new HMEFMessage(part.getInputStream());
|
||||
|
||||
//hmef.getBody();
|
||||
List<org.apache.poi.hmef.Attachment> attachments = hmef.getAttachments();
|
||||
for(org.apache.poi.hmef.Attachment attachment : attachments)
|
||||
{
|
||||
String subName = attachment.getLongFilename();
|
||||
|
||||
NodeRef attachmentNode = fileFolderService.searchSimple(destinationFolder, subName);
|
||||
if (attachmentNode == null)
|
||||
{
|
||||
/*
|
||||
* If the node with the given name does not already exist
|
||||
* Create the content node to contain the attachment
|
||||
*/
|
||||
FileInfo createdFile = fileFolderService.create(
|
||||
destinationFolder,
|
||||
subName,
|
||||
ContentModel.TYPE_CONTENT);
|
||||
|
||||
attachmentNode = createdFile.getNodeRef();
|
||||
|
||||
serviceRegistry.getNodeService().createAssociation(
|
||||
messageFile,
|
||||
attachmentNode,
|
||||
ImapModel.ASSOC_IMAP_ATTACHMENT);
|
||||
|
||||
|
||||
byte[] bytes = attachment.getContents();
|
||||
ContentWriter writer = fileFolderService.getWriter(attachmentNode);
|
||||
|
||||
//TODO ENCODING - attachment.getAttribute(TNEFProperty.);
|
||||
String extension = attachment.getExtension();
|
||||
String mimetype = mimetypeService.getMimetype(extension);
|
||||
if(mimetype != null)
|
||||
{
|
||||
writer.setMimetype(mimetype);
|
||||
}
|
||||
|
||||
OutputStream os = writer.getContentOutputStream();
|
||||
ByteArrayInputStream is = new ByteArrayInputStream(bytes);
|
||||
FileCopyUtils.copy(is, os);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// not TNEF
|
||||
NodeRef attachmentNode = fileFolderService.searchSimple(destinationFolder, fileName);
|
||||
if (attachmentNode == null)
|
||||
{
|
||||
/*
|
||||
* If the node with the given name does not already exist
|
||||
* Create the content node to contain the attachment
|
||||
*/
|
||||
FileInfo createdFile = fileFolderService.create(
|
||||
destinationFolder,
|
||||
fileName,
|
||||
ContentModel.TYPE_CONTENT);
|
||||
|
||||
attachmentNode = createdFile.getNodeRef();
|
||||
|
||||
serviceRegistry.getNodeService().createAssociation(
|
||||
messageFile,
|
||||
attachmentNode,
|
||||
ImapModel.ASSOC_IMAP_ATTACHMENT);
|
||||
|
||||
|
||||
// the part is a normal IMAP attachment
|
||||
ContentWriter writer = fileFolderService.getWriter(attachmentNode);
|
||||
writer.setMimetype(contentType.getBaseType());
|
||||
|
||||
String charset = contentType.getParameter("charset");
|
||||
if(charset != null)
|
||||
{
|
||||
writer.setEncoding(charset);
|
||||
}
|
||||
|
||||
OutputStream os = writer.getContentOutputStream();
|
||||
FileCopyUtils.copy(part.getInputStream(), os);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -18,13 +18,18 @@
|
||||
*/
|
||||
package org.alfresco.repo.imap;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.mail.Flags;
|
||||
import javax.mail.Session;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
import javax.transaction.UserTransaction;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
@@ -37,10 +42,12 @@ import org.alfresco.repo.importer.ACPImportPackageHandler;
|
||||
import org.alfresco.repo.management.subsystems.ChildApplicationContextFactory;
|
||||
import org.alfresco.repo.model.filefolder.FileFolderServiceImpl;
|
||||
import org.alfresco.repo.node.integrity.IntegrityChecker;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.permissions.AccessDeniedException;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.model.FileFolderService;
|
||||
import org.alfresco.service.cmr.model.FileInfo;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.repository.StoreRef;
|
||||
@@ -55,7 +62,6 @@ import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.service.transaction.TransactionService;
|
||||
import org.alfresco.util.ApplicationContextHelper;
|
||||
import org.alfresco.util.PropertyMap;
|
||||
import org.alfresco.util.Utf7;
|
||||
import org.alfresco.util.config.RepositoryFolderConfigBean;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
@@ -285,18 +291,24 @@ public class ImapServiceImplTest extends TestCase
|
||||
assertTrue("folder A found", foundA);
|
||||
assertTrue("folder B found", foundB);
|
||||
|
||||
mf = imapService.listMailboxes(user, MAILBOX_PATTERN);
|
||||
assertEquals("can't repeat the listing of folders", 2, mf.size());
|
||||
|
||||
mf = imapService.listMailboxes(user, MAILBOX_PATTERN);
|
||||
assertEquals("can't repeat the listing of folders", 2, mf.size());
|
||||
|
||||
/**
|
||||
* The new mailboxes should be subscribed?
|
||||
*/
|
||||
List<AlfrescoImapFolder> aif = imapService.listSubscribedMailboxes(user, MAILBOX_PATTERN);
|
||||
assertEquals(2, aif.size());
|
||||
assertEquals("not subscribed to two mailboxes", 2, aif.size());
|
||||
|
||||
/**
|
||||
* Unsubscribe to one of the mailboxes.
|
||||
*/
|
||||
imapService.unsubscribe(user, MAILBOX_NAME_B);
|
||||
List<AlfrescoImapFolder> aif2 = imapService.listSubscribedMailboxes(user, MAILBOX_PATTERN);
|
||||
assertEquals(1, aif2.size());
|
||||
assertEquals("not subscribed to one mailbox", 1, aif2.size());
|
||||
}
|
||||
|
||||
public void testListSubscribedMailbox() throws Exception
|
||||
@@ -514,8 +526,8 @@ public class ImapServiceImplTest extends TestCase
|
||||
|
||||
public void testRenameAccentedMailbox() throws Exception
|
||||
{
|
||||
String MAILBOX_ACCENTED_NAME_A = "H<EFBFBD>tel";
|
||||
String MAILBOX_ACCENTED_NAME_B = "H<EFBFBD>telXX";
|
||||
String MAILBOX_ACCENTED_NAME_A = "H<EFBFBD>tel";
|
||||
String MAILBOX_ACCENTED_NAME_B = "H<EFBFBD>telXX";
|
||||
|
||||
imapService.createMailbox(user, MAILBOX_ACCENTED_NAME_A);
|
||||
imapService.deleteMailbox(user, MAILBOX_ACCENTED_NAME_A);
|
||||
@@ -526,4 +538,45 @@ public class ImapServiceImplTest extends TestCase
|
||||
assertTrue("Can't rename mailbox", checkMailbox(user, MAILBOX_ACCENTED_NAME_B));
|
||||
imapService.deleteMailbox(user, MAILBOX_ACCENTED_NAME_B);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test attachment extraction with a TNEF message
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testAttachmentExtraction() throws Exception
|
||||
{
|
||||
AuthenticationUtil.setRunAsUserSystem();
|
||||
/**
|
||||
* Load a TNEF message
|
||||
*/
|
||||
ClassPathResource fileResource = new ClassPathResource("imap/test-tnef-message.eml");
|
||||
assertNotNull("unable to find test resource test-tnef-message.eml", fileResource);
|
||||
InputStream is = new FileInputStream(fileResource.getFile());
|
||||
MimeMessage message = new MimeMessage(Session.getDefaultInstance(new Properties()), is);
|
||||
|
||||
/**
|
||||
* Create a test node containing the message
|
||||
*/
|
||||
String storePath = "workspace://SpacesStore";
|
||||
String companyHomePathInStore = "/app:company_home";
|
||||
StoreRef storeRef = new StoreRef(storePath);
|
||||
NodeRef storeRootNodeRef = nodeService.getRootNode(storeRef);
|
||||
|
||||
List<NodeRef> nodeRefs = searchService.selectNodes(storeRootNodeRef, companyHomePathInStore, null, namespaceService, false);
|
||||
NodeRef companyHomeNodeRef = nodeRefs.get(0);
|
||||
|
||||
FileInfo f1 = fileFolderService.create(companyHomeNodeRef, "ImapServiceImplTest", ContentModel.TYPE_FOLDER);
|
||||
FileInfo d2 = fileFolderService.create(f1.getNodeRef(), "ImapServiceImplTest", ContentModel.TYPE_FOLDER);
|
||||
FileInfo f2 = fileFolderService.create(f1.getNodeRef(), "test-tnef-message.eml", ContentModel.TYPE_CONTENT);
|
||||
|
||||
ContentWriter writer = fileFolderService.getWriter(f2.getNodeRef());
|
||||
writer.putContent(new FileInputStream(fileResource.getFile()));
|
||||
|
||||
NodeRef folder = imapService.extractAttachments(f1.getNodeRef(), f2.getNodeRef(), message);
|
||||
assertNotNull(folder);
|
||||
|
||||
List<FileInfo> files = fileFolderService.listFiles(folder);
|
||||
assertTrue("three files not found", files.size() == 3);
|
||||
|
||||
}
|
||||
}
|
||||
|
17
source/java/org/alfresco/repo/imap/package-info.java
Normal file
17
source/java/org/alfresco/repo/imap/package-info.java
Normal file
@@ -0,0 +1,17 @@
|
||||
/**
|
||||
* The implementation of the Alfresco Imap Server
|
||||
*
|
||||
* <p>
|
||||
* AlfrescoImapServer which implements the IMAP protocol. It contains an instance of the Ice Green ImapServer and delegates imap commands to
|
||||
* AlfrescoImapHostManager and AlfrescoImapUserManager. AlfrescoImapHostManager in turn delegates to ImapService and AlfrescoImapUserManager uses the PersonService.
|
||||
*
|
||||
* <p>
|
||||
* ImapServiceImpl provides the implementation of the various IMAP commands on an alfresco repository. Also contains the transaction and security boundary.
|
||||
*
|
||||
* <p>
|
||||
* AlfrescoImapFolder contains the implementation of IMAPFolders and contains messages.
|
||||
*
|
||||
* @since 3.2
|
||||
*
|
||||
*/
|
||||
package org.alfresco.repo.imap;
|
Reference in New Issue
Block a user