}
foreach ($val as $val2) {
- if (!isset($folder_list[$val2]) &&
- ($elt = $imptree->element($val2))) {
- $folder_list[$val2] = $elt;
+ if (!isset($folder_list[$val2]) && isset($imptree[$val2])) {
+ $folder_list[$val2] = $imptree[$val2];
}
}
}
*/
protected function _getPollInformation($mbox)
{
- $imptree = $GLOBALS['injector']->getInstance('IMP_Imap_Tree');
- $elt = $imptree->get($mbox);
- if (!$imptree->isPolled($elt)) {
- return array();
- }
-
- try {
- $count = ($info = $GLOBALS['injector']->getInstance('IMP_Imap')->getOb()->status($mbox, Horde_Imap_Client::STATUS_UNSEEN))
- ? intval($info['unseen'])
- : 0;
- } catch (Horde_Imap_Client_Exception $e) {
- $count = 0;
- }
+ $imaptree = $GLOBALS['injector']->getInstance('IMP_Imap_Tree');
- return array($mbox => $count);
+ return $imaptree[$mbox]->polled
+ ? array($mbox => $imaptree[$mbox]->poll_info->unseen)
+ : array();
}
/**
if (!empty($changes['a'])) {
$result['a'] = array();
foreach ($changes['a'] as $val) {
- $result['a'][] = $this->_createMailboxElt(is_object($val) ? $val : $imptree->element($val));
+ $result['a'][] = $this->_createMailboxElt(is_object($val) ? $val : $imptree[$val]);
}
}
// Skip the base element, since any change there won't ever be
// updated on-screen.
if ($val != IMP_Imap_Tree::BASE_ELT) {
- $result['c'][] = $this->_createMailboxElt($imptree->element($val));
+ $result['c'][] = $this->_createMailboxElt($imptree[$val]);
}
}
}
* @license http://www.fsf.org/copyleft/gpl.html GPL
* @package IMP
*/
-class IMP_Imap_Tree
+class IMP_Imap_Tree implements ArrayAccess
{
/* Constants for mailboxElt attributes. */
const ELT_NOSELECT = 1;
*/
public function peek($name)
{
- if (!($elt = $this->get($name))) {
+ if (!($elt = $this[$name])) {
return false;
}
- foreach (array_slice($this->_parent[$elt['p']], array_search($elt['v'], $this->_parent[$elt['p']]) + 1) as $val) {
+ foreach (array_slice($this->_parent[$elt->parent], array_search($elt->value, $this->_parent[$elt->parent]) + 1) as $val) {
if ($this->_activeElt($this->_tree[$val])) {
return true;
}
}
/**
- * Returns the requested element.
- *
- * @param string $name The name of the tree element.
- *
- * @return array Returns the requested element or false if not found.
- */
- public function get($name)
- {
- $name = $this->_convertName($name);
-
- return isset($this->_tree[$name])
- ? $this->_tree[$name]
- : false;
- }
-
- /**
* Insert a folder/mailbox into the tree.
*
* @param mixed $id The name of the folder (or a list of folder names)
!$this->isContainer($mailbox)) &&
(($mask & self::FLIST_VFOLDER) ||
!$this->isVFolder($mailbox))) {
- $ret_array[$mailbox['v']] = $this->element($mailbox);
+ $ret_array[$mailbox['v']] = $this[$mailbox['v']];
}
} while (($mailbox = $this->next($nextmask)));
}
}
/**
- * Return extended information on an element.
- *
- * @param mixed $name The name of the tree element or a tree element.
- *
- * @return IMP_Imap_Tree_Element Returns the mailbox element or false if
- * not found.
- */
- public function element($mailbox)
- {
- if (!is_array($mailbox)) {
- $mailbox = $this->get($mailbox);
- }
-
- return $mailbox
- ? new IMP_Imap_Tree_Element($mailbox, $this)
- : false;
- }
-
- /**
* Sort a level in the tree.
*
* @param string $id The parent folder whose children need to be sorted.
return $mbox . $new;
}
+ /* ArrayAccess methods. */
+
+ public function offsetExists($offset)
+ {
+ return isset($this->_tree[$this->_convertName($offset)]);
+ }
+
+ public function offsetGet($offset)
+ {
+ return new IMP_Imap_Tree_Element($this->_tree[$this->_convertName($offset)], $this);
+ }
+
+ public function offsetSet($offset, $value)
+ {
+ $this->insert($offset);
+ }
+
+ public function offsetUnset($offset)
+ {
+ $this->delete($offset);
+ }
+
}