Search in sources :

Example 1 with EmailMessagePart

use of org.alfresco.service.cmr.email.EmailMessagePart in project alfresco-repository by Alfresco.

the class AbstractEmailMessageHandler method addAttachments.

/**
 * Extracts the attachments from the given message and adds them to the space.  All attachments
 * are linked back to the original node that they are attached to.
 *
 * @param spaceNodeRef      the space to add the documents into
 * @param nodeRef           the node to which the documents will be attached
 * @param message           the email message
 */
protected void addAttachments(NodeRef spaceNodeRef, NodeRef nodeRef, EmailMessage message) {
    // Add attachments
    EmailMessagePart[] attachments = message.getAttachments();
    for (EmailMessagePart attachment : attachments) {
        String fileName = attachment.getFileName();
        InputStream contentIs = attachment.getContent();
        MimetypeService mimetypeService = getMimetypeService();
        String mimetype = mimetypeService.guessMimetype(fileName);
        String encoding = attachment.getEncoding();
        NodeRef attachmentNode = addAttachment(getNodeService(), spaceNodeRef, nodeRef, fileName);
        writeContent(attachmentNode, contentIs, mimetype, encoding);
    }
}
Also used : NodeRef(org.alfresco.service.cmr.repository.NodeRef) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) MimetypeService(org.alfresco.service.cmr.repository.MimetypeService) EmailMessagePart(org.alfresco.service.cmr.email.EmailMessagePart)

Aggregations

BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 EmailMessagePart (org.alfresco.service.cmr.email.EmailMessagePart)1 MimetypeService (org.alfresco.service.cmr.repository.MimetypeService)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1