Project

General

Profile

Bug #17310 ยป quoted-printable.diff

Administrator Admin, 2007-05-14 18:11

View differences:

TYPO3_trunk/t3lib/class.t3lib_div.php (working copy)
*
* @param string Content to encode
* @param integer Length of the lines, default is 76
* @param boolean $header indicates, that $string should be encoded for an email header line
* @return string The QP encoded string
*/
function quoted_printable($string,$maxlen=76) {
function quoted_printable($string,$maxlen=76,$header=false) {
// Make sure the string contains only Unix linebreaks
$string = str_replace(chr(13).chr(10), chr(10), $string); // Replace Windows breaks (\r\n)
$string = str_replace(chr(13), chr(10), $string); // Replace Mac breaks (\r)
......
$newVal.='='.$linebreak; // Add a line break
$len=0; // Reset the length counter
}
if (($ordVal>=33 && $ordVal<=60) || ($ordVal>=62 && $ordVal<=126) || $ordVal==9 || $ordVal==32) {
if ( !$header && ( ($ordVal>=33 && $ordVal<=60) || ($ordVal>=62 && $ordVal<=126) || $ordVal==9 || $ordVal==32) ) {
$newVal.=$char; // This character is ok, add it to the message
$len++;
} elseif ( $header && ( ( $ordVal>=32 && $ordVal<=126 && ! ( $ordVal==61 || $ordVal==63 || $ordVal==95 ) ) ) ) {
$newVal .= $char;
$len++;
} else {
$newVal.=sprintf('=%02X',$ordVal); // Special character, needs to be encoded
$len+=3;
......
if (strstr($line,'###')) return $line;
// Check if any non-ASCII characters are found - otherwise encoding is not needed
if (!preg_match('/[^'.chr(32).'-'.chr(127).']/',$line)) return $line;
// if (!preg_match('/[^'.chr(32).'-'.chr(127).']/',$line)) return $line;
if (!preg_match('/[^\w\d]/',$line)) return $line;
// Wrap email addresses in a special marker
$line = preg_replace('/([^ ]+@[^ ]+)/', '###$1###', $line);
......
break;
case 'quoted-printable':
default:
$qpValue = t3lib_div::quoted_printable($part,1000);
$qpValue = t3lib_div::quoted_printable($part,1000,true);
if ($part!=$qpValue) {
$qpValue = str_replace(' ','_',$qpValue); // Encoded words in the header should not contain non-encoded spaces. "_" is a shortcut for "=20". See RFC 2047 for details.
$part = '=?'.$charset.'?Q?'.$qpValue.'?=';
    (1-1/1)