PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Mail » Mail_Mime » Bug #3318

mimeDecode.php - decoding of emails not consistent?

Details

Submitted2005-01-27 22:24 UTC
Fromtatlar at yahoo dot com
StatusNo Feedback
PackageMail_Mime
PHP Version4.3.10
OSLinux SuSE
Roadmaps(Not assigned)

Comments

[2005-01-27 22:24 UTC] tatlar at yahoo dot com

Description:
------------
Version of Mail_MIME: 1.2.1
Revision: 1.34
Apache: 2.0.50

PHP compile command:
'./configure' '--with-mysql' '--enable-track-vars' '--
enable-force-cgi-redirect' '--with-gettext' '--with-
config-file-path=/etc' '--prefix=/usr' '--enable-shaed'
'--verbose' '--with-gd' '--with-ttf' '--enable-debug'
'--with-jpeg-dir=/usr' '--with-png-dir=/usr' '--with-
zlib' '--with-mcrypt=/usr' '--with-apxs2=/usr/sbin/
apxs2'

Hi there,
I am using mimeDecode.php and on the whole the package
works very well and I can decode images and documents
easily. However, when trying to decode PDF files it
appears to be inconsistent in displaying the structure
of the mime message. Here are the relevant headers of
two emails that have a similar structure, but are
interpreted differently by mimeDecode.php:

Email 1:
--------
--=====================_87283877==_
Content-Type: text/plain; charset="us-ascii";
format=flowed

The message

--=====================_87283877==_
Content-Type: application/pdf; name="file1.pdf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="file1.pdf"

Email 2:
--------
--=====================_90532498==_
Content-Type: text/plain; charset="us-ascii";
format=flowed

The next message

--=====================_90532498==_
Content-Type: application/pdf; name="file2.pdf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="file2.pdf"

Reproduce code:
---------------
Source code used to decode the messages:

require( "Mail/mimeDecode.php" ) ;
$params['include_bodies'] = true ;
$params['decode_bodies'] = true ;
$params['decode_headers'] = true ;
$handle = fopen( $mailfile, 'r' ) ;
fseek( $handle, $foff ) ;
$contents = fread( $handle, $bytes ) ;
$decoder = new Mail_mimeDecode( $contents ) ;
$structure = $decoder->decode( $params ) ;
fclose( $handle ) ;

if( $structure->ctype_primary != 'text' ) {
echo "<strong>Attachments:</strong><br/>\n\t" ;
foreach( $structure->parts as $part ) {
if( isset( $part->disposition ) ) {
if( $part->disposition == 'attachment' OR $part->disposition == 'inline' ) {
$filename = $part->ctype_parameters['name'] ;
$file = $part->body ;
$filename_path = $tmp_dir . $filename ;
if( !$fp = fopen( $tmp_dir . $filename, 'wb' ) ) {
echo "Cannot create a new file ($filename)";
}
if( !fwrite( $fp, $file ) ) {
echo "Cannot write to file ($filename)" ;
}
if( fclose( $fp ) ) {
echo "<a href=\"$tmp_dir$filename\">$filename</a><br/>\n" ;
}
} else {
echo "Attachment is in an unknown MIME format!" ;
}
}
}
}

Expected result:
----------------
This is the result from the above code with Email 1:
----------------------------------------------------

[ctype_primary] => text
[ctype_secondary] => plain
[ctype_parameters] => Array
(
[charset] => us-ascii
[format] => flowed
)

[body] => The message

)

[1] => stdClass Object
(
[headers] => Array
(
[content-type] =>
application/pdf;
name="file1.pdf"
[content-transfer-encoding]
=> base64
[content-disposition] =>
attachment;
filename="file1.pdf"
)

[ctype_primary] => application
[ctype_secondary] => pdf
[ctype_parameters] => Array
(
[name] => file1.pdf
)

[disposition] => attachment
[d_parameters] => Array
(
[filename] => file1.pdf
)

[body] => %PDF-1.4
<PDF CODE>

And with Email 2:
-----------------
[ctype_primary] => multipart
[ctype_secondary] => mixed
[ctype_parameters] => Array
(
[boundary] =>
=====================_87283877==_
)

[parts] => Array
(
[0] => stdClass Object
(
[headers] => Array
(
[content-type] => text/
plain; charset="us-ascii"; format=flowed
)

[ctype_primary] => text
[ctype_secondary] => plain
[ctype_parameters] => Array
(
[charset] => us-ascii
[format] => flowed
)

[body] => The next message
)

)

)

Actual result:
--------------
With the second message, even though the headers in the
raw message are equivalent, the attachment is not
interpreted to be a PDF file.

Thanks very much for taking the time to help out!