fix detection of emails inside mbox
MODIFY
CHANGES.txt
CHANGES.txt
Release 1.17 - ???
+ * Fix detection of emails extracted from mbox (TIKA-2456)
+
* Add OverrideDetector and allow PSTParser to specify body content type
as text or html -- to avoid incorrect auto-detection of
rfc/mbox, etc. (TIKA-2454)

MODIFY
tika-parsers/src/main/java/org/apache/tika/parser/mbox/MboxParser.java
tika-parsers/src/main/java/org/apache/tika/parser/mbox/MboxParser.java
@@ -103,6 +103,7 @@ public class MboxParser extends AbstractParser {
Queue<String> multiline = new LinkedList<String>();
mailMetadata.add(EMAIL_FROMLINE_METADATA, curLine.substring(MBOX_RECORD_DIVIDER.length()));
mailMetadata.set(Metadata.CONTENT_TYPE, "message/rfc822");
+ mailMetadata.set(TikaCoreProperties.CONTENT_TYPE_OVERRIDE, "message/rfc822");
curLine = reader.readLine();
if (curLine == null) {
break;

MODIFY
tika-parsers/src/test/java/org/apache/tika/parser/mbox/MboxParserTest.java
tika-parsers/src/test/java/org/apache/tika/parser/mbox/MboxParserTest.java
@@ -152,4 +152,19 @@ public class MboxParserTest {
assertContains("When a Mapper completes", handler.toString());
}
+
+ @Test
+ public void testOverrideDetector() throws Exception {
+ ContentHandler handler = new BodyContentHandler();
+ Metadata metadata = new Metadata();
+ ParseContext context = new ParseContext();
+ context.set(Parser.class, new AutoDetectParser());
+
+ try (InputStream stream = getStream("/test-documents/single_mail.mbox")) {
+ mboxParser.parse(stream, handler, metadata, context);
+ }
+
+ Metadata firstMail = mboxParser.getTrackingMetadata().get(0);
+ assertEquals("message/rfc822", firstMail.get(Metadata.CONTENT_TYPE));
+ }
}

TIKA-2456: fix detection of emails inside mbox