/** */ 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; } }
/** * Obtain a list of mailboxes. * * @param array $pattern The mailbox search pattern(s). * @param integer $mode Which mailboxes to return. * @param array $options Additional options. 'no_listext' will skip * using the LIST-EXTENDED capability. * @param array $subscribed A list of subscribed mailboxes. * * @return array See listMailboxes((). * * @throws Horde_Imap_Client_Exception */ protected function _getMailboxList($pattern, $mode, $options, $subscribed = null) { $check = $mode != Horde_Imap_Client::MBOX_ALL && !is_null($subscribed); // Setup entry for use in _parseList(). $pipeline = $this->_pipeline(); $pipeline->data['mailboxlist'] = array('check' => $check, 'ext' => false, 'options' => $options, 'subexist' => $mode == Horde_Imap_Client::MBOX_SUBSCRIBED_EXISTS, 'subscribed' => $check ? array_flip(array_map('strval', $subscribed)) + array('INBOX' => true) : null); $pipeline->data['listresponse'] = array(); $cmds = array(); $return_opts = new Horde_Imap_Client_Data_Format_List(); if ($this->queryCapability('LIST-EXTENDED') && empty($options['no_listext'])) { $cmd = $this->_command('LIST'); $pipeline->data['mailboxlist']['ext'] = true; $select_opts = new Horde_Imap_Client_Data_Format_List(); $subscribed = false; if ($mode == Horde_Imap_Client::MBOX_SUBSCRIBED || $mode == Horde_Imap_Client::MBOX_SUBSCRIBED_EXISTS) { $select_opts->add('SUBSCRIBED'); $return_opts->add('SUBSCRIBED'); $subscribed = true; } if (!empty($options['remote'])) { $select_opts->add('REMOTE'); } if (!empty($options['recursivematch'])) { $select_opts->add('RECURSIVEMATCH'); } $cmd->add(array($select_opts, '')); $tmp = new Horde_Imap_Client_Data_Format_List(); foreach ($pattern as $val) { if ($subscribed && strcasecmp($val, 'INBOX') === 0) { $cmds[] = $this->_command('LIST')->add(array('', 'INBOX')); } else { $tmp->add(new Horde_Imap_Client_Data_Format_ListMailbox($val)); } } if (count($tmp)) { $cmd->add($tmp); $cmds[] = $cmd; } if (!empty($options['children'])) { $return_opts->add('CHILDREN'); } if (!empty($options['special_use'])) { $return_opts->add('SPECIAL-USE'); } } else { foreach ($pattern as $val) { $cmds[] = $this->_command($mode == Horde_Imap_Client::MBOX_SUBSCRIBED ? 'LSUB' : 'LIST')->add(array('', new Horde_Imap_Client_Data_Format_ListMailbox($val))); } } /* LIST-STATUS does NOT depend on LIST-EXTENDED. */ if (!empty($options['status']) && $this->queryCapability('LIST-STATUS')) { $available_status = array(Horde_Imap_Client::STATUS_MESSAGES, Horde_Imap_Client::STATUS_RECENT, Horde_Imap_Client::STATUS_UIDNEXT, Horde_Imap_Client::STATUS_UIDVALIDITY, Horde_Imap_Client::STATUS_UNSEEN, Horde_Imap_Client::STATUS_HIGHESTMODSEQ); $status_opts = array(); foreach (array_intersect($this->_statusFields, $available_status) as $key => $val) { if ($options['status'] & $val) { $status_opts[] = $key; } } if (count($status_opts)) { $return_opts->add(array('STATUS', new Horde_Imap_Client_Data_Format_List(array_map('strtoupper', $status_opts)))); } } foreach ($cmds as $val) { if (count($return_opts)) { $val->add(array('RETURN', $return_opts)); } $pipeline->add($val); } try { $lr = $this->_sendCmd($pipeline)->data['listresponse']; } catch (Horde_Imap_Client_Exception_ServerResponse $e) { /* Archiveopteryx 3.1.3 can't process empty list-select-opts list. * Retry using base IMAP4rev1 functionality. */ if ($e->status === Horde_Imap_Client_Interaction_Server::BAD && $this->queryCapability('LIST-EXTENDED')) { $this->_unsetCapability('LIST-EXTENDED'); return $this->_listMailboxes($pattern, $mode, $options); } throw $e; } if (!empty($options['flat'])) { return array_values($lr); } /* Add in STATUS return, if needed. */ if (!empty($options['status'])) { foreach ($pattern as $val) { $val_utf8 = Horde_Imap_Client_Utf7imap::Utf7ImapToUtf8($val); if (isset($lr[$val_utf8])) { $lr[$val_utf8]['status'] = $this->_prepareStatusResponse($status_opts, $val_utf8); } } } return $lr; }
/** * 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; }
/** * Convert a string from UTF-8 to UTF7-IMAP. * * @param string $str The UTF-8 string. * @param boolean $force 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. * @throws Horde_Imap_Client_Exception */ public static function Utf8ToUtf7Imap($str, $force = true) { if ($str instanceof Horde_Imap_Client_Mailbox) { return $str->utf7imap; } $str = strval($str); /* No need to do conversion if all chars are in US-ASCII range or if * no ampersand is present. But will assume that an already encoded * ampersand means string is in UTF7-IMAP already. */ if (!$force && !preg_match('/[\\x80-\\xff]|&$|&(?![,+A-Za-z0-9]*-)/', $str)) { return $str; } /* Try mbstring, if available, which should be faster. Don't use the * IMAP utf7_* functions because they are known to be buggy. */ if (is_null(self::$_mbstring)) { self::$_mbstring = extension_loaded('mbstring'); } if (self::$_mbstring) { return @mb_convert_encoding($str, 'UTF7-IMAP', 'UTF-8'); } $u8len = strlen($str); $i = 0; $base64 = false; $p = ''; $ptr =& self::$_base64; while ($u8len) { $u8 = $str[$i]; $c = ord($u8); if ($c < 0x80) { $ch = $c; $n = 0; } elseif ($c < 0xc2) { throw new Horde_Imap_Client_Exception(Horde_Imap_Client_Translation::r("Error converting UTF7-IMAP string."), Horde_Imap_Client_Exception::UTF7IMAP_CONVERSION); } elseif ($c < 0xe0) { $ch = $c & 0x1f; $n = 1; } elseif ($c < 0xf0) { $ch = $c & 0xf; $n = 2; } elseif ($c < 0xf8) { $ch = $c & 0x7; $n = 3; } elseif ($c < 0xfc) { $ch = $c & 0x3; $n = 4; } elseif ($c < 0xfe) { $ch = $c & 0x1; $n = 5; } else { throw new Horde_Imap_Client_Exception(Horde_Imap_Client_Translation::r("Error converting UTF7-IMAP string."), Horde_Imap_Client_Exception::UTF7IMAP_CONVERSION); } if ($n > --$u8len) { throw new Horde_Imap_Client_Exception(Horde_Imap_Client_Translation::r("Error converting UTF7-IMAP string."), Horde_Imap_Client_Exception::UTF7IMAP_CONVERSION); } ++$i; for ($j = 0; $j < $n; ++$j) { $o = ord($str[$i + $j]); if (($o & 0xc0) !== 0x80) { throw new Horde_Imap_Client_Exception(Horde_Imap_Client_Translation::r("Error converting UTF7-IMAP string."), Horde_Imap_Client_Exception::UTF7IMAP_CONVERSION); } $ch = $ch << 6 | $o & 0x3f; } if ($n > 1 && !($ch >> $n * 5 + 1)) { throw new Horde_Imap_Client_Exception(Horde_Imap_Client_Translation::r("Error converting UTF7-IMAP string."), Horde_Imap_Client_Exception::UTF7IMAP_CONVERSION); } $i += $n; $u8len -= $n; if ($ch < 0x20 || $ch >= 0x7f) { if (!$base64) { $p .= '&'; $base64 = true; $b = 0; $k = 10; } if ($ch & ~0xffff) { $ch = 0xfffe; } $p .= $ptr[$b | $ch >> $k]; $k -= 6; for (; $k >= 0; $k -= 6) { $p .= $ptr[$ch >> $k & 0x3f]; } $b = $ch << -$k & 0x3f; $k += 16; } else { if ($base64) { if ($k > 10) { $p .= $ptr[$b]; } $p .= '-'; $base64 = false; } $p .= chr($ch); if (chr($ch) === '&') { $p .= '-'; } } } if ($base64) { if ($k > 10) { $p .= $ptr[$b]; } $p .= '-'; } return $p; }
/** * Obtain a list of mailboxes. * * @param mixed $pattern The mailbox search pattern(s). * @param integer $mode Which mailboxes to return. * @param array $options Additional options. 'no_listext' will skip * using the LIST-EXTENDED capability. * @param array $subscribed A list of subscribed mailboxes. * * @return array See listMailboxes((). * * @throws Horde_Imap_Client_Exception */ protected function _getMailboxList($pattern, $mode, $options, $subscribed = null) { $check = $mode != Horde_Imap_Client::MBOX_ALL && !is_null($subscribed); // Setup cache entry for use in _parseList() $t =& $this->_temp; $t['mailboxlist'] = array('check' => $check, 'ext' => false, 'options' => $options, 'subexist' => $mode == Horde_Imap_Client::MBOX_SUBSCRIBED_EXISTS, 'subscribed' => $check ? array_flip(array_map('strval', $subscribed)) : null); $t['listresponse'] = array(); $return_opts = new Horde_Imap_Client_Data_Format_List(); if ($this->queryCapability('LIST-EXTENDED') && empty($options['no_listext'])) { $cmd = $this->_clientCommand('LIST'); $t['mailboxlist']['ext'] = true; $select_opts = new Horde_Imap_Client_Data_Format_List(); if ($mode == Horde_Imap_Client::MBOX_SUBSCRIBED || $mode == Horde_Imap_Client::MBOX_SUBSCRIBED_EXISTS) { $select_opts->add('SUBSCRIBED'); $return_opts->add('SUBSCRIBED'); } if (!empty($options['remote'])) { $select_opts->add('REMOTE'); } if (!empty($options['recursivematch'])) { $select_opts->add('RECURSIVEMATCH'); } $cmd->add(array($select_opts, '')); if (!is_array($pattern)) { $pattern = array($pattern); } $tmp = new Horde_Imap_Client_Data_Format_List(); foreach ($pattern as $val) { $tmp->add(new Horde_Imap_Client_Data_Format_ListMailbox($val)); } $cmd->add($tmp); if (!empty($options['children'])) { $return_opts->add('CHILDREN'); } if (!empty($options['special_use'])) { $return_opts->add('SPECIAL-USE'); } } else { if (is_array($pattern)) { $return_array = array(); foreach ($pattern as $val) { $return_array = array_merge($return_array, $this->_getMailboxList($val, $mode, $options, $subscribed)); } return $return_array; } $cmd = $this->_clientCommand(array($mode == Horde_Imap_Client::MBOX_SUBSCRIBED ? 'LSUB' : 'LIST', '', new Horde_Imap_Client_Data_Format_ListMailbox($pattern))); } /* LIST-STATUS does NOT depend on LIST-EXTENDED. */ if (!empty($options['status']) && $this->queryCapability('LIST-STATUS')) { $status_mask = array(Horde_Imap_Client::STATUS_MESSAGES => 'MESSAGES', Horde_Imap_Client::STATUS_RECENT => 'RECENT', Horde_Imap_Client::STATUS_UIDNEXT => 'UIDNEXT', Horde_Imap_Client::STATUS_UIDVALIDITY => 'UIDVALIDITY', Horde_Imap_Client::STATUS_UNSEEN => 'UNSEEN', Horde_Imap_Client::STATUS_HIGHESTMODSEQ => 'HIGHESTMODSEQ'); $status_opts = new Horde_Imap_Client_Data_Format_List(); foreach ($status_mask as $key => $val) { if ($options['status'] & $key) { $status_opts->add($val); } } if (count($status_opts)) { $return_opts->add(array('STATUS', $status_opts)); } } if (count($return_opts)) { $cmd->add(array('RETURN', $return_opts)); } $this->_sendLine($cmd); if (!empty($options['flat'])) { return array_values($t['listresponse']); } /* Add in STATUS return, if needed. */ if (!empty($options['status'])) { if (!is_array($pattern)) { $pattern = array($pattern); } foreach ($pattern as $val) { $val_utf8 = Horde_Imap_Client_Utf7imap::Utf7ImapToUtf8($val); if (isset($t['listresponse'][$val_utf8]) && isset($t['status'][$val_utf8])) { $t['listresponse'][$val_utf8]['status'] = $t['status'][$val_utf8]; } } } return $t['listresponse']; }
/** * Unserialize data. * * @param mixed $data The data to be unserialized. * @param mixed $mode The mode of unserialization. Can be either a * single mode or array of modes. If array, will be * unserialized in the order provided. * @param mixed $params Any additional parameters the unserialization * method requires. * * @return mixed Unserialized data. * @throws Horde_Serialize_Exception */ protected static function _unserialize(&$data, $mode, $params = null) { switch ($mode) { case self::NONE: break; case self::RAW: $data = rawurldecode($data); break; case self::URL: $data = urldecode($data); break; case self::WDDX: $data = wddx_deserialize($data); break; case self::BZIP: // $params['small'] = Use bzip2 'small memory' mode? $data = bzdecompress($data, isset($params['small']) ? $params['small'] : false); break; case self::IMAP8: $data = quoted_printable_decode($data); break; case self::IMAPUTF7: $data = Horde_String::convertCharset(Horde_Imap_Client_Utf7imap::Utf7ImapToUtf8($data), 'UTF-8', 'ISO-8859-1'); break; case self::IMAPUTF8: $data = Horde_Mime::encode($data); break; case self::BASIC: $data2 = @unserialize($data); // Unserialize can return false both on error and if $data is the // false value. if ($data2 === false && $data == serialize(false)) { return $data2; } $data = $data2; break; case self::GZ_DEFLATE: $data = gzinflate($data); break; case self::BASE64: $data = base64_decode($data); break; case self::GZ_COMPRESS: $data = gzuncompress($data); break; // $params = Output character set // $params = Output character set case self::UTF7: $data = Horde_String::convertCharset($data, 'utf-7', $params); break; // $params = Output character set // $params = Output character set case self::UTF7_BASIC: $data = self::unserialize($data, array(self::BASIC, self::UTF7), $params); break; case self::JSON: $out = json_decode($data); if (!is_null($out) || strcasecmp($data, 'null') === 0) { return $out; } break; case self::LZF: $data = @lzf_decompress($data); break; } if ($data === false) { throw new Horde_Serialize_Exception('Unserialization failed.'); } return $data; }
/** * 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)); }
public function getDisplayName() { return \Horde_Imap_Client_Utf7imap::Utf7ImapToUtf8($this->folder_id); }