Since having problems with the new phpmailers EncodeQP function and its Char and Line/WordWrap Handling, I reintroduce the functionality of the old

class.
This commit is contained in:
Klaus Leithoff 2008-07-08 08:38:56 +00:00
parent 2e28640d9e
commit 9dfa6f6d4c

View File

@ -1415,44 +1415,63 @@ class PHPMailer {
* @return string * @return string
*/ */
public function EncodeQP( $input = '', $line_max = 76, $space_conv = false ) { public function EncodeQP( $input = '', $line_max = 76, $space_conv = false ) {
$hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); //old behavior
$lines = preg_split('/(?:\r\n|\r|\n)/', $input); if ($line_max==76 && $space_conv === false) {
$eol = "\r\n"; $encoded = $this->FixEOL($input);
$escape = '='; if (substr($encoded, -(strlen($this->LE))) != $this->LE)
$output = ''; $encoded .= $this->LE;
while( list(, $line) = each($lines) ) {
$linlen = strlen($line); // Replace every high ascii, control and = characters
$newline = ''; $encoded = preg_replace('/([\000-\010\013\014\016-\037\075\177-\377])/e',
for($i = 0; $i < $linlen; $i++) { "'='.sprintf('%02X', ord('\\1'))", $encoded);
$c = substr( $line, $i, 1 ); // Replace every spaces and tabs when it's the last character on a line
$dec = ord( $c ); $encoded = preg_replace("/([\011\040])".$this->LE."/e",
if ( ( $i == 0 ) && ( $dec == 46 ) ) { // convert first point in the line into =2E "'='.sprintf('%02X', ord('\\1')).'".$this->LE."'", $encoded);
$c = '=2E';
} // Maximum line length of 76 characters before CRLF (74 + space + '=')
if ( $dec == 32 ) { $encoded = $this->WrapText($encoded, $line_max-2, true);
if ( $i == ( $linlen - 1 ) ) { // convert space at eol only
$c = '=20'; return $encoded;
} else if ( $space_conv ) { } else {
$c = '=20'; $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);
} elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required $eol = "\r\n";
$h2 = floor($dec/16); $escape = '=';
$h1 = floor($dec%16); $output = '';
$c = $escape.$hex[$h2].$hex[$h1]; while( list(, $line) = each($lines) ) {
} $linlen = strlen($line);
if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted $newline = '';
$output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay for($i = 0; $i < $linlen; $i++) {
$newline = ''; $c = substr( $line, $i, 1 );
// check if newline first character will be point or not $dec = ord( $c );
if ( $dec == 46 ) { if ( ( $i == 0 ) && ( $dec == 46 ) ) { // convert first point in the line into =2E
$c = '=2E'; $c = '=2E';
} }
} if ( $dec == 32 ) {
$newline .= $c; if ( $i == ( $linlen - 1 ) ) { // convert space at eol only
} // end of for $c = '=20';
$output .= $newline.$eol; } else if ( $space_conv ) {
} // end of while $c = '=20';
return trim($output); }
} elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required
$h2 = floor($dec/16);
$h1 = floor($dec%16);
$c = $escape.$hex[$h2].$hex[$h1];
}
if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted
$output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay
$newline = '';
// check if newline first character will be point or not
if ( $dec == 46 ) {
$c = '=2E';
}
}
$newline .= $c;
} // end of for
$output .= $newline.$eol;
} // end of while
return trim($output);
}
} }
/** /**