PHP Classes

Bug in MIME Parser?

Recommend this page to a friend!

      PHP MIME Email Message Parser  >  All threads  >  Bug in MIME Parser?  >  (Un) Subscribe thread alerts  
Subject:Bug in MIME Parser?
Summary:Bug in the MIME parser?
Messages:7
Author:Alex Tween
Date:2008-08-04 04:45:13
Update:2008-08-24 02:43:09
 

  1. Bug in MIME Parser?   Reply   Report abuse  
Picture of Alex Tween Alex Tween - 2008-08-04 04:45:13
if i try to parse a message that within the message body starts a new line with "From " such as "From the President", i get an error: "incomplete message body part". the problem is the code around line 544:

$start = strtolower(substr($this->buffer, $next, strlen($break.'from ')));
if(!strcmp($break.'from ', $start)) { /* signal end of message */ }

the system sees "from " and it thinks it's reached the end of the message. i imagine some mhtml message bodies end like that necessitating that check, but mhtml messages will occasionally contain that phrase within the body too.

i'm not sure how to fix it because i don't know anything about the mhtml case that this is trying to handle. if it is a bug, are there any more planned patches for the mime parser that a fix for this could be a part of?

thanks. overall, the parser works really great.

  2. Re: Bug in MIME Parser?   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2008-08-04 04:57:53 - In reply to message 1 from Alex Tween
Are you setting the mbox flag to 1. If so, set it to 0 if you are parsing single messages and not mailbox archives in the mbox format.

  3. Re: Bug in MIME Parser?   Reply   Report abuse  
Picture of Alex Tween Alex Tween - 2008-08-13 06:40:44 - In reply to message 2 from Manuel Lemos
i just changed the mbox setting to 0 and got this error:

"The mime parser could not process the file - invalid header name line:0"

since the problem occurs immediately when mbox is 0 (i.e. line 0), i'll paste the beginning here with the real server names altered:

****
From [email protected] Wed Jul 23 13:04:22 2008
Received: from prod.nobody.com (prod.nobody.com [65.201.162.17])
by server1.nobody.com (8.13.1/8.13.1) with SMTP id m6221
for <[email protected]>;
****
I think this also has to do with the check that happens at line 544. I didn't mention this before but if i comment out lines 544-557 and then line 570 (the closing brace of the if), then my files are imported correctly! The problem seems to revolve around the check for the "From ", and the fact that at least when mbox = 1, the parser doesn't account for "From " starting a new line by just being part of the english language, apart from the fact that it can appear in the headers.


  4. Re: Bug in MIME Parser?   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2008-08-13 17:15:38 - In reply to message 3 from Alex Tween
Yes, the From header line is not valid. It is used to separated messages in mbox files that may contain multiple messages.

I will add an option to tolerate From headers in regular messages.

  5. Re: Bug in MIME Parser?   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2008-08-15 00:52:54 - In reply to message 3 from Alex Tween
Actually the class is already tolerating From headers in regular messages.

You just need to make sure that the variable ignore_syntax_errors is set to 1 and mbox is set to 0. The class return a warning but it will not fail.

  6. Re: Bug in MIME Parser?   Reply   Report abuse  
Picture of Alex Tween Alex Tween - 2008-08-24 01:43:10 - In reply to message 5 from Manuel Lemos
i agree that your suggestion is possible, but the condition i am talking about is actually a valid case and isn't really a syntax error at all, so ideally one wouldn't be generated (but then again, it isn't my parser ;) ).

  7. Re: Bug in MIME Parser?   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2008-08-24 02:43:09 - In reply to message 6 from Alex Tween
There seems to be a misunderstanding here. The class parses individual messages with a line starting with From word without errors if you set the mbox variable 0. That is all you need to do, change that variable.