[PEAR-BUG] Bug #18578 [Fbk->Csd]: Can't get the filename of an attachment

[email protected]
Newsgroups php.pear.bugs
Message-ID <[email protected]>
Edit report at http://pear.php.net/bugs/bug.php?id=18578&edit=1

 ID:               18578
 Updated by:       [email protected]
 Reported By:      ruediger dot bente at gmx dot de
 Summary:          Can't get the filename of an attachment
-Status:           Feedback
+Status:           Closed
 Type:             Bug
 Package:          Mail_mimeDecode
 Operating System: Linux (Ubuntu-Server)
 Package Version:  1.5.5
 PHP Version:      5.3.1
-Assigned To:      
+Assigned To:      alan_k
 Roadmap Versions: 
 New Comment:

-Status:      Feedback
+Status:      Closed
-Assigned To:
+Assigned To: alan_k
This bug has been fixed in SVN.

If this was a documentation problem, the fix will appear on pear.php.net
by the end of next Sunday (CET).

If this was a problem with the pear.php.net website, the change should
be live shortly.

Otherwise, the fix will appear in the package's next release.

Thank you for the report and for helping us make PEAR better.

Found the problem.. should be fixed in svn.


Previous Comments:
------------------------------------------------------------------------

[2011-08-22 07:33:31] alan_k

-Status: Open
+Status: Feedback
We are unable to reproduce the bug as reported.
Please provide a simple script (10 lines or less)
or a link to an external script that can be used
to reproduce the bug.

If you can provide the script, feel free to add it
to this bug and change the status back to "Open".

Thank you for your interest in PEAR.


I tried reproducing this, seed ->ctype_parameters['name'] - it appears
to work ok.

MIME-Version: 1.0
Content-Type: multipart/mixed;
	boundary="----=_NextPart_000_00D9_01CC5841.3C854FF0"

Subject: test

This is a multi-part message in MIME format.

------=_NextPart_000_00D9_01CC5841.3C854FF0
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: 7bit

test

 

------=_NextPart_000_00D9_01CC5841.3C854FF0
Content-Type: application/pdf;
 name="=?UTF-8?B?QmVrbGVpZHVuZ3NtYcOfZS5wZGY=?="
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
 filename*0*=UTF-8''%42%65%6B%6C%65%69%64%75%6E%67%73%6D%61%C3%9F%65%2E%70;
 filename*1*=%64%66

JVBERi0xLjQKJcOkw7zDtsOfCjIgMCBvYmoKPDwvTGVuZ3RoIDMgMCBSL0ZpbHRlci9GbGF0
ZURlY29kZT4+CnN0cmVhbQp4nM2dS6/uNnam5/4VexzAO5JIiRJgHKBcrmqgZ5UYyCDILJ0G
.......
 
------=_NextPart_000_00D9_01CC5841.3C854FF0--

<?php

require_once 'Mail/mimeDecode.php';

 
$structure = Mail_mimeDecode::decode(array(
   'include_bodies' => true,
   'decode_bodies'  => true,
   'decode_headers' => true,
   'input' => file_get_contents(__DIR__.'/bug18578.txt'),
));
          

print_r($structure);




stdClass Object
(
    [headers] => Array
        (
            [mime-version] => 1.0
            [content-type] => multipart/mixed;
boundary="----=_NextPart_000_00D9_01CC5841.3C854FF0"
        )

    [ctype_primary] => multipart
    [ctype_secondary] => mixed
    [ctype_parameters] => Array
        (
            [boundary] => ----=_NextPart_000_00D9_01CC5841.3C854FF0
        )

    [parts] => Array
        (
            [0] => stdClass Object
                (
                    [headers] => Array
                        (
                            [content-type] => text/plain;
charset="us-ascii"
                            [content-transfer-encoding] => 7bit
                        )

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

                    [body] => test

 


                )

            [1] => stdClass Object
                (
                    [headers] => Array
                        (
                            [content-type] => application/pdf;
name="Bekleidungsmaße.pdf"
                            [content-transfer-encoding] => base64
                            [content-disposition] => attachment;
filename*0*=UTF-8''%42%65%6B%6C%65%69%64%75%6E%67%73%6D%61%C3%9F%65%2E%70;
filename*1*=%64%66
                        )

                    [ctype_primary] => application
                    [ctype_secondary] => pdf
                    [ctype_parameters] => Array
                        (
                            [name] => Bekleidungsmaße.pdf
                        )

                    [disposition] => attachment
                    [d_parameters] => Array
                        (
                            [filename*0*] =>
UTF-8%42%65%6B%6C%65%69%64%75%6E%67%73%6D%61%C3%9F%65%2E%70
                            [filename*1*] => %64%66
                        )

                    [body] => %PDF-1.4
%äüöß
2 0 obj
<</Length 3 0 R/Filter/FlateDecode>>
stream
x??K??6v???{?;?H?`?\?j?g?? ?,?
                )

        )

)

------------------------------------------------------------------------

[2011-06-01 14:26:08] ruebezahl

Description:
------------
$part->ctype_parameters['filename'] has no valid value or is blank.

Mimepart of the attachement looks like this:

--------------060808080706060305030508
Content-Type: application/pdf;
 name="=?UTF-8?B?QmVrbGVpZHVuZ3NtYcOfZS5wZGY=?="
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
 filename*0*=UTF-8''%42%65%6B%6C%65%69%64%75%6E%67%73%6D%61%C3%9F%65%2E%70;
 filename*1*=%64%66

JVBERi0xLjQKJcOkw7zDtsOfCjIgMCBvYmoKPDwvTGVuZ3RoIDMgMCBSL0ZpbHRlci9GbGF0
ZURlY29kZT4+CnN0cmVhbQp4nM2dS6/uNnam5/4VexzAO5JIiRJgHKBcrmqgZ5UYyCDILJ0G
.......

Mail was sent by Thunderbird 3.1.10

Test script:
---------------
	require_once 'Mail/mimeDecode.php';

	$input = file_get_contents("/tmp/druckmessage");
	$params['include_bodies'] = true;
	$params['decode_bodies']  = true;
	$params['decode_headers'] = true;
	$params['input'] = $input;
	$structure = Mail_mimeDecode::decode($params);

foreach ($structure->parts as $part) 
{
    // only save if an attachment
    if (isset($part->disposition) and     
($part->disposition=='attachment')) 
		{
// open file
		$fp = fopen($part->ctype_parameters['filename'], 'w');
			// write body
			fwrite($fp, $part->body);
			// close file
			fclose($fp);
		}
	}	

Expected result:
----------------
Like to get the filename out of the mimepart header

Actual result:
--------------
filename is blank

after adding a
    print_r($structure->ctype_parameters);
before the foreach
and a
     print($part->ctype_primary . '  //  ' . $part->disposition);
after the foreach
the result is the following:

Array
(
    [boundary] => ------------060808080706060305030508
)
text  //
application  //  attachment

------------------------------------------------------------------------


-- 
Edit this bug report at http://pear.php.net/bugs/bug.php?id=18578&edit=1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.