Usable in both basic and dynamic views.
Author: Chuck Hagenbuch (chuck@horde.org)
Author: Michael Slusarz (slusarz@horde.org)
Inheritance: extends IMP_Basic_Base
Example #1
0
 /**
  */
 protected function _init()
 {
     global $injector, $notification;
     if (!$this->indices->mailbox->access_search) {
         $notification->push(_("Searching is not available."), 'horde.error');
         $this->indices->mailbox->url('mailbox')->redirect();
     }
     $imp_flags = $injector->getInstance('IMP_Flags');
     $imp_search = $injector->getInstance('IMP_Search');
     /* If search_basic is set, we are processing the search query. */
     if ($this->vars->search_basic) {
         $c_list = array();
         if ($this->vars->search_criteria_text) {
             switch ($this->vars->search_criteria) {
                 case 'from':
                 case 'subject':
                     $c_list[] = new IMP_Search_Element_Header($this->vars->search_criteria_text, $this->vars->search_criteria, $this->vars->search_criteria_not);
                     break;
                 case 'recip':
                     $c_list[] = new IMP_Search_Element_Recipient($this->vars->search_criteria_text, $this->vars->search_criteria_not);
                     break;
                 case 'body':
                 case 'text':
                     $c_list[] = new IMP_Search_Element_Text($this->vars->search_criteria_text, $this->vars->search_criteria == 'body', $this->vars->search_criteria_not);
                     break;
             }
         }
         if ($this->vars->search_criteria_flag) {
             $formdata = $imp_flags->parseFormId($this->vars->search_criteria_flag);
             $c_list[] = new IMP_Search_Element_Flag($formdata['flag'], $formdata['set'] && !$this->vars->search_criteria_flag_not);
         }
         if (empty($c_list)) {
             $notification->push(_("No search criteria specified."), 'horde.error');
         } else {
             /* Store the search in the session. */
             $q_ob = $imp_search->createQuery($c_list, array('id' => IMP_Search::BASIC_SEARCH, 'mboxes' => array($this->indices->mailbox), 'type' => IMP_Search::CREATE_QUERY));
             /* Redirect to the mailbox screen. */
             IMP_Mailbox::get($q_ob)->url('mailbox')->redirect();
         }
     }
     $flist = $imp_flags->getList(array('imap' => true, 'mailbox' => $this->indices->mailbox));
     $flag_set = array();
     foreach ($flist as $val) {
         $flag_set[] = array('val' => $val->form_set, 'label' => $val->label);
     }
     /* Prepare the search template. */
     $view = new Horde_View(array('templatePath' => IMP_TEMPLATES . '/basic/search'));
     $view->addHelper('FormTag');
     $view->addHelper('Tag');
     $view->action = self::url();
     $view->advsearch = Horde::link($this->indices->mailbox->url(IMP_Basic_Search::url()));
     $view->mbox = $this->indices->mailbox->form_to;
     $view->search_title = sprintf(_("Search %s"), $this->indices->mailbox->display_html);
     $view->flist = $flag_set;
     $this->title = _("Search");
     $this->output = $view->render('search-basic');
 }
Example #2
0
 /**
  */
 public function __construct(Horde_Variables $vars)
 {
     global $page_output;
     $this->vars = $vars;
     $this->indices = new IMP_Indices_Mailbox($vars);
     $page_output->addLinkTag(array('href' => IMP_Basic_Search::url(), 'rel' => 'search', 'type' => null));
     $mimecss = new Horde_Themes_Element('mime.css');
     $page_output->addStylesheet($mimecss->fs, $mimecss->uri);
     $this->_init();
 }
