/** * 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) * * @return array Metadata entry-value hash array on success, NULL on error * @since 0.5-beta */ public function get_metadata($folder, $entries, $options = array()) { if (!$this->check_connection()) { return null; } if ($this->get_capability('METADATA') || !strlen($folder) && $this->get_capability('METADATA-SERVER')) { return $this->conn->getMetadata($folder, $entries, $options); } else { if ($this->get_capability('ANNOTATEMORE') || $this->get_capability('ANNOTATEMORE2')) { $queries = array(); $res = array(); // Convert entry names foreach ((array) $entries as $entry) { list($ent, $attr) = $this->md2annotate($entry); $queries[$attr][] = $ent; } // @TODO: Honor MAXSIZE and DEPTH options foreach ($queries as $attrib => $entry) { if ($result = $this->conn->getAnnotation($folder, $entry, $attrib)) { $res = array_merge_recursive($res, $result); } } return $res; } } return null; }
/** * Returns IMAP metadata/annotations (GETMETADATA/GETANNOTATION) * * @param string $mailbox Mailbox name (empty for server metadata) * @param array $entries Entries * @param array $options Command options (with MAXSIZE and DEPTH keys) * * @return array Metadata entry-value hash array on success, NULL on error * * @access public * @since 0.5-beta */ function get_metadata($mailbox, $entries, $options = array()) { if ($mailbox) { $mailbox = $this->mod_mailbox($mailbox); } if ($this->get_capability('METADATA') || !strlen($mailbox && $this->get_capability('METADATA-SERVER'))) { return $this->conn->getMetadata($mailbox, $entries, $options); } else { if ($this->get_capability('ANNOTATEMORE') || $this->get_capability('ANNOTATEMORE2')) { $queries = array(); $res = array(); // Convert entry names foreach ($entries as $entry) { list($ent, $attr) = $this->md2annotate($entry); $queries[$attr][] = $ent; } // @TODO: Honor MAXSIZE and DEPTH options foreach ($queries as $attrib => $entry) { if ($result = $this->conn->getAnnotation($mailbox, $entry, $attrib)) { $res = array_merge($res, $result); } } return $res; } } return NULL; }
/** * 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 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(), $force = false) { $entries = (array) $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); if (is_array($cached_data)) { return $cached_data; } } if (!$this->check_connection()) { return null; } if ($this->get_capability('METADATA') || !strlen($folder) && $this->get_capability('METADATA-SERVER')) { $res = $this->conn->getMetadata($folder, $entries, $options); } else { if ($this->get_capability('ANNOTATEMORE') || $this->get_capability('ANNOTATEMORE2')) { $queries = array(); $res = array(); // Convert entry names foreach ($entries as $entry) { list($ent, $attr) = $this->md2annotate($entry); $queries[$attr][] = $ent; } // @TODO: Honor MAXSIZE and DEPTH options foreach ($queries as $attrib => $entry) { $result = $this->conn->getAnnotation($folder, $entry, $attrib); // an error, invalidate any previous getAnnotation() results if (!is_array($result)) { return null; } else { foreach ($result as $fldr => $data) { $res[$fldr] = array_merge((array) $res[$fldr], $data); } } } } } if (isset($res)) { if (!$force) { $this->update_cache($cache_key, $res); } return $res; } return null; }