note 99018 deleted from function.quoted-printable-encode by danbrown
| From: | danbrown@php.net | Date: | Thu, 22 Jul 2010 14:41:44 +0000 |
| Subject: | note 99018 deleted from function.quoted-printable-encode by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-171043@lists.php.net to get a copy of this message | ||
Note Submitter: poulphunter at yahoo dot fr
----
I use that for PHP < 5.3 :
function mime_qp_long_line($input,$line_max = 76)
{
$length=strlen($input);
$output='';
$output.=$input[0];
$outlen=1;
for ($i=1;$i<$length;$i++)
{
$outlen++;
if ($input[$i]=='=')
{
if ((intval($outlen/$line_max)!=intval(($outlen+2)/$line_max)))
{
$output.="=\n";
$outlen+=3;
}
}
$output.=$input[$i];
if ((($outlen+1)%$line_max)===0 && $input[$i]!='=')
{
$output.="=\n";
$outlen++;
}
}
return $output;
}
function quoted_printable_encode($input, $line_max = 76) {
$hex =
array('0','1','2','3','4','5','6','7',
'8','9','A','B','C','D','E','F');
$lines = preg_split("/(?:\r\n|\r|\n)/", $input);
/* the linebreak also counts as characters in the mime_qp_long_line
* rule of spam-assassin */
$escape = "=";
$output = "";
$cur_conv_line = "";
$length = 0;
$whitespace_pos = 0;
$addtl_chars = 0;
// iterate lines
for ($j=0; $j<count($lines); $j++) {
$line = $lines[$j];
$linlen = strlen($line);
// iterate chars
for ($i = 0; $i < $linlen; $i++)
{
$c = substr($line, $i, 1);
$dec = ord($c);
$length++;
if ($dec == 32) {
// space occurring at end of line, need to encode
if (($i == ($linlen - 1))) {
$c = "=20";
$length += 2;
}
$addtl_chars = 0;
$whitespace_pos = $i;
} elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) {
$h2 = floor($dec/16); $h1 = floor($dec%16);
$c = $escape . $hex["$h2"] . $hex["$h1"];
$length += 2;
$addtl_chars += 2;
}
$cur_conv_line .= $c;
} // end of for
$length = 0;
$whitespace_pos = 0;
$output .= $cur_conv_line;
$cur_conv_line = "";
if ($j<=count($lines)-1) {
$output .= $linebreak;
}
} // end for
return mime_qp_long_line(trim($output),$line_max);
} // end quoted_printable_encode