Example #3
0
 /**
  */
 protected function _init()
 {
     global $injector, $notification, $page_output, $prefs, $registry, $session;
     /* Redirect back to the mailbox if folder use is not allowed. */
     $imp_imap = $injector->getInstance('IMP_Factory_Imap')->create();
     if (!$imp_imap->access(IMP_Imap::ACCESS_FOLDERS)) {
         $notification->push(_("The folder view is not enabled."), 'horde.error');
         Horde::url('mailbox', true)->redirect();
     }
     /* Decide whether or not to show all the unsubscribed mailboxes. */
     $subscribe = $prefs->getValue('subscribe');
     $showAll = !$subscribe || $session->get('imp', 'showunsub');
     $page_output->addScriptFile('hordecore.js', 'horde');
     $page_output->addScriptFile('folders.js');
     /* Get the base URL for this page. */
     $folders_url = self::url()->setRaw(true);
     /* These JS defines are required by all sub-pages. */
     $page_output->addInlineJsVars(array('ImpFolders.folders_url' => strval($folders_url), 'ImpFolders.text' => array('download1' => _("All messages in the following mailbox(es) will be downloaded into one MBOX file:"), 'download2' => _("This may take some time. Are you sure you want to continue?"), 'oneselect' => _("Only one mailbox should be selected for this action."), 'rename1' => _("You are renaming the mailbox:"), 'rename2' => _("Please enter the new name:"), 'select' => _("Please select a mailbox before you perform this action."), 'subfolder1' => _("You are creating a subfolder to"), 'subfolder2' => _("Please enter the name of the new mailbox:"), 'toplevel' => _("You are creating a top-level mailbox.") . "\n" . _("Please enter the name of the new mailbox:"))));
     /* Initialize the IMP_Ftree object. */
     $ftree = $injector->getInstance('IMP_Ftree');
     /* $mbox_list entries are urlencoded. */
     $mbox_list = isset($this->vars->mbox_list) ? IMP_Mailbox::formFrom($this->vars->mbox_list) : array();
     /* META refresh time (might be altered by actionID). */
     $refresh_time = $prefs->getValue('refresh_time');
     /* Set up the master View object. */
     $view = new Horde_View(array('templatePath' => IMP_TEMPLATES . '/basic/folders'));
     $view->addHelper('FormTag');
     $view->addHelper('Tag');
     $token = $session->getToken();
     $view->token = $token;
     /* Run through the action handlers. */
     if ($this->vars->actionID) {
         try {
             $session->checkToken($this->vars->token);
         } catch (Horde_Exception $e) {
             $notification->push($e);
             $this->vars->actionID = null;
         }
     }
     switch ($this->vars->actionID) {
         case 'expand_all_folders':
             $ftree->expandAll();
             break;
         case 'collapse_all_folders':
             $ftree->collapseAll();
             break;
         case 'rebuild_tree':
             $ftree->init();
             break;
         case 'expunge_mbox':
             if (!empty($mbox_list)) {
                 $injector->getInstance('IMP_Message')->expungeMailbox(array_fill_keys($mbox_list, null));
             }
             break;
         case 'delete_mbox':
             foreach ($mbox_list as $val) {
                 $val->delete();
             }
             break;
         case 'download_mbox':
         case 'download_mbox_zip':
             IMP_Contents_View::downloadUrl('mbox', array('actionID' => 'download_mbox', 'mbox_list' => $this->vars->mbox_list, 'type' => $this->vars->actionID == 'download_mbox' ? 'mbox' : 'mboxzip'))->redirect();
             exit;
         case 'import_mbox':
             if ($this->vars->import_mbox) {
                 try {
                     $notification->push($injector->getInstance('IMP_Mbox_Import')->import($this->vars->import_mbox, 'mbox_upload'), 'horde.success');
                 } catch (Horde_Exception $e) {
                     $notification->push($e);
                 }
                 $this->vars->actionID = null;
             } else {
                 $refresh_time = null;
             }
             break;
         case 'create_mbox':
             if (isset($this->vars->new_mailbox)) {
                 try {
                     $parent = empty($mbox_list) ? IMP_Mailbox::get(IMP_Ftree::BASE_ELT) : $mbox_list[0];
                     $new_mbox = $parent->createMailboxName($this->vars->new_mailbox);
                     if ($new_mbox->exists) {
                         $notification->push(sprintf(_("Mailbox \"%s\" already exists."), $new_mbox->display), 'horde.warning');
                     } else {
                         $new_mbox->create();
                     }
                 } catch (Horde_Exception $e) {
                     $notification->push($e);
                 }
             }
             break;
         case 'rename_mbox':
             // $old_names may be URL encoded.
             $old_names = array_map('trim', explode("\n", $this->vars->old_names));
             $new_names = array_map('trim', explode("\n", $this->vars->new_names));
             $iMax = count($new_names);
             if (!empty($new_names) && !empty($old_names) && $iMax == count($old_names)) {
                 for ($i = 0; $i < $iMax; ++$i) {
                     $old_name = IMP_Mailbox::formFrom($old_names[$i]);
                     $old_ns = $old_name->namespace_info;
                     $new = trim($new_names[$i], $old_ns->delimiter);
                     /* If this is a personal namespace, then anything goes as
                      * far as the input. Just append the personal namespace to
                      * it. */
                     if ($old_ns->type === $old_ns::NS_PERSONAL || strlen($old_ns->name) && stripos($new_names[$i], $old_ns->name) !== 0) {
                         $new = $old_ns->name . $new;
                     }
                     $old_name->rename($new);
                 }
             }
             break;
         case 'subscribe_mbox':
         case 'unsubscribe_mbox':
             if (empty($mbox_list)) {
                 $notification->push(_("No mailboxes were specified"), 'horde.message');
             } else {
                 foreach ($mbox_list as $val) {
                     $val->subscribe($this->vars->actionID == 'subscribe_mbox');
                 }
             }
             break;
         case 'toggle_subscribed_view':
             if ($subscribe) {
                 $showAll = !$showAll;
                 $session->set('imp', 'showunsub', $showAll);
             }
             break;
         case 'poll_mbox':
             if (!empty($mbox_list)) {
                 $ftree->poll->addPollList($mbox_list);
             }
             break;
         case 'nopoll_mbox':
             if (!empty($mbox_list)) {
                 $ftree->poll->removePollList($mbox_list);
             }
             break;
         case 'empty_mbox':
             if (!empty($mbox_list)) {
                 $injector->getInstance('IMP_Message')->emptyMailbox($mbox_list);
             }
             break;
         case 'mark_mbox_seen':
         case 'mark_mbox_unseen':
             if (!empty($mbox_list)) {
                 $injector->getInstance('IMP_Message')->flagAllInMailbox(array('\\seen'), $mbox_list, $this->vars->actionID == 'mark_mbox_seen');
             }
             break;
         case 'delete_mbox_confirm':
         case 'empty_mbox_confirm':
             if (!empty($mbox_list)) {
                 $loop = array();
                 foreach ($mbox_list as $val) {
                     switch ($this->vars->actionID) {
                         case 'delete_mbox_confirm':
                             if (!$val->access_deletembox) {
                                 $notification->push(sprintf(_("The mailbox \"%s\" may not be deleted."), $val->display), 'horde.error');
                                 continue 2;
                             }
                             break;
                         case 'empty_mbox_confirm':
                             if (!$val->access_empty) {
                                 $notification->push(sprintf(_("The mailbox \"%s\" may not be emptied."), $val->display), 'horde.error');
                                 continue 2;
                             }
                             break;
                     }
                     try {
                         $elt_info = $imp_imap->status($val, Horde_Imap_Client::STATUS_MESSAGES);
                     } catch (IMP_Imap_Exception $e) {
                         $elt_info = null;
                     }
                     $data = array('name' => $val->display, 'msgs' => $elt_info ? $elt_info['messages'] : 0, 'val' => $val->form_to);
                     $loop[] = $data;
                 }
                 if (!count($loop)) {
                     break;
                 }
                 $page_output->addScriptFile('stripe.js', 'horde');
                 $this->title = _("Folder Actions - Confirmation");
                 $v = clone $view;
                 if ($this->vars->actionID == 'delete_mbox_confirm') {
                     $v->actionID = 'delete_mbox';
                     $v->delete = true;
                 } elseif ($this->vars->actionID == 'empty_mbox_confirm') {
                     $v->actionID = 'empty_mbox';
                     $v->empty = true;
                 }
                 $v->mboxes = $loop;
                 $v->folders_url = $folders_url;
                 $this->output = $v->render('folders_confirm');
                 return;
             }
             break;
         case 'mbox_size':
             if (!empty($mbox_list)) {
                 $loop = array();
                 $sum = 0;
                 foreach ($mbox_list as $val) {
                     $size = $val->size;
                     $data = array('name' => $val->display, 'size' => sprintf(_("%.2fMB"), $size / (1024 * 1024)), 'sort' => $size);
                     $sum += $size;
                     $loop[] = $data;
                 }
                 /* Prepare the topbar. */
                 $injector->getInstance('Horde_View_Topbar')->subinfo = $injector->getInstance('IMP_View_Subinfo')->render();
                 $v = clone $view;
                 $v->folders_url = $folders_url;
                 $v->mboxes = $loop;
                 $v->mboxes_sum = sprintf(_("%.2fMB"), $sum / (1024 * 1024));
                 $page_output->addScriptFile('stripe.js', 'horde');
                 $page_output->addScriptFile('tables.js', 'horde');
                 $this->title = _("Mailbox Sizes");
                 $this->output = $v->render('folders_size');
                 return;
             }
             break;
         case 'search':
             if (!empty($mbox_list)) {
                 IMP_Basic_Search::url()->add(array('mailbox_list' => IMP_Mailbox::formTo($mbox_list), 'subfolder' => 1))->redirect();
             }
             break;
     }
     $this->title = _("Folder Navigator");
     $folders_url->add('token', $token);
     /* Prepare the topbar. */
     $injector->getInstance('Horde_View_Topbar')->subinfo = $injector->getInstance('IMP_View_Subinfo')->render();
     if ($session->get('imp', 'file_upload') && $this->vars->actionID == 'import_mbox') {
         /* Prepare import template. */
         $v = clone $view;
         $v->folders_url = $folders_url;
         $v->import_mbox = $mbox_list[0];
         $this->output = $v->render('import');
         return;
     }
     /* Prepare the header template. */
     $head_view = clone $view;
     $head_view->folders_url = $folders_url;
     /* Prepare the actions template. */
     $actions = clone $view;
     $actions->addHelper('Horde_Core_View_Helper_Accesskey');
     $actions->addHelper('Horde_Core_View_Helper_Help');
     $actions->id = 0;
     $actions->refresh = Horde::widget(array('title' => _("_Refresh"), 'url' => $folders_url->copy()));
     $actions->create_mbox = $imp_imap->access(IMP_Imap::ACCESS_CREATEMBOX) && $imp_imap->access(IMP_Imap::ACCESS_CREATEMBOX_MAX);
     if ($prefs->getValue('subscribe')) {
         $actions->subscribe = true;
         $subToggleText = $showAll ? _("Hide Unsubscribed") : _("Show All");
         $actions->toggle_subscribe = Horde::widget(array('url' => $folders_url->copy()->add(array('actionID' => 'toggle_subscribed_view', 'token' => $token)), 'title' => $subToggleText, 'nocheck' => true));
     }
     $actions->nav_poll = !$prefs->isLocked('nav_poll') && !$prefs->getValue('nav_poll_all');
     $actions->notrash = !$prefs->getValue('use_trash');
     $actions->file_upload = $session->get('imp', 'file_upload');
     $actions->expand_all = Horde::widget(array('url' => $folders_url->copy()->add(array('actionID' => 'expand_all_folders', 'token' => $token)), 'title' => _("Expand All"), 'nocheck' => true));
     $actions->collapse_all = Horde::widget(array('url' => $folders_url->copy()->add(array('actionID' => 'collapse_all_folders', 'token' => $token)), 'title' => _("Collapse All"), 'nocheck' => true));
     /* Build the folder tree. */
     $iterator = new IMP_Ftree_IteratorFilter($ftree);
     $iterator->add(array($iterator::REMOTE, $iterator::VFOLDER));
     if ($showAll) {
         $ftree->loadUnsubscribed();
         $iterator->remove($iterator::UNSUB);
     }
     $tree = $ftree->createTree('imp_folders', array('checkbox' => true, 'editvfolder' => true, 'iterator' => $iterator, 'poll_info' => true));
     $displayNames = $fullNames = array();
     foreach ($ftree as $val) {
         $mbox_ob = $val->mbox_ob;
         $tmp = $displayNames[] = $mbox_ob->display;
         $tmp2 = $mbox_ob->display_notranslate;
         if ($tmp != $tmp2) {
             $fullNames[strval($val)] = $tmp2;
         }
     }
     $page_output->addInlineJsVars(array('ImpFolders.ajax' => $registry->getServiceLink('ajax', 'imp')->url, 'ImpFolders.displayNames' => $displayNames, 'ImpFolders.fullNames' => $fullNames, '-ImpFolders.mbox_expand' => intval($prefs->getValue('nav_expanded') == 2)));
     $page_output->metaRefresh($refresh_time, $this->url());
     Horde::startBuffer();
     $tree->renderTree();
     $this->output = $head_view->render('head') . $actions->render('actions') . Horde::endBuffer();
     if (count($tree) > 10) {
         $actions->id = 1;
         $this->output .= $actions->render('actions');
     }
     /* No need for extra template - close out the tags here. */
     $this->output .= '</form>';
 }
