12 use 
function base64_encode;
 
   13 use 
function chunk_split;
 
   18 use 
function microtime;
 
   20 use 
function preg_match;
 
   23 use 
function str_replace;
 
   28 use 
function strtoupper;
 
   30 use 
function substr_replace;
 
   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);
 
  460             switch (ord(substr($chunk, strlen($chunk) - 1))) {
 
  462                     $chunk = substr_replace($chunk, 
'=09', strlen($chunk) - 1, 1);
 
  465                     $chunk = substr_replace($chunk, 
'=20', strlen($chunk) - 1, 1);
 
  470             $out        .= $chunk . 
'=' . $lineEnd;
 
  471             $initialPtr += $continueAt;
 
  474         $out = rtrim($out, $lineEnd);
 
  475         $out = rtrim($out, 
'=');
 
  486     private static function _encodeQuotedPrintable($str)
 
  489         $str = str_replace(
'=', 
'=3D', $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);
 
  535             $substr      = substr($str, strlen(
$token));
 
  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;
 
  562             if (strlen($str) === 0) {
 
  563                 $lines[$currentLine] .= $tmp;
 
  568         for ($i = 0, 
$count = count($lines); $i < 
$count; $i++) {
 
  569             $lines[$i] = 
" " . $prefix . $lines[$i] . 
"?=";
 
  571         $str = trim(implode($lineEnd, $lines));
 
  581     private static function getNextQuotedPrintableToken($str)
 
  583         if (0 === strpos($str, 
'=')) {
 
  584             $token = substr($str, 0, 3);
 
  586             $token = substr($str, 0, 1);
 
  603         $lineLength = self::LINELENGTH,
 
  604         $lineEnd = self::LINEEND
 
  606         $prefix          = 
'=?' . $charset . 
'?B?';
 
  608         $remainingLength = $lineLength - strlen($prefix) - strlen(
$suffix);
 
  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);
 
  631         return rtrim(chunk_split(base64_encode($str), $lineLength, $lineEnd));
 
  644             $this->
boundary = 
'=_' . md5(microtime(1) . static::$makeUnique++);
 
  660     public static function encode($str, $encoding, $EOL = self::LINEEND)
 
  664                 return static::encodeBase64($str, self::LINELENGTH, $EOL);
 
  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)) {
 
  723             return strtoupper($matches[
'charset']);
 
Support class for MultiPart Mime Messages.
static encodeBase64Header( $str, $charset, $lineLength=self::LINELENGTH, $lineEnd=self::LINEEND)
Encode a given string in mail header compatible base64 encoding.
const MESSAGE_DELIVERY_STATUS
static encodeBase64( $str, $lineLength=self::LINELENGTH, $lineEnd=self::LINEEND)
Encode a given string in base64 encoding and break lines according to the maximum linelength.
const MULTIPART_ALTERNATIVE
static encode($str, $encoding, $EOL=self::LINEEND)
Encode the given string with the given encoding.
static mimeDetectCharset($str)
Detect MIME charset.
boundary()
Return a MIME boundary.
const ENCODING_QUOTEDPRINTABLE
static isPrintable($str)
Check if the given string is "printable".
__construct($boundary=null)
Constructor.
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 DISPOSITION_ATTACHMENT
mimeEnd($EOL=self::LINEEND)
Return MIME ending.
boundaryLine($EOL=self::LINEEND)
Return a MIME boundary line.
static encodeQuotedPrintable( $str, $lineLength=self::LINELENGTH, $lineEnd=self::LINEEND)
Encode a given string with the QUOTED_PRINTABLE mechanism and wrap the lines.
if($item instanceof \ElggEntity) elseif($item instanceof \ElggRiverItem) elseif($item instanceof \ElggRelationship) elseif(is_callable([ $item, 'getType']))