/** * Initialize the tree. */ 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; } }
/** * URL Parameters: * <pre> * - criteria_form: (string) JSON representation of the search query. * - edit_query: (integer) If true, edit a search query (contained in * 'mailbox' parameter). * - edit_query_filter: (string) The name of the filter being edited. * - edit_query_vfolder: (string) The name of the virtual folder being * edited. * - mailbox: (string) Mailbox parameter. * - mailbox_list: (array) A list of mailboxes to process (base64url * encoded) If empty, uses 'mailbox' parameter. * - mboxes_form: (string) JSON representation of the list of mailboxes * for the query. Hash containing 2 keys: mbox & * subfolder. Both values are base64url encoded. * - search_label: (string) The label to use when saving the search. * - search_type: (string) The type of saved search ('filter', * 'vfolder'). If empty, the search should not be saved. * - subfolder: (boolean) If set, search mailbox will default to * subfolder search. * </pre> */ protected function _init() { global $injector, $notification, $page_output, $prefs, $registry; /* Define the criteria list. */ $criteria = array('from' => array('label' => _("From"), 'type' => 'header'), 'recip' => array('label' => _("Recipients (To/Cc/Bcc)"), 'type' => 'header'), 'to' => array('label' => _("To"), 'type' => 'header'), 'cc' => array('label' => _("Cc"), 'type' => 'header'), 'bcc' => array('label' => _("Bcc"), 'type' => 'header'), 'subject' => array('label' => _("Subject"), 'type' => 'header'), 'customhdr' => array('label' => _("Custom Header"), 'type' => 'customhdr'), 'body' => array('label' => _("Body"), 'type' => 'text'), 'text' => array('label' => _("Entire Message"), 'type' => 'text'), 'date_range' => array('label' => _("Date"), 'type' => 'date'), 'older' => array('label' => _("Older Than"), 'type' => 'within'), 'younger' => array('label' => _("Younger Than"), 'type' => 'within'), 'size_smaller' => array('label' => _("Size (KB) <"), 'type' => 'size'), 'size_larger' => array('label' => _("Size (KB) >"), 'type' => 'size')); $filters = array('bulk' => array('label' => _("Bulk Messages"), 'type' => 'filter'), 'attach' => array('label' => _("Contains Attachment(s)"), 'type' => 'filter'), 'mailinglist' => array('label' => _("Mailing List Messages"), 'type' => 'filter'), 'personal' => array('label' => _("Personal Messages"), 'type' => 'filter')); /* Define some constants. */ $constants = array('within' => array('d' => IMP_Search_Element_Within::INTERVAL_DAYS, 'm' => IMP_Search_Element_Within::INTERVAL_MONTHS, 'y' => IMP_Search_Element_Within::INTERVAL_YEARS)); if (isset($this->vars->mailbox_list)) { if (is_array($this->vars->mailbox_list)) { $default_mailbox = IMP_Mailbox::get('INBOX'); $search_mailbox = IMP_Mailbox::formFrom($this->vars->mailbox_list); } else { $default_mailbox = IMP_Mailbox::formFrom($this->vars->mailbox_list); $search_mailbox = array($default_mailbox); } } elseif (isset($this->vars->mailbox)) { $default_mailbox = IMP_Mailbox::formFrom($this->vars->mailbox); $search_mailbox = array($default_mailbox); } else { $default_mailbox = IMP_Mailbox::get('INBOX'); $search_mailbox = array($default_mailbox); } /* Check that searching is allowed. */ if (!$injector->getInstance('IMP_Factory_Imap')->create()->access(IMP_Imap::ACCESS_SEARCH)) { $default_mailbox->url('mailbox')->redirect(); } $imp_flags = $injector->getInstance('IMP_Flags'); $imp_search = $injector->getInstance('IMP_Search'); $dynamic_view = $registry->getView() == Horde_Registry::VIEW_DYNAMIC; $js_vars = array(); /* Generate the search query if 'criteria_form' is present in the form * data. */ if ($this->vars->criteria_form) { $c_list = array(); foreach (json_decode($this->vars->criteria_form) as $val) { switch ($val->t) { case 'from': case 'to': case 'cc': case 'bcc': case 'subject': $c_list[] = new IMP_Search_Element_Header($val->v, $val->t, $val->n); break; case 'recip': $c_list[] = new IMP_Search_Element_Recipient($val->v, $val->n); break; case 'customhdr': $c_list[] = new IMP_Search_Element_Header($val->v->s, $val->v->h, $val->n); break; case 'body': case 'text': $c_list[] = new IMP_Search_Element_Text($val->v, $val->t == 'body', $val->n); break; case 'date_range': $c_list[] = new IMP_Search_Element_Daterange($val->b ? new DateTime($val->b) : 0, $val->e ? new DateTime($val->e) : 0, $val->n); break; case 'older': case 'younger': $c_list[] = new IMP_Search_Element_Within($val->v->v, $constants['within'][$val->v->l], $val->t == 'older'); break; case 'size_smaller': case 'size_larger': $c_list[] = new IMP_Search_Element_Size($val->v, $val->t == 'size_larger'); break; case 'or': $c_list[] = new IMP_Search_Element_Or(); break; case 'bulk': $c_list[] = new IMP_Search_Element_Bulk($val->n); break; case 'attach': $c_list[] = new IMP_Search_Element_Attachment($val->n); break; case 'mailinglist': $c_list[] = new IMP_Search_Element_Mailinglist($val->n); break; case 'personal': $c_list[] = new IMP_Search_Element_Personal($val->n); break; case 'flag': /* Flag search. */ $formdata = $imp_flags->parseFormId(rawurldecode($val->v)); $c_list[] = new IMP_Search_Element_Flag($formdata['flag'], $formdata['set'] && !$val->n); break; } } $redirect_dynamic = true; $redirect_target = false; switch ($this->vars->search_type) { case 'filter': $q_ob = $imp_search->createQuery($c_list, array('id' => IMP_Mailbox::formFrom($this->vars->edit_query_filter), 'label' => $this->vars->search_label, 'type' => IMP_Search::CREATE_FILTER)); if ($this->vars->edit_query_filter) { $notification->push(sprintf(_("Filter \"%s\" edited successfully."), $this->vars->search_label), 'horde.success'); $redirect_dynamic = false; $redirect_target = 'prefs'; } else { $notification->push(sprintf(_("Filter \"%s\" created succesfully."), $this->vars->search_label), 'horde.success'); } break; case 'vfolder': $form = json_decode($this->vars->mboxes_form); $q_ob = $imp_search->createQuery($c_list, array('id' => IMP_Mailbox::formFrom($this->vars->edit_query_vfolder), 'label' => $this->vars->search_label, 'mboxes' => IMP_Mailbox::formFrom($form->mbox), 'subfolders' => IMP_Mailbox::formFrom($form->subfolder), 'type' => IMP_Search::CREATE_VFOLDER)); if ($this->vars->edit_query_vfolder) { $notification->push(sprintf(_("Virtual Folder \"%s\" edited successfully."), $this->vars->search_label), 'horde.success'); $redirect_target = 'prefs'; } else { $notification->push(sprintf(_("Virtual Folder \"%s\" created succesfully."), $this->vars->search_label), 'horde.success'); $redirect_target = 'mailbox'; } break; default: $form = json_decode($this->vars->mboxes_form); $q_ob = $imp_search->createQuery($c_list, array('mboxes' => IMP_Mailbox::formFrom($form->mbox), 'subfolders' => IMP_Mailbox::formFrom($form->subfolder))); $redirect_target = 'mailbox'; break; } /* Redirect to the mailbox page. */ if ($redirect_target) { if ($dynamic_view && $redirect_dynamic) { echo '<html><head>' . Horde::wrapInlineScript(array('window.parent.DimpBase.go("mbox", "' . $q_ob->mbox_ob->form_to . '")')) . '</head></html>'; exit; } switch ($redirect_target) { case 'mailbox': $q_ob->mbox_ob->url('mailbox')->redirect(); break; case 'prefs': $registry->getServiceLink('prefs', 'imp')->add('group', 'searches')->redirect(); break; } exit; } } /* Prepare the search view. */ $view = new Horde_View(array('templatePath' => IMP_TEMPLATES . '/search')); $view->addHelper('Text'); $view->addHelper('Tag'); $view->addHelper('FormTag'); $view->action = self::url(); /* Determine if we are editing a search query. */ $q_ob = $default_mailbox->getSearchOb(); if ($this->vars->edit_query && $default_mailbox->search) { if ($default_mailbox->vfolder) { if (!$default_mailbox->editvfolder) { $notification->push(_("Built-in Virtual Folders cannot be edited."), 'horde.error'); $registry->getServiceLink('prefs', 'imp')->add('group', 'searches')->redirect(); } $view->edit_query = true; $view->edit_query_vfolder = $default_mailbox->form_to; } elseif ($imp_search->isFilter($q_ob)) { if (!$imp_search->isFilter($q_ob, true)) { $notification->push(_("Built-in Filters cannot be edited."), 'horde.error'); $registry->getServiceLink('prefs', 'imp')->add('group', 'searches')->redirect(); } $view->edit_query = true; $view->edit_query_filter = $default_mailbox->form_to; } if ($view->edit_query) { $view->search_label = $q_ob->label; $js_vars['ImpSearch.prefsurl'] = strval($registry->getServiceLink('prefs', 'imp')->add('group', 'searches')->setRaw(true)); } } else { /* Process list of recent searches. */ $iterator = IMP_Search_IteratorFilter::create(IMP_Search_IteratorFilter::QUERY); $rs = array(); foreach ($iterator as $val) { $rs[$val->formid] = array('c' => $val->criteria, 'f' => array('m' => IMP_Mailbox::formTo($val->all ? array(IMP_Search_Query::ALLSEARCH) : array_map('strval', $val->mbox_list)), 's' => IMP_Mailbox::formTo(array_map('strval', $val->subfolder_list))), 'l' => Horde_String::truncate($val->querytext)); } if (!empty($rs)) { $js_vars['ImpSearch.i_recent'] = $rs; } $s_mboxes = IMP_Mailbox::formTo($search_mailbox); $js_vars['ImpSearch.i_mboxes'] = array('m' => $this->vars->subfolder ? array() : $s_mboxes, 's' => $this->vars->subfolder ? $s_mboxes : array()); } if ($default_mailbox->search) { $js_vars['ImpSearch.i_criteria'] = $q_ob->criteria; $js_vars['ImpSearch.i_mboxes'] = array('m' => IMP_Mailbox::formTo($q_ob->all ? array(IMP_Search_Query::ALLSEARCH) : $q_ob->mbox_list), 's' => IMP_Mailbox::formTo($q_ob->subfolder_list)); } /* Create the criteria list. */ $c_list = $types = array(); foreach ($criteria as $key => $val) { $c_list[] = array('l' => $val['label'], 'v' => $key); $types[$key] = $val['type']; } $view->clist = $c_list; /* Create the filter list. These are all-or-nothing searches. */ $f_list = array(); foreach ($filters as $key => $val) { $f_list[] = array('l' => $val['label'], 'v' => $key); $types[$key] = 'filter'; } $view->filterlist = $f_list; /* Create the flag list. */ $flist = $imp_flags->getList(array('imap' => true, 'mailbox' => $default_mailbox)); $flag_set = array(); foreach ($flist as $val) { $flag_set[] = array('l' => $val->label, 'v' => rawurlencode($val->form_set)); $types[rawurlencode($val->form_set)] = 'flag'; } $view->flist = $flag_set; /* Generate master mailbox list. */ $mbox_list = array(); if (!$view->edit_query_filter) { $js_vars['ImpSearch.allsearch'] = IMP_Mailbox::formTo(IMP_Search_Query::ALLSEARCH); $ob = $injector->getInstance('IMP_Search_Ui')->getSearchMboxList(); $mbox_list = $ob->mbox_list; $view->subscribe = $prefs->getValue('subscribe'); $view->tree = $ob->tree->getTree(); } /* Prepare the topbar. */ if (!$dynamic_view) { $injector->getInstance('Horde_View_Topbar')->subinfo = $injector->getInstance('IMP_View_Subinfo')->render(); } Horde_Core_Ui_JsCalendar::init(); $page_output->addScriptFile('hordecore.js', 'horde'); $page_output->addScriptFile('horde.js', 'horde'); $page_output->addScriptFile('search.js'); $page_output->addInlineJsVars(array_merge($js_vars, array('ImpSearch.data' => array('constants' => $constants, 'dynamic_view' => $dynamic_view, 'inbox' => IMP_Mailbox::get('INBOX')->form_to, 'mbox_list' => $mbox_list, 'months' => Horde_Core_Ui_JsCalendar::months(), 'searchmbox' => $default_mailbox->form_to, 'types' => $types), 'ImpSearch.text' => array('and' => _("and"), 'customhdr' => _("Custom Header:"), 'datereset' => _("Date Reset"), 'dateselection' => _("Date Selection"), 'flag' => _("Flag:"), 'loading' => _("Loading..."), 'need_criteria' => _("Please select at least one search criteria."), 'need_date' => _("Need at least one date in the date range search."), 'need_mbox' => _("Please select at least one mailbox to search."), 'need_label' => _("Saved searches require a label."), 'not_match' => _("Do NOT Match"), 'or' => _("OR"), 'search_all' => _("Search All Mailboxes"), 'search_term' => _("Search Term:"), 'subfolder_search' => _("Search all subfolders?"), 'to' => _("to")))), array('onload' => true)); if ($dynamic_view) { if (!$this->vars->edit_query) { $view->return_mailbox_val = sprintf(_("Return to %s"), $default_mailbox->display_html); } $page_output->topbar = $page_output->sidebar = false; $this->header_params = array('html_id' => 'htmlAllowScroll'); } $this->title = _("Search"); $this->output = $view->render('search'); }
/** * @param boolean $static Ignored in this driver. */ public function getTree($static = false) { global $injector; $this->_nodes = $this->_tree->getNodes(); $filter = $injector->createInstance('Horde_Text_Filter'); $view = new Horde_View(array('templatePath' => IMP_TEMPLATES . '/flist')); $view->addHelper('FormTag'); $view->addHelper('Tag'); $view->optgroup = $this->getOption('optgroup'); /* Custom HTML. */ if ($customhtml = $this->getOption('customhtml')) { $view->customhtml = $customhtml; } /* Heading. */ if (($heading = $this->getOption('heading')) && strlen($heading) > 0) { $view->heading = $heading; } /* New mailbox entry. */ if ($this->getOption('new_mbox')) { $imp_imap = $injector->getInstance('IMP_Factory_Imap')->create(); if ($imp_imap->access(IMP_Imap::ACCESS_CREATEMBOX) && $imp_imap->access(IMP_Imap::ACCESS_CREATEMBOX_MAX)) { $view->new_mbox = true; } } /* Virtual folders. */ if ($this->getOption('inc_vfolder')) { $iterator = IMP_Search_IteratorFilter::create(IMP_Search_IteratorFilter::VFOLDER); $vfolder_list = array(); foreach ($iterator as $val) { $form_to = IMP_Mailbox::formTo($val); $vfolder_list[] = array('l' => $filter->filter($val->label, 'space2html', array('encode' => true)), 'sel' => !empty($this->_nodes[$form_to]['selected']), 'v' => $form_to); } if (!empty($vfolder_list)) { $view->vfolder = $vfolder_list; } } /* Add the list of editable tasklists to the list. */ if ($this->getOption('inc_tasklists')) { $tasklist = new IMP_Indices_Copy_Tasklist(); $view->tasklist = array(); foreach ($tasklist->getTasklists() as $key => $val) { $view->tasklist[] = array('l' => $filter->filter($val->get('name'), 'space2html', array('encode' => true)), 'v' => $key); } } /* Add the list of editable notepads to the list. */ if ($this->getOption('inc_notepads')) { $notepad = new IMP_Indices_Copy_Notepad(); $view->notepad = array(); foreach ($notepad->getNotepads() as $key => $val) { $view->notepad[] = array('l' => $filter->filter($val->get('name'), 'space2html', array('encode' => true)), 'v' => $key); } } /* Prepare filter list. */ $this->_filter = ($filter = $this->getOption('filter')) ? array_flip($filter) : array(); $tree = ''; foreach ($this->_tree->getRootNodes() as $node_id) { $tree .= $this->_buildTree($node_id); } $view->tree = $tree; return $view->render('flist'); }
/** */ protected function _init() { global $injector, $notification, $page_output, $prefs, $registry, $session; $mailbox = $this->indices->mailbox; /* Call the mailbox redirection hook, if requested. */ try { $redirect = $injector->getInstance('Horde_Core_Hooks')->callHook('mbox_redirect', 'imp', array($mailbox)); if (!empty($redirect)) { Horde::url($redirect, true)->redirect(); } } catch (Horde_Exception_HookNotSet $e) { } $mailbox_url = Horde::url('basic.php')->add('page', 'mailbox'); $mailbox_imp_url = $mailbox->url('mailbox')->add('newmail', 1); $imp_flags = $injector->getInstance('IMP_Flags'); $imp_imap = $mailbox->imp_imap; $imp_search = $injector->getInstance('IMP_Search'); /* Run through the action handlers */ if (($actionID = $this->vars->actionID) && $actionID != 'message_missing') { try { $session->checkToken($this->vars->token); } catch (Horde_Exception $e) { $notification->push($e); $actionID = null; } } /* We know we are going to be exclusively dealing with this mailbox, * so select it on the IMAP server (saves some STATUS calls). Open * R/W to clear the RECENT flag. This call will catch invalid * mailboxes. */ $imp_imap->openMailbox($mailbox, Horde_Imap_Client::OPEN_READWRITE); $imp_mailbox = $mailbox->list_ob; /* Determine if mailbox is readonly. */ $readonly = $mailbox->readonly; switch ($actionID) { case 'change_sort': $mailbox->setSort($this->vars->sortby, $this->vars->sortdir); break; case 'blacklist': $injector->getInstance('IMP_Filter')->blacklistMessage($this->indices); break; case 'whitelist': $injector->getInstance('IMP_Filter')->whitelistMessage($this->indices); break; case 'spam_report': $injector->getInstance('IMP_Factory_Spam')->create(IMP_Spam::SPAM)->report($this->indices); break; case 'innocent_report': $injector->getInstance('IMP_Factory_Spam')->create(IMP_Spam::INNOCENT)->report($this->indices); break; case 'message_missing': $notification->push(_("Requested message not found."), 'horde.error'); break; case 'fwd_digest': case 'redirect_messages': case 'template_edit': if (count($this->indices)) { $compose_actions = array('fwd_digest' => 'fwd_digest', 'redirect_messages' => 'redirect_compose', 'template_edit' => 'template_edit'); $clink = new IMP_Compose_Link($this->vars); $options = array_merge(array('actionID' => $compose_actions[$actionID], 'muid' => strval($this->indices)), $clink->args); if ($prefs->getValue('compose_popup')) { $page_output->addInlineScript(array(Horde::popupJs(IMP_Basic_Compose::url(), array('novoid' => true, 'params' => array_merge(array('popup' => 1), $options)))), true); } else { IMP_Basic_Compose::url()->add($options)->redirect(); } } break; case 'delete_messages': $injector->getInstance('IMP_Message')->delete($this->indices, array('mailboxob' => $imp_mailbox)); break; case 'undelete_messages': $injector->getInstance('IMP_Message')->undelete($this->indices); break; case 'move_messages': case 'copy_messages': if (isset($this->vars->targetMbox) && count($this->indices) && (!$readonly || $actionID == 'copy_messages')) { $targetMbox = IMP_Mailbox::formFrom($this->vars->targetMbox); if (!empty($this->vars->newMbox) && $this->vars->newMbox == 1) { $targetMbox = IMP_Mailbox::get($this->vars->targetMbox)->namespace_append; $newMbox = true; } else { $targetMbox = IMP_Mailbox::formFrom($this->vars->targetMbox); $newMbox = false; } $injector->getInstance('IMP_Message')->copy($targetMbox, $actionID == 'move_messages' ? 'move' : 'copy', $this->indices, array('create' => $newMbox, 'mailboxob' => $imp_mailbox)); } break; case 'flag_messages': if (!$readonly && $this->vars->flag && count($this->indices)) { $flag = $imp_flags->parseFormId($this->vars->flag); $injector->getInstance('IMP_Message')->flag(array($flag['set'] ? 'add' : 'remove' => array($flag['flag'])), $this->indices); } break; case 'filter_messages': if (!$readonly) { $filter = IMP_Mailbox::formFrom($this->vars->filter); $q_ob = null; if (strpos($filter, self::FLAG_FILTER_PREFIX) === 0) { /* Flag filtering. */ $flag_filter = $imp_flags->parseFormId(substr($filter, strpos($filter, "") + 1)); try { $q_ob = $imp_search->createQuery(array(new IMP_Search_Element_Flag($flag_filter['flag'], $flag_filter['set'])), array('mboxes' => array($mailbox), 'type' => IMP_Search::CREATE_QUERY)); } catch (InvalidArgumentException $e) { } } else { /* Pre-defined filters. */ try { $q_ob = $imp_search->applyFilter($filter, array($mailbox)); } catch (InvalidArgumentException $e) { } } if ($q_ob) { IMP_Mailbox::get($q_ob)->url('mailbox')->redirect(); exit; } } break; case 'hide_deleted': $mailbox->setHideDeletedMsgs(!$prefs->getValue('delhide')); break; case 'expunge_mailbox': $injector->getInstance('IMP_Message')->expungeMailbox(array(strval($mailbox) => 1), array('mailboxob' => $imp_mailbox)); break; case 'filter': $mailbox->filter(); break; case 'empty_mailbox': $injector->getInstance('IMP_Message')->emptyMailbox(array(strval($mailbox))); break; case 'view_messages': $mailbox->url(IMP_Basic_Thread::url(), null, false)->add(array('mode' => 'msgview', 'muid' => strval($this->indices)))->redirect(); break; } /* Token to use in requests. */ $token = $session->getToken(); $search_mbox = $mailbox->search; /* Deal with filter options. */ if (!$readonly && IMP_Filter::canApplyFilters() && !$mailbox->filterOnDisplay() && ($mailbox->inbox || $prefs->getValue('filter_any_mailbox') && !$search_mbox)) { $filter_url = $mailbox_imp_url->copy()->add(array('actionID' => 'filter', 'token' => $token)); } /* Generate folder options list. */ if ($imp_imap->access(IMP_Imap::ACCESS_FOLDERS)) { $iterator = new IMP_Ftree_IteratorFilter($injector->getInstance('IMP_Ftree')); $iterator->add($iterator::NONIMAP); $folder_options = new IMP_Ftree_Select(array('heading' => _("Messages to"), 'inc_notepads' => true, 'inc_tasklists' => true, 'iterator' => $iterator, 'new_mbox' => true)); } /* Build the list of messages in the mailbox. */ $pageOb = $imp_mailbox->buildMailboxPage($this->vars->mpage, $this->vars->start); $show_preview = $prefs->getValue('preview_enabled'); $mbox_info = $imp_mailbox->getMailboxArray(range($pageOb['begin'], $pageOb['end']), array('headers' => true, 'preview' => (int) $show_preview, 'type' => $prefs->getValue('atc_flag'))); /* Determine sorting preferences. */ $sortpref = $mailbox->getSort(); $thread_sort = $sortpref->sortby == Horde_Imap_Client::SORT_THREAD; /* Determine if we are going to show the Hide/Purge Deleted Message * links. */ if (!($use_trash = $prefs->getValue('use_trash')) && !$mailbox->vinbox) { $showdelete = array('hide' => true, 'purge' => $mailbox->access_expunge); } else { $showdelete = array('hide' => false, 'purge' => false); } if ($showdelete['hide'] && !$prefs->isLocked('delhide')) { if ($prefs->getValue('delhide')) { $deleted_prompt = _("Show Deleted"); } else { $deleted_prompt = _("Hide Deleted"); } } /* Generate paging links. */ if ($pageOb['pagecount']) { if ($pageOb['page'] == 1) { $url_first = $url_prev = null; $pages_first = 'navfirstgreyImg'; $pages_prev = 'navleftgreyImg'; } else { $url_first = $mailbox_imp_url->copy()->add('mpage', 1); $pages_first = 'navfirstImg'; $url_prev = $mailbox_imp_url->copy()->add('mpage', $pageOb['page'] - 1); $pages_prev = 'navleftImg'; } if ($pageOb['page'] == $pageOb['pagecount']) { $url_last = $url_next = null; $pages_last = 'navlastgreyImg'; $pages_next = 'navrightgreyImg'; } else { $url_next = $mailbox_imp_url->copy()->add('mpage', $pageOb['page'] + 1); $pages_next = 'navrightImg'; $url_last = $mailbox_imp_url->copy()->add('mpage', $pageOb['pagecount']); $pages_last = 'navlastImg'; } } /* Generate RSS link. */ if ($mailbox->inbox) { $rss_box = ''; } else { $ns_info = $mailbox->namespace_info; if (is_null($ns_info)) { $rss_box = null; } else { $rss_box = str_replace(rawurlencode($ns_info->delimiter), '/', rawurlencode($ns_info->delimiter . ($ns_info->type == $ns_info::NS_PERSONAL ? $ns_info->stripNamespace($mailbox) : $mailbox))); } } if (!is_null($rss_box)) { $page_output->addLinkTag(array('href' => Horde::url('rss.php', true, -1) . $rss_box)); } /* If user wants the mailbox to be refreshed, set time here. */ $refresh_url = $mailbox_imp_url->copy()->add('mpage', $pageOb['page']); if (isset($filter_url)) { $filter_url->add('mpage', $pageOb['page']); } /* Determine if we are showing previews. */ $preview_tooltip = $show_preview ? $prefs->getValue('preview_show_tooltip') : false; if (!$preview_tooltip) { $strip_preview = $prefs->getValue('preview_strip_nl'); } $unread = $imp_mailbox->unseenMessages(Horde_Imap_Client::SEARCH_RESULTS_COUNT); $page_output->addInlineJsVars(array('ImpMailbox.pop3' => intval(!$mailbox->is_imap), 'ImpMailbox.text' => array('delete_messages' => _("Are you sure you wish to PERMANENTLY delete these messages?"), 'delete_all' => _("Are you sure you wish to delete all mail in this mailbox?"), 'delete_vfolder' => _("Are you sure you want to delete this Virtual Folder Definition?"), 'innocent_report' => _("Are you sure you wish to report this message as innocent?"), 'moveconfirm' => _("Are you sure you want to move the message(s)? (Some message information might get lost, like message headers, text formatting or attachments!)"), 'newmbox' => _("You are copying/moving to a new mailbox.") . "\n" . _("Please enter a name for the new mailbox:") . "\n", 'no' => _("No"), 'selectone' => _("You must select at least one message first."), 'selectonlyone' => _("You must select only one message for this action."), 'spam_report' => _("Are you sure you wish to report this message as spam?"), 'submit' => _("You must select at least one message first."), 'target_mbox' => _("You must select a target mailbox first.")), 'ImpMailbox.unread' => intval($unread))); $pagetitle = $this->title = $mailbox->label; if ($mailbox->editvfolder) { $query_text = wordwrap($imp_search[$mailbox]->querytext); $pagetitle .= ' [' . Horde::linkTooltip('#', $query_text, '', '', '', $query_text) . _("Virtual Folder") . '</a>]'; $this->title .= ' [' . _("Virtual Folder") . ']'; } elseif ($mailbox->editquery) { $query_text = wordwrap($imp_search[$mailbox]->querytext); $pagetitle = Horde::linkTooltip('#', $query_text, '', '', '', $query_text) . $pagetitle . '</a>'; } else { $pagetitle = $this->title = htmlspecialchars($this->title); } /* Generate mailbox summary string. */ $subinfo = new IMP_View_Subinfo(array('mailbox' => $mailbox)); $subinfo->value = $pagetitle . ' ('; if (empty($pageOb['end'])) { $subinfo->value .= _("No Messages"); } else { $subinfo->value .= $pageOb['pagecount'] > 1 ? sprintf(_("%d Messages"), $pageOb['msgcount']) . ' / ' . sprintf(_("Page %d of %d"), $pageOb['page'], $pageOb['pagecount']) : sprintf(_("%d Messages"), $pageOb['msgcount']); } $subinfo->value .= ')'; $injector->getInstance('Horde_View_Topbar')->subinfo = $subinfo->render(); $page_output->addScriptFile('hordecore.js', 'horde'); $page_output->addScriptFile('mailbox.js'); $page_output->addScriptPackage('Horde_Core_Script_Package_Dialog'); $page_output->metaRefresh($prefs->getValue('refresh_time'), $refresh_url); /* Prepare the header template. */ $view = new Horde_View(array('templatePath' => IMP_TEMPLATES . '/basic/mailbox')); $view->addHelper('FormTag'); $view->addHelper('Horde_Core_View_Helper_Accesskey'); $view->addHelper('Tag'); $hdr_view = clone $view; $hdr_view->readonly = $readonly; $hdr_view->refresh_url = $refresh_url; if (isset($filter_url)) { $hdr_view->filter_url = $filter_url; } if ($mailbox->access_search) { if (!$search_mbox) { $hdr_view->search_url = $mailbox->url(IMP_Basic_Searchbasic::url()); } else { if ($mailbox->editvfolder) { $edit_search = _("Edit Virtual Folder"); } elseif ($mailbox->query) { if ($mailbox->editquery) { $edit_search = _("Edit Search Query"); } else { /* Basic search results. */ $search_mailbox = IMP_Mailbox::get($imp_search[$mailbox]->mboxes[0]); $hdr_view->search_url = $search_mailbox->url(IMP_Basic_Searchbasic::url()); $hdr_view->searchclose = $search_mailbox->url('mailbox'); } } if (isset($edit_search)) { $hdr_view->edit_search_url = $imp_search->editUrl($mailbox); $hdr_view->edit_search_title = $edit_search; } } } if ($mailbox->access_empty) { $hdr_view->empty = $mailbox_imp_url->copy()->add(array('actionID' => 'empty_mailbox', 'token' => $token)); } $this->output = $hdr_view->render('header'); /* If no messages, exit immediately. */ if (empty($pageOb['end'])) { if ($pageOb['anymsg'] && isset($deleted_prompt)) { /* Show 'Show Deleted' prompt if mailbox has no viewable * message but has hidden, deleted messages. */ $del_view = clone $view; $del_view->hide = Horde::widget(array('url' => $refresh_url->copy()->add(array('actionID' => 'hide_deleted', 'token' => $token)), 'class' => 'hideAction', 'title' => $deleted_prompt)); if ($mailbox->access_expunge) { $del_view->purge = Horde::widget(array('url' => $refresh_url->copy()->add(array('actionID' => 'expunge_mailbox', 'token' => $token)), 'class' => 'purgeAction', 'title' => _("Pur_ge Deleted"))); } $this->output .= $del_view->render('actions_deleted'); } $empty_view = clone $view; $empty_view->search_mbox = $search_mbox; $this->output .= $empty_view->render('empty_mailbox'); return; } $clink_ob = new IMP_Compose_Link(); $clink = $clink_ob->link(); /* Display the navbar and actions if there is at least 1 message in * mailbox. */ if ($pageOb['msgcount']) { /* Prepare the navbar template. */ $n_view = clone $view; $n_view->id = 1; $n_view->readonly = $readonly; $filtermsg = false; if ($mailbox->access_flags) { $args = array('imap' => true, 'mailbox' => $search_mbox ? null : $mailbox); $form_set = $form_unset = array(); foreach ($imp_flags->getList($args) as $val) { if ($val->canset) { $form_set[] = array('f' => $val->form_set, 'l' => $val->label, 'v' => IMP_Mailbox::formTo(self::FLAG_FILTER_PREFIX . $val->form_set)); $form_unset[] = array('f' => $val->form_unset, 'l' => $val->label, 'v' => IMP_Mailbox::formTo(self::FLAG_FILTER_PREFIX . $val->form_unset)); } } $n_view->flaglist_set = $form_set; $n_view->flaglist_unset = $form_unset; if (!$search_mbox && $mailbox->access_search) { $filtermsg = $n_view->flag_filter = true; } } if (!$search_mbox && $mailbox->access_filters) { $filters = array(); $iterator = IMP_Search_IteratorFilter::create(IMP_Search_IteratorFilter::FILTER); foreach ($iterator as $val) { $filters[] = array('l' => $val->label, 'v' => IMP_Mailbox::formTo($val)); } if (!empty($filters)) { $filtermsg = true; $n_view->filters = $filters; } } $n_view->filtermsg = $filtermsg; if ($imp_imap->access(IMP_Imap::ACCESS_FOLDERS)) { $n_view->move = Horde::widget(array('url' => '#', 'class' => 'moveAction', 'title' => _("Move"), 'nocheck' => true)); $n_view->copy = Horde::widget(array('url' => '#', 'class' => 'copyAction', 'title' => _("Copy"), 'nocheck' => true)); $n_view->folder_options = $folder_options; } $n_view->mailbox_url = $mailbox_url; $n_view->mailbox = $mailbox->form_to; if ($pageOb['pagecount'] > 1) { $n_view->multiple_page = true; $n_view->pages_first = $pages_first; $n_view->url_first = $url_first; $n_view->pages_prev = $pages_prev; $n_view->url_prev = $url_prev; $n_view->pages_next = $pages_next; $n_view->url_next = $url_next; $n_view->pages_last = $pages_last; $n_view->url_last = $url_last; $n_view->page_val = $pageOb['page']; $n_view->page_size = Horde_String::length($pageOb['pagecount']); } $this->output .= $n_view->render('navbar'); /* Prepare the actions template. */ $a_view = clone $view; if ($mailbox->access_deletemsgs) { $del_class = $use_trash && $mailbox->trash ? 'permdeleteAction' : 'deleteAction'; $a_view->delete = Horde::widget(array('url' => '#', 'class' => $del_class, 'title' => _("_Delete"))); } if ($showdelete['purge'] || $mailbox->vtrash) { $a_view->undelete = Horde::widget(array('url' => '#', 'class' => 'undeleteAction', 'title' => _("_Undelete"))); } $mboxactions = array(); if ($showdelete['purge']) { $mailbox_link = $mailbox_imp_url->copy()->add('mpage', $pageOb['page']); if (isset($deleted_prompt)) { $mboxactions[] = Horde::widget(array('url' => $mailbox_link->copy()->add(array('actionID' => 'hide_deleted', 'token' => $token)), 'class' => 'hideAction', 'title' => $deleted_prompt)); } $mboxactions[] = Horde::widget(array('url' => $mailbox_link->copy()->add(array('actionID' => 'expunge_mailbox', 'token' => $token)), 'class' => 'purgeAction', 'title' => _("Pur_ge Deleted"))); } if (!$sortpref->sortby_locked && $sortpref->sortby != Horde_Imap_Client::SORT_SEQUENCE) { $mboxactions[] = Horde::widget(array('url' => $mailbox_imp_url->copy()->add(array('sortby' => Horde_Imap_Client::SORT_SEQUENCE, 'actionID' => 'change_sort', 'token' => $token)), 'title' => _("Clear Sort"))); } if ($mailbox->templates) { $a_view->templateedit = Horde::widget(array('url' => '#', 'class' => 'templateeditAction', 'title' => _("Edit Template"))); $mboxactions[] = Horde::widget(array('url' => $clink->copy()->add(array('actionID' => 'template_new')), 'title' => _("Create New Template"))); } $a_view->mboxactions = $mboxactions; if ($registry->hasMethod('mail/blacklistFrom')) { $a_view->blacklist = Horde::widget(array('url' => '#', 'class' => 'blacklistAction', 'title' => _("_Blacklist"))); } if ($registry->hasMethod('mail/whitelistFrom')) { $a_view->whitelist = Horde::widget(array('url' => '#', 'class' => 'whitelistAction', 'title' => _("_Whitelist"))); } if (IMP_Compose::canCompose()) { $a_view->forward = Horde::widget(array('url' => '#', 'class' => 'forwardAction', 'title' => _("Fo_rward"))); $a_view->redirect = Horde::widget(array('url' => '#', 'class' => 'redirectAction', 'title' => _("Redirect"))); } if ($mailbox->spam_show) { $a_view->spam = Horde::widget(array('url' => '#', 'class' => 'spamAction', 'title' => _("Report as Spam"))); } if ($mailbox->innocent_show) { $a_view->innocent = Horde::widget(array('url' => '#', 'class' => 'innocentAction', 'title' => _("Report as Innocent"))); } $a_view->view_messages = Horde::widget(array('url' => '#', 'class' => 'viewAction', 'title' => _("View Messages"))); $this->output .= $a_view->render('actions'); } /* Define some variables now so we don't have to keep redefining in * the foreach loop or the templates. */ $lastMbox = ''; $mh_count = 0; $sortImg = $sortpref->sortdir ? 'sortup' : 'sortdown'; $headers = array(Horde_Imap_Client::SORT_TO => array('id' => 'mboxto', 'stext' => _("Sort by To Address"), 'text' => _("To")), Horde_Imap_Client::SORT_FROM => array('id' => 'mboxfrom', 'stext' => _("Sort by From Address"), 'text' => _("Fro_m")), Horde_Imap_Client::SORT_THREAD => array('id' => 'mboxthread', 'stext' => _("Sort by Thread"), 'text' => _("_Thread")), Horde_Imap_Client::SORT_SUBJECT => array('id' => 'mboxsubject', 'stext' => _("Sort by Subject"), 'text' => _("Sub_ject")), IMP::IMAP_SORT_DATE => array('id' => 'mboxdate', 'stext' => _("Sort by Date"), 'text' => _("Dat_e")), Horde_Imap_Client::SORT_SIZE => array('id' => 'mboxsize', 'stext' => _("Sort by Message Size"), 'text' => _("Si_ze"))); /* If this is the Drafts or Sent-Mail mailbox, sort by To instead of * From. */ if ($mailbox->special_outgoing) { unset($headers[Horde_Imap_Client::SORT_FROM]); } else { unset($headers[Horde_Imap_Client::SORT_TO]); } /* Determine which of Subject/Thread to emphasize. */ if (!$mailbox->access_sortthread || $sortpref->sortby_locked) { unset($headers[Horde_Imap_Client::SORT_THREAD]); if ($sortpref->sortby_locked && $thread_sort) { $sortpref->sortby = Horde_Imap_Client::SORT_SUBJECT; } } else { if ($thread_sort) { $extra = Horde_Imap_Client::SORT_SUBJECT; $standard = Horde_Imap_Client::SORT_THREAD; } else { $extra = Horde_Imap_Client::SORT_THREAD; $standard = Horde_Imap_Client::SORT_SUBJECT; } $headers[$standard]['altsort'] = Horde::widget(array('url' => $mailbox_imp_url->copy()->add(array('actionID' => 'change_sort', 'token' => $token, 'sortby' => $extra)), 'title' => $headers[$extra]['text'])); unset($headers[$extra]); } foreach ($headers as $key => $val) { $ptr =& $headers[$key]; if ($sortpref->sortby == $key) { $csl_icon = '<span class="iconImg ' . $sortImg . '"></span>'; if ($sortpref->sortdir_locked) { $ptr['change_sort_link'] = $csl_icon; $ptr['change_sort_widget'] = Horde::stripAccessKey($val['text']); } else { $tmp = $mailbox_imp_url->copy()->add(array('sortby' => $key, 'sortdir' => intval(!$sortpref->sortdir), 'actionID' => 'change_sort', 'token' => $token)); $ptr['change_sort_link'] = Horde::link($tmp, $val['stext'], null, null, null, $val['stext']) . $csl_icon . '</a>'; $ptr['change_sort_widget'] = Horde::widget(array('url' => $tmp, 'title' => $val['text'])); } } else { $ptr['change_sort_link'] = null; $ptr['change_sort_widget'] = $sortpref->sortby_locked ? Horde::stripAccessKey($val['text']) : Horde::widget(array('url' => $mailbox_imp_url->copy()->add(array('actionID' => 'change_sort', 'token' => $token, 'sortby' => $key)), 'title' => $val['text'])); } $ptr['class'] = 'horde-split-left'; } /* Output the form start. */ $f_view = clone $view; $f_view->mailbox = $mailbox->form_to; $f_view->mailbox_url = $mailbox_url; $f_view->page = $pageOb['page']; $f_view->token = $token; $this->output .= $f_view->render('form_start'); /* Prepare the message headers template. */ $mh_view = clone $view; $mh_view->headers = $headers; if (!$search_mbox) { $mh_view->show_checkbox = !$mh_count++; $this->output .= $mh_view->render('message_headers'); } /* Initialize repetitively used variables. */ $fromlinkstyle = $prefs->getValue('from_link'); $imp_ui = new IMP_Mailbox_Ui($mailbox); /* Display message information. */ $msgs = array(); $search_view = clone $view; $summary_view = clone $view; while (list(, $ob) = each($mbox_info['overview'])) { if ($search_mbox) { if (empty($lastMbox) || $ob['mailbox'] != $lastMbox) { if (!empty($lastMbox)) { $this->_outputSummaries($msgs, $summary_view); $msgs = array(); } $mbox = IMP_Mailbox::get($ob['mailbox']); $search_view->mbox_link = Horde::link($mbox->url($mailbox_url), sprintf(_("View messages in %s"), $mbox->display), 'smallheader') . $mbox->display_html . '</a>'; $this->output .= $search_view->render('searchmbox'); $mh_view->show_checkbox = !$mh_count++; $this->output .= $mh_view->render('message_headers'); } } $lastMbox = $ob['mailbox']; /* Initialize the data fields. */ $msg = array('bg' => '', 'buid' => $imp_mailbox->getBuid($ob['mailbox'], $ob['uid']), 'class' => '', 'date' => $imp_ui->getDate($ob['envelope']->date), 'preview' => '', 'status' => '', 'size' => IMP::sizeFormat($ob['size'])); /* Generate the target link. */ if ($mailbox->drafts || $mailbox->templates) { $clink_copy = clone $clink_ob; $clink_copy->args['buid'] = $msg['buid']; $clink_copy->args['mailbox'] = $mailbox; $target = $clink_copy->link()->add(array('actionID' => $mailbox->drafts ? 'draft' : 'template')); } else { $target = $mailbox->url('message', $msg['buid']); } /* Get all the flag information. */ $flag_parse = $imp_flags->parse(array('flags' => $ob['flags'], 'headers' => $ob['headers'], 'runhook' => $ob, 'personal' => $ob['envelope']->to)); $css_class = $subject_flags = array(); foreach ($flag_parse as $val) { if ($val instanceof IMP_Flag_User) { $subject_flags[] = $val; } else { if (!$val->bgdefault) { $msg['bg'] = $val->bgcolor; } $css_class[] = $val->css; $msg['status'] .= $val->span; } } $msg['class'] = implode(' ', $css_class); /* Show message preview? */ if ($show_preview && isset($ob['preview'])) { if (empty($ob['preview'])) { $ptext = '[[' . _("No Preview Text") . ']]'; } else { $ptext = empty($strip_preview) ? str_replace("\r", '', $ob['preview']) : preg_replace(array('/\\n/', '/(\\s)+/'), array(' ', '$1'), str_replace("\r", "\n", $ob['preview'])); if (!$preview_tooltip) { $ptext = $injector->getInstance('Horde_Core_Factory_TextFilter')->filter($ptext, 'text2html', array('parselevel' => Horde_Text_Filter_Text2html::NOHTML)); } $maxlen = $prefs->getValue('preview_maxlen'); if (Horde_String::length($ptext) > $maxlen) { $ptext = Horde_String::truncate($ptext, $maxlen); } elseif (empty($ob['previewcut'])) { $ptext .= '[[' . _("END") . ']]'; } } $msg['preview'] = $ptext; } /* Format the From: Header. */ $getfrom = $imp_ui->getFrom($ob['envelope']); $msg['from'] = htmlspecialchars($getfrom['from'], ENT_QUOTES, 'UTF-8'); switch ($fromlinkstyle) { case 0: $from_tmp = array(); foreach ($getfrom['from_list']->base_addresses as $from_ob) { $from_tmp[] = call_user_func_array(array('Horde', $preview_tooltip ? 'linkTooltip' : 'link'), array($clink->copy()->add(array('actionID' => 'mailto_link', 'to' => strval($from_ob))), sprintf(_("New Message to %s"), $from_ob->label))) . htmlspecialchars($from_ob->label, ENT_QUOTES, 'UTF-8') . '</a>'; } if (!empty($from_tmp)) { $msg['from'] = implode(', ', $from_tmp); } break; default: $from_uri = $mailbox->url('message', $msg['buid']); $msg['from'] = Horde::link($from_uri) . $msg['from'] . '</a>'; break; } /* Format the Subject: Header. */ $msg['subject'] = $imp_ui->getSubject($ob['envelope']->subject, true); $msg['subject'] = $preview_tooltip ? substr(Horde::linkTooltip($target, $msg['preview'], '', '', '', $msg['preview']), 0, -1) . ' class="mboxSubject">' . $msg['subject'] . '</a>' : substr(Horde::link($target, $imp_ui->getSubject($ob['envelope']->subject)), 0, -1) . ' class="mboxSubject">' . $msg['subject'] . '</a>' . (!empty($msg['preview']) ? '<br /><small>' . $msg['preview'] . '</small>' : ''); /* Add subject flags. */ foreach ($subject_flags as $val) { $flag_label = Horde_String::truncate($val->label, 12); $msg['subject'] = '<span class="' . $val->css . '" style="' . ($val->bgdefault ? '' : 'background:' . htmlspecialchars($val->bgcolor) . ';') . 'color:' . htmlspecialchars($val->fgcolor) . '" title="' . htmlspecialchars($val->label) . '">' . htmlspecialchars($flag_label) . '</span>' . $msg['subject']; } /* Set up threading tree now. */ if ($thread_sort) { $t_ob = $imp_mailbox->getThreadOb($ob['idx']); $msg['subject'] = ($sortpref->sortdir ? $t_ob->reverse_img : $t_ob->img) . ' ' . $msg['subject']; } $msgs[$msg['buid']] = $msg; } $this->_outputSummaries($msgs, $summary_view); $this->output .= '</form>'; /* If there are 20 messages or less, don't show the actions/navbar * again. */ if ($pageOb['end'] - $pageOb['begin'] >= 20) { $this->output .= $a_view->render('actions'); $n_view->id = 2; $this->output .= $n_view->render('navbar'); } }
/** * Upgrade IMP 5.0.x virtual folders. */ protected function _upgradeVirtualFolders6() { $imp_search = $GLOBALS['injector']->getInstance('IMP_Search'); $iterator = IMP_Search_IteratorFilter::create(IMP_Search_IteratorFilter::VFOLDER | IMP_Search_IteratorFilter::DISABLED); foreach ($iterator as $val) { $replace = false; $tmp = $val->query; foreach (array_keys($tmp) as $key2) { if ($tmp[$key2] instanceof IMP_Search_Element_Date) { $criteria = $tmp[$key2]->data; switch ($criteria->t) { case IMP_Search_Element_Date::DATE_ON: $ob = new IMP_Search_Element_Daterange(new DateTime('@' . $criteria->d), new DateTime('@' . $criteria->d)); break; case IMP_Search_Element_Date::DATE_BEFORE: $ob = new IMP_Search_Element_Daterange(null, new DateTime('@' . $criteria->d)); break; case IMP_Search_Element_Date::DATE_SINCE: $ob = new IMP_Search_Element_Daterange(new DateTime('@' . $criteria->d), null); break; } $tmp[$key2] = $ob; $replace = true; } } if ($replace) { $val->replace($tmp); $imp_search[$val->id] = $val; } } }
/** */ public function update(Horde_Core_Prefs_Ui $ui) { global $injector, $notification; $imp_search = $injector->getInstance('IMP_Search'); switch ($ui->vars->searches_action) { case 'delete': /* Remove 'enable_' prefix. */ $key = substr($ui->vars->searches_data, 7); if ($ob = $imp_search[$key]) { if ($imp_search->isVFolder($ob)) { $notification->push(sprintf(_("Virtual Folder \"%s\" deleted."), $ob->label), 'horde.success'); } elseif ($imp_search->isFilter($ob)) { $notification->push(sprintf(_("Filter \"%s\" deleted."), $ob->label), 'horde.success'); } unset($imp_search[$key]); } break; default: /* Update enabled status for Virtual Folders. */ $iterator = IMP_Search_IteratorFilter::create(IMP_Search_IteratorFilter::DISABLED | IMP_Search_IteratorFilter::VFOLDER); $vfolders = array(); foreach ($iterator as $val) { $form_key = 'enable_' . $val->id; /* Only change enabled status for virtual folders displayed * on the preferences screen. */ if ($val->prefDisplay) { $val->enabled = !empty($ui->vars->{$form_key}); $vfolders[$val->id] = $val; } } $imp_search->setVFolders($vfolders); /* Update enabled status for Filters. */ $iterator = IMP_Search_IteratorFilter::create(IMP_Search_IteratorFilter::DISABLED | IMP_Search_IteratorFilter::FILTER); $filters = array(); foreach ($iterator as $val) { $form_key = 'enable_' . $val->id; $val->enabled = !empty($ui->vars->{$form_key}); $filters[$val->id] = $val; } $imp_search->setFilters($filters); break; } return false; }
/** */ 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?")); } }
/** * @param boolean $static Ignored in this driver. */ public function getTree($static = false) { global $conf, $injector, $registry; $this->_nodes = $this->_tree->getNodes(); $filter = $injector->createInstance('Horde_Text_Filter'); $view = new Horde_View(array('templatePath' => IMP_TEMPLATES . '/basic/flist')); $view->addHelper('FormTag'); $view->addHelper('Tag'); $view->optgroup = $this->getOption('optgroup'); /* Custom HTML. */ if ($customhtml = $this->getOption('customhtml')) { $view->customhtml = $customhtml; } /* Heading. */ if (($heading = $this->getOption('heading')) && strlen($heading) > 0) { $view->heading = $heading; } /* New mailbox entry. */ if ($this->getOption('new_mbox')) { $imp_imap = $injector->getInstance('IMP_Factory_Imap')->create(); if ($imp_imap->access(IMP_Imap::ACCESS_CREATEMBOX) && $imp_imap->access(IMP_Imap::ACCESS_CREATEMBOX_MAX)) { $view->new_mbox = true; } } /* Virtual folders. */ if ($this->getOption('inc_vfolder')) { $iterator = IMP_Search_IteratorFilter::create(IMP_Search_IteratorFilter::VFOLDER); $vfolder_list = array(); foreach ($iterator as $val) { $form_to = IMP_Mailbox::formTo($val); $vfolder_list[] = array('l' => $filter->filter($val->label, 'space2html', array('encode' => true)), 'sel' => !empty($this->_nodes[$form_to]['selected']), 'v' => $form_to); } if (!empty($vfolder_list)) { $view->vfolder = $vfolder_list; } } /* Add the list of editable tasklists to the list. */ if ($this->getOption('inc_tasklists') && $conf['tasklist']['use_tasklist'] && $registry->hasMethod('tasks/listTasklists')) { try { $tasklists = $registry->call('tasks/listTasklists', array(false, Horde_Perms::EDIT)); if (count($tasklists)) { $tasklist_list = array(); foreach ($tasklists as $id => $tasklist) { $tasklist_list[] = array('l' => $filter->filter($tasklist->get('name'), 'space2html', array('encode' => true)), 'v' => IMP_Mailbox::formTo(IMP::TASKLIST_EDIT . $id)); } $view->tasklist = $tasklist_list; } } catch (Horde_Exception $e) { } } /* Add the list of editable notepads to the list. */ if ($this->getOption('inc_notepads') && $conf['notepad']['use_notepad'] && $registry->hasMethod('notes/listNotepads')) { try { $notepads = $registry->call('notes/listNotepads', array(false, Horde_Perms::EDIT)); if (count($notepads)) { foreach ($notepads as $id => $notepad) { $notepad_list[] = array('l' => $filter->filter($notepad->get('name'), 'space2html', array('encode' => true)), 'v' => IMP_Mailbox::formTo(IMP::NOTEPAD_EDIT . $id)); } $view->notepad = $notepad_list; } } catch (Horde_Exception $e) { } } /* Prepare filter list. */ $this->_filter = ($filter = $this->getOption('filter')) ? array_flip($filter) : array(); $tree = ''; foreach ($this->_tree->getRootNodes() as $node_id) { $tree .= $this->_buildTree($node_id); } $view->tree = $tree; return $view->render('flist'); }