@Test public void testMetadata() throws Exception { TikaInputStream stream = getTestFile(file); Metadata metadata = new Metadata(); ContentHandler handler = new BodyContentHandler(); TNEFParser tnef = new TNEFParser(); tnef.parse(stream, handler, metadata, new ParseContext()); assertEquals("This is a test message", metadata.get(TikaCoreProperties.TITLE)); assertEquals("This is a test message", metadata.get(TikaCoreProperties.SUBJECT)); }
public void parse( InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { EmbeddedDocumentExtractor embeddedExtractor = EmbeddedDocumentUtil.getEmbeddedDocumentExtractor(context); HMEFMessage msg = new HMEFMessage(stream); String subject = msg.getSubject(); if (subject != null && subject.length() > 0) { metadata.set(TikaCoreProperties.TITLE, subject); metadata.set(TikaCoreProperties.SUBJECT, subject); } XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata); xhtml.startDocument(); 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, xhtml ); } 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, xhtml ); } xhtml.endDocument(); }
TNEFParser extends AbstractParser { public void parse( InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { EmbeddedDocumentExtractor embeddedExtractor = EmbeddedDocumentUtil.getEmbeddedDocumentExtractor(context); HMEFMessage msg = new HMEFMessage(stream); String subject = msg.getSubject(); if (subject != null && subject.length() > 0) { metadata.set(TikaCoreProperties.TITLE, subject); metadata.set(TikaCoreProperties.SUBJECT, subject); } XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata); xhtml.startDocument(); 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, xhtml ); } 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, xhtml ); } xhtml.endDocument(); } }
TNEFParser extends AbstractParser { public void parse( InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { EmbeddedDocumentExtractor embeddedExtractor = EmbeddedDocumentUtil.getEmbeddedDocumentExtractor(context); HMEFMessage msg = new HMEFMessage(stream); String subject = msg.getSubject(); if (subject != null && subject.length() > 0) { metadata.set(TikaCoreProperties.TITLE, subject); metadata.set(TikaCoreProperties.SUBJECT, subject); } XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata); xhtml.startDocument(); 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, xhtml ); } 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, xhtml ); } xhtml.endDocument(); }  }
TNEFParser extends AbstractParser { public void parse( InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { EmbeddedDocumentExtractor embeddedExtractor = EmbeddedDocumentUtil.getEmbeddedDocumentExtractor(context); HMEFMessage msg = new HMEFMessage(stream); String subject = msg.getSubject(); if (subject != null && subject.length() > 0) { metadata.set(TikaCoreProperties.TITLE, subject); metadata.set(TikaCoreProperties.SUBJECT, subject); } XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata); xhtml.startDocument(); 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, xhtml ); } 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, xhtml ); } xhtml.endDocument(); }  Set<MediaType> getSupportedTypes(ParseContext context); void parse(
            InputStream stream, ContentHandler handler,
            Metadata metadata, ParseContext context); }
TNEFParser extends AbstractParser { public void parse( InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { EmbeddedDocumentExtractor embeddedExtractor = EmbeddedDocumentUtil.getEmbeddedDocumentExtractor(context); HMEFMessage msg = new HMEFMessage(stream); String subject = msg.getSubject(); if (subject != null && subject.length() > 0) { metadata.set(TikaCoreProperties.TITLE, subject); metadata.set(TikaCoreProperties.SUBJECT, subject); } XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata); xhtml.startDocument(); 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, xhtml ); } 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, xhtml ); } xhtml.endDocument(); }  Set<MediaType> getSupportedTypes(ParseContext context); void parse(
            InputStream stream, ContentHandler handler,
            Metadata metadata, ParseContext context);  }