public function getMailboxes();
/**
+ * Retrieves the specified annotation for the complete list of mailboxes.
+ *
+ * @param string $annotation The name of the annotation to retrieve.
+ *
+ * @return array An associative array combining the folder names as key with
+ * the corresponding annotation value.
+ */
+ public function listAnnotation($annotation);
+
+ /**
* Does the given folder exist?
*
* @param string $folder The folder to check.
}
return $this->_namespace;
}
+
+ /**
+ * Split a name for the METADATA extension into the correct syntax for the
+ * older ANNOTATEMORE version.
+ *
+ * @param string $name A name for a metadata entry.
+ *
+ * @return array A list of two elements: The entry name and the value
+ * type.
+ * @throws Horde_Imap_Client_Exception
+ */
+ protected function _getAnnotateMoreEntry($name)
+ {
+ if (substr($name, 0, 7) == '/shared') {
+ return array(substr($name, 7), 'value.shared');
+ } else if (substr($name, 0, 8) == '/private') {
+ return array(substr($name, 8), 'value.priv');
+ }
+
+ $this->_exception('Invalid METADATA entry: ' . $name);
+ }
+
}
\ No newline at end of file
return $folders;
}
+
+ /**
+ * Retrieves the specified annotation for the complete list of mailboxes.
+ *
+ * @param string $annotation The name of the annotation to retrieve.
+ *
+ * @return array An associative array combining the folder names as key with
+ * the corresponding annotation value.
+ */
+ public function listAnnotation($annotation)
+ {
+ list($entry, $value) = $this->_getAnnotateMoreEntry($annotation);
+ $list = array();
+ foreach ($this->getMailboxes() as $mailbox) {
+ $result = imap_getannotation($this->_getImap(), $mailbox, $entry, $value);
+ if (isset($result[$value])) {
+ $list[$mailbox] = $result[$value];
+ }
+ }
+ return $list;
+ }
+
/**
* Opens the given folder.
*
}
/**
+ * Retrieves the specified annotation for the complete list of mailboxes.
+ *
+ * @param string $annotation The name of the annotation to retrieve.
+ *
+ * @return array An associative array combining the folder names as key with
+ * the corresponding annotation value.
+ */
+ public function listAnnotation($annotation)
+ {
+ return $this->_driver->listAnnotation($annotation);
+ }
+
+ /**
* Does the given folder exist?
*
* @param string $folder The folder to check.
}
/**
+ * Retrieves the specified annotation for the complete list of mailboxes.
+ *
+ * @param string $annotation The name of the annotation to retrieve.
+ *
+ * @return array An associative array combining the folder names as key with
+ * the corresponding annotation value.
+ */
+ public function listAnnotation($annotation)
+ {
+ $result = $this->_imap->getMetadata('*', $annotation);
+ $data = array();
+ foreach ($result as $folder => $annotations) {
+ if (isset($annotations[$annotation])) {
+ $data[$folder] = $annotations[$annotation];
+ }
+ }
+ return $data;
+ }
+
+ /**
* Opens the given folder.
*
* @param string $folder The folder to open
private $_data;
/**
+ * The regular expression for converting folder names.
+ *
+ * @var string
+ */
+ private $_conversion_pattern;
+
+ /**
* The data of the mailbox currently opened
*
* @var array
}
/**
- * Parse the folder name into an id for this mock driver.
+ * Convert the external folder id to an internal mailbox name.
*
- * @return string The folder id.
+ * @param string $folder The external folder name.
+ *
+ * @return string The internal mailbox id.
*/
- private function _parseFolder($folder)
+ private function _convertToInternal($folder)
{
if (substr($folder, 0, 5) == 'INBOX') {
$user = explode('@', $this->_user);
}
/**
+ * Convert the internal mailbox name into an external folder id.
+ *
+ * @param string $mbox The internal mailbox name.
+ *
+ * @return string The external folder id.
+ */
+ private function _convertToExternal($mbox)
+ {
+ if ($this->_conversion_pattern === null) {
+ $user = explode('@', $this->getAuth());
+ $this->_conversion_pattern = '#^user/' . $user[0] . '#';
+ }
+ return preg_replace($this->_conversion_pattern, 'INBOX', $mbox);;
+ }
+
+ /**
* Return the id of the user currently authenticated.
*
* @return string The id of the user that opened the IMAP connection.
*/
public function getMailboxes()
{
- $user = explode('@', $this->getAuth());
- $pattern = '#^user/' . $user[0] . '#';
$result = array();
foreach (array_keys($this->_data) as $mbox) {
- $result[] = preg_replace($pattern, 'INBOX', $mbox);
+ $result[] = $this->_convertToExternal($mbox);
+ }
+ return $result;
+ }
+
+ /**
+ * Retrieves the specified annotation for the complete list of mailboxes.
+ *
+ * @param string $annotation The name of the annotation to retrieve.
+ *
+ * @return array An associative array combining the folder names as key with
+ * the corresponding annotation value.
+ */
+ public function listAnnotation($annotation)
+ {
+ $result = array();
+ foreach (array_keys($this->_data) as $mbox) {
+ if (isset($this->_data[$mbox]['annotations'][$annotation])) {
+ $result[$this->_convertToExternal($mbox)] = $this->_data[$mbox]['annotations'][$annotation];
+ }
}
return $result;
}
*/
public function select($folder)
{
- $folder = $this->_parseFolder($folder);
+ $folder = $this->_convertToInternal($folder);
if (!isset($GLOBALS['KOLAB_TESTING'][$folder])) {
throw new Horde_Kolab_Storage_Exception(sprintf("IMAP folder %s does not exist!", $folder));
}
*/
public function exists($folder)
{
+ //@todo: make faster by directly accessing the _data array.
$folders = $this->getMailboxes();
if (in_array($folder, $folders)) {
return true;
*/
public function getAnnotation($entry, $mailbox_name)
{
- $mailbox_name = $this->_parseFolder($mailbox_name);
+ $mailbox_name = $this->_convertToInternal($mailbox_name);
$old_mbox = null;
if ($mailbox_name != $this->_mboxname) {
$old_mbox = $this->_mboxname;
}
/**
+ * Retrieves the specified annotation for the complete list of mailboxes.
+ *
+ * @param string $annotation The name of the annotation to retrieve.
+ *
+ * @return array An associative array combining the folder names as key with
+ * the corresponding annotation value.
+ */
+ public function listAnnotation($annotation)
+ {
+ list($entry, $value) = $this->_getAnnotateMoreEntry($annotation);
+ $list = array();
+ $result = $this->_imap->getAnnotation($entry, $value, '*');
+ foreach ($result as $element) {
+ if (isset($element['ATTRIBUTES'][$value])) {
+ $list[$element['MAILBOX']] = $element['ATTRIBUTES'][$value];
+ }
+ }
+ return $list;
+ }
+
+ /**
* Opens the given folder.
*
* @param string $folder The folder to open
}
/**
+ * Retrieves the specified annotation for the complete list of mailboxes.
+ *
+ * @param string $annotation The name of the annotation to retrieve.
+ *
+ * @return array An associative array combining the folder names as key with
+ * the corresponding annotation value.
+ */
+ public function listAnnotation($annotation)
+ {
+ list($entry, $value) = $this->_getAnnotateMoreEntry($annotation);
+ $result = $this->_imap->getAnnotation('*', $entry, $value);
+ if (empty($result)) {
+ return array();
+ }
+ $data = array();
+ foreach ($result as $folder => $annotations) {
+ if (isset($annotations[$annotation])) {
+ $data[$folder] = $annotations[$annotation];
+ }
+ }
+ return $data;
+ }
+
+ /**
* Opens the given folder.
*
* @param string $folder The folder to open