| | |
| | | */ |
| | | public function __construct() |
| | | { |
| | | $this->conn = new rcube_imap_generic(); |
| | | $this->conn = new rcube_imap_generic(); |
| | | $this->plugins = rcube::get_instance()->plugins; |
| | | |
| | | // Set namespace and delimiter from session, |
| | |
| | | return; |
| | | } |
| | | |
| | | $config = rcube::get_instance()->config; |
| | | $config = rcube::get_instance()->config; |
| | | $imap_personal = $config->get('imap_ns_personal'); |
| | | $imap_other = $config->get('imap_ns_other'); |
| | | $imap_shared = $config->get('imap_ns_shared'); |
| | |
| | | |
| | | $_SESSION['imap_namespace'] = $this->namespace; |
| | | $_SESSION['imap_delimiter'] = $this->delimiter; |
| | | } |
| | | |
| | | /** |
| | | * Returns IMAP server vendor name |
| | | * |
| | | * @return string Vendor name |
| | | * @since 1.2 |
| | | */ |
| | | public function get_vendor() |
| | | { |
| | | if ($_SESSION['imap_vendor'] !== null) { |
| | | return $_SESSION['imap_vendor']; |
| | | } |
| | | |
| | | $config = rcube::get_instance()->config; |
| | | $imap_vendor = $config->get('imap_vendor'); |
| | | |
| | | if ($imap_vendor) { |
| | | return $imap_vendor; |
| | | } |
| | | |
| | | if (!$this->check_connection()) { |
| | | return; |
| | | } |
| | | |
| | | if (($ident = $this->conn->data['ID']) === null) { |
| | | $ident = $this->conn->id(array( |
| | | 'name' => 'Roundcube', |
| | | 'version' => RCUBE_VERSION, |
| | | 'php' => PHP_VERSION, |
| | | 'os' => PHP_OS, |
| | | )); |
| | | } |
| | | |
| | | $vendor = (string) (!empty($ident) ? $ident['name'] : ''); |
| | | $ident = strtolower($vendor . ' ' . $this->conn->data['GREETING']); |
| | | $vendors = array('cyrus', 'dovecot', 'uw-imap', 'gmail', 'hmail'); |
| | | |
| | | foreach ($vendors as $v) { |
| | | if (strpos($ident, $v) !== false) { |
| | | $vendor = $v; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | return $_SESSION['imap_vendor'] = $vendor; |
| | | } |
| | | |
| | | /** |
| | |
| | | * |
| | | * @param mixed $uids Message UIDs as array or comma-separated string, or '*' |
| | | * @param string $flag Flag to set: SEEN, UNDELETED, DELETED, RECENT, ANSWERED, DRAFT, MDNSENT |
| | | * @param string $folder Folder name |
| | | * @param string $folder Folder name |
| | | * @param boolean $skip_cache True to skip message cache clean up |
| | | * |
| | | * @return boolean Operation status |
| | |
| | | */ |
| | | public function folder_size($folder) |
| | | { |
| | | if (!strlen($folder)) { |
| | | return false; |
| | | } |
| | | |
| | | if (!$this->check_connection()) { |
| | | return 0; |
| | | } |
| | | |
| | | // On Cyrus we can use special folder annotation, which should be much faster |
| | | if ($this->get_vendor() == 'cyrus') { |
| | | $idx = '/shared/vendor/cmu/cyrus-imapd/size'; |
| | | $result = $this->get_metadata($folder, $idx, array(), true); |
| | | |
| | | if (!empty($result) && is_numeric($result[$folder][$idx])) { |
| | | return $result[$folder][$idx]; |
| | | } |
| | | } |
| | | |
| | | // @TODO: could we try to use QUOTA here? |
| | |
| | | /** |
| | | * Returns IMAP metadata/annotations (GETMETADATA/GETANNOTATION) |
| | | * |
| | | * @param string $folder Folder name (empty for server metadata) |
| | | * @param array $entries Entries |
| | | * @param array $options Command options (with MAXSIZE and DEPTH keys) |
| | | * @param string $folder Folder name (empty for server metadata) |
| | | * @param array $entries Entries |
| | | * @param array $options Command options (with MAXSIZE and DEPTH keys) |
| | | * @param bool $force Disables cache use |
| | | * |
| | | * @return array Metadata entry-value hash array on success, NULL on error |
| | | * @since 0.5-beta |
| | | */ |
| | | public function get_metadata($folder, $entries, $options=array()) |
| | | public function get_metadata($folder, $entries, $options = array(), $force = false) |
| | | { |
| | | $entries = (array)$entries; |
| | | $entries = (array) $entries; |
| | | |
| | | // create cache key |
| | | // @TODO: this is the simplest solution, but we do the same with folders list |
| | | // maybe we should store data per-entry and merge on request |
| | | sort($options); |
| | | sort($entries); |
| | | $cache_key = 'mailboxes.metadata.' . $folder; |
| | | $cache_key .= '.' . md5(serialize($options).serialize($entries)); |
| | | if (!$force) { |
| | | // create cache key |
| | | // @TODO: this is the simplest solution, but we do the same with folders list |
| | | // maybe we should store data per-entry and merge on request |
| | | sort($options); |
| | | sort($entries); |
| | | $cache_key = 'mailboxes.metadata.' . $folder; |
| | | $cache_key .= '.' . md5(serialize($options).serialize($entries)); |
| | | |
| | | // get cached data |
| | | $cached_data = $this->get_cache($cache_key); |
| | | // get cached data |
| | | $cached_data = $this->get_cache($cache_key); |
| | | |
| | | if (is_array($cached_data)) { |
| | | return $cached_data; |
| | | if (is_array($cached_data)) { |
| | | return $cached_data; |
| | | } |
| | | } |
| | | |
| | | if (!$this->check_connection()) { |
| | |
| | | } |
| | | |
| | | if (isset($res)) { |
| | | $this->update_cache($cache_key, $res); |
| | | if (!$force) { |
| | | $this->update_cache($cache_key, $res); |
| | | } |
| | | |
| | | return $res; |
| | | } |
| | | |