Search in sources :

Example 11 with MAPIAttribute

use of org.apache.poi.hmef.attribute.MAPIAttribute in project poi by apache.

the class HMEFContentsExtractor method getBodyAttribute.

protected MAPIAttribute getBodyAttribute() {
    MAPIAttribute body = message.getMessageMAPIAttribute(MAPIProperty.RTF_COMPRESSED);
    if (body != null)
        return body;
    // See bug #59786 - we'd really like a test file to confirm if this
    //  is the right properties + if this is truely general or not!
    MAPIProperty uncompressedBody = MAPIProperty.createCustom(0x3fd9, Types.ASCII_STRING, "Uncompressed Body");
    // Return this uncompressed one, or null if that isn't their either
    return message.getMessageMAPIAttribute(uncompressedBody);
}
Also used : MAPIAttribute(org.apache.poi.hmef.attribute.MAPIAttribute) MAPIProperty(org.apache.poi.hsmf.datatypes.MAPIProperty)

Example 12 with MAPIAttribute

use of org.apache.poi.hmef.attribute.MAPIAttribute in project poi by apache.

the class HMEFContentsExtractor method extractMessageBody.

/**
     * Extracts the RTF message body to the supplied file
     */
public void extractMessageBody(File dest) throws IOException {
    MAPIAttribute body = getBodyAttribute();
    if (body == null) {
        System.err.println("No message body found, " + dest + " not created");
        return;
    }
    if (body instanceof MAPIStringAttribute) {
        String name = dest.toString();
        if (name.endsWith(".rtf")) {
            name = name.substring(0, name.length() - 4);
        }
        dest = new File(name + ".txt");
    }
    OutputStream fout = new FileOutputStream(dest);
    try {
        if (body instanceof MAPIStringAttribute) {
            // Save in a predictable encoding, not raw bytes
            String text = ((MAPIStringAttribute) body).getDataString();
            fout.write(text.getBytes(StringUtil.UTF8));
        } else {
            // Save the raw bytes, should be raw RTF
            fout.write(body.getData());
        }
    } finally {
        fout.close();
    }
}
Also used : MAPIStringAttribute(org.apache.poi.hmef.attribute.MAPIStringAttribute) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) MAPIAttribute(org.apache.poi.hmef.attribute.MAPIAttribute) File(java.io.File)

Example 13 with MAPIAttribute

use of org.apache.poi.hmef.attribute.MAPIAttribute in project tika by apache.

the class TNEFParser method parse.

/**
     * Extracts properties and text from an MS Document input stream
     */
public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException {
    // We work by recursing, so get the appropriate bits
    EmbeddedDocumentExtractor embeddedExtractor = EmbeddedDocumentUtil.getEmbeddedDocumentExtractor(context);
    // Ask POI to process the file for us
    HMEFMessage msg = new HMEFMessage(stream);
    // Set the message subject if known
    String subject = msg.getSubject();
    if (subject != null && subject.length() > 0) {
        // TODO: Move to title in Tika 2.0
        metadata.set(TikaCoreProperties.TRANSITION_SUBJECT_TO_DC_TITLE, subject);
    }
    // Recurse into the message body RTF
    MAPIAttribute attr = msg.getMessageMAPIAttribute(MAPIProperty.RTF_COMPRESSED);
    if (attr != null && attr instanceof MAPIRtfAttribute) {
        MAPIRtfAttribute rtf = (MAPIRtfAttribute) attr;
        handleEmbedded("message.rtf", "application/rtf", rtf.getData(), embeddedExtractor, handler);
    }
    // Recurse into each attachment in turn
    for (Attachment attachment : msg.getAttachments()) {
        String name = attachment.getLongFilename();
        if (name == null || name.length() == 0) {
            name = attachment.getFilename();
        }
        if (name == null || name.length() == 0) {
            String ext = attachment.getExtension();
            if (ext != null) {
                name = "unknown" + ext;
            }
        }
        handleEmbedded(name, null, attachment.getContents(), embeddedExtractor, handler);
    }
}
Also used : HMEFMessage(org.apache.poi.hmef.HMEFMessage) MAPIRtfAttribute(org.apache.poi.hmef.attribute.MAPIRtfAttribute) EmbeddedDocumentExtractor(org.apache.tika.extractor.EmbeddedDocumentExtractor) MAPIAttribute(org.apache.poi.hmef.attribute.MAPIAttribute) Attachment(org.apache.poi.hmef.Attachment)

Aggregations

MAPIAttribute (org.apache.poi.hmef.attribute.MAPIAttribute)13 MAPIRtfAttribute (org.apache.poi.hmef.attribute.MAPIRtfAttribute)5 ByteArrayInputStream (java.io.ByteArrayInputStream)3 POIDataSamples (org.apache.poi.POIDataSamples)2 HMEFMessage (org.apache.poi.hmef.HMEFMessage)2 MAPIStringAttribute (org.apache.poi.hmef.attribute.MAPIStringAttribute)2 TNEFAttribute (org.apache.poi.hmef.attribute.TNEFAttribute)2 MAPIProperty (org.apache.poi.hsmf.datatypes.MAPIProperty)2 Test (org.junit.Test)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 Attachment (org.apache.poi.hmef.Attachment)1 TNEFDateAttribute (org.apache.poi.hmef.attribute.TNEFDateAttribute)1 TNEFStringAttribute (org.apache.poi.hmef.attribute.TNEFStringAttribute)1 EmbeddedDocumentExtractor (org.apache.tika.extractor.EmbeddedDocumentExtractor)1