Example #4
0
 /**
  */
 public function topbarCreate(Horde_Tree_Renderer_Base $tree, $parent = null, array $params = array())
 {
     global $injector, $registry;
     if (IMP_Compose::canCompose()) {
         $clink = new IMP_Compose_Link();
         $tree->addNode(array('id' => strval($parent) . 'compose', 'parent' => $parent, 'label' => _("New Message"), 'expanded' => false, 'params' => array('icon' => Horde_Themes::img('compose.png'), 'url' => $clink->link()->setRaw(true))));
     }
     $imp_imap = $injector->getInstance('IMP_Factory_Imap')->create();
     if ($imp_imap->access(IMP_Imap::ACCESS_SEARCH)) {
         $onclick = null;
         switch ($registry->getView()) {
             case $registry::VIEW_DYNAMIC:
                 $url = Horde::url('dynamic.php', true)->add('page', 'mailbox')->setAnchor('search');
                 $onclick = 'if (window.DimpBase) { DimpBase.go(\'search\') }';
                 break;
             default:
                 $url = IMP_Basic_Search::url(array('full' => true));
                 break;
         }
         $tree->addNode(array('id' => strval($parent) . 'search', 'parent' => $parent, 'label' => _("Search"), 'expanded' => false, 'params' => array('icon' => Horde_Themes::img('search.png'), 'url' => $url, 'onclick' => $onclick)));
     }
 }
