php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66117 imap_fetchstructure dparameters[0]->value incomplete
Submitted: 2013-11-19 13:01 UTC Modified: 2021-02-03 15:55 UTC
Votes:3
Avg. Score:4.3 ± 0.9
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:0 (0.0%)
From: saygushkin at gmail dot com Assigned: cmb (profile)
Status: No Feedback Package: IMAP related
PHP Version: 5.4.22 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: saygushkin at gmail dot com
New email:
PHP Version: OS:

 

 [2013-11-19 13:01 UTC] saygushkin at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.imap-fetchstructure#refsect1-function.imap-fetchstructure-returnvalues
---

I attached to the mail of the file with name "пустой файл.txt".
Filename in dparameters->value is incomplete.
Mail source code:

--------------030200090909050404050001
Content-Type: text/plain; charset="UTF-8";
	name="=?UTF-8?B?0L/Rg9GB0YLQvtC5INGE0LDQudC7LnR4dA==?="
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
	filename*0*="UTF-8''%D0%BF%D1%83%D1%81%D1%82%D0%BE%D0%B9%20%D1%84%D0%B0%D0";
	filename*1*="%B9%D0%BB%2E%74%78%74"

0L/Rg9GB0YLQvtC5INGE0LDQudC7Cg==

--------------030200090909050404050001--

Test script:
---------------
$imapStream = imap_open($imapPath, $login, $password);

$mailIds = imap_search($imapStream, 'ALL', SE_UID);

$mailId = array_shift(mailIds);

$mailStructure = imap_fetchstructure($imapStream, $mailId, FT_UID);

var_dump($mailStructure);
var_dump($mailStructure->parts[1]->dparameters[0]->value);
var_dump(urldecode('%D0%BF%D1%83%D1%81%D1%82%D0%BE%D0%B9%20%D1%84%D0%B0%D0'));

Expected result:
----------------
["dparameters"]=>
array(1) {
  [0]=>
  object(stdClass)#724 (2) {
    ["attribute"]=>
    string(8) "filename"
    ["value"]=>
    string(61) "UTF-8''%D0%BF%D1%83%D1%81%D1%82%D0%BE%D0%B9%20%D1%84%D0%B0%D0"
  }
}
["ifparameters"]=>
int(1)
["parameters"]=>
array(2) {
  [0]=>
  object(stdClass)#725 (2) {
    ["attribute"]=>
    string(7) "charset"
    ["value"]=>
    string(5) "UTF-8"
  }
  [1]=>
  object(stdClass)#726 (2) {
    ["attribute"]=>
    string(4) "name"
    ["value"]=>
    string(48) "=?UTF-8?B?0L/Rg9GB0YLQvtC5INGE0LDQudC7LnR4dA==?="
  }
}

string(61) "UTF-8''%D0%BF%D1%83%D1%81%D1%82%D0%BE%D0%B9%20%D1%84%D0%B0%D0"
string(18) "пустой фа�"

Actual result:
--------------
["dparameters"]=>
array(1) {
  [0]=>
  object(stdClass)#724 (2) {
    ["attribute"]=>
    string(8) "filename"
    ["value"]=>
    string(61) "UTF-8''%D0%BF%D1%83%D1%81%D1%82%D0%BE%D0%B9%20%D1%84%D0%B0%D0%B9%D0%BB%2E%74%78%74"
  }
}
["ifparameters"]=>
int(1)
["parameters"]=>
array(2) {
  [0]=>
  object(stdClass)#725 (2) {
    ["attribute"]=>
    string(7) "charset"
    ["value"]=>
    string(5) "UTF-8"
  }
  [1]=>
  object(stdClass)#726 (2) {
    ["attribute"]=>
    string(4) "name"
    ["value"]=>
    string(48) "=?UTF-8?B?0L/Rg9GB0YLQvtC5INGE0LDQudC7LnR4dA==?="
  }
}

string(61) "UTF-8''%D0%BF%D1%83%D1%81%D1%82%D0%BE%D0%B9%20%D1%84%D0%B0%D0%B9%D0%BB%2E%74%78%74"
string(25) "пустой файл.txt"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-11-19 13:05 UTC] saygushkin at gmail dot com
-Summary: CentOS release 6.2 (Final) +Summary: imap_fetchstructure dparameters[0]->value incomplete
 [2013-11-19 13:05 UTC] saygushkin at gmail dot com
fix summary
 [2013-11-19 19:21 UTC] requinix@php.net
Expected and actual outputs are backwards.

The relevant RFC is #2231: "MIME Parameter Value and Encoded Word Extensions: Character Sets, Languages, and Continuations"
http://tools.ietf.org/html/rfc2231

tl;dr: the filename would be interpreted as coming in multiple parts (because of the *Ns) and contains charset info (because of the trailing *s), and the value is decoded as UTF-8 (raw value is formatted as charset'language'value).
 [2020-10-16 14:27 UTC] cmb@php.net
-Status: Open +Status: Feedback -Assigned To: +Assigned To: cmb
 [2020-10-16 14:27 UTC] cmb@php.net
Based on requinix' comment, it's pretty clear what happens: the
continuation is ignored.  I can, however, not reproduce the
reported behavior.
 [2020-10-25 04:22 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
 [2021-02-03 15:15 UTC] amal dot mellouli at gmail dot com
HELLO

We are looking for solution to our problem which is : deal with filename*n* for example filename*0* / filename*1*, ... They don't appear in the result of the function imap_fetchstructure.
The body content appears but not the attachment's content.

Have you any solution please,

Best regards
 [2021-02-03 15:26 UTC] cmb@php.net
See <https://www.php.net/support>.
 [2021-02-03 15:49 UTC] amal dot mellouli at gmail dot com
Sorry, We could not find any reply or solution on the link.
Could you please tell us which function to execute to get attachment having name as filename*n*

Thanks a lot,

best regards
 [2021-02-03 15:55 UTC] cmb@php.net
For a list of more appropriate places to ask for help using PHP,
please visit http://www.php.net/support.php as this bug system is
not the appropriate forum for asking support questions.  Due to
the volume of reports we can not explain in detail here why your
report is not a bug.  The support channels will be able to provide
an explanation for you.

Thank you for your interest in PHP.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 12:01:28 2024 UTC