barbushin / php-imap

Manage mailboxes, filter/get/delete emails in PHP (supports IMAP/POP3/NNTP)
MIT License
1.65k stars 459 forks source link

[BUG] Long attachment names are truncated on rfc2231 email header #684

Open christianasche opened 1 year ago

christianasche commented 1 year ago

Environment (please complete the following information):

Describe the bug

Receiving email attachments with the following header creates incomplete filenames.

Content-Disposition: attachment;
    filename*0*="utf-8''A%20very%20very%20...%20";
    filename*1*="long%20filename.pdf"

The name property of the IncomingMailAttachment object should be 'A very very ... long filename.pdf', but instead is 'A very very ...'. The part in filename1 is missing.

The filename is already truncated in der $params parameter of the downloadAttachment() method.

Without further investigation, I think the cause could probably be in line 1755 of src/PhpImap/Mailbox.php.

$paramName = \strtolower(\preg_match('~^(.*?)\*~', $param->attribute, $matches) ? (!isset($matches[1]) ?: $matches[1]) : $param->attribute);

Receiving email attachments with this type of header works as expected:

Content-Disposition: attachment;
    filename="A very very ... long filename.pdf"; ...