PHP Classes

Headers of particular length (apparently) cause parser to fail

Recommend this page to a friend!

      PHP MIME Email Message Parser  >  All threads  >  Headers of particular length...  >  (Un) Subscribe thread alerts  
Subject:Headers of particular length...
Summary:Headers of particular length (apparently) cause parser to fail
Messages:4
Author:danilcha
Date:2017-07-20 19:50:55
 

  1. Headers of particular length...   Reply   Report abuse  
Picture of danilcha danilcha - 2017-07-20 19:50:55
Dear Manuel,

Thank you again for your parser! I'm using them for already almost 10 years.

Recently we started to receive emails that fail to be properly parsed. This is probably because we switched to Office 365, which appends hundreds of header lines.

This is one of such messages: https://www.dropbox.com/s/1imr5556b02g8m4/mail1530913.eml?dl=0

If you parse it, it is parsed, and detects 2 parts. The second part is OK, but the first pars is left unparsed. It sees the whole part, including the headers, as the content. I use the following code to check it:

$parser = new mime_parser_class();
$decoded = null;
$parser->Decode(['File' => 'mail1530913.eml'], $decoded);
print_r($decoded[0]['Parts'][0]['Headers']);

It outputs no headers. However, if I add or delete a single character from any header of the main part, it outputs the correct headers:

[content-type:] => text/plain
[some-other-header:] => present

  2. Re: Headers of particular length...   Reply   Report abuse  
Picture of danilcha danilcha - 2017-08-11 16:35:58 - In reply to message 1 from danilcha
Any news on this issue?

  3. Re: Headers of particular length...   Reply   Report abuse  
Picture of danilcha danilcha - 2017-08-11 16:46:48 - In reply to message 1 from danilcha
By the way, the same problem happens when I pass the email source as a string to the parser. So the issue is not related to file reading.

  4. Re: Headers of particular length...   Reply   Report abuse  
Picture of danilcha danilcha - 2017-08-11 17:09:12 - In reply to message 1 from danilcha
So, apparently, in the case of the example email, the offset of the first part is 16001 bytes, but the parser thinks it's 16000. Created a temporary workaround like that:

$parser->message_buffer_length = 64 * 1024;