getSpecialMailboxesSort() public static method

Return the list of sorted special mailboxes.
public static getSpecialMailboxesSort ( ) : array
return array The list of sorted special mailboxes (IMP_Mailbox objects).
Beispiel #1
0
 /**
  * AJAX action: Check access rights for creation of a submailbox.
  *
  * Variables used:
  *   - all: (integer) If 1, return all mailboxes. Otherwise, return only
  *          INBOX, special mailboxes, and polled mailboxes.
  *
  * @return string  HTML to use for the folder tree.
  */
 public function smartmobileFolderTree()
 {
     $ftree = $GLOBALS['injector']->getInstance('IMP_Ftree');
     /* Poll all mailboxes on initial display. */
     $this->_base->queue->poll($ftree->poll->getPollList(), true);
     $iterator = new AppendIterator();
     /* Add special mailboxes explicitly. INBOX should appear first. */
     $special = new ArrayIterator();
     $special->append($ftree['INBOX']);
     foreach (IMP_Mailbox::getSpecialMailboxesSort() as $val) {
         if (isset($ftree[$val])) {
             $special->append($ftree[$val]);
         }
     }
     $iterator->append($special);
     /* Now add polled mailboxes. */
     $filter = new IMP_Ftree_IteratorFilter($ftree);
     $filter->add(array($filter::CONTAINERS, $filter::REMOTE, $filter::SPECIALMBOXES));
     if (!$this->vars->all) {
         $filter->add($filter::POLLED);
     }
     $filter->mboxes = array('INBOX');
     $iterator->append($filter);
     return $ftree->createTree($this->vars->all ? 'smobile_folders_all' : 'smobile_folders', array('iterator' => $iterator, 'render_type' => 'IMP_Tree_Jquerymobile'))->getTree(true);
 }
Beispiel #2
0
 /**
  * AJAX action: List mailboxes.
  *
  * Variables used:
  *   - all: (integer) 1 to show all mailboxes.
  *   - base: (string) The base mailbox.
  *   - expall: (boolean) 1 to expand all (requires 'all').
  *   - initial: (string) 1 to indicate the initial request for mailbox
  *              list.
  *   - mboxes: (string) The list of mailboxes to process (JSON encoded
  *             array; mailboxes are base64url encoded).
  *   - reload: (integer) 1 to force reload of mailboxes.
  *   - unsub: (integer) 1 to show unsubscribed mailboxes.
  *
  * @return boolean  True.
  */
 public function listMailboxes()
 {
     global $injector, $prefs, $session;
     $ftree = $injector->getInstance('IMP_Ftree');
     $iterator = new AppendIterator();
     /* This might be a long running operation. */
     if ($this->vars->initial) {
         $session->close();
         $ftree->eltdiff->clear();
         /* @todo: Correctly handle unsubscribed mailboxes in ftree. */
         if ($ftree->unsubscribed_loaded && !$this->vars->reload) {
             $ftree->init();
         }
     }
     if ($this->vars->reload) {
         $ftree->init();
     }
     $filter = new IMP_Ftree_IteratorFilter($ftree);
     if ($this->vars->unsub) {
         $ftree->loadUnsubscribed();
         $filter->remove($filter::UNSUB);
     }
     if (isset($this->vars->base)) {
         $this->_base->queue->setMailboxOpt('base', $this->vars->base);
     }
     if ($this->vars->all) {
         $this->_base->queue->setMailboxOpt('all', 1);
         $iterator->append($filter);
         if ($this->vars->expall) {
             $this->vars->action = 'expand';
             $this->_base->callAction('toggleMailboxes');
         }
     } elseif ($this->vars->initial || $this->vars->reload) {
         $special = new ArrayIterator();
         $special->append($ftree['INBOX']);
         /* Add special mailboxes explicitly to the initial folder list,
          * since they are ALWAYS displayed, may appear outside of the
          * folder slice requested, and need to be sorted logically. */
         $s_elts = array();
         foreach (IMP_Mailbox::getSpecialMailboxesSort() as $val) {
             if (isset($ftree[$val])) {
                 $special->append($val);
                 $s_elts[] = $ftree[$val];
             }
         }
         $iterator->append($special);
         /* Go through and find any parent elements that contain only
          * special mailbox children - this need to be suppressed in
          * display. */
         $filter2 = clone $filter;
         $filter2->add(array($filter2::CONTAINERS, $filter2::SPECIALMBOXES));
         $no_children = array();
         foreach (array_unique($s_elts) as $val) {
             while (($val = $val->parent) && !$val->base_elt) {
                 $filter2->iterator = new IMP_Ftree_Iterator($val);
                 foreach ($filter2 as $val) {
                     /* If we found at least one viewable mailbox, this
                      * element needs its children to be displayed. */
                     break 2;
                 }
                 $no_children[] = strval($val);
             }
         }
         if (!empty($no_children)) {
             $this->_base->queue->ftreeCallback = function ($id, $ob) use($no_children) {
                 if (in_array($id, $no_children)) {
                     unset($ob->ch);
                 }
             };
         }
         /* Add regular mailboxes. */
         $no_mbox = false;
         switch ($prefs->getValue('nav_expanded')) {
             case IMP_Ftree_Prefs_Expanded::NO:
                 $filter->add($filter::CHILDREN);
                 break;
             case IMP_Ftree_Prefs_Expanded::YES:
                 $this->_base->queue->setMailboxOpt('expand', 1);
                 $no_mbox = true;
                 break;
             case IMP_Ftree_Prefs_Expanded::LAST:
                 $filter->add($filter::EXPANDED);
                 $this->_base->queue->setMailboxOpt('expand', 1);
                 break;
         }
         $filter->mboxes = array('INBOX');
         $iterator->append($filter);
         if (!$no_mbox) {
             $mboxes = IMP_Mailbox::formFrom(json_decode($this->vars->mboxes));
             foreach ($mboxes as $val) {
                 if (!$val->inbox) {
                     $ancestors = new IMP_Ftree_IteratorFilter(new IMP_Ftree_Iterator_Ancestors($val->tree_elt));
                     if ($this->vars->unsub) {
                         $ancestors->remove($ancestors::UNSUB);
                     }
                     $iterator->append($ancestors);
                 }
             }
         }
     } else {
         $filter->add($filter::EXPANDED);
         $this->_base->queue->setMailboxOpt('expand', 1);
         foreach (array_filter(IMP_Mailbox::formFrom(json_decode($this->vars->mboxes))) as $val) {
             $filter->iterator = new IMP_Ftree_Iterator($val->tree_elt);
             $iterator->append($filter);
             $ftree->expand($val);
         }
     }
     array_map(array($ftree->eltdiff, 'add'), array_unique(iterator_to_array($iterator, false)));
     if ($this->vars->initial) {
         $session->start();
         /* We need at least 1 changed mailbox. If not, something went
          * wrong and we should reinitialize the folder list. */
         if (!$ftree->eltdiff->changed_elts) {
             $this->vars->reload = true;
             $this->listMailboxes();
             $this->vars->reload = false;
         }
     }
     return true;
 }