From 99d43c8e0fc1153a3cdd83d9596f0412a8cb0831 Mon Sep 17 00:00:00 2001 From: x2000habouzit Date: Fri, 29 Oct 2004 14:59:26 +0000 Subject: [PATCH] more clever + should close #80 --- include/xorg.misc.inc.php | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/include/xorg.misc.inc.php b/include/xorg.misc.inc.php index d7f1235..e989557 100644 --- a/include/xorg.misc.inc.php +++ b/include/xorg.misc.inc.php @@ -18,32 +18,31 @@ * Foundation, Inc., * * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * *************************************************************************** - $Id: xorg.misc.inc.php,v 1.7 2004-10-21 13:12:06 x2000habouzit Exp $ + $Id: xorg.misc.inc.php,v 1.8 2004-10-29 14:59:26 x2000habouzit Exp $ ***************************************************************************/ 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); - $eol = "\r\n"; - $linebreak = "=0A"; + $eol = "\n"; + $linebreak = "=0D=0A=\n "; $escape = "="; $output = ""; - for ($j=0;$j $line) { $linlen = strlen($line); $newline = ""; for($i = 0; $i < $linlen; $i++) { - $c = substr($line, $i, 1); + $c = $line{$i}; $dec = ord($c); - if ( ($dec == 32) && ($i == ($linlen - 1)) ) { // convert space at eol only + if ( ($dec == 32) && ($i == ($linlen - 1)) ) { + // convert space at eol only $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"]; + } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { + // always encode "\t", which is *not* required + $c = $escape.strtoupper(sprintf("%02x",$dec)); } if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted - $output .= $newline.$escape."\n"; // soft line break; " =\r\n" is okay + $output .= $newline.$escape.$eol; $newline = " "; } $newline .= $c; -- 2.1.4