mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-12-22 14:41:29 +01:00
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:
parent
2e28640d9e
commit
9dfa6f6d4c
@ -1415,44 +1415,63 @@ class PHPMailer {
|
||||
* @return string
|
||||
*/
|
||||
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');
|
||||
$lines = preg_split('/(?:\r\n|\r|\n)/', $input);
|
||||
$eol = "\r\n";
|
||||
$escape = '=';
|
||||
$output = '';
|
||||
while( list(, $line) = each($lines) ) {
|
||||
$linlen = strlen($line);
|
||||
$newline = '';
|
||||
for($i = 0; $i < $linlen; $i++) {
|
||||
$c = substr( $line, $i, 1 );
|
||||
$dec = ord( $c );
|
||||
if ( ( $i == 0 ) && ( $dec == 46 ) ) { // convert first point in the line into =2E
|
||||
$c = '=2E';
|
||||
}
|
||||
if ( $dec == 32 ) {
|
||||
if ( $i == ( $linlen - 1 ) ) { // convert space at eol only
|
||||
$c = '=20';
|
||||
} else if ( $space_conv ) {
|
||||
$c = '=20';
|
||||
}
|
||||
} 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);
|
||||
//old behavior
|
||||
if ($line_max==76 && $space_conv === false) {
|
||||
$encoded = $this->FixEOL($input);
|
||||
if (substr($encoded, -(strlen($this->LE))) != $this->LE)
|
||||
$encoded .= $this->LE;
|
||||
|
||||
// Replace every high ascii, control and = characters
|
||||
$encoded = preg_replace('/([\000-\010\013\014\016-\037\075\177-\377])/e',
|
||||
"'='.sprintf('%02X', ord('\\1'))", $encoded);
|
||||
// Replace every spaces and tabs when it's the last character on a line
|
||||
$encoded = preg_replace("/([\011\040])".$this->LE."/e",
|
||||
"'='.sprintf('%02X', ord('\\1')).'".$this->LE."'", $encoded);
|
||||
|
||||
// Maximum line length of 76 characters before CRLF (74 + space + '=')
|
||||
$encoded = $this->WrapText($encoded, $line_max-2, true);
|
||||
|
||||
return $encoded;
|
||||
} else {
|
||||
$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);
|
||||
$eol = "\r\n";
|
||||
$escape = '=';
|
||||
$output = '';
|
||||
while( list(, $line) = each($lines) ) {
|
||||
$linlen = strlen($line);
|
||||
$newline = '';
|
||||
for($i = 0; $i < $linlen; $i++) {
|
||||
$c = substr( $line, $i, 1 );
|
||||
$dec = ord( $c );
|
||||
if ( ( $i == 0 ) && ( $dec == 46 ) ) { // convert first point in the line into =2E
|
||||
$c = '=2E';
|
||||
}
|
||||
if ( $dec == 32 ) {
|
||||
if ( $i == ( $linlen - 1 ) ) { // convert space at eol only
|
||||
$c = '=20';
|
||||
} else if ( $space_conv ) {
|
||||
$c = '=20';
|
||||
}
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user