@Test public void testParse() throws Exception { Metadata metadata = new Metadata(); ContentHandler handler = new ToHTMLContentHandler(); ParseContext context = new ParseContext(); EmbeddedTrackingExtrator trackingExtrator = new EmbeddedTrackingExtrator(context); context.set(EmbeddedDocumentExtractor.class, trackingExtrator); context.set(Parser.class, new AutoDetectParser()); AUTO_DETECT_PARSER.parse(getResourceAsStream("/test-documents/testPST.pst"), handler, metadata, context); String output = handler.toString(); assertFalse(output.isEmpty()); assertTrue(output.contains("<meta name=\"Content-Length\" content=\"271360\">")); assertTrue(output.contains("<meta name=\"Content-Type\" content=\"application/vnd.ms-outlook-pst\">")); assertTrue(output.contains("<body><div class=\"email-folder\"><h1>")); assertTrue(output.contains("<div class=\"embedded\" id=\"&lt;530D9CAC.5080901@gmail.com&gt;\"><h1>Re: Feature Generators</h1>")); assertTrue(output.contains("<div class=\"embedded\" id=\"&lt;1393363252.28814.YahooMailNeo@web140906.mail.bf1.yahoo.com&gt;\"><h1>Re: init tokenizer fails: \"Bad type in putfield/putstatic\"</h1>")); assertTrue(output.contains("Gary Murphy commented on TIKA-1250:")); assertTrue(output.contains("<div class=\"email-folder\"><h1>Racine (pour la recherche)</h1>")); List<Metadata> metaList = trackingExtrator.trackingMetadata; assertEquals(6, metaList.size()); Metadata firstMail = metaList.get(0); assertEquals("Jörn Kottmann", firstMail.get(TikaCoreProperties.CREATOR)); assertEquals("Re: Feature Generators", firstMail.get(TikaCoreProperties.TITLE)); assertEquals("kottmann@gmail.com", firstMail.get("senderEmailAddress")); assertEquals("users@opennlp.apache.org", firstMail.get("displayTo")); assertEquals("", firstMail.get("displayCC")); assertEquals("", firstMail.get("displayBCC")); }
public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { EmbeddedDocumentExtractor embeddedExtractor = EmbeddedDocumentUtil.getEmbeddedDocumentExtractor(context); metadata.set(Metadata.CONTENT_TYPE, MS_OUTLOOK_PST_MIMETYPE.toString()); XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata); xhtml.startDocument(); TikaInputStream in = TikaInputStream.get(stream); PSTFile pstFile = null; try { pstFile = new PSTFile(in.getFile().getPath()); metadata.set(Metadata.CONTENT_LENGTH, valueOf(pstFile.getFileHandle().length())); boolean isValid = pstFile.getFileHandle().getFD().valid(); metadata.set("isValid", valueOf(isValid)); if(pstFile.getPSTFileType() == PSTFile.PST_TYPE_2013_UNICODE) { throw new TikaException("OST 2013 support not added yet. It will be when https: } if (isValid) { parseFolder(xhtml, pstFile.getRootFolder(), embeddedExtractor); } } catch (TikaException e) { throw e; } catch (Exception e) { throw new TikaException(e.getMessage(), e); } finally { if (pstFile != null && pstFile.getFileHandle() != null) { try { pstFile.getFileHandle().close(); } catch (IOException e) { } } } xhtml.endDocument(); }
OutlookPSTParser extends AbstractParser { public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { EmbeddedDocumentExtractor embeddedExtractor = EmbeddedDocumentUtil.getEmbeddedDocumentExtractor(context); metadata.set(Metadata.CONTENT_TYPE, MS_OUTLOOK_PST_MIMETYPE.toString()); XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata); xhtml.startDocument(); TikaInputStream in = TikaInputStream.get(stream); PSTFile pstFile = null; try { pstFile = new PSTFile(in.getFile().getPath()); metadata.set(Metadata.CONTENT_LENGTH, valueOf(pstFile.getFileHandle().length())); boolean isValid = pstFile.getFileHandle().getFD().valid(); metadata.set("isValid", valueOf(isValid)); if(pstFile.getPSTFileType() == PSTFile.PST_TYPE_2013_UNICODE) { throw new TikaException("OST 2013 support not added yet. It will be when https: } if (isValid) { parseFolder(xhtml, pstFile.getRootFolder(), embeddedExtractor); } } catch (TikaException e) { throw e; } catch (Exception e) { throw new TikaException(e.getMessage(), e); } finally { if (pstFile != null && pstFile.getFileHandle() != null) { try { pstFile.getFileHandle().close(); } catch (IOException e) { } } } xhtml.endDocument(); } }
OutlookPSTParser extends AbstractParser { public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { EmbeddedDocumentExtractor embeddedExtractor = EmbeddedDocumentUtil.getEmbeddedDocumentExtractor(context); metadata.set(Metadata.CONTENT_TYPE, MS_OUTLOOK_PST_MIMETYPE.toString()); XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata); xhtml.startDocument(); TikaInputStream in = TikaInputStream.get(stream); PSTFile pstFile = null; try { pstFile = new PSTFile(in.getFile().getPath()); metadata.set(Metadata.CONTENT_LENGTH, valueOf(pstFile.getFileHandle().length())); boolean isValid = pstFile.getFileHandle().getFD().valid(); metadata.set("isValid", valueOf(isValid)); if(pstFile.getPSTFileType() == PSTFile.PST_TYPE_2013_UNICODE) { throw new TikaException("OST 2013 support not added yet. It will be when https: } if (isValid) { parseFolder(xhtml, pstFile.getRootFolder(), embeddedExtractor); } } catch (TikaException e) { throw e; } catch (Exception e) { throw new TikaException(e.getMessage(), e); } finally { if (pstFile != null && pstFile.getFileHandle() != null) { try { pstFile.getFileHandle().close(); } catch (IOException e) { } } } xhtml.endDocument(); }  }
OutlookPSTParser extends AbstractParser { public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { EmbeddedDocumentExtractor embeddedExtractor = EmbeddedDocumentUtil.getEmbeddedDocumentExtractor(context); metadata.set(Metadata.CONTENT_TYPE, MS_OUTLOOK_PST_MIMETYPE.toString()); XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata); xhtml.startDocument(); TikaInputStream in = TikaInputStream.get(stream); PSTFile pstFile = null; try { pstFile = new PSTFile(in.getFile().getPath()); metadata.set(Metadata.CONTENT_LENGTH, valueOf(pstFile.getFileHandle().length())); boolean isValid = pstFile.getFileHandle().getFD().valid(); metadata.set("isValid", valueOf(isValid)); if(pstFile.getPSTFileType() == PSTFile.PST_TYPE_2013_UNICODE) { throw new TikaException("OST 2013 support not added yet. It will be when https: } if (isValid) { parseFolder(xhtml, pstFile.getRootFolder(), embeddedExtractor); } } catch (TikaException e) { throw e; } catch (Exception e) { throw new TikaException(e.getMessage(), e); } finally { if (pstFile != null && pstFile.getFileHandle() != null) { try { pstFile.getFileHandle().close(); } catch (IOException e) { } } } xhtml.endDocument(); }  Set<MediaType> getSupportedTypes(ParseContext context); void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context); }
OutlookPSTParser extends AbstractParser { public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context) throws IOException, SAXException, TikaException { EmbeddedDocumentExtractor embeddedExtractor = EmbeddedDocumentUtil.getEmbeddedDocumentExtractor(context); metadata.set(Metadata.CONTENT_TYPE, MS_OUTLOOK_PST_MIMETYPE.toString()); XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata); xhtml.startDocument(); TikaInputStream in = TikaInputStream.get(stream); PSTFile pstFile = null; try { pstFile = new PSTFile(in.getFile().getPath()); metadata.set(Metadata.CONTENT_LENGTH, valueOf(pstFile.getFileHandle().length())); boolean isValid = pstFile.getFileHandle().getFD().valid(); metadata.set("isValid", valueOf(isValid)); if(pstFile.getPSTFileType() == PSTFile.PST_TYPE_2013_UNICODE) { throw new TikaException("OST 2013 support not added yet. It will be when https: } if (isValid) { parseFolder(xhtml, pstFile.getRootFolder(), embeddedExtractor); } } catch (TikaException e) { throw e; } catch (Exception e) { throw new TikaException(e.getMessage(), e); } finally { if (pstFile != null && pstFile.getFileHandle() != null) { try { pstFile.getFileHandle().close(); } catch (IOException e) { } } } xhtml.endDocument(); }  Set<MediaType> getSupportedTypes(ParseContext context); void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context); static final MediaType MS_OUTLOOK_PST_MIMETYPE; }