-
- Notifications
You must be signed in to change notification settings - Fork 183
Description
Describe the bug
The getAttachment function cannot find the attachment because the returned boundary is not properly parsed.
Only using the getAttachment () function.
In the mail header, when there is a string after the boundary, the regex also takes that string. This creates a bad boundary, and the attachment is not found.
Code to Reproduce
The following code returns:
"----=EDF_mixed"; charset="ISO-8859-1"
and after clearBoundaryString, this code return the bad boundary:
----=EDF_mixed charset=ISO-8859-1
<?php $part_of_header = 'Content-Type: multipart/mixed; boundary="----=EDF_mixed"; charset="ISO-8859-1"'; // Header.php, function getBoundary() - l.176 $actual_pattern = "/boundary\=(.*)/i"; // Header.php, function find() - l.159 if (preg_match_all($actual_pattern, $part_of_header, $matches)) { if (isset($matches[1])) { if(count($matches[1]) > 0) { var_dump( $matches[1][0]); } } } The following code returns:
"----=EDF_mixed"
and after clearBoundaryString, this code return the good boundary:
----=EDF_mixed
<?php $part_of_header = 'Content-Type: multipart/mixed; boundary="----=EDF_mixed"; charset="ISO-8859-1"'; // Header.php, l.176 $actual_pattern = "/boundary=\"?([^\"]*)[\";\s]/i"; if (preg_match_all($actual_pattern, $part_of_header, $matches)) { if (isset($matches[1])) { if(count($matches[1]) > 0) { var_dump( $matches[1][0]); } } } Expected behavior
Change the regex to:
/boundary=\"?([^\"]*)[\";\s]/i
like the example in the documentation:
https://www.php-imap.com/api/header
Desktop / Server (please complete the following information):
- OS: Ubuntu
- PHP: 7.4.13
- Version: v2.4.0