You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@tika.apache.org by Ingo Siebert <in...@cas.de> on 2016/10/05 16:06:37 UTC
Tika: parsing mixed content e-mails
Hi,
I just used Tika (org.apache.tika:tika-parsers:1.13) to parse an e-mail
with multipart/mixed content.
Please have a look at the attachment (renamed to txt).
The parsing result of Tika is the file in plain text including all
headers an boundary elements.
The words in the attachment are also not parsed.
Is this the defined behaviour of Tika?
I only expected the body content of each part and used that simple test
code to investigate that problem.
final TikaInputStream tikaInputStream = TikaInputStream.get(emlFile);
final Metadata metadata = new Metadata();
metadata.set(TikaCoreProperties.CONTENT_TYPE_HINT, "message/rfc822");
metadata.set(TikaMetadataKeys.RESOURCE_NAME_KEY, "mixedtest.eml");
final BodyContentHandler handler = new BodyContentHandler(20000000);
final AutoDetectParser parser = new AutoDetectParser();
parser.parse(tikaInputStream, handler, metadata);
System.out.println(handler.toString());
System.out.println("type: " +
parser.getDetector().detect(tikaInputStream, metadata));
The type result is "message/rfc822", which is pretty fine I think.
Do I have to parse the EML myself into different content parts to get
only the body text of each part?
I expected that Tika resolves that kind of multi-part files.
Best regards
Ingo
Re: Tika: parsing mixed content e-mails
Posted by Ingo Siebert <in...@cas.de>.
Am 06.10.2016 um 10:58 schrieb Nick Burch:
> On Thu, 6 Oct 2016, Ingo Siebert wrote:
>> Am 05.10.2016 um 20:04 schrieb Nick Burch:
>>> On Wed, 5 Oct 2016, Ingo Siebert wrote:
>>>> I just used Tika (org.apache.tika:tika-parsers:1.13) to parse an
>>>> e-mail with multipart/mixed content.
>>>
>>> How do you want to get the various parts back? All text inlined, or
>>> a special callback for each part? What about the metadata for the
>>> parts?
>>
>> A MS Office document consists also of several parts and chapters and
>> I get them as one string.
>
> A MS Office document can have other documents, images, sounds etc
> embedded in it too! You have to ask Tika for those in the same way
Ok, I never thought about that.
Thank you.
>
>> At least for my use-case I would be sufficient to get the data
>> concatenated into on string, but I would also be nice if I get the
>> parts separately.
>
> If you pop a EmbeddedDocumentExtractor onto the ParseContext, that'll
> be called to let you handle each part in turn. You might want a
> ParsingEmbeddedDocumentExtractor to give you parsed contents rather
> than raw parts
>
>
I'll take a look at ParsingEmbeddedDocumentExtractor you mentioned,
thank you.
In the mean time I tested the following code, which only returns only
one part because the HTMLParser is used.
I think the AutoDetectParser chooses the wrong parser, because if I
manually choose the RFC822Parser then the output is quite fine.
What's your opionion?
final AutoDetectParser wrapped = new AutoDetectParser();
final RecursiveParserWrapper wrapper = new RecursiveParserWrapper(wrapped,
new
BasicContentHandlerFactory(BasicContentHandlerFactory.HANDLER_TYPE.TEXT,
-1));
wrapper.parse(tikaInputStream, new DefaultHandler(), metadata, new
ParseContext());
final List<Metadata> list = wrapper.getMetadata();
System.out.println("parts: " + list.size());
Ingo
Re: Tika: parsing mixed content e-mails
Posted by Nick Burch <ap...@gagravarr.org>.
On Thu, 6 Oct 2016, Ingo Siebert wrote:
> Am 05.10.2016 um 20:04 schrieb Nick Burch:
>> On Wed, 5 Oct 2016, Ingo Siebert wrote:
>>> I just used Tika (org.apache.tika:tika-parsers:1.13) to parse an e-mail
>>> with multipart/mixed content.
>>
>> How do you want to get the various parts back? All text inlined, or a
>> special callback for each part? What about the metadata for the parts?
>
> A MS Office document consists also of several parts and chapters and I get
> them as one string.
A MS Office document can have other documents, images, sounds etc embedded
in it too! You have to ask Tika for those in the same way
> At least for my use-case I would be sufficient to get the data concatenated
> into on string, but I would also be nice if I get the parts separately.
If you pop a EmbeddedDocumentExtractor onto the ParseContext, that'll be
called to let you handle each part in turn. You might want a
ParsingEmbeddedDocumentExtractor to give you parsed contents rather than
raw parts
Nick
Re: Tika: parsing mixed content e-mails
Posted by Ingo Siebert <in...@cas.de>.
Am 05.10.2016 um 20:04 schrieb Nick Burch:
> On Wed, 5 Oct 2016, Ingo Siebert wrote:
>> I just used Tika (org.apache.tika:tika-parsers:1.13) to parse an
>> e-mail with multipart/mixed content.
>
> How do you want to get the various parts back? All text inlined, or a
> special callback for each part? What about the metadata for the parts?
A MS Office document consists also of several parts and chapters and I
get them as one string.
The metadata are not interesting for me.
At least for my use-case I would be sufficient to get the data
concatenated into on string, but I would also be nice if I get the parts
separately.
>
>> The parsing result of Tika is the file in plain text including all
>> headers an boundary elements.
>> The words in the attachment are also not parsed.
>>
>> Is this the defined behaviour of Tika?
>
> It is if you don't tell Tika to recurse into embedded resources
Please can you give me a hint what I have to do to archive that?
>
> Nick
Thank you for your answer.
Re: Tika: parsing mixed content e-mails
Posted by Nick Burch <ap...@gagravarr.org>.
On Wed, 5 Oct 2016, Ingo Siebert wrote:
> I just used Tika (org.apache.tika:tika-parsers:1.13) to parse an e-mail with
> multipart/mixed content.
How do you want to get the various parts back? All text inlined, or a
special callback for each part? What about the metadata for the parts?
> The parsing result of Tika is the file in plain text including all headers an
> boundary elements.
> The words in the attachment are also not parsed.
>
> Is this the defined behaviour of Tika?
It is if you don't tell Tika to recurse into embedded resources
Nick