Example usage for org.apache.poi.hsmf.datatypes AttachmentChunks isEmbeddedMessage

List of usage examples for org.apache.poi.hsmf.datatypes AttachmentChunks isEmbeddedMessage

Introduction

In this page you can find the example usage for org.apache.poi.hsmf.datatypes AttachmentChunks isEmbeddedMessage.

Prototype

public boolean isEmbeddedMessage() 

Source Link

Document

Is this Attachment an embedded MAPI message?

Usage

From source file:com.openkm.util.MailUtils.java

License:Open Source License

/**
 * Add attachments to an imported mail./*from w w  w .j a v  a2 s  .  c o m*/
 */
public static void addAttachments(String token, com.openkm.bean.Mail mail, MAPIMessage msg, String userId)
        throws DatabaseException, RepositoryException, PathNotFoundException, ItemExistsException,
        VirusDetectedException, UserQuotaExceededException, UnsupportedMimeTypeException, ExtensionException,
        AccessDeniedException, IOException, AutomationException, FileSizeExceededException {
    for (AttachmentChunks att : msg.getAttachmentFiles()) {
        if (!att.isEmbeddedMessage()) {
            String attFileName = att.attachFileName.toString();
            if (att.attachLongFileName != null) {
                attFileName = att.attachLongFileName.toString();
            }

            log.debug("Importing attachment: {}", attFileName);
            String fileName = FileUtils.getFileName(attFileName);
            String fileExtension = FileUtils.getFileExtension(attFileName);
            String testName = fileName + "." + fileExtension;

            // Test if already exists a document with the same name in the mail
            for (int j = 1; OKMRepository.getInstance().hasNode(token, mail.getPath() + "/" + testName); j++) {
                // log.debug("Trying with: {}", testName);
                testName = fileName + " (" + j + ")." + fileExtension;
            }

            Document attachment = new Document();
            String mimeType = MimeTypeConfig.mimeTypes.getContentType(testName.toLowerCase());
            attachment.setMimeType(mimeType);
            attachment.setPath(mail.getPath() + "/" + testName);
            ByteArrayInputStream bais = new ByteArrayInputStream(att.attachData.getValue());

            if (Config.REPOSITORY_NATIVE) {
                new DbDocumentModule().create(token, attachment, bais, att.attachData.getValue().length,
                        userId);
            } else {
                // Other implementation
            }

            IOUtils.closeQuietly(bais);
        }
    }
}