Example #5
0
 /**
  * Returns a link to edit a given search query.
  *
  * @param string $id  The search query id.
  *
  * @return Horde_Url  The URL to the search page.
  */
 public function editUrl($id)
 {
     global $registry;
     $mbox = IMP_Mailbox::get($this->createSearchId($id));
     switch ($registry->getView()) {
         case $registry::VIEW_BASIC:
             return $mbox->url(IMP_Basic_Search::url())->add(array('edit_query' => 1));
         case $registry::VIEW_DYNAMIC:
             return IMP_Dynamic_Mailbox::url()->setAnchor('search:' . json_encode(array('edit_query' => 1, 'mailbox' => $mbox->form_to)));
     }
 }
Example #6
0
 /**
  */
 protected function _addMailboxVars()
 {
     global $injector, $prefs, $registry;
     /* Does server support ACLs? */
     $imp_imap = $injector->getInstance('IMP_Factory_Imap')->create();
     $acl = $imp_imap->access(IMP_Imap::ACCESS_ACL);
     $subscribe = $prefs->getValue('subscribe');
     $this->js_conf += array_filter(array('URI_LISTINFO' => strval(IMP_Basic_Listinfo::url()->setRaw(true)), 'URI_MESSAGE' => strval(IMP_Dynamic_Message::url()->setRaw(true)), 'URI_PORTAL' => strval($registry->getServiceLink('portal')->setRaw(true)), 'URI_PREFS_IMP' => strval($registry->getServiceLink('prefs', 'imp')->setRaw(true)), 'URI_SEARCH' => strval(IMP_Basic_Search::url()->setRaw(true)), 'URI_THREAD' => strval(IMP_Basic_Thread::url()->setRaw(true)), 'FLAG_DELETED' => Horde_Imap_Client::FLAG_DELETED, 'FLAG_DRAFT' => Horde_Imap_Client::FLAG_DRAFT, 'FLAG_INNOCENT' => Horde_Imap_Client::FLAG_NOTJUNK, 'FLAG_SEEN' => Horde_Imap_Client::FLAG_SEEN, 'FLAG_SPAM' => Horde_Imap_Client::FLAG_JUNK, 'msglist_template_horiz' => file_get_contents(IMP_TEMPLATES . '/dynamic/msglist_horiz.html'), 'msglist_template_vert' => file_get_contents(IMP_TEMPLATES . '/dynamic/msglist_vert.html'), 'acl' => $acl, 'filter_any' => intval($prefs->getValue('filter_any_mailbox')), 'fsearchid' => IMP_Mailbox::formTo(IMP_Search::MBOX_PREFIX . IMP_Search::FILTERSEARCH), 'initial_page' => is_null($initial_page = IMP::getInitialPage()->mbox) ? null : $initial_page->form_to, 'mbox_expand' => intval($prefs->getValue('nav_expanded') == 2), 'name' => $registry->get('name', 'imp'), 'poll_alter' => intval(!$prefs->isLocked('nav_poll') && !$prefs->getValue('nav_poll_all')), 'qsearchid' => IMP_Mailbox::formTo(IMP_Search::MBOX_PREFIX . IMP_Search::QUICKSEARCH), 'refresh_time' => intval($prefs->getValue('refresh_time')), 'sidebar_width' => max(intval($prefs->getValue('sidebar_width')), 150), 'sort' => array('from' => array('c' => 'msgFrom', 't' => _("From"), 'v' => Horde_Imap_Client::SORT_FROM), 'to' => array('c' => 'msgFrom', 'ec' => 'msgFromTo', 't' => _("To"), 'v' => Horde_Imap_Client::SORT_TO), 'subject' => array('c' => 'msgSubject', 't' => _("Subject"), 'v' => Horde_Imap_Client::SORT_SUBJECT), 'thread' => array('c' => 'msgSubject', 'v' => Horde_Imap_Client::SORT_THREAD), 'date' => array('c' => 'msgDate', 't' => _("Date"), 'v' => IMP::IMAP_SORT_DATE), 'msgarrival' => array('c' => 'msgDate', 'v' => Horde_Imap_Client::SORT_ARRIVAL), 'msgdate' => array('c' => 'msgDate', 'v' => Horde_Imap_Client::SORT_DATE), 'sequence' => array('v' => Horde_Imap_Client::SORT_SEQUENCE), 'size' => array('c' => 'msgSize', 't' => _("Size"), 'v' => Horde_Imap_Client::SORT_SIZE)), 'subscribe' => intval($subscribe)));
     $context = array('ctx_container' => array('_mbox' => '', '_sep1' => null, 'create' => _("Create subfolder"), 'rename' => _("Rename"), 'delete' => _("Delete subfolders"), '_sep2' => null, 'search' => _("Search"), '_sep3' => null, 'expand' => _("Expand All"), 'collapse' => _("Collapse All")), 'ctx_datesort' => array('*msgarrival' => _("Arrival Time"), '*msgdate' => _("Message Date")), 'ctx_flag' => array(), 'ctx_flagunset' => array(), 'ctx_flag_search' => array(), 'ctx_mbox_flag' => array('seen' => _("Seen"), 'unseen' => _("Unseen")), 'ctx_noactions' => array('_mbox' => '', '_sep1' => null, 'noaction' => _("No actions available")), 'ctx_remoteauth' => array('_mbox' => '', '_sep1' => null, 'create' => _("Create Mailbox"), 'logout' => _("Log Out")), 'ctx_sortopts' => array('from' => _("From"), 'to' => _("To"), 'subject' => _("Subject"), 'thread' => _("Thread"), 'msgarrival' => _("Date (Arrival)"), 'msgdate' => _("Date (Message)"), 'size' => _("Size"), '_sep1' => null, 'sequence' => _("No Sort")), 'ctx_subjectsort' => array('thread' => _("Thread Sort")), 'ctx_template' => array('edit' => _("Edit Template"), 'new' => _("Create New Template")), 'ctx_vcontainer' => array('_mbox' => _("Virtual Folders"), '_sep1' => null, 'edit' => _("Edit Virtual Folders")), 'ctx_vfolder' => array('_mbox' => '', '_sep1' => null, 'edit' => _("Edit Virtual Folder"), 'delete' => _("Delete Virtual Folder")));
     /* Folder options context menu. */
     if ($imp_imap->access(IMP_Imap::ACCESS_FOLDERS)) {
         $context['ctx_folderopts'] = array('new' => _("Create Mailbox"), 'sub' => _("Hide Unsubscribed"), 'unsub' => _("Show All Mailboxes"), 'expand' => _("Expand All"), 'collapse' => _("Collapse All"), '_sep1' => null, 'reload' => _("Rebuild Folder List"));
     }
     if (!$subscribe) {
         unset($context['ctx_folderopts']['sub'], $context['ctx_folderopts']['unsub']);
     }
     /* Message context menu. */
     $context['ctx_message'] = array('_sub1' => array('resume' => _("Resume Draft"), 'template' => _("Use Template"), 'template_edit' => _("Edit Template"), 'view' => _("View Message")), 'reply' => _("Reply"), 'forward' => _("Forward"), '_sub2' => array('_sep1' => null, 'setflag' => _("Mark as") . '...', 'unsetflag' => _("Unmark as") . '...'), '_sep2' => null, 'spam' => _("Report as Spam"), 'innocent' => _("Report as Innocent"), 'blacklist' => _("Blacklist"), 'whitelist' => _("Whitelist"), 'addfilter' => _("Create Filter"), 'delete' => _("Delete"), 'undelete' => _("Undelete"), '_sub3' => array('_sep3' => null, 'source' => _("View Source")));
     if (empty($imp_imap->config->spam_params)) {
         unset($context['ctx_message']['spam']);
     }
     if (empty($imp_imap->config->innocent_params)) {
         unset($context['ctx_message']['innocent']);
     }
     if (!$registry->hasLink('mail/newEmailFilter')) {
         unset($context['ctx_message']['addfilter']);
     }
     $view_source = $injector->getInstance('Horde_Core_Perms')->hasAppPermission('view_msg_source');
     if (!$view_source) {
         unset($context['ctx_message']['_sub3']);
     }
     /* Mailbox context menu. */
     $context['ctx_mbox'] = array('_mbox' => '', '_sep1' => null, 'create' => _("Create subfolder"), 'rename' => _("Rename"), 'empty' => _("Empty"), 'delete' => _("Delete"), '_sep2' => null, 'setflag' => _("Mark all as"), '_sep3' => null, 'poll' => _("Check for New Mail"), 'nopoll' => _("Do Not Check for New Mail"), 'sub' => _("Subscribe"), 'unsub' => _("Unsubscribe"), '_sep4' => null, 'search' => _("Search"), '_sub1' => array('_sep5' => null, 'expand' => _("Expand All"), 'collapse' => _("Collapse All")), '_sep6' => null, 'export' => _("Export"), 'import' => _("Import"), '_sep7' => null, 'size' => _("Mailbox Size"), '_sub2' => array('_sep8' => null, 'acl' => _("Edit ACL")));
     if (!$subscribe) {
         unset($context['ctx_mbox']['sub'], $context['ctx_mbox']['unsub']);
     }
     if (!$imp_imap->access(IMP_Imap::ACCESS_IMPORT)) {
         unset($context['ctx_mbox']['import']);
     }
     if (!$imp_imap->access(IMP_Imap::ACCESS_FLAGS)) {
         unset($context['ctx_mbox']['_sep2'], $context['ctx_mbox']['setflag'], $context['ctx_mbox']['_sep3'], $context['ctx_mbox']['poll'], $context['ctx_mbox']['nopoll']);
     }
     if (!$imp_imap->access(IMP_Imap::ACCESS_FOLDERS)) {
         unset($context['ctx_mbox']['_sep7'], $context['ctx_mbox']['size']);
     }
     if (!$imp_imap->access(IMP_Imap::ACCESS_SEARCH)) {
         unset($context['ctx_mbox']['_sep4'], $context['ctx_mbox']['search']);
     }
     if (!$imp_imap->access(IMP_Imap::ACCESS_FLAGS) || $prefs->isLocked('acl')) {
         unset($context['ctx_mbox']['_sub2']);
     }
     /* Other Actions context menu. */
     $context['ctx_oa'] = array('preview_hide' => _("Hide Preview"), 'preview_show' => _("Show Preview"), 'layout_horiz' => _("Horizontal Layout"), 'layout_vert' => _("Vertical Layout"), '_sub1' => array('_sep1' => null, 'setflag' => _("Mark as") . '...', 'unsetflag' => _("Unmark as") . '...'), 'blacklist' => _("Blacklist"), 'whitelist' => _("Whitelist"), '_sub2' => array('_sep2' => null, 'purge_deleted' => _("Purge Deleted"), 'undelete' => _("Undelete")), 'show_deleted' => _("Show Deleted"), 'hide_deleted' => _("Hide Deleted"), '_sub3' => array('_sep3' => null, 'clear_sort' => _("Clear Sort")));
     if ($prefs->isLocked('delhide')) {
         unset($context['ctx_oa']['hide_deleted']);
     }
     /* Shared between message and other actions menus. */
     if (!$registry->hasMethod('mail/blacklistFrom')) {
         unset($context['ctx_message']['blacklist'], $context['ctx_oa']['blacklist']);
     }
     if (!$registry->hasMethod('mail/whitelistFrom')) {
         unset($context['ctx_message']['whitelist'], $context['ctx_oa']['whitelist']);
     }
     /* Preview context menu. */
     $context['ctx_preview'] = array('save' => _("Save"), 'viewsource' => _("View Source"), 'allparts' => _("All Parts"), 'thread' => _("View Thread"), 'listinfo' => _("List Info"));
     if (!$view_source) {
         unset($context['ctx_preview']['viewsource']);
     }
     /* Search related context menus. */
     if ($imp_imap->access(IMP_Imap::ACCESS_SEARCH)) {
         $context['ctx_filteropts'] = array('*filter' => _("Filter By"), '*flag' => _("Show Only"), '*flagnot' => _("Don't Show"));
         if (IMP_Filter::canApplyFilters()) {
             $context['ctx_filteropts']['_sub1'] = array('_sep1' => null, 'applyfilters' => _("Apply Filters"));
         }
         $context['ctx_qsearchopts'] = array('*all' => _("Entire Message"), '*body' => _("Body"), '*from' => _("From"), '*recip' => _("Recipients (To/Cc/Bcc)"), '*subject' => _("Subject"), '_sep1' => null, '*advanced' => _("Advanced Search..."));
         /* Generate filter array. */
         $iterator = IMP_Search_IteratorFilter::create(IMP_Search_IteratorFilter::FILTER);
         $context['ctx_filter'] = array();
         foreach ($iterator as $val) {
             if ($val->enabled) {
                 $context['ctx_filter']['*' . $val->id] = $val->label;
             }
         }
     }
     /* Remote accounts context menu. */
     if ($imp_imap->access(IMP_Imap::ACCESS_REMOTE)) {
         $context['ctx_rcontainer'] = array('*prefs' => _("Manage Remote Accounts"));
     }
     $this->js_context = array_merge($context, $this->js_context);
     $this->js_text += array('atc_downloadall' => _("Download All (%s)"), 'badaddr' => _("Invalid Address"), 'badsubject' => _("Invalid Subject"), 'baselevel' => _("base level of the folder tree"), 'check' => _("Checking..."), 'copyto' => _("Copy %s to %s"), 'create_prompt' => _("Create mailbox:"), 'createsub_prompt' => _("Create subfolder of %s:"), 'delete_mbox' => _("Permanently delete %s?"), 'download_mbox' => _("All messages in this mailbox will be downloaded into the format that you choose. Depending on the size of the mailbox, this action may take awhile."), 'empty_mbox' => _("Permanently delete all %d messages in %s?"), 'import_mbox' => _("Mbox or .eml file:"), 'import_mbox_loading' => _("Importing (this may take some time)..."), 'listmsg_wait' => _("The server is still generating the message list."), 'listmsg_timeout' => _("The server was unable to generate the message list."), 'loading' => _("Loading..."), 'message_0' => _("No messages"), 'message_1' => _("1 message"), 'message_2' => _("%d messages"), 'mboxsize' => _("%s is: %s."), 'moveto' => _("Move %s to %s"), 'newflag_name' => _("Flag Name:"), 'newflag_wait' => _("Creating New Flag..."), 'no_folder_name' => _("Must enter a folder name"), 'onlogout' => _("Logging Out..."), 'portal' => _("Portal"), 'prefs' => _("User Options"), 'remote_password' => _("Password for %s:"), 'rename_prompt' => _("Rename %s to:"), 'search' => _("Search"), 'search_input' => _("Search (%s)"), 'search_time' => _("Results are %d Minutes Old"), 'selected' => _("%s selected."), 'slidertext' => _("Messages %d - %d"), 'vfolder' => _("Virtual Folder: %s"), 'vp_empty' => _("There are no messages in this mailbox."), 'vp_empty_search' => _("No messages matched the search query."));
     if ($subscribe) {
         $this->js_text += array('subscribe_mbox' => _("Subscribe to %s?"), 'subscribe_mbox_subfolders' => _("Subscribe to all subfolders of %s?"), 'unsubscribe_mbox' => _("Unsubscribe to %s?"), 'unsubscribe_mbox_subfolders' => _("Unsubscribe to all subfolders of %s?"));
     }
 }