public function init()
{
global $injector, $session;
$access_folders = $injector->getInstance('IMP_Factory_Imap')->create()->access(IMP_Imap::ACCESS_FOLDERS);
/* Reset class variables to the defaults. */
$this->_accounts = $this->_elts = $this->_parent = array();
$this->_changed = true;
$old_track = isset($this->_eltdiff) && $this->_eltdiff->track;
$this->_eltdiff = new IMP_Ftree_Eltdiff();
/* Create a placeholder element to the base of the tree so we can
* keep track of whether the base level needs to be sorted. */
$this->_elts[self::BASE_ELT] = self::ELT_NEED_SORT | self::ELT_NONIMAP;
$this->_parent[self::BASE_ELT] = array();
$mask = IMP_Ftree_Account::INIT;
if (!$access_folders || !$this->subscriptions || $session->get('imp', 'showunsub')) {
$mask |= IMP_Ftree_Account::UNSUB;
$this->setAttribute('subscribed', self::BASE_ELT, true);
}
/* Add base account. */
$ob = $this->_accounts[self::BASE_ELT] = $access_folders ? new IMP_Ftree_Account_Imap() : new IMP_Ftree_Account_Inboxonly();
array_map(array($this, '_insertElt'), $ob->getList(null, $mask));
if ($access_folders) {
/* Add remote servers. */
$this->insert(iterator_to_array($injector->getInstance('IMP_Remote')));
/* Add virtual folders to the tree. */
$this->insert(iterator_to_array(IMP_Search_IteratorFilter::create(IMP_Search_IteratorFilter::VFOLDER)));
}
if ($old_track) {
$this->eltdiff->track = true;
}
}