Ejemplo n.º 1
0
 /**
  * Returns encoded data based upon encoding passed to it
  *
  * @param $data     The data to encode.
  * @param $encoding The encoding type to use, 7bit, base64,
  *                  or quoted-printable.
  */
 private function getEncodedData($data, $encoding)
 {
     switch ($encoding) {
         case '8bit':
         case '7bit':
             return $data;
             break;
         case 'quoted-printable':
             return $this->quotedPrintableEncode($data);
             break;
         case 'base64':
             return rtrim(chunk_explode(base64_encode($data), 76, MAIL_MIMEPART_CRLF));
             break;
         default:
             return $data;
     }
 }
Ejemplo n.º 2
0
 public function encode($input)
 {
     return rtrim(chunk_explode(base64_encode($input), 76, defined('MAIL_MIME_PART_CRLF') ? MAIL_MIME_PART_CRLF : "\r\n"));
 }
Ejemplo n.º 3
0
 /**
  * Encode a header string to best (shortest) of Q, B, quoted or none.
  * @access public
  * @return string
  */
 public function EncodeHeader($str, $position = 'text')
 {
     $x = 0;
     switch (strtolower($position)) {
         case 'phrase':
             if (!preg_match('/[\\200-\\377]/', $str)) {
                 // Can't use addslashes as we don't know what value has magic_quotes_sybase
                 $encoded = addcslashes($str, "..\\\"");
                 if ($str == $encoded && !preg_match('/[^A-Za-z0-9!#$%&\'*+\\/=?^_`{|}~ -]/', $str)) {
                     return $encoded;
                 } else {
                     return "\"{$encoded}\"";
                 }
             }
             $x = preg_match_all('/[^\\040\\041\\043-\\133\\135-\\176]/', $str, $matches);
             break;
         case 'comment':
             $x = preg_match_all('/[()"]/', $str, $matches);
             // Fall-through
         // Fall-through
         case 'text':
         default:
             $x += preg_match_all('/[\\000-\\010\\013\\014\\016-\\037\\177-\\377]/', $str, $matches);
             break;
     }
     if ($x == 0) {
         return $str;
     }
     $maxlen = 75 - 7 - strlen($this->CharSet);
     // Try to select the encoding which should produce the shortest output
     if (strlen($str) / 3 < $x) {
         $encoding = 'B';
         if (function_exists('mb_strlen') && $this->HasMultiBytes($str)) {
             // Use a custom function which correctly encodes and wraps long
             // multibyte strings without breaking lines within a character
             $encoded = $this->Base64EncodeWrapMB($str);
         } else {
             $encoded = base64_encode($str);
             $maxlen -= $maxlen % 4;
             $encoded = trim(chunk_explode($encoded, $maxlen, "\n"));
         }
     } else {
         $encoding = 'Q';
         $encoded = $this->EncodeQ($str, $position);
         $encoded = $this->WrapText($encoded, $maxlen, true);
         $encoded = str_replace('=' . $this->LE, "\n", trim($encoded));
     }
     $encoded = preg_replace('/^(.*)$/m', " =?" . $this->CharSet . "?{$encoding}?\\1?=", $encoded);
     $encoded = trim(str_replace("\n", $this->LE, $encoded));
     return $encoded;
 }