mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-24 17:32:48 +00:00
Email Server and EmailService in a working state.
- Fixed authentication - Fixed I18N - Fixed mimetype and encoding issues Changed 'avm' remote ports and hosts to be 'alfresco.rmi.services' as the 'avm' was starting to creep into non-avm stuff. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@7281 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -24,26 +24,28 @@
|
||||
*/
|
||||
package org.alfresco.email.server.handler;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.Serializable;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.email.server.EmailServerModel;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationComponent;
|
||||
import org.alfresco.repo.content.encoding.ContentCharsetFinder;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.cmr.email.EmailMessage;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
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;
|
||||
import org.alfresco.service.cmr.search.ResultSet;
|
||||
import org.alfresco.service.cmr.search.SearchService;
|
||||
import org.alfresco.service.cmr.security.AuthenticationService;
|
||||
import org.alfresco.service.cmr.security.PersonService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@@ -60,17 +62,16 @@ public abstract class AbstractEmailMessageHandler implements EmailMessageHandler
|
||||
{
|
||||
private static final Log log = LogFactory.getLog(EmailMessageHandler.class);
|
||||
|
||||
private AuthenticationService authenticationService;
|
||||
private AuthenticationComponent authenticationComponent;
|
||||
private DictionaryService dictionaryService;
|
||||
private NodeService nodeService;
|
||||
private PersonService personService;
|
||||
private SearchService searchService;
|
||||
private ContentService contentService;
|
||||
private MimetypeService mimetypeService;
|
||||
|
||||
/**
|
||||
* @return Alfresco Content Service.
|
||||
*/
|
||||
public ContentService getContentService()
|
||||
protected ContentService getContentService()
|
||||
{
|
||||
return contentService;
|
||||
}
|
||||
@@ -84,41 +85,25 @@ public abstract class AbstractEmailMessageHandler implements EmailMessageHandler
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Alfresco Authentication Component.
|
||||
* @return the Alfresco dictionary service
|
||||
*/
|
||||
public AuthenticationComponent getAuthenticationComponent()
|
||||
protected DictionaryService getDictionaryService()
|
||||
{
|
||||
return authenticationComponent;
|
||||
return dictionaryService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param authenticationComponent Alfresco Authentication Component.
|
||||
* @param dictionaryService Alfresco dictionary service
|
||||
*/
|
||||
public void setAuthenticationComponent(AuthenticationComponent authenticationComponent)
|
||||
public void setDictionaryService(DictionaryService dictionaryService)
|
||||
{
|
||||
this.authenticationComponent = authenticationComponent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Alfresco Authentication Service.
|
||||
*/
|
||||
public AuthenticationService getAuthenticationService()
|
||||
{
|
||||
return authenticationService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param authenticationService Alfresco Authentication Service.
|
||||
*/
|
||||
public void setAuthenticationService(AuthenticationService authenticationService)
|
||||
{
|
||||
this.authenticationService = authenticationService;
|
||||
this.dictionaryService = dictionaryService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Alfresco Node Service.
|
||||
*/
|
||||
public NodeService getNodeService()
|
||||
protected NodeService getNodeService()
|
||||
{
|
||||
return nodeService;
|
||||
}
|
||||
@@ -131,39 +116,30 @@ public abstract class AbstractEmailMessageHandler implements EmailMessageHandler
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Alfesco Person Service.
|
||||
*/
|
||||
public PersonService getPersonService()
|
||||
{
|
||||
return personService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param personService Alfresco Person Service.
|
||||
*/
|
||||
public void setPersonService(PersonService personService)
|
||||
{
|
||||
this.personService = personService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Alfresco Search Service.
|
||||
*/
|
||||
public SearchService getSearchService()
|
||||
{
|
||||
return searchService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param searchService Alfresco Search Service.
|
||||
*/
|
||||
|
||||
public void setSearchService(SearchService searchService)
|
||||
{
|
||||
this.searchService = searchService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the service used to determine mimeypte and encoding
|
||||
*/
|
||||
protected MimetypeService getMimetypeService()
|
||||
{
|
||||
return mimetypeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mimetypeService the the service to determine mimetype and encoding
|
||||
*/
|
||||
public void setMimetypeService(MimetypeService mimetypeService)
|
||||
{
|
||||
this.mimetypeService = mimetypeService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param to Email address which user part specifies node-dbid
|
||||
* @return Referance to requested node.
|
||||
@@ -206,12 +182,12 @@ public abstract class AbstractEmailMessageHandler implements EmailMessageHandler
|
||||
*
|
||||
* @param nodeRef Target node.
|
||||
* @param content Text for writting.
|
||||
* @param contentType MIME content type. For exaple you can set this parameter to "text/html" or "text/xml", etc.
|
||||
* @param mimetype MIME content type. For exaple you can set this parameter to "text/html" or "text/xml", etc.
|
||||
*/
|
||||
protected void writeContent(NodeRef nodeRef, String content, String contentType)
|
||||
protected void writeContent(NodeRef nodeRef, String content, String mimetype)
|
||||
{
|
||||
InputStream inputStream = new ByteArrayInputStream(content.getBytes());
|
||||
writeContent(nodeRef, inputStream, contentType, "UTF-8");
|
||||
InputStream inputStream = new ByteArrayInputStream(content.getBytes(Charset.forName("UTF-8")));
|
||||
writeContent(nodeRef, inputStream, mimetype, "UTF-8");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -219,20 +195,35 @@ public abstract class AbstractEmailMessageHandler implements EmailMessageHandler
|
||||
*
|
||||
* @param nodeRef Target node.
|
||||
* @param content Content stream.
|
||||
* @param contentType MIME content type.
|
||||
* @param mimetype MIME content type.
|
||||
* @param encoding Encoding. Can be null for non text based content.
|
||||
*/
|
||||
protected void writeContent(NodeRef nodeRef, InputStream content, String contentType, String encoding)
|
||||
protected void writeContent(NodeRef nodeRef, InputStream content, String mimetype, String encoding)
|
||||
{
|
||||
InputStream bis = new BufferedInputStream(content, 4092);
|
||||
|
||||
// Guess the encoding if it is text
|
||||
if (mimetypeService.isText(mimetype))
|
||||
{
|
||||
ContentCharsetFinder charsetFinder = mimetypeService.getContentCharsetFinder();
|
||||
encoding = charsetFinder.getCharset(bis, mimetype).name();
|
||||
}
|
||||
else if (encoding == null)
|
||||
{
|
||||
encoding = "UTF-8";
|
||||
}
|
||||
|
||||
if (log.isDebugEnabled())
|
||||
{
|
||||
log.debug("Write content (MimeType=\"" + contentType + "\", Encoding=\"" + encoding + "\"");
|
||||
log.debug("Write content (MimeType=\"" + mimetype + "\", Encoding=\"" + encoding + "\"");
|
||||
}
|
||||
|
||||
|
||||
ContentService contentService = getContentService();
|
||||
ContentWriter writer = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
|
||||
writer.setMimetype(contentType);
|
||||
writer.setMimetype(mimetype);
|
||||
writer.setEncoding(encoding);
|
||||
writer.putContent(content);
|
||||
writer.putContent(bis);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -41,6 +41,7 @@ import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.namespace.NamespaceService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.PropertyMap;
|
||||
|
||||
/**
|
||||
* Abstact class implements common logic for forum processing email mesages.
|
||||
@@ -62,12 +63,20 @@ public abstract class AbstractForumEmailMessageHandler extends AbstractEmailMess
|
||||
Date now = new Date();
|
||||
String nodeName = "posted-" + new SimpleDateFormat("dd-MM-yyyy-hh-mm-ss").format(now) + ".html";
|
||||
|
||||
Map<QName, Serializable> properties = new HashMap<QName, Serializable>(1);
|
||||
PropertyMap properties = new PropertyMap(3);
|
||||
properties.put(ContentModel.PROP_NAME, nodeName);
|
||||
|
||||
ChildAssociationRef childAssoc = nodeService.createNode(nodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, nodeName),
|
||||
ForumModel.TYPE_POST, properties);
|
||||
NodeRef postNode = childAssoc.getChildRef();
|
||||
NodeRef postNode = nodeService.getChildByName(nodeRef, ContentModel.ASSOC_CONTAINS, nodeName);
|
||||
if (postNode == null)
|
||||
{
|
||||
ChildAssociationRef childAssoc = nodeService.createNode(
|
||||
nodeRef,
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, nodeName),
|
||||
ForumModel.TYPE_POST,
|
||||
properties);
|
||||
postNode = childAssoc.getChildRef();
|
||||
}
|
||||
|
||||
// Add necessary aspects
|
||||
properties.clear();
|
||||
@@ -116,26 +125,34 @@ public abstract class AbstractForumEmailMessageHandler extends AbstractEmailMess
|
||||
/**
|
||||
* Adds topic node into Alfresco repository
|
||||
*
|
||||
* @param parentNode Parent node
|
||||
* @param name Topic name
|
||||
* @return Reference to created node
|
||||
* @param parentNode Parent node
|
||||
* @param name Topic name
|
||||
* @return Reference to created node
|
||||
*/
|
||||
protected NodeRef addTopicNode(NodeRef parentNode, String name)
|
||||
{
|
||||
|
||||
NodeService nodeService = getNodeService();
|
||||
Map<QName, Serializable> properties = new HashMap<QName, Serializable>(1);
|
||||
properties.put(ContentModel.PROP_NAME, name);
|
||||
|
||||
ChildAssociationRef association = getNodeService().createNode(parentNode, ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, name),
|
||||
ForumModel.TYPE_TOPIC, properties);
|
||||
NodeRef topic = association.getChildRef();
|
||||
NodeRef topicNode = nodeService.getChildByName(parentNode, ContentModel.ASSOC_CONTAINS, name);
|
||||
if (topicNode == null)
|
||||
{
|
||||
ChildAssociationRef association = nodeService.createNode(
|
||||
parentNode,
|
||||
ContentModel.ASSOC_CONTAINS,
|
||||
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, name),
|
||||
ForumModel.TYPE_TOPIC,
|
||||
properties);
|
||||
topicNode = association.getChildRef();
|
||||
}
|
||||
|
||||
// Add necessary aspects
|
||||
properties.clear();
|
||||
properties.put(ApplicationModel.PROP_ICON, "topic");
|
||||
getNodeService().addAspect(topic, ApplicationModel.ASPECT_UIFACETS, properties);
|
||||
getNodeService().addAspect(topicNode, ApplicationModel.ASPECT_UIFACETS, properties);
|
||||
|
||||
return topic;
|
||||
return topicNode;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -30,12 +30,12 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.alfresco.i18n.I18NUtil;
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ApplicationModel;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.model.ForumModel;
|
||||
import org.alfresco.service.cmr.dictionary.DictionaryService;
|
||||
import org.alfresco.service.cmr.email.EmailMessage;
|
||||
import org.alfresco.service.cmr.email.EmailMessageException;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.NodeService;
|
||||
@@ -64,9 +64,10 @@ public class DocumentEmailMessageHandler extends AbstractForumEmailMessageHandle
|
||||
messageSubject = "EMPTY_SUBJECT_" + System.currentTimeMillis();
|
||||
}
|
||||
|
||||
QName contentType = getNodeService().getType(nodeRef);
|
||||
QName nodeTypeQName = getNodeService().getType(nodeRef);
|
||||
|
||||
if (contentType.equals(ContentModel.TYPE_CONTENT))
|
||||
DictionaryService dictionaryService = getDictionaryService();
|
||||
if (dictionaryService.isSubClass(nodeTypeQName, ContentModel.TYPE_CONTENT))
|
||||
{
|
||||
NodeRef forumNode = getForumNode(nodeRef);
|
||||
|
||||
@@ -87,7 +88,9 @@ public class DocumentEmailMessageHandler extends AbstractForumEmailMessageHandle
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new EmailMessageException(I18NUtil.getMessage("email.server.incorrect-node-type"));
|
||||
throw new AlfrescoRuntimeException("\n" +
|
||||
"Message handler " + this.getClass().getName() + " cannot handle type " + nodeTypeQName + ".\n" +
|
||||
"Check the message handler mappings.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +102,7 @@ public class DocumentEmailMessageHandler extends AbstractForumEmailMessageHandle
|
||||
*/
|
||||
private NodeRef addForumNode(NodeRef nodeRef)
|
||||
{
|
||||
NodeService nodeService=getNodeService();
|
||||
NodeService nodeService = getNodeService();
|
||||
//Add discussable aspect to content node
|
||||
if (!nodeService.hasAspect(nodeRef, ForumModel.ASPECT_DISCUSSABLE))
|
||||
{
|
||||
|
@@ -25,19 +25,25 @@
|
||||
package org.alfresco.email.server.handler;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.Serializable;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.mail.MessagingException;
|
||||
|
||||
import org.alfresco.email.server.EmailServerModel;
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.i18n.I18NUtil;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.service.cmr.email.EmailMessage;
|
||||
import org.alfresco.service.cmr.email.EmailMessageException;
|
||||
import org.alfresco.service.cmr.email.EmailMessagePart;
|
||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||
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.namespace.NamespaceService;
|
||||
@@ -53,6 +59,10 @@ import org.apache.commons.logging.LogFactory;
|
||||
*/
|
||||
public class FolderEmailMessageHandler extends AbstractEmailMessageHandler
|
||||
{
|
||||
private static final String MSG_RECEIVED_BY_SMTP = "email.server.msg.received_by_smtp";
|
||||
private static final String MSG_DEFAULT_SUBJECT = "email.server.msg.default_subject";
|
||||
private static final String ERR_MAIL_READ_ERROR = "email.server.err.mail_read_error";
|
||||
|
||||
private static final Log log = LogFactory.getLog(FolderEmailMessageHandler.class);
|
||||
|
||||
/**
|
||||
@@ -67,90 +77,82 @@ public class FolderEmailMessageHandler extends AbstractEmailMessageHandler
|
||||
try
|
||||
{
|
||||
// Check type of the node. It must be a SPACE
|
||||
QName nodeTypeName = getNodeService().getType(nodeRef);
|
||||
QName nodeTypeQName = getNodeService().getType(nodeRef);
|
||||
|
||||
if (nodeTypeName.equals(ContentModel.TYPE_FOLDER))
|
||||
if (getDictionaryService().isSubClass(nodeTypeQName, ContentModel.TYPE_FOLDER))
|
||||
{
|
||||
// Add the content into the system
|
||||
addAlfrescoContent(nodeRef, message, null);
|
||||
addAlfrescoContent(nodeRef, message);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (log.isDebugEnabled())
|
||||
{
|
||||
log.debug("Addressed node type isn't a folder. Message has been passed without any actions.");
|
||||
}
|
||||
throw new AlfrescoRuntimeException("\n" +
|
||||
"Message handler " + this.getClass().getName() + " cannot handle type " + nodeTypeQName + ".\n" +
|
||||
"Check the message handler mappings.");
|
||||
}
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
throw new EmailMessageException(I18NUtil.getMessage("email.server.content-error"), ex);
|
||||
throw new EmailMessageException(ERR_MAIL_READ_ERROR, ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add content to Alfresco repository
|
||||
*
|
||||
* @param spaceNodeRef Addressed node
|
||||
* @param mailParser Mail message
|
||||
* @param nameConflictResolver String that can be used as part of name for resolving name conflict.
|
||||
* @throws IOException Exception can be thrown while saving a content into Alfresco repository.
|
||||
* @throws MessagingException Exception can be thrown while parsing e-mail message.
|
||||
* @param spaceNodeRef Addressed node
|
||||
* @param mailParser Mail message
|
||||
* @throws IOException Exception can be thrown while saving a content into Alfresco repository.
|
||||
* @throws MessagingException Exception can be thrown while parsing e-mail message.
|
||||
*/
|
||||
public void addAlfrescoContent(NodeRef spaceNodeRef, EmailMessage message, String nameConflictResolver) throws IOException
|
||||
public void addAlfrescoContent(NodeRef spaceNodeRef, EmailMessage message) throws IOException
|
||||
{
|
||||
// Set default values for email fields
|
||||
if (nameConflictResolver == null)
|
||||
nameConflictResolver = "";
|
||||
String messageSubject = "EMPTY_SUBJECT_" + nameConflictResolver;
|
||||
if (message.getSubject().length() != 0)
|
||||
String messageSubject = message.getSubject();
|
||||
if (messageSubject == null || messageSubject.length() == 0)
|
||||
{
|
||||
messageSubject = message.getSubject() + nameConflictResolver;
|
||||
Date now = new Date();
|
||||
messageSubject = I18NUtil.getMessage(MSG_DEFAULT_SUBJECT, new SimpleDateFormat("dd-MM-yyyy-hh-mm-ss").format(now));
|
||||
}
|
||||
|
||||
// Create node
|
||||
if (log.isDebugEnabled())
|
||||
{
|
||||
log.debug("Adding main content node ...");
|
||||
}
|
||||
// Create main content node
|
||||
NodeRef contentNodeRef;
|
||||
contentNodeRef = addContentNode(getNodeService(), spaceNodeRef, messageSubject);
|
||||
|
||||
// Add titled aspect
|
||||
addTitledAspect(contentNodeRef, messageSubject);
|
||||
|
||||
addTitledAspect(contentNodeRef, messageSubject, message.getFrom());
|
||||
// Add emailed aspect
|
||||
addEmailedAspect(contentNodeRef, message);
|
||||
|
||||
// Write the message content
|
||||
|
||||
if (message.getBody() != null)
|
||||
writeContent(contentNodeRef, message.getBody().getContent(), message.getBody().getContentType(), message.getBody().getEncoding());
|
||||
else
|
||||
writeContent(contentNodeRef, "<The message was empty>");
|
||||
if (log.isDebugEnabled())
|
||||
{
|
||||
log.debug("Main content node has been added.");
|
||||
InputStream contentIs = message.getBody().getContent();
|
||||
// The message body is plain text, unless an extension has been provided
|
||||
MimetypeService mimetypeService = getMimetypeService();
|
||||
String mimetype = mimetypeService.guessMimetype(messageSubject);
|
||||
if (mimetype.equals(MimetypeMap.MIMETYPE_BINARY))
|
||||
{
|
||||
mimetype= MimetypeMap.MIMETYPE_TEXT_PLAIN;
|
||||
}
|
||||
// Use the default encoding. It will get overridden if the body is text.
|
||||
String encoding = message.getBody().getEncoding();
|
||||
|
||||
writeContent(contentNodeRef, contentIs, mimetype, encoding);
|
||||
}
|
||||
|
||||
// Add attachments
|
||||
EmailMessagePart[] attachments = message.getAttachments();
|
||||
for (EmailMessagePart attachment : attachments)
|
||||
{
|
||||
NodeRef attachmentNode;
|
||||
String fileName = attachment.getFileName();
|
||||
|
||||
// Add name conflict resolver if necessary
|
||||
if (nameConflictResolver.length() != 0)
|
||||
{
|
||||
if (fileName.lastIndexOf('.') != -1)
|
||||
fileName = fileName.substring(0, fileName.lastIndexOf('.')) + " (" + nameConflictResolver + ")" + fileName.substring(fileName.lastIndexOf('.'));
|
||||
else
|
||||
fileName += " (" + nameConflictResolver + ")";
|
||||
}
|
||||
InputStream contentIs = attachment.getContent();
|
||||
|
||||
MimetypeService mimetypeService = getMimetypeService();
|
||||
String mimetype = mimetypeService.guessMimetype(fileName);
|
||||
String encoding = attachment.getEncoding();
|
||||
|
||||
attachmentNode = addAttachment(getNodeService(), spaceNodeRef, contentNodeRef, fileName);
|
||||
writeContent(attachmentNode, attachment.getContent(), attachment.getContentType(), attachment.getEncoding());
|
||||
NodeRef attachmentNode = addAttachment(getNodeService(), spaceNodeRef, contentNodeRef, fileName);
|
||||
writeContent(attachmentNode, contentIs, mimetype, encoding);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,11 +180,25 @@ public class FolderEmailMessageHandler extends AbstractEmailMessageHandler
|
||||
*/
|
||||
private NodeRef addContentNode(NodeService nodeService, NodeRef parent, String name, QName assocType)
|
||||
{
|
||||
Map<QName, Serializable> contentProps = new HashMap<QName, Serializable>();
|
||||
contentProps.put(ContentModel.PROP_NAME, name);
|
||||
ChildAssociationRef associationRef = nodeService.createNode(parent, assocType, QName.createQName(NamespaceService.CONTENT_MODEL_PREFIX, name), ContentModel.TYPE_CONTENT,
|
||||
contentProps);
|
||||
return associationRef.getChildRef();
|
||||
NodeRef childNodeRef = nodeService.getChildByName(parent, assocType, name);
|
||||
if (childNodeRef != null)
|
||||
{
|
||||
// The node is present already. Make sure the name csae is correct
|
||||
nodeService.setProperty(childNodeRef, ContentModel.PROP_NAME, name);
|
||||
}
|
||||
else
|
||||
{
|
||||
Map<QName, Serializable> contentProps = new HashMap<QName, Serializable>();
|
||||
contentProps.put(ContentModel.PROP_NAME, name);
|
||||
ChildAssociationRef associationRef = nodeService.createNode(
|
||||
parent,
|
||||
assocType,
|
||||
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, name),
|
||||
ContentModel.TYPE_CONTENT,
|
||||
contentProps);
|
||||
childNodeRef = associationRef.getChildRef();
|
||||
}
|
||||
return childNodeRef;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -203,9 +219,15 @@ public class FolderEmailMessageHandler extends AbstractEmailMessageHandler
|
||||
|
||||
NodeRef attachmentNode = addContentNode(nodeService, folder, fileName);
|
||||
|
||||
// Remove 'attached' aspect so that we work with the document in its clean form
|
||||
if (nodeService.hasAspect(attachmentNode, EmailServerModel.ASPECT_ATTACHED))
|
||||
{
|
||||
nodeService.removeAspect(attachmentNode, EmailServerModel.ASPECT_ATTACHED);
|
||||
}
|
||||
|
||||
// Add attached aspect
|
||||
Map<QName, Serializable> attachedProps = new HashMap<QName, Serializable>();
|
||||
nodeService.addAspect(attachmentNode, EmailServerModel.ASPECT_ATTACHED, attachedProps);
|
||||
nodeService.addAspect(attachmentNode, EmailServerModel.ASPECT_ATTACHED, null);
|
||||
// Recreate the association
|
||||
nodeService.createAssociation(attachmentNode, mainContentNode, EmailServerModel.ASSOC_ATTACHMENT);
|
||||
|
||||
if (log.isDebugEnabled())
|
||||
@@ -221,11 +243,11 @@ public class FolderEmailMessageHandler extends AbstractEmailMessageHandler
|
||||
* @param nodeRef Target node.
|
||||
* @param title Title
|
||||
*/
|
||||
private void addTitledAspect(NodeRef nodeRef, String title)
|
||||
private void addTitledAspect(NodeRef nodeRef, String title, String from)
|
||||
{
|
||||
Map<QName, Serializable> titledProps = new HashMap<QName, Serializable>();
|
||||
titledProps.put(ContentModel.PROP_TITLE, title);
|
||||
titledProps.put(ContentModel.PROP_DESCRIPTION, "Received by SMTP");
|
||||
titledProps.put(ContentModel.PROP_DESCRIPTION, I18NUtil.getMessage(MSG_RECEIVED_BY_SMTP, from));
|
||||
getNodeService().addAspect(nodeRef, ContentModel.ASPECT_TITLED, titledProps);
|
||||
|
||||
if (log.isDebugEnabled())
|
||||
|
@@ -24,10 +24,9 @@
|
||||
*/
|
||||
package org.alfresco.email.server.handler;
|
||||
|
||||
import org.alfresco.i18n.I18NUtil;
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ForumModel;
|
||||
import org.alfresco.service.cmr.email.EmailMessage;
|
||||
import org.alfresco.service.cmr.email.EmailMessageException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
@@ -55,9 +54,9 @@ public class ForumEmailMessageHandler extends AbstractForumEmailMessageHandler
|
||||
messageSubject = "EMPTY_SUBJECT_" + System.currentTimeMillis();
|
||||
}
|
||||
|
||||
QName nodeType = getNodeService().getType(nodeRef);
|
||||
QName nodeTypeQName = getNodeService().getType(nodeRef);
|
||||
|
||||
if (nodeType.equals(ForumModel.TYPE_FORUM))
|
||||
if (getDictionaryService().isSubClass(nodeTypeQName, ForumModel.TYPE_FORUM))
|
||||
{
|
||||
NodeRef topicNode = getTopicNode(nodeRef, messageSubject);
|
||||
|
||||
@@ -69,7 +68,9 @@ public class ForumEmailMessageHandler extends AbstractForumEmailMessageHandler
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new EmailMessageException(I18NUtil.getMessage("email.server.incorrect-node-type"));
|
||||
throw new AlfrescoRuntimeException("\n" +
|
||||
"Message handler " + this.getClass().getName() + " cannot handle type " + nodeTypeQName + ".\n" +
|
||||
"Check the message handler mappings.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -24,10 +24,9 @@
|
||||
*/
|
||||
package org.alfresco.email.server.handler;
|
||||
|
||||
import org.alfresco.i18n.I18NUtil;
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ForumModel;
|
||||
import org.alfresco.service.cmr.email.EmailMessage;
|
||||
import org.alfresco.service.cmr.email.EmailMessageException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
|
||||
@@ -44,20 +43,26 @@ public class TopicEmailMessageHandler extends AbstractForumEmailMessageHandler
|
||||
*/
|
||||
public void processMessage(NodeRef nodeRef, EmailMessage message)
|
||||
{
|
||||
QName nodeType = getNodeService().getType(nodeRef);
|
||||
QName nodeTypeQName = getNodeService().getType(nodeRef);
|
||||
NodeRef topicNode = null;
|
||||
|
||||
if (nodeType.equals(ForumModel.TYPE_TOPIC))
|
||||
if (getDictionaryService().isSubClass(nodeTypeQName, ForumModel.TYPE_TOPIC))
|
||||
{
|
||||
topicNode = nodeRef;
|
||||
}
|
||||
else if (nodeType.equals(ForumModel.TYPE_POST))
|
||||
else if (getDictionaryService().isSubClass(nodeTypeQName, ForumModel.TYPE_POST))
|
||||
{
|
||||
topicNode = getNodeService().getPrimaryParent(nodeRef).getChildRef();
|
||||
topicNode = getNodeService().getPrimaryParent(nodeRef).getParentRef();
|
||||
if (topicNode == null)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("A POST node has no primary parent: " + nodeRef);
|
||||
}
|
||||
}
|
||||
if (topicNode == null)
|
||||
else
|
||||
{
|
||||
throw new EmailMessageException(I18NUtil.getMessage("email.server.incorrect-node-ref"));
|
||||
throw new AlfrescoRuntimeException("\n" +
|
||||
"Message handler " + this.getClass().getName() + " cannot handle type " + nodeTypeQName + ".\n" +
|
||||
"Check the message handler mappings.");
|
||||
}
|
||||
addPostNode(topicNode, message);
|
||||
}
|
||||
|
Reference in New Issue
Block a user