mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
125603 rmunteanu: Merged 5.1.1 (5.1.1) to 5.1.N (5.1.2) 125484 slanglois: MNT-16155 Update source headers - remove old Copyrights from Java and JSP dource files git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@125781 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
126 lines
3.7 KiB
Java
126 lines
3.7 KiB
Java
package org.alfresco.repo.imap;
|
|
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
|
|
import javax.activation.DataHandler;
|
|
import javax.mail.MessagingException;
|
|
import javax.mail.internet.MimePartDataSource;
|
|
import javax.mail.util.SharedByteArrayInputStream;
|
|
|
|
import org.alfresco.model.ContentModel;
|
|
import org.alfresco.service.ServiceRegistry;
|
|
import org.alfresco.service.cmr.model.FileInfo;
|
|
import org.alfresco.service.cmr.repository.ContentIOException;
|
|
import org.alfresco.service.cmr.repository.ContentReader;
|
|
import org.alfresco.service.cmr.repository.ContentService;
|
|
|
|
/**
|
|
* Extended MimeMessage to represent a content stored in the Alfresco repository.
|
|
*
|
|
* @author Arseny Kovalchuk
|
|
*/
|
|
public class ImapModelMessage extends AbstractMimeMessage
|
|
{
|
|
/**
|
|
* Constructs {@link ImapModelMessage} object.
|
|
*
|
|
* @param fileInfo - reference to the {@link FileInfo} object representing the message.
|
|
* @param serviceRegistry - serviceRegistry object.
|
|
* @param generateBody - if {@code true} message body will be generated.
|
|
*
|
|
* @throws MessagingException if generation of the body fails.
|
|
*/
|
|
public ImapModelMessage(FileInfo fileInfo, ServiceRegistry serviceRegistry, boolean generateBody) throws MessagingException
|
|
{
|
|
super(fileInfo, serviceRegistry, generateBody);
|
|
}
|
|
|
|
@Override
|
|
public void buildMessageInternal() throws MessagingException
|
|
{
|
|
if (generateBody != false)
|
|
{
|
|
setMessageHeaders();
|
|
buildImapMessage();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* This method builds MimeMessage based on either ImapModel or ContentModel type.
|
|
*
|
|
* @throws MessagingException
|
|
*/
|
|
private void buildImapMessage() throws MessagingException
|
|
{
|
|
modified = false;
|
|
saved = false;
|
|
buildRFC822Message();
|
|
saved = true;
|
|
}
|
|
|
|
private void buildRFC822Message() throws MessagingException
|
|
{
|
|
ContentService contentService = serviceRegistry.getContentService();
|
|
ContentReader reader = contentService.getReader(messageFileInfo.getNodeRef(), ContentModel.PROP_CONTENT);
|
|
InputStream is = null;
|
|
try
|
|
{
|
|
is = reader.getContentInputStream();
|
|
this.parse(is);
|
|
}
|
|
catch (ContentIOException e)
|
|
{
|
|
//logger.error(e);
|
|
throw new MessagingException("The error occured during message creation from content stream.", e);
|
|
}
|
|
finally
|
|
{
|
|
if (is != null)
|
|
{
|
|
try
|
|
{
|
|
is.close();
|
|
}
|
|
catch (IOException e)
|
|
{
|
|
throw new MessagingException("The error occured during message creation from content stream.", e);
|
|
}
|
|
is = null;
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected InputStream getContentStream() throws MessagingException
|
|
{
|
|
try
|
|
{
|
|
if (this.contentStream == null)
|
|
{
|
|
if (content != null)
|
|
{
|
|
return new SharedByteArrayInputStream(content);
|
|
}
|
|
else
|
|
{
|
|
throw new MessagingException("No content");
|
|
}
|
|
}
|
|
return this.contentStream;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
throw new MessagingException(e.getMessage(),e);
|
|
}
|
|
}
|
|
|
|
/*
|
|
protected void parse(InputStream inputstream) throws MessagingException
|
|
{
|
|
headers = createInternetHeaders(inputstream);
|
|
contentStream = inputstream;
|
|
}
|
|
*/
|
|
}
|