PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Mail » Mail_Mime » Bug #7561

Mail_mimePart::_quotedPrintableEncode() misbehavior with mbstring overload

Details

Submitted2006-05-05 09:23 UTC
Fromphp at diptyque dot net
Assignedcipri
StatusClosed
PackageMail_Mime
PHP VersionIrrelevant
OSFreeBSD
Roadmaps1.4.0, 1.4.0a1

Comments

[2006-05-05 09:23 UTC] php at diptyque dot net

Description:
------------
Mail_mimePart::_quotedPrintableEncode() does not properly
encode multi-byte characters when mbstring overload is
enabled: it only encodes the first byte and skips any
following byte(s)

; php.ini Multi-byte string setup
mbstring.language = Neutral; (UTF-8)
mbstring.func_overload = 6; see [1]
mbstring.internal_encoding = UTF-8
mbstring.http_output = UTF-8

[1]
(http://www.php.net/manual/en/ref.mbstring.php#mbstring.ove
rload)

Test script:
---------------
=begin TEST
<?php

require_once 'Mail/mimePart.php';

// string is UTF-8 encoded
$input = "Micha\xC3\xABl \xC3\x89ric St\xC3\xA9phane";

$rv = Mail_mimePart::_quotedPrintableEncode($input);
echo $rv, "\n";

?>
=end TEST

A multi-byte string agnostic patch:

=begin DIFF
diff -u mimePart.php.bak mimePart.php
--- mimePart.php.bak Thu Jan 19 13:09:40 2006
+++ mimePart.php Tue Apr 25 11:19:34 2006
@@ -318,11 +318,12 @@

while(list(, $line) = each($lines)){

- $linlen = strlen($line);
+ $line = preg_split('//', $line, -1, PREG_SPLIT_NO_EMPTY);
+ $linlen = count($line);
$newline = '';

for ($i = 0; $i < $linlen; $i++) {
- $char = substr($line, $i, 1);
+ $char = $line[$i];
$dec = ord($char);

if (($dec == 32) AND ($i == ($linlen - 1))){ // convert space at eol only
=end DIFF

Expected result:
----------------
Micha=C3=ABl =C3=89ric St=C3=A9phane

Actual result:
--------------
Micha=C3l =C3ric St=C3phane