PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Mail » Mail_Mime » Bug #6726

_mimeencodeheaders

Details

Submitted2006-02-08 11:19 UTC
Fromvilius dot simonaitis at gmail dot com
Assignedcipri
StatusBogus
PackageMail_Mime
PHP VersionIrrelevant
OSAll
Roadmaps(Not assigned)

Comments

[2006-02-08 11:19 UTC] vilius dot simonaitis at gmail dot com

Description:
------------
function _encodeHeaders encodes UTF-8 characters and spaces incorectly. In case of more than one non-latin character in one word, ir encodes them incerectly.
It also encodes spaces incorectly.

function _encodeHeaders($input)
{
foreach ($input as $hdr_name => $hdr_value) {
preg_match_all('/((\w*[\x80-\xFF]+\w*)+\s*)/', $hdr_value, $matches);
foreach ($matches[1] as $value) {
$replacement = preg_replace('/([\x80-\xFF])/e',
'"=" .
strtoupper(dechex(ord("\1")))',
$value);
$hdr_value = str_replace($value, '=?' .
$this->_build_params['head_charset'] .
'?Q?' . $replacement . '?=',
$hdr_value);
}
$input[$hdr_name] = $hdr_value;
}

return $input;
}

Test script:
---------------
$string = "Greitas rudas èiukèë ðoka per girtà rusà";
preg_match_all('/((\w*[\x80-\xFF]+\w*)+\s*)/', $string, $matches);

echo "<pre>";
print_r($matches);
echo "</pre>";

Expected result:
----------------
The test should match four whole words together with leading spaces:

Array
(
[0] => Array
(
[0] => èiukèë
[1] => ðoka
[2] => girtà
[3] => rusà
)

[1] => Array
(
[0] => èiukèë
[1] => ðoka
[2] => girtà
[3] => rusà
)

[2] => Array
(
[0] => ?ë
[1] => ðoka
[2] => girtà
[3] => rusà
)

)

Actual result:
--------------
Current preg_match splits the second UTF-8 character into two pieces. This result incorect subject in mail: some character and spaces are dissapearing.

Array
(
[0] => Array
(
[0] => èiukĊ [1] => ?ë
[2] => ðoka
[3] => girtà
[4] => rusà
)

[1] => Array
(
[0] => èiukĊ [1] => ?ë
[2] => ðoka
[3] => girtà
[4] => rusà
)

)