PHP Classes

bug in decoding jpg attachment

Recommend this page to a friend!

      PHP MIME Email Message Parser  >  All threads  >  bug in decoding jpg attachment  >  (Un) Subscribe thread alerts  
Subject:bug in decoding jpg attachment
Summary:jpeg is malformed when message parts are dumped to disk
Messages:5
Author:G. Miernicki
Date:2008-11-17 23:46:26
Update:2008-11-28 21:30:18
 

  1. bug in decoding jpg attachment   Reply   Report abuse  
Picture of G. Miernicki G. Miernicki - 2008-11-17 23:46:29
I attempted to decode an email with a jpg image attached. When I turned on the option to dump body parts to disk, the jpg image is dumped, but malformed.

Please see the images below:

original image:
img89.imageshack.us/my.php?image=10 ...

decoded image:
img525.imageshack.us/my.php?image=3 ...

Please advise on possible workaround.

G

  2. Re: bug in decoding jpg attachment   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2008-11-18 00:08:54 - In reply to message 1 from G. Miernicki
Can you provide the e-mail message data that you used to pass to the class and if possible the script that you used to call the class?

  3. Re: bug in decoding jpg attachment   Reply   Report abuse  
Picture of G. Miernicki G. Miernicki - 2008-11-18 16:20:00 - In reply to message 2 from Manuel Lemos
Since the email attachment is about 205k, the email text file is rather large. So, I hosted it here:

divshare.com/download/5850989-bf3

The code for the script I executed to process the email is:

<?php
/*
* test_message_decoder.php
*
* @(#) $Header: /home/mlemos/cvsroot/mimeparser/test_message_decoder.php,v 1.7 2008/01/08 02:02:32 mlemos Exp $
*
*/

include_once("dBug.php");

require_once('rfc822_addresses.php');
require_once('mime_parser.php');

$message_file=((IsSet($_SERVER['argv']) && count($_SERVER['argv'])>1) ? $_SERVER['argv'][1] : 'email.txt');
$mime=new mime_parser_class;

/*
* Set to 0 for parsing a single message file
* Set to 1 for parsing multiple messages in a single file in the mbox format
*/
$mime->mbox = 1;

/*
* Set to 0 for not decoding the message bodies
*/
$mime->decode_bodies = 1;

/*
* Set to 0 to make syntax errors make the decoding fail
*/
$mime->ignore_syntax_errors = 0;

$parameters=array(
'File'=>$message_file,

/* Read a message from a string instead of a file */
/* 'Data'=>'My message data string', */

/* Save the message body parts to a directory */
'SaveBody'=>'./dump/',

/* Do not retrieve or save message body parts */
'SkipBody'=>1,
);

/*
* The following lines are for testing purposes.
* Remove these lines when adapting this example to real applications.
*/
if(defined('__TEST'))
{
if(IsSet($__test_options['parameters']))
$parameters=$__test_options['parameters'];
if(IsSet($__test_options['mbox']))
$mime->mbox=$__test_options['mbox'];
if(IsSet($__test_options['decode_bodies']))
$mime->decode_bodies=$__test_options['decode_bodies'];
}

if(!$mime->Decode($parameters, $decoded))
echo 'MIME message decoding error: '.$mime->error.' at position '.$mime->error_position."\n";
else
{
echo 'MIME message decoding successful.'."\n";
echo (count($decoded)==1 ? '1 message was found.' : count($decoded).' messages were found.'),"\n";
for($message = 0; $message < count($decoded); $message++)
{
echo 'Message ',($message+1),':',"\n";
new dBug($decoded[$message]);
if($mime->Analyze($decoded[$message], $results)) {
echo "<br><br><br>";
new dBug($results);
}
else
echo 'MIME message analyse error: '.$mime->error."\n";
}
for($warning = 0, Reset($mime->warnings); $warning < count($mime->warnings); Next($mime->warnings), $warning++)
{
$w = Key($mime->warnings);
echo 'Warning: ', $mime->warnings[$w], ' at position ', $w, "\n";
}
}
?>

  4. Re: bug in decoding jpg attachment   Reply   Report abuse  
Picture of G. Miernicki G. Miernicki - 2008-11-20 17:56:34 - In reply to message 3 from G. Miernicki
I also used pop3.stream.php to fetch the email from the IMAP server. Perhaps the error lays in how I pulled it down from there?

  5. Re: bug in decoding jpg attachment   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2008-11-28 21:30:18 - In reply to message 3 from G. Miernicki
I tried to open the image in the message in Thunderbird and it also appears to corrupted. I suppose the problem is with the program that sends the message or some gateway by which the message passed until it arrived.