399 "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F\x7F\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F\xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF\xB0\xB1\xB2\xB3\xB4\xB5\xB6\xB7\xB8\xB9\xBA\xBB\xBC\xBD\xBE\xBF\xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF";
412 return (strcspn($str, self::$qpKeysString) == strlen($str));
425 $lineLength = self::LINELENGTH,
426 $lineEnd = self::LINEEND
430 $str = self::_encodeQuotedPrintable($str);
433 while (strlen($str) > 0) {
435 if ($ptr > $lineLength) {
440 $pos = strrpos(substr($str, 0, $ptr),
'=');
441 if (
$pos !==
false &&
$pos >= $ptr - 2) {
446 if ($ptr > 0 && $str[$ptr - 1] ==
' ') {
451 $out .= substr($str, 0, $ptr) .
'=' . $lineEnd;
452 $str = substr($str, $ptr);
455 $out = rtrim($out, $lineEnd);
456 $out = rtrim($out,
'=');
467 private static function _encodeQuotedPrintable($str)
469 $str = str_replace(
'=',
'=3D', $str);
470 $str = str_replace(self::$qpKeys, self::$qpReplaceValues, $str);
489 $str, $charset, $lineLength = self::LINELENGTH, $lineEnd = self::LINEEND
493 $prefix = sprintf(
'=?%s?Q?', $charset);
494 $lineLength = $lineLength - strlen(
$prefix) - 3;
496 $str = self::_encodeQuotedPrintable($str);
500 array(
'?',
' ',
'_',
','), array(
'=3F',
'=20',
'=5F',
'=2C'), $str
504 $lines = array(0 =>
"");
508 while (strlen($str) > 0) {
509 $currentLine = max(count($lines) - 1, 0);
510 $token = self::getNextQuotedPrintableToken($str);
511 $str = substr($str, strlen(
$token));
517 if (strlen($lines[$currentLine] . $tmp) > $lineLength) {
518 $lines[$currentLine + 1] = $tmp;
520 $lines[$currentLine] .= $tmp;
525 if (strlen($str) == 0) {
526 $lines[$currentLine] .= $tmp;
531 for (
$i = 0;
$i < count($lines);
$i++) {
534 $str = trim(implode($lineEnd, $lines));
545 private static function getNextQuotedPrintableToken($str)
547 if (substr($str, 0, 1) ==
"=") {
548 $token = substr($str, 0, 3);
550 $token = substr($str, 0, 1);
566 $str, $charset, $lineLength = self::LINELENGTH, $lineEnd = self::LINEEND
569 $prefix =
'=?' . $charset .
'?B?';
571 $remainingLength = $lineLength - strlen(
$prefix) - strlen(
$suffix);
574 $encodedValue = str_replace(
579 return $encodedValue;
592 $str, $lineLength = self::LINELENGTH, $lineEnd = self::LINEEND
595 return rtrim(chunk_split(base64_encode($str), $lineLength, $lineEnd));
606 if ($boundary ===
null) {
607 $this->_boundary =
'=_' . md5(microtime(1) . self::$makeUnique++);
609 $this->_boundary = $boundary;
621 public static function encode($str, $encoding, $EOL = self::LINEEND)
657 return $EOL .
'--' . $this->_boundary . $EOL;
668 return $EOL .
'--' . $this->_boundary .
'--' . $EOL;
static encode($str, $encoding, $EOL=self::LINEEND)
const ENCODING_QUOTEDPRINTABLE
static encodeQuotedPrintableHeader( $str, $charset, $lineLength=self::LINELENGTH, $lineEnd=self::LINEEND)
static encodeBase64( $str, $lineLength=self::LINELENGTH, $lineEnd=self::LINEEND)
static encodeQuotedPrintable( $str, $lineLength=self::LINELENGTH, $lineEnd=self::LINEEND)
const MULTIPART_ALTERNATIVE
const DISPOSITION_ATTACHMENT
static encodeBase64Header( $str, $charset, $lineLength=self::LINELENGTH, $lineEnd=self::LINEEND)
__construct($boundary=null)
boundaryLine($EOL=self::LINEEND)
mimeEnd($EOL=self::LINEEND)