59 public const CHARSET_REGEX =
'#=\?(?P<charset>[\x21\x23-\x26\x2a\x2b\x2d\x5e\5f\60\x7b-\x7ea-zA-Z0-9]+)\?(?P<encoding>[\x21\x23-\x26\x2a\x2b\x2d\x5e\5f\60\x7b-\x7ea-zA-Z0-9]+)\?(?P<text>[\x21-\x3e\x40-\x7e]+)#';
403 "\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";
417 return strcspn($str, static::$qpKeysString) ===
strlen($str);
430 $lineLength = self::LINELENGTH,
431 $lineEnd = self::LINEEND
434 $str = self::_encodeQuotedPrintable($str);
438 $strLength =
strlen($str);
439 while ($initialPtr < $strLength) {
440 $continueAt = $strLength - $initialPtr;
442 if ($continueAt > $lineLength) {
443 $continueAt = $lineLength;
446 $chunk =
substr($str, $initialPtr, $continueAt);
449 $endingMarkerPos =
strrpos($chunk,
'=');
450 if ($endingMarkerPos !==
false && $endingMarkerPos >=
strlen($chunk) - 2) {
451 $chunk =
substr($chunk, 0, $endingMarkerPos);
452 $continueAt = $endingMarkerPos;
455 if (
ord($chunk[0]) === 0x2E) {
456 $chunk =
'=2E' .
substr($chunk, 1);
470 $out .= $chunk .
'=' . $lineEnd;
471 $initialPtr += $continueAt;
474 $out =
rtrim($out, $lineEnd);
475 $out =
rtrim($out,
'=');
486 private static function _encodeQuotedPrintable($str)
490 $str =
str_replace(static::$qpKeys, static::$qpReplaceValues, $str);
514 $lineLength = self::LINELENGTH,
515 $lineEnd = self::LINEEND,
519 $prefix =
sprintf(
'=?%s?Q?', $charset);
520 $lineLength = $lineLength -
strlen($prefix) - 3;
522 $str = self::_encodeQuotedPrintable($str);
525 $str =
str_replace([
'?',
',',
' ',
'_',
'(',
')'], [
'=3F',
'=2C',
'=20',
'=5F',
'=28',
'=29'], $str);
532 while (
strlen($str) > 0) {
533 $currentLine =
max(
count($lines) - 1, 0);
534 $token = static::getNextQuotedPrintableToken($str);
536 $str =
false === $substr ?
'' : $substr;
542 if ($currentLine === 0) {
544 $currentLineLength =
strlen($lines[$currentLine] . $tmp) + $headerNameSize;
546 $currentLineLength =
strlen($lines[$currentLine] . $tmp);
549 $lineLimitReached = $currentLineLength > $lineLength;
550 $noCurrentLine = $lines[$currentLine] ===
'';
551 if ($noCurrentLine && $lineLimitReached) {
552 $lines[$currentLine] = $tmp;
553 $lines[$currentLine + 1] =
'';
554 }
elseif ($lineLimitReached) {
555 $lines[$currentLine + 1] = $tmp;
557 $lines[$currentLine] .= $tmp;
563 $lines[$currentLine] .= $tmp;
569 $lines[$i] =
" " . $prefix . $lines[$i] .
"?=";
581 private static function getNextQuotedPrintableToken($str)
583 if (0 ===
strpos($str,
'=')) {
603 $lineLength = self::LINELENGTH,
604 $lineEnd = self::LINEEND
606 $prefix =
'=?' . $charset .
'?B?';
610 $encodedValue = static::encodeBase64($str, $remainingLength, $lineEnd);
611 $encodedValue =
str_replace($lineEnd,
$suffix . $lineEnd .
' ' . $prefix, $encodedValue);
612 $encodedValue = $prefix . $encodedValue .
$suffix;
613 return $encodedValue;
627 $lineLength = self::LINELENGTH,
628 $lineEnd = self::LINEEND
630 $lineLength = $lineLength - ($lineLength % 4);
660 public static function encode($str, $encoding, $EOL = self::LINEEND)
663 case self::ENCODING_BASE64:
664 return static::encodeBase64($str, self::LINELENGTH, $EOL);
666 case self::ENCODING_QUOTEDPRINTABLE:
667 return static::encodeQuotedPrintable($str, self::LINELENGTH, $EOL);
697 return $EOL .
'--' . $this->
boundary . $EOL;
709 return $EOL .
'--' . $this->
boundary .
'--' . $EOL;
722 if (
preg_match(self::CHARSET_REGEX, $str, $matches)) {
boundaryLine($EOL=self::LINEEND)
Return a MIME boundary line.
static encodeBase64Header($str, $charset, $lineLength=self::LINELENGTH, $lineEnd=self::LINEEND)
Encode a given string in mail header compatible base64 encoding.
const DISPOSITION_ATTACHMENT
Support class for MultiPart Mime Messages.
static encodeQuotedPrintableHeader($str, $charset, $lineLength=self::LINELENGTH, $lineEnd=self::LINEEND, $headerNameSize=0)
Encode a given string with the QUOTED_PRINTABLE mechanism for Mail Headers.
const ENCODING_QUOTEDPRINTABLE
static mimeDetectCharset($str)
Detect MIME charset.
if($item instanceof\ElggEntity) elseif($item instanceof\ElggRiverItem) elseif($item instanceof\ElggRelationship) elseif(is_callable([$item, 'getType']))
mimeEnd($EOL=self::LINEEND)
Return MIME ending.
static isPrintable($str)
Check if the given string is "printable".
const MULTIPART_ALTERNATIVE
static encode($str, $encoding, $EOL=self::LINEEND)
Encode the given string with the given encoding.
boundary()
Return a MIME boundary.
static encodeBase64($str, $lineLength=self::LINELENGTH, $lineEnd=self::LINEEND)
Encode a given string in base64 encoding and break lines according to the maximum linelength...
static encodeQuotedPrintable($str, $lineLength=self::LINELENGTH, $lineEnd=self::LINEEND)
Encode a given string with the QUOTED_PRINTABLE mechanism and wrap the lines.
__construct($boundary=null)
Constructor.
const MESSAGE_DELIVERY_STATUS