It seems the problem is that you are not adding the line break characters when you are joining the header and body lines.
Try changing this:
$str = $headers[$line];
to this:
$str = $headers[$line]."\r\n";
And this:
$str = $body[$line];
to this:
$str = $body[$line]."\r\n";
But there is an even better way to pull messages from the POP3 server and pass them to the MIME parser class.
You can use the POP3 stream handler provided by the POP3 package and use like a file name of a regular file, so the POP3 class internally retrieve the message data as if it were a real file.
Read this tutorial article for more information:
phpclasses.org/blog/package/2/post/
...