/**
  * Encode string
  *
  * @param   string str
  * @param   string charset defaults to XP default encoding
  * @return  string
  */
 public static function encode($str, $charset = xp::ENCODING)
 {
     $r = array(' ' => '_');
     foreach (QuotedPrintable::getCharsToEncode() as $i) {
         $r[chr($i)] = '=' . strtoupper(dechex($i));
     }
     return sprintf('=?%s?Q?%s?=', $charset, strtr($str, $r));
 }
Beispiel #2
0
 /**
  * Check if a string needs to be encoded and encode it if necessary
  *
  * @param   string str
  * @return  string
  */
 protected function _qstr($str)
 {
     static $q;
     if (!isset($q)) {
         $q = QuotedPrintable::getCharsToEncode();
     }
     $n = FALSE;
     for ($i = 0, $s = strlen($str); $i < $s; $i++) {
         if (!in_array(ord($str[$i]), $q)) {
             continue;
         }
         $n = TRUE;
         break;
     }
     return $n ? QuotedPrintable::encode($str, $this->getCharset()) : $str;
 }