Utf8ToUtf7Imap() public static method

Convert a string from UTF-8 to UTF7-IMAP.
public static Utf8ToUtf7Imap ( string $str, boolean $force = true ) : string
$str string The UTF-8 string.
$force boolean Assume $str is UTF-8 (no-autodetection)? If false, attempts to auto-detect if string is already in UTF7-IMAP.
return string The converted UTF7-IMAP string.
Beispiel #1
0
 /**
  */
 public function __get($name)
 {
     switch ($name) {
         case 'list_escape':
             return preg_replace("/\\*+/", '%', $this->utf8);
         case 'utf7imap':
             if (!isset($this->_utf7imap)) {
                 $n = Horde_Imap_Client_Utf7imap::Utf8ToUtf7Imap($this->_utf8);
                 $this->_utf7imap = $n == $this->_utf8 ? true : $n;
             }
             return $this->_utf7imap === true ? $this->_utf8 : $this->_utf7imap;
         case 'utf8':
             if (!isset($this->_utf8)) {
                 $this->_utf8 = Horde_Imap_Client_Utf7imap::Utf7ImapToUtf8($this->_utf7imap);
                 if ($this->_utf8 == $this->_utf7imap) {
                     $this->_utf7imap = true;
                 }
             }
             return $this->_utf8;
     }
 }
Beispiel #2
0
 /**
  * Internal function used to do charset conversion.
  *
  * @param string $input  See self::convertCharset().
  * @param string $from   See self::convertCharset().
  * @param string $to     See self::convertCharset().
  *
  * @return string  The converted string.
  */
 protected static function _convertCharset($input, $from, $to)
 {
     /* Use utf8_[en|de]code() if possible and if the string isn't too
      * large (less than 16 MB = 16 * 1024 * 1024 = 16777216 bytes) - these
      * functions use more memory. */
     if (Horde_Util::extensionExists('xml') && (strlen($input) < 16777216 || !Horde_Util::extensionExists('iconv') || !Horde_Util::extensionExists('mbstring'))) {
         if ($to == 'utf-8' && in_array($from, array('iso-8859-1', 'us-ascii', 'utf-8'))) {
             return utf8_encode($input);
         }
         if ($from == 'utf-8' && in_array($to, array('iso-8859-1', 'us-ascii', 'utf-8'))) {
             return utf8_decode($input);
         }
     }
     /* Try UTF7-IMAP conversions. */
     if ($from == 'utf7-imap' || $to == 'utf7-imap') {
         try {
             if ($from == 'utf7-imap') {
                 return self::convertCharset(Horde_Imap_Client_Utf7imap::Utf7ImapToUtf8($input), 'UTF-8', $to);
             } else {
                 if ($from == 'utf-8') {
                     $conv = $input;
                 } else {
                     $conv = self::convertCharset($input, $from, 'UTF-8');
                 }
                 return Horde_Imap_Client_Utf7imap::Utf8ToUtf7Imap($conv);
             }
         } catch (Horde_Imap_Client_Exception $e) {
             return $input;
         }
     }
     /* Try iconv with transliteration. */
     if (Horde_Util::extensionExists('iconv')) {
         unset($php_errormsg);
         ini_set('track_errors', 1);
         $out = @iconv($from, $to . '//TRANSLIT', $input);
         $errmsg = isset($php_errormsg);
         ini_restore('track_errors');
         if (!$errmsg && $out !== false) {
             return $out;
         }
     }
     /* Try mbstring. */
     if (Horde_Util::extensionExists('mbstring')) {
         $out = @mb_convert_encoding($input, $to, self::_mbstringCharset($from));
         if (!empty($out)) {
             return $out;
         }
     }
     return $input;
 }
Beispiel #3
0
 /**
  * Serialize data.
  *
  * @param mixed $data    The data to be serialized.
  * @param mixed $mode    The mode of serialization. Can be
  *                       either a single mode or array of modes.
  *                       If array, will be serialized in the
  *                       order provided.
  * @param mixed $params  Any additional parameters the serialization method
  *                       requires.
  *
  * @return string  A serialized string.
  * @throws Horde_Serialize_Exception
  */
 protected static function _serialize($data, $mode, $params = null)
 {
     switch ($mode) {
         case self::NONE:
             break;
             // $params['level'] = Level of compression (default: 3)
             // $params['workfactor'] = How does compression phase behave when given
             //                         worst case, highly repetitive, input data
             //                         (default: 30)
         // $params['level'] = Level of compression (default: 3)
         // $params['workfactor'] = How does compression phase behave when given
         //                         worst case, highly repetitive, input data
         //                         (default: 30)
         case self::BZIP:
             $data = bzcompress($data, isset($params['level']) ? $params['level'] : 3, isset($params['workfactor']) ? $params['workfactor'] : 30);
             if (is_integer($data)) {
                 $data = false;
             }
             break;
         case self::WDDX:
             $data = wddx_serialize_value($data);
             break;
         case self::IMAP8:
             $data = Horde_Mime::quotedPrintableEncode($data);
             break;
         case self::IMAPUTF7:
             $data = Horde_Imap_Client_Utf7imap::Utf8ToUtf7Imap(Horde_String::convertCharset($data, 'ISO-8859-1', 'UTF-8'));
             break;
         case self::IMAPUTF8:
             $data = Horde_Mime::decode($data);
             break;
             // $params['level'] = Level of compression (default: 3)
         // $params['level'] = Level of compression (default: 3)
         case self::GZ_DEFLATE:
             $data = gzdeflate($data, isset($params['level']) ? $params['level'] : 3);
             break;
         case self::BASIC:
             $data = serialize($data);
             break;
             // $params['level'] = Level of compression (default: 3)
         // $params['level'] = Level of compression (default: 3)
         case self::GZ_COMPRESS:
             $data = gzcompress($data, isset($params['level']) ? $params['level'] : 3);
             break;
         case self::BASE64:
             $data = base64_encode($data);
             break;
             // $params['level'] = Level of compression (default: 3)
         // $params['level'] = Level of compression (default: 3)
         case self::GZ_ENCODE:
             $data = gzencode($data, isset($params['level']) ? $params['level'] : 3);
             break;
         case self::RAW:
             $data = rawurlencode($data);
             break;
         case self::URL:
             $data = urlencode($data);
             break;
             // $params = Source character set
         // $params = Source character set
         case self::UTF7:
             $data = Horde_String::convertCharset($data, $params, 'UTF-7');
             break;
             // $params = Source character set
         // $params = Source character set
         case self::UTF7_BASIC:
             $data = self::serialize($data, array(self::UTF7, self::BASIC), $params);
             break;
         case self::JSON:
             $tmp = json_encode($data);
             /* Basic error handling attempts.
              * TODO: JSON_ERROR_UTF8 = 5; available as of PHP 5.3.3 */
             if (json_last_error() === 5) {
                 $data = json_encode(Horde_String::convertCharset($data, $params, 'UTF-8', true));
             } else {
                 $data = $tmp;
             }
             break;
         case self::LZF:
             $data = lzf_compress($data);
             break;
     }
     if ($data === false) {
         throw new Horde_Serialize_Exception('Serialization failed.');
     }
     return $data;
 }
Beispiel #4
0
 /**
  * List the ACL rights for a given mailbox/identifier. The server must
  * support the IMAP ACL extension (RFC 2086/4314).
  *
  * @param mixed $mailbox      A mailbox. Either a Horde_Imap_Client_Mailbox
  *                            object or a string (UTF-8).
  * @param string $identifier  The identifier to query (UTF-8).
  *
  * @return Horde_Imap_Client_Data_AclRights  An ACL data rights object.
  *
  * @throws Horde_Imap_Client_Exception
  * @throws Horde_Imap_Client_Exception_NoSupportExtension
  */
 public function listACLRights($mailbox, $identifier)
 {
     $this->login();
     if (!$this->_capability('ACL')) {
         throw new Horde_Imap_Client_Exception_NoSupportExtension('ACL');
     }
     return $this->_listACLRights(Horde_Imap_Client_Mailbox::get($mailbox), Horde_Imap_Client_Utf7imap::Utf8ToUtf7Imap($identifier));
 }