0 && substr($line, -1) == ' ' || substr($line, -1) == '\t') /* if (linelen > 0 && (line[linelen-1] == ' ' || line[linelen-1] == '\t')) */ { if ($linelen < 74) { /* sprintf (line+linelen-1, "=%2.2X", (unsigned char) line[linelen-1]); */ $line = substr_replace($line, sprintf("=%2.2X", ord(substr($line, -1))), -1); /* fputs (line, fout); */ $fout .= $line; } else { /* int savechar = line[linelen-1]; */ $savechar = substr($line, -1); /* line[linelen-1] = '='; line[linelen] = 0; fputs (line, fout); fprintf (fout, "\n=%2.2X", (unsigned char) savechar); */ $line = substr_replace($line, '=', -1); $fout .= $line . "\n" . sprintf("=%2.2X", ord($savechar)); $line = ""; } } else { /* line[linelen] = 0; */ $line = ""; /* fputs (line, fout); */ $fout .= $line; } /* fputc ('\n', fout); */ $fout .= "\n"; $linelen = 0; } else if (ord($c) != 9 && (ord($c) < 32 || ord($c) > 126 || ord($c) == '=')) { /* Check to make sure there is enough room for the quoted character. * If not, wrap to the next line. */ if ($linelen > 73) { $line .= "=\n"; $fout .= $line; /* line[linelen++] = '='; line[linelen] = 0; fputs (line, fout); fputc ('\n', fout); */ $linelen = 0; } /* sprintf (line+linelen,"=%2.2X", (unsigned char) c); */ $line .= sprintf("=%2.2X", ord($c)); $linelen += 3; } else { /* Don't worry about wrapping the line here. That will happen during * the next iteration when I'll also know what the next character is. */ /* line[linelen++] = c; */ $line .= $c; } } /* Take care of anything left in the buffer */ if ($linelen > 0) { if (substr($line, -1) == ' ' || substr($line, -1) == '\t') { /* take care of trailing whitespace */ if ($linelen < 74) /* sprintf (line+linelen-1, "=%2.2X", (unsigned char) line[linelen-1]); */ $line = substr_replace($line, sprintf("=%2.2X", ord(substr($line, -1))), -1); else { /* savechar = line[linelen-1]; line[linelen-1] = '='; line[linelen] = 0; fputs (line, fout); fputc ('\n', fout); sprintf (line, "=%2.2X", (unsigned char) savechar); */ $savechar = substr($line, -1); $line = substr_replace($line, '=', -1); $fout .= $line . "\n"; $line = sprintf("=%2.2X", ord($savechar)); } } /* else line[linelen] = 0; */ /* fputs (line, fout); */ $fout .= $line; } return $fout; } /* function translated from a C version taken from * cclient-2001a, a C imap access library */ function qp_encode_cclient($string) { $hex = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'); $ret = ""; $i = 0; $lp = 0; while ($i < strlen($string)) { /* for each char */ /* true line break? */ if ( (($c = $string[$i++]) == '\015') && ($i < strlen($string)) && ($string[$i] == '\012')) { $ret .= '\015'; $ret .= $string[$i++]; $lp = 0; /* reset line count */ } else { /* not a line break */ /* quoting required? */ if (ctype_cntrl($c) || (ord($c) == 0x7f) || (ord($c) & 0x80) || ($c == '=') || (($c == ' ') && ($string[$i] == '\015'))) { if (($lp += 3) > MAXL) { /* would line overflow? */ $ret .= "=\015\012"; $lp = 3; } $ret .= '='; /* quoting character */ $h2 = floor(ord($c)/16); $h1 = floor(ord($c)%16); $ret .= $hex[$h2]; $ret .= $hex[$h1]; /* les operateurs de shift en PHP sont merdiques, ceci ne * fonctionne pas */ /* $ret .= $hex[((int)$c) >> 4]; */ /* high order 4 bits */ /* $ret .= $hex[((int)$c) & 0xf]; */ /* low order 4 bits */ } else { if ( (++$lp) > MAXL) { /* would line overflow? */ $ret .= "=\015\012"; $lp = 1; } $ret .= $c; /* ordinary character */ } } } return $ret; } if (!function_exists("imap_8bit")) { function imap_8bit($str) { return str_replace("\r",'', qp_encode_cclient($str)); } } if (!function_exists("ctype_cntrl")) { function ctype_cntrl($str) { return (ord($str) > 0 && ord($str) < 32); } } ?>