Автор: Michael Slusarz (slusarz@horde.org)
Наследование: implements ArrayAccess, implements Countable, implements IteratorAggregate
Пример #1
0
 /**
  * Constructor.
  */
 public function __construct()
 {
     global $page_output, $prefs, $registry;
     $this->_files[] = new Horde_Script_File_JsDir('compose.js', 'imp');
     $this->_files[] = new Horde_Script_File_JsDir('draghandler.js', 'imp');
     $this->_files[] = new Horde_Script_File_JsDir('editor.js', 'imp');
     $this->_files[] = new Horde_Script_File_JsDir('imp.js', 'imp');
     if (!$prefs->isLocked('default_encrypt') && (IMP_Pgp::enabled() || IMP_Smime::enabled())) {
         $page_output->addScriptPackage('Horde_Core_Script_Package_Dialog');
         $this->_files[] = new Horde_Script_File_JsDir('passphrase.js', 'imp');
     }
     if (!IMP_Compose::canHtmlCompose()) {
         return;
     }
     switch ($registry->getView()) {
         case $registry::VIEW_BASIC:
         case $registry::VIEW_DYNAMIC:
             $this->_files[] = new Horde_Script_File_JsDir('ckeditor/imageupload.js', 'imp');
             $this->_files[] = new Horde_Script_File_JsDir('ckeditor/images.js', 'imp');
             $page_output->addInlineJsVars(array('ImpCkeditorImgs.related_attr' => IMP_Compose::RELATED_ATTR));
             $js = new Horde_Script_File_JsDir('ckeditor/pasteattachment.js', 'imp');
             $upload_url = $registry->getServiceLink('ajax', 'imp')->url . 'addAttachmentCkeditor';
             $page_output->addInlineScript(array('if (window.CKEDITOR) { CKEDITOR.on("loaded", function(e) {' . 'CKEDITOR.plugins.addExternal("pasteattachment", "' . $js->url->url . '", "");' . 'CKEDITOR.config.filebrowserImageUploadUrl = "' . $upload_url . '";' . '}); };'), true);
             break;
     }
 }
Пример #2
0
 /**
  * Output the menu.
  *
  * @param string $page  The current page ('compose', 'folders', 'mailbox',
  *                                        'message', 'search').
  * @param array $items  Additional menu items to add to the menu. First
  *                      element is label, second is URL to link to.
  *
  * @return string  The menu.
  */
 public function getMenu($page, $items = array())
 {
     if (!in_array($page, array('mailbox', 'message')) || !$this->indices->mailbox->inbox) {
         $items[] = array(_("Inbox"), IMP_Minimal_Mailbox::url(array('mailbox' => 'INBOX')));
     }
     if (!in_array($page, array('compose', 'search')) && IMP_Compose::canCompose()) {
         $items[] = array(_("New Message"), IMP_Minimal_Compose::url());
     }
     if (!in_array($page, array('folders', 'search')) && $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->access(IMP_Imap::ACCESS_FOLDERS)) {
         $items[] = array(_("Folders"), IMP_Minimal_Folders::url());
     }
     $items[] = array(_("Log out"), $GLOBALS['registry']->getServiceLink('logout', 'imp')->setRaw(false));
     $menu = new Horde_Menu();
     foreach ($menu->getSiteLinks() as $menuitem) {
         if ($menuitem != 'separator') {
             $items[] = array($menuitem['text'], $menuitem['url']);
         }
     }
     return $items;
 }
Пример #3
0
 /**
  */
 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');
     }
 }
Пример #4
0
 /**
  */
 protected function _addIdentityJs()
 {
     global $injector, $page_output;
     $identities = array();
     $identity = $injector->getInstance('IMP_Identity');
     $sigs = $identity->hasSignature(true);
     foreach (array_keys(iterator_to_array($identity)) as $ident) {
         $sm = $identity->getValue(IMP_Mailbox::MBOX_SENT, $ident);
         $entry = array('sm_name' => $sm ? $sm->form_to : '', 'sm_save' => (bool) $identity->saveSentmail($ident), 'sm_title' => $sm ? $sm->display_notranslate : '', 'sm_display' => $sm ? $sm->display_html : '', 'bcc' => strval($identity->getBccAddresses($ident)));
         if ($sigs) {
             $sig = $identity->getSignature('text', $ident);
             $html_sig = $identity->getSignature('html', $ident);
             if (!strlen($html_sig) && strlen($sig)) {
                 $html_sig = IMP_Compose::text2html($sig);
             }
             $sig_dom = new Horde_Domhtml($html_sig, 'UTF-8');
             $html_sig = '';
             foreach ($sig_dom->getBody()->childNodes as $child) {
                 $html_sig .= $sig_dom->dom->saveXml($child);
             }
             $entry['sig'] = trim($sig);
             $entry['hsig'] = $html_sig;
         }
         $identities[] = $entry;
     }
     $page_output->addInlineJsVars(array('ImpCompose.identities' => $identities));
 }
Пример #5
0
 /**
  * Returns the full signature based on the current settings for the
  * signature itself, the dashes and the position.
  *
  * @param string $type    Either 'text' or 'html'.
  * @param integer $ident  The identity to retrieve the signature from.
  *
  * @return string  The full signature.
  * @throws Horde_Exception
  */
 public function getSignature($type = 'text', $ident = null)
 {
     if (is_null($ident)) {
         $ident = $this->getDefault();
     }
     $convert = false;
     $key = $ident . '|' . $type;
     $val = null;
     if (isset($this->_cached['signatures'][$key])) {
         return $this->_cached['signatures'][$key];
     }
     if ($type == 'html') {
         $val = $this->getValue('signature_html', $ident);
         if (!strlen($val)) {
             $convert = true;
             $val = null;
         }
     }
     if (is_null($val)) {
         $val = $this->getValue('signature', $ident);
         if (strlen($val) && $type == 'text') {
             $val = str_replace("\r\n", "\n", $val);
             $val = $this->getValue('sig_dashes', $ident) ? "\n-- \n" . $val : "\n\n" . $val;
         }
     }
     if ($val && $type == 'html') {
         if ($convert) {
             $val = IMP_Compose::text2html(trim($val));
         }
         $val = '<div>' . $val . '</div>';
     }
     $this->_cached['signatures'][$key] = $val;
     return $val;
 }
Пример #6
0
 /**
  * URL Parameters:
  *   a: (string) Action ID.
  *   allto: (boolean) View all To addresses?
  *   buid: (string) Browser UID.
  *   t: (string) Token.
  */
 protected function _init()
 {
     global $injector, $notification, $page_output, $prefs, $session;
     $imp_mailbox = $this->indices->mailbox->list_ob;
     $imp_mailbox->setIndex($this->indices);
     $mailbox_url = IMP_Minimal_Mailbox::url(array('mailbox' => $this->indices->mailbox));
     /* Make sure we have a valid index. */
     if (!$imp_mailbox->isValidIndex()) {
         $mailbox_url->add('a', 'm')->redirect();
     }
     $imp_ui = $injector->getInstance('IMP_Message_Ui');
     /* Run through action handlers */
     $msg_delete = false;
     switch ($this->vars->a) {
         // 'd' = delete message
         case 'd':
             $old_index = $imp_mailbox->getIndex();
             try {
                 $session->checkToken($this->vars->t);
                 $msg_delete = (bool) $injector->getInstance('IMP_Message')->delete($this->indices, array('mailboxob' => $imp_mailbox));
             } catch (Horde_Exception $e) {
                 $notification->push($e);
             }
             break;
             // 'u' = undelete message
         // 'u' = undelete message
         case 'u':
             $old_index = $imp_mailbox->getIndex();
             $injector->getInstance('IMP_Message')->undelete($this->indices);
             break;
             // 'rs' = report spam
             // 'ri' = report innocent
         // 'rs' = report spam
         // 'ri' = report innocent
         case 'rs':
         case 'ri':
             $old_index = $imp_mailbox->getIndex();
             $msg_delete = $injector->getInstance('IMP_Factory_Spam')->create($this->vars->a == 'rs' ? IMP_Spam::SPAM : IMP_Spam::INNOCENT)->report($this->indices, array('mailboxob' => $imp_mailbox)) === 1;
             break;
     }
     if ($msg_delete && $imp_ui->moveAfterAction($this->indices->mailbox)) {
         $imp_mailbox->setIndex(1);
     }
     /* We may have done processing that has taken us past the end of the
      * message array, so we will return to the mailbox. */
     if (!$imp_mailbox->isValidIndex() || $msg_delete && $prefs->getValue('mailbox_return')) {
         $mailbox_url->add('s', $old_index)->redirect();
     }
     /* Now that we are done processing, get the index and array index of
      * the current message. */
     $msg_index = $imp_mailbox[$imp_mailbox->getIndex()];
     $mailbox = $msg_index['m'];
     $uid = $msg_index['u'];
     $buid = $imp_mailbox->getBuid($mailbox, $uid);
     /* Get envelope/flag/header information. */
     try {
         $imp_imap = $mailbox->imp_imap;
         /* Need to fetch flags before HEADERTEXT, because SEEN flag might
          * be set before we can grab it. */
         $query = new Horde_Imap_Client_Fetch_Query();
         $query->flags();
         $flags_ret = $imp_imap->fetch($mailbox, $query, array('ids' => $imp_imap->getIdsOb($uid)));
         $query = new Horde_Imap_Client_Fetch_Query();
         $query->envelope();
         $fetch_ret = $imp_imap->fetch($mailbox, $query, array('ids' => $imp_imap->getIdsOb($uid)));
     } catch (IMP_Imap_Exception $e) {
         $mailbox_url->add('a', 'm')->redirect();
     }
     $envelope = $fetch_ret->first()->getEnvelope();
     $flags = $flags_ret->first()->getFlags();
     /* Parse the message. */
     try {
         $imp_contents = $injector->getInstance('IMP_Factory_Contents')->create(new IMP_Indices($imp_mailbox));
         $mime_headers = $imp_contents->getHeaderAndMarkAsSeen();
     } catch (IMP_Exception $e) {
         $mailbox_url->add('a', 'm')->redirect();
     }
     /* Get the starting index for the current message and the message
      * count. */
     $msgindex = $imp_mailbox->getIndex();
     $msgcount = count($imp_mailbox);
     /* Generate the mailbox link. */
     $mailbox_link = $mailbox_url->add('s', $msgindex);
     $self_link = self::url(array('buid' => $buid, 'mailbox' => $this->indices->mailbox));
     /* Create the Identity object. */
     $user_identity = $injector->getInstance('IMP_Identity');
     /* Develop the list of headers to display. */
     $basic_headers = $imp_ui->basicHeaders();
     $display_headers = $msgAddresses = array();
     if ($subject = $mime_headers->getValue('subject')) {
         /* Filter the subject text, if requested. */
         $subject = Horde_String::truncate(IMP::filterText($subject), 50);
     } else {
         $subject = _("[No Subject]");
     }
     $display_headers['subject'] = $subject;
     $format_date = $imp_ui->getLocalTime($envelope->date);
     if (!empty($format_date)) {
         $display_headers['date'] = $format_date;
     }
     /* Build From address links. */
     $display_headers['from'] = $imp_ui->buildAddressLinks($envelope->from, null, false);
     /* Build To/Cc/Bcc links. */
     foreach (array('to', 'cc', 'bcc') as $val) {
         $msgAddresses[] = $mime_headers->getValue($val);
         $addr_val = $imp_ui->buildAddressLinks($envelope->{$val}, null, false);
         if (!empty($addr_val)) {
             $display_headers[$val] = $addr_val;
         }
     }
     /* Check for the presence of mailing list information. */
     $list_info = $imp_ui->getListInformation($mime_headers);
     /* See if the priority has been set. */
     switch ($priority = $injector->getInstance('IMP_Mime_Headers')->getPriority($mime_headers)) {
         case 'high':
         case 'low':
             $basic_headers['priority'] = _("Priority");
             $display_headers['priority'] = Horde_String::ucfirst($priority);
             break;
     }
     /* Set the status information of the message. */
     $status = '';
     $match_identity = $identity = null;
     if (!empty($msgAddresses)) {
         $match_identity = $identity = $user_identity->getMatchingIdentity($msgAddresses);
         if (is_null($identity)) {
             $identity = $user_identity->getDefault();
         }
     }
     $flag_parse = $injector->getInstance('IMP_Flags')->parse(array('flags' => $flags, 'personal' => $match_identity));
     foreach ($flag_parse as $val) {
         if ($abbrev = $val->abbreviation) {
             $status .= $abbrev;
         } elseif ($val instanceof IMP_Flag_User) {
             $status .= ' *' . Horde_String::truncate($val->label, 8) . '*';
         }
     }
     /* Create the body of the message. */
     $inlineout = $imp_contents->getInlineOutput(array('display_mask' => IMP_Contents::RENDER_INLINE, 'no_inline_all' => true));
     $msg_text = $inlineout['msgtext'];
     $this->view->msg = nl2br($injector->getInstance('Horde_Core_Factory_TextFilter')->filter($msg_text, 'space2html'));
     $menu = array();
     if ($this->indices->mailbox->access_deletemsgs) {
         $menu[] = in_array(Horde_Imap_Client::FLAG_DELETED, $flags) ? array(_("Undelete"), $self_link->copy()->add('a', 'u')) : array(_("Delete"), $self_link->copy()->add(array('a' => 'd', 't' => $session->getToken())));
     }
     /* Add compose actions (Reply, Reply List, Reply All, Forward,
      * Redirect, Edit as New). */
     if (IMP_Compose::canCompose()) {
         $clink_ob = new IMP_Compose_Link();
         $clink_ob->args['buid'] = $buid;
         $clink_ob->args['mailbox'] = $this->indices->mailbox;
         $clink = $clink_ob->link()->add(array('identity' => $identity));
         $menu[] = array(_("Reply"), $clink->copy()->add(array('a' => 'r')));
         if ($list_info['reply_list']) {
             $menu[] = array(_("Reply to List"), $clink->copy()->add(array('a' => 'rl')));
         }
         $addr_ob = clone $envelope->to;
         $addr_ob->add($envelope->cc);
         $addr_ob->setIteratorFilter(0, $user_identity->getAllFromAddresses());
         if (count($addr_ob)) {
             $menu[] = array(_("Reply All"), $clink->copy()->add(array('a' => 'ra')));
         }
         $menu[] = array(_("Forward"), $clink->copy()->add(array('a' => 'f')));
         $menu[] = array(_("Redirect"), $clink->copy()->add(array('a' => 'rc')));
         $menu[] = array(_("Edit as New"), $clink->copy()->add(array('a' => 'en')));
     }
     /* Generate previous/next links. */
     if ($prev_msg = $imp_mailbox[$imp_mailbox->getIndex() - 1]) {
         $menu[] = array(_("Previous Message"), self::url(array('buid' => $imp_mailbox->getBuid($prev_msg['m'], $prev_msg['u']), 'mailbox' => $this->indices->mailbox)));
     }
     if ($next_msg = $imp_mailbox[$imp_mailbox->getIndex() + 1]) {
         $menu[] = array(_("Next Message"), self::url(array('buid' => $imp_mailbox->getBuid($next_msg['m'], $next_msg['u']), 'mailbox' => $this->indices->mailbox)));
     }
     $menu[] = array(sprintf(_("To %s"), $this->indices->mailbox->label), $mailbox_link);
     if ($mailbox->spam_show) {
         $menu[] = array(_("Report as Spam"), $self_link->copy()->add(array('a' => 'rs', 't' => $session->getToken())));
     }
     if ($mailbox->innocent_show) {
         $menu[] = array(_("Report as Innocent"), $self_link->copy()->add(array('a' => 'ri', 't' => $session->getToken())));
     }
     $this->view->menu = $this->getMenu('message', $menu);
     $hdrs = array();
     foreach ($display_headers as $head => $val) {
         $tmp = array('label' => $basic_headers[$head]);
         if (Horde_String::lower($head) == 'to' && !isset($this->vars->allto) && ($pos = strpos($val, ',')) !== false) {
             $val = Horde_String::substr($val, 0, $pos);
             $tmp['all_to'] = $self_link->copy()->add('allto', 1);
         }
         $tmp['val'] = $val;
         $hdrs[] = $tmp;
     }
     $this->view->hdrs = $hdrs;
     $atc = array();
     foreach ($inlineout['atc_parts'] as $key) {
         $summary = $imp_contents->getSummary($key, IMP_Contents::SUMMARY_BYTES | IMP_Contents::SUMMARY_SIZE | IMP_Contents::SUMMARY_DESCRIP | IMP_Contents::SUMMARY_DOWNLOAD);
         $tmp = array('descrip' => $summary['description_raw'], 'size' => $summary['size'], 'type' => $summary['type']);
         if (!empty($summary['download'])) {
             /* Preference: if set, only show download confirmation screen
              * if attachment over a certain size. */
             $tmp['download'] = IMP_Minimal_Messagepart::url(array('buid' => $buid, 'mailbox' => $this->indices->mailbox))->add('atc', $key);
         }
         if ($imp_contents->canDisplay($key, IMP_Contents::RENDER_INLINE)) {
             $tmp['view'] = IMP_Minimal_Messagepart::url(array('buid' => $buid, 'mailbox' => $this->indices->mailbox))->add('id', $key);
         }
         $atc[] = $tmp;
     }
     $this->view->atc = $atc;
     $this->title = $display_headers['subject'];
     $this->view->title = ($status ? $status . ' ' : '') . sprintf(_("(Message %d of %d)"), $msgindex, $msgcount);
     $page_output->noDnsPrefetch();
     $this->_pages[] = 'message';
     $this->_pages[] = 'menu';
 }
Пример #7
0
 * IMPORTANT: DO NOT EDIT THIS FILE! DO NOT COPY prefs.php TO prefs.local.php!
 * Local overrides ONLY MUST be placed in prefs.local.php or prefs.d/.
 * If the 'vhosts' setting has been enabled in Horde's configuration, you can
 * use prefs-servername.php.
 */
// *** Personal Information Preferences ***
$prefGroups['identities'] = array('column' => _("General"), 'label' => _("Personal Information"), 'desc' => _("Change the name, address, and signature that people see when they read and reply to your email."), 'members' => array('replyto_addr', 'alias_addr', 'tieto_addr', 'bcc_addr', 'signature', 'sig_dashes', 'signature_html_select', 'save_sent_mail', 'sent_mail_folder', 'sentmailselect'), 'type' => 'identities');
$_prefs['replyto_addr'] = array('value' => '', 'advanced' => true, 'type' => 'text', 'desc' => _("Your Reply-to: address: <em>(optional)</em>"));
$_prefs['alias_addr'] = array('value' => '', 'advanced' => true, 'type' => 'textarea', 'desc' => _("Your alias addresses: <em>(optional, enter each address on a new line)</em>"));
$_prefs['tieto_addr'] = array('value' => '', 'advanced' => true, 'type' => 'textarea', 'desc' => _("Addresses to explicitly tie to this identity: <em>(optional, enter each address on a new line)</em>"));
$_prefs['bcc_addr'] = array('value' => '', 'advanced' => true, 'type' => 'textarea', 'desc' => _("Addresses to BCC all messages: <em>(optional, enter each address on a new line)</em>"));
$_prefs['signature'] = array('value' => '', 'type' => 'textarea', 'desc' => _("Your signature:"));
$_prefs['sig_dashes'] = array('value' => 1, 'type' => 'checkbox', 'desc' => _("Precede your text signature with dashes ('-- ')?"));
// User's HTML signature - UI widget
$_prefs['signature_html_select'] = array('type' => 'special', 'handler' => 'IMP_Prefs_Special_HtmlSignature', 'requires_nolock' => array('signature_html'), 'suppress' => function () {
    return !IMP_Compose::canHtmlCompose();
});
// User's HTML signature
$_prefs['signature_html'] = array('value' => '');
// Show signature on compose screen?
$_prefs['signature_show_compose'] = array('value' => 0, 'type' => 'checkbox', 'desc' => _("Show the signature on the compose screen?"));
$_prefs['save_sent_mail'] = array('value' => 1, 'type' => 'checkbox', 'desc' => _("Save sent mail?"));
// sent mail mailbox
$_prefs['sent_mail_folder'] = array('value' => 'Sent');
// sent mail mailbox selection widget.
$_prefs['sentmailselect'] = array('type' => 'special', 'handler' => 'IMP_Prefs_Special_Sentmail', 'requires_nolock' => array('sent_mail_folder'));
// *** ACL Preferences ***
$prefGroups['acl'] = array('column' => _("General"), 'label' => _("Share Mailboxes"), 'desc' => _("Share your mailboxes with other users."), 'members' => array('aclmanagement'), 'suppress' => function () {
    return !$GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->access(IMP_Imap::ACCESS_ACL);
});
// ACL preference management screen
Пример #8
0
 /**
  * URL Parameters:
  *   - a: (string) The action ID.
  *   - action: (string) The action ID (used on redirect page).
  *   - bcc: (string) BCC address(es).
  *   - bcc_expand_[1-5]: (string) Expand matches for BCC addresses.
  *   - cc: (string) CC address(es).
  *   - cc_expand_[1-5]: (string) Expand matches for BCC addresses.
  *   - composeCache: (string) Compose object cache ID.
  *   - from: (string) From address to use.
  *   - identity: (integer) The identity to use for composing.
  *   - message: (string) Message text.
  *   - subject: (string) Message subject.
  *   - to: (string) To address(es).
  *   - to_expand_[1-5]: (string) Expand matches for To addresses.
  *   - u: (string) Unique ID (cache buster).
  */
 protected function _init()
 {
     global $injector, $notification, $prefs, $registry;
     /* The message text and headers. */
     $expand = array();
     $header = array('to' => '', 'cc' => '', 'bcc' => '');
     $msg = '';
     $this->title = _("Compose Message");
     /* Get the list of headers to display. */
     $display_hdrs = array('to' => _("To: "), 'cc' => _("Cc: "), 'bcc' => "Bcc: ");
     /* Set the current identity. */
     $identity = $injector->getInstance('IMP_Identity');
     if (!$prefs->isLocked('default_identity') && isset($this->vars->identity)) {
         $identity->setDefault($this->vars->identity);
     }
     /* Determine if mailboxes are readonly. */
     $drafts = IMP_Mailbox::getPref(IMP_Mailbox::MBOX_DRAFTS);
     $readonly_drafts = $drafts && $drafts->readonly;
     $sent_mail = $identity->getValue(IMP_Mailbox::MBOX_SENT);
     $save_sent_mail = !$sent_mail || $sent_mail->readonly ? false : $prefs->getValue('save_sent_mail');
     /* Determine if compose mode is disabled. */
     $compose_disable = !IMP_Compose::canCompose();
     /* Initialize objects. */
     $imp_compose = $injector->getInstance('IMP_Factory_Compose')->create($this->vars->composeCache);
     /* Are attachments allowed? */
     $attach_upload = $imp_compose->canUploadAttachment();
     foreach (array_keys($display_hdrs) as $val) {
         $header[$val] = $this->vars->{$val};
         /* If we are reloading the screen, check for expand matches. */
         if ($this->vars->composeCache) {
             $expanded = array();
             for ($i = 0; $i < 5; ++$i) {
                 if ($tmp = $this->vars->get($val . '_expand_' . $i)) {
                     $expanded[] = $tmp;
                 }
             }
             if (!empty($expanded)) {
                 $header['to'] = strlen($header['to']) ? implode(', ', $expanded) . ', ' . $header['to'] : implode(', ', $expanded);
             }
         }
     }
     /* Add attachment. */
     if ($attach_upload && isset($_FILES['upload_1']) && strlen($_FILES['upload_1']['name'])) {
         try {
             $atc_ob = $imp_compose->addAttachmentFromUpload('upload_1');
             if ($atc_ob[0] instanceof IMP_Compose_Exception) {
                 throw $atc_ob[0];
             }
             if ($this->vars->a == _("Expand Names")) {
                 $notification->push(sprintf(_("Added \"%s\" as an attachment."), $atc_ob[0]->getPart()->getName()), 'horde.success');
             }
         } catch (IMP_Compose_Exception $e) {
             $this->vars->a = null;
             $notification->push($e, 'horde.error');
         }
     }
     /* Run through the action handlers. */
     switch ($this->vars->a) {
         // 'd' = draft
         // 'en' = edit as new
         // 't' = template
         case 'd':
         case 'en':
         case 't':
             try {
                 switch ($this->vars->a) {
                     case 'd':
                         $result = $imp_compose->resumeDraft($this->indices, array('format' => 'text'));
                         $this->view->resume = true;
                         break;
                     case 'en':
                         $result = $imp_compose->editAsNew($this->indices, array('format' => 'text'));
                         break;
                     case 't':
                         $result = $imp_compose->useTemplate($this->indices, array('format' => 'text'));
                         break;
                 }
                 $msg = $result['body'];
                 $header = array_merge($header, $this->_convertToHeader($result));
                 if (!is_null($result['identity']) && $result['identity'] != $identity->getDefault() && !$prefs->isLocked('default_identity')) {
                     $identity->setDefault($result['identity']);
                     $sent_mail = $identity->getValue(IMP_Mailbox::MBOX_SENT);
                 }
             } catch (IMP_Compose_Exception $e) {
                 $notification->push($e);
             }
             break;
         case _("Expand Names"):
             foreach (array_keys($display_hdrs) as $val) {
                 if ($val == 'to' || $this->vars->action != 'rc') {
                     $res = $this->_expandAddresses($header[$val]);
                     if (is_string($res)) {
                         $header[$val] = $res;
                     } else {
                         $header[$val] = $res[0];
                         $expand[$val] = array_slice($res, 1);
                     }
                 }
             }
             if (isset($this->vars->action)) {
                 $this->vars->a = $this->vars->action;
             }
             break;
             // 'r' = reply
             // 'rl' = reply to list
             // 'ra' = reply to all
         // 'r' = reply
         // 'rl' = reply to list
         // 'ra' = reply to all
         case 'r':
         case 'ra':
         case 'rl':
             $actions = array('r' => IMP_Compose::REPLY_SENDER, 'ra' => IMP_Compose::REPLY_ALL, 'rl' => IMP_Compose::REPLY_LIST);
             try {
                 $reply_msg = $imp_compose->replyMessage($actions[$this->vars->a], $this->_getContents(), array('format' => 'text', 'to' => $header['to']));
             } catch (IMP_Exception $e) {
                 $notification->push($e, 'horde.error');
                 break;
             }
             $header = $this->_convertToHeader($reply_msg);
             $notification->push(_("Reply text will be automatically appended to your outgoing message."), 'horde.message');
             $this->title = _("Reply");
             break;
             // 'f' = forward
         // 'f' = forward
         case 'f':
             try {
                 $fwd_msg = $imp_compose->forwardMessage(IMP_Compose::FORWARD_ATTACH, $this->_getContents(), false);
             } catch (IMP_Exception $e) {
                 $notification->push($e, 'horde.error');
                 break;
             }
             $header = $this->_convertToHeader($fwd_msg);
             $notification->push(_("Forwarded message will be automatically added to your outgoing message."), 'horde.message');
             $this->title = _("Forward");
             break;
             // 'rc' = redirect compose
         // 'rc' = redirect compose
         case 'rc':
             $imp_compose->redirectMessage($this->indices);
             $this->title = _("Redirect");
             break;
         case _("Redirect"):
             try {
                 $num_msgs = $imp_compose->sendRedirectMessage($header['to']);
                 $imp_compose->destroy('send');
                 $notification->push(ngettext("Message redirected successfully.", "Messages redirected successfully.", count($num_msgs)), 'horde.success');
                 IMP_Minimal_Mailbox::url(array('mailbox' => $this->indices->mailbox))->redirect();
             } catch (Horde_Exception $e) {
                 $this->vars->a = 'rc';
                 $notification->push($e);
             }
             break;
         case _("Save Draft"):
         case _("Send"):
             switch ($this->vars->a) {
                 case _("Save Draft"):
                     if ($readonly_drafts) {
                         break 2;
                     }
                     break;
                 case _("Send"):
                     if ($compose_disable) {
                         break 2;
                     }
                     break;
             }
             $message = strval($this->vars->message);
             $f_to = $header['to'];
             $old_header = $header;
             $header = array();
             switch ($imp_compose->replyType(true)) {
                 case IMP_Compose::REPLY:
                     try {
                         $reply_msg = $imp_compose->replyMessage(IMP_Compose::REPLY_SENDER, $imp_compose->getContentsOb(), array('to' => $f_to));
                         $msg = $reply_msg['body'];
                     } catch (IMP_Exception $e) {
                         $notification->push($e, 'horde.error');
                         $msg = '';
                     }
                     $message .= "\n" . $msg;
                     break;
                 case IMP_Compose::FORWARD:
                     try {
                         $fwd_msg = $imp_compose->forwardMessage(IMP_Compose::FORWARD_ATTACH, $imp_compose->getContentsOb());
                         $msg = $fwd_msg['body'];
                     } catch (IMP_Exception $e) {
                         $notification->push($e, 'horde.error');
                     }
                     $message .= "\n" . $msg;
                     break;
             }
             try {
                 $header['from'] = strval($identity->getFromLine(null, $this->vars->from));
             } catch (Horde_Exception $e) {
                 $header['from'] = '';
             }
             $header['replyto'] = $identity->getValue('replyto_addr');
             $header['subject'] = strval($this->vars->subject);
             foreach (array_keys($display_hdrs) as $val) {
                 $header[$val] = $old_header[$val];
             }
             switch ($this->vars->a) {
                 case _("Save Draft"):
                     try {
                         $notification->push($imp_compose->saveDraft($header, $message), 'horde.success');
                         if ($prefs->getValue('close_draft')) {
                             $imp_compose->destroy('save_draft');
                             IMP_Minimal_Mailbox::url(array('mailbox' => $this->indices->mailbox))->redirect();
                         }
                     } catch (IMP_Compose_Exception $e) {
                         $notification->push($e);
                     }
                     break;
                 case _("Send"):
                     try {
                         $imp_compose->buildAndSendMessage($message, $header, $identity, array('readreceipt' => $prefs->getValue('request_mdn') == 'always', 'save_sent' => $save_sent_mail, 'sent_mail' => $sent_mail));
                         $imp_compose->destroy('send');
                         $notification->push(_("Message sent successfully."), 'horde.success');
                         IMP_Minimal_Mailbox::url(array('mailbox' => $this->indices->mailbox))->redirect();
                     } catch (IMP_Compose_Exception $e) {
                         $notification->push($e);
                         /* Switch to tied identity. */
                         if (!is_null($e->tied_identity)) {
                             $identity->setDefault($e->tied_identity);
                             $notification->push(_("Your identity has been switched to the identity associated with the current recipient address. The identity will not be checked again during this compose action."));
                         }
                     }
                     break;
             }
             break;
         case _("Cancel"):
             $imp_compose->destroy('cancel');
             IMP_Minimal_Mailbox::url(array('mailbox' => $this->indices->mailbox))->redirect();
             exit;
         case _("Discard Draft"):
             $imp_compose->destroy('discard');
             IMP_Minimal_Mailbox::url(array('mailbox' => $this->indices->mailbox))->redirect();
             exit;
     }
     /* Grab any data that we were supplied with. */
     if (empty($msg)) {
         $msg = strval($this->vars->message);
     }
     if (empty($header['subject'])) {
         $header['subject'] = strval($this->vars->subject);
     }
     $this->view->cacheid = $imp_compose->getCacheId();
     $this->view->hmac = $imp_compose->getHmac();
     $this->view->menu = $this->getMenu('compose');
     $this->view->url = self::url();
     $this->view->user = $registry->getAuth();
     switch ($this->vars->a) {
         case 'rc':
             $this->_pages[] = 'redirect';
             $this->_pages[] = 'menu';
             unset($display_hdrs['cc'], $display_hdrs['bcc']);
             break;
         default:
             $this->_pages[] = 'compose';
             $this->_pages[] = 'menu';
             $this->view->compose_enable = !$compose_disable;
             $this->view->msg = $msg;
             $this->view->save_draft = $injector->getInstance('IMP_Factory_Imap')->create()->access(IMP_Imap::ACCESS_DRAFTS) && !$readonly_drafts;
             $this->view->subject = $header['subject'];
             $select_list = $identity->getSelectList();
             $default_identity = $identity->getDefault();
             if ($prefs->isLocked('default_identity')) {
                 $select_list = array($default_identity => $select_list[$default_identity]);
             }
             $tmp = array();
             foreach ($select_list as $key => $val) {
                 $tmp[] = array('key' => $key, 'sel' => $key == $default_identity, 'val' => $val);
             }
             $this->view->identities = $tmp;
             if ($attach_upload) {
                 $this->view->attach = true;
                 if (count($imp_compose)) {
                     $atc_part = $imp_compose[0]->getPart();
                     $this->view->attach_name = $atc_part->getName();
                     $this->view->attach_size = IMP::sizeFormat($atc_part->getBytes());
                     $this->view->attach_type = $atc_part->getType();
                 }
             }
             $this->title = _("Message Composition");
     }
     $hdrs = array();
     foreach ($display_hdrs as $key => $val) {
         $tmp = array('key' => $key, 'label' => $val, 'val' => $header[$key]);
         if (isset($expand[$key])) {
             $tmp['matchlabel'] = count($expand[$key][1]) > 5 ? sprintf(_("Ambiguous matches for \"%s\" (first 5 matches displayed):"), $expand[$key][0]) : sprintf(_("Ambiguous matches for \"%s\":"), $expand[$key][0]);
             $tmp['match'] = array();
             foreach ($expand[$key][1] as $key2 => $val2) {
                 if ($key2 == 5) {
                     break;
                 }
                 $tmp['match'][] = array('id' => $key . '_expand_' . $key2, 'val' => $val2);
             }
         }
         $hdrs[] = $tmp;
     }
     $this->view->hdrs = $hdrs;
     $this->view->title = $this->title;
 }
Пример #9
0
 /**
  * Generates AJAX response task data from the queue.
  *
  * For compose autocomplete address error data (key: 'compose-addr'), an
  * array with keys as the autocomplete DOM element and the values as
  * arrays. The value arrays have keys as the autocomplete address ID, and
  * the value is a space-separated list of classnames to add.
  *
  * For compose attachment data (key: 'compose-atc'), an array of objects
  * with these properties:
  *   - icon: (string) Data url string containing icon information.
  *   - name: (string) The attachment name
  *   - num: (integer) The current attachment number
  *   - size: (string) The size of the attachment
  *   - type: (string) The MIME type of the attachment
  *   - view: (boolean) Link to attachment preivew page
  *
  * For compose cacheid data (key: 'compose'), an object with these
  * properties:
  *   - atclimit: (integer) If set, no further attachments are allowed.
  *   - cacheid: (string) Current cache ID of the compose message.
  *
  * For flag data (key: 'flag'), an array of objects with these properties:
  *   - add: (array) The list of flags that were added.
  *   - buids: (string) Indices of the messages that have changed (IMAP
  *            sequence string; mboxes are base64url encoded).
  *   - remove: (array) The list of flags that were removed.
  *   - replace: (array) Replace the flag list with these flags.
  *
  * For flag configuration data (key: 'flag-config'), an array containing
  * flag data. All flags returned in dynamic mode; only flags labeled below
  * as [sm] are returned in smartmobile mode:
  *   - a: (boolean) Indicates a flag that can be *a*ltered.
  *   - b: (string) Background color [sm].
  *   - c: (string) CSS class.
  *   - f: (string) Foreground color [sm].
  *   - i: (string) CSS icon [sm].
  *   - id: (string) Flag ID (IMAP flag id).
  *   - l: (string) Flag label [sm].
  *   - s: (boolean) Indicates a flag that can be *s*earched for [sm].
  *   - u: (boolean) Indicates a *u*ser flag.
  *
  * For mailbox data (key: 'mailbox'), an array with these keys:
  *   - a: (array) Mailboxes that were added (base64url encoded).
  *   - all: (integer) TODO
  *   - base: (string) TODO
  *   - c: (array) Mailboxes that were changed (base64url encoded).
  *   - d: (array) Mailboxes that were deleted (base64url encoded).
  *   - expand: (integer) Expand subfolders on load.
  *   - switch: (string) Load this mailbox (base64url encoded).
  *
  * For maillog data (key: 'maillog'), an object with these properties:
  *   - buid: (integer) BUID.
  *   - log: (array) List of log entries.
  *   - mbox: (string) Mailbox.
  *
  * For message preview data (key: 'message'), an object with these
  * properties:
  *   - buid: (integer) BUID.
  *   - data: (object) Message viewport data.
  *   - mbox: (string) Mailbox.
  *
  * For poll data (key: 'poll'), an array with keys as base64url encoded
  * mailbox names, values as the number of unseen messages.
  *
  * For quota data (key: 'quota'), an array with these keys:
  *   - m: (string) Quota message.
  *   - p: (integer) Quota percentage.
  *
  * @param IMP_Ajax_Application $ajax  The AJAX object.
  */
 public function add(IMP_Ajax_Application $ajax)
 {
     global $injector;
     /* Add autocomplete address error information. */
     if (!empty($this->_addr)) {
         $ajax->addTask('compose-addr', $this->_addr);
         $this->_addr = array();
     }
     /* Add compose attachment information. */
     if (!empty($this->_atc)) {
         $ajax->addTask('compose-atc', $this->_atc);
         $this->_atc = array();
     }
     /* Add compose information. */
     if (!is_null($this->_compose)) {
         $compose = new stdClass();
         if (!$this->_compose->additionalAttachmentsAllowed()) {
             $compose->atclimit = 1;
         }
         $compose->cacheid = $this->_compose->getCacheId();
         $compose->hmac = $this->_compose->getHmac();
         $ajax->addTask('compose', $compose);
         $this->_compose = null;
     }
     /* Add flag information. */
     if (!empty($this->_flag)) {
         $ajax->addTask('flag', array_unique($this->_flag, SORT_REGULAR));
         $this->_flag = array();
     }
     /* Add flag configuration. */
     switch ($this->_flagconfig) {
         case Horde_Registry::VIEW_DYNAMIC:
         case Horde_Registry::VIEW_SMARTMOBILE:
             $flags = array();
             foreach ($injector->getInstance('IMP_Flags')->getList() as $val) {
                 $tmp = array('b' => $val->bgdefault ? null : $val->bgcolor, 'f' => $val->fgcolor, 'id' => $val->id, 'l' => $val->label, 's' => intval($val instanceof IMP_Flag_Imap));
                 if ($this->_flagconfig === Horde_Registry::VIEW_DYNAMIC) {
                     $tmp += array('a' => $val->canset, 'c' => $val->css, 'i' => $val->css ? null : $val->cssicon, 'u' => intval($val instanceof IMP_Flag_User));
                 }
                 $flags[] = array_filter($tmp);
             }
             $ajax->addTask('flag-config', $flags);
             break;
     }
     /* Add folder tree information. */
     $this->_addFtreeInfo($ajax);
     /* Add maillog information. */
     $this->_addMaillogInfo($ajax);
     /* Add message information. */
     if (!empty($this->_messages)) {
         $ajax->addTask('message', $this->_messages);
         $this->_messages = array();
     }
     /* Add poll information. */
     $poll = $poll_list = array();
     if (!empty($this->_poll)) {
         foreach ($this->_poll as $val) {
             $poll_list[strval($val)] = 1;
         }
     }
     if (count($poll_list)) {
         $imap_ob = $injector->getInstance('IMP_Factory_Imap')->create();
         if ($imap_ob->init) {
             try {
                 foreach ($imap_ob->status(array_keys($poll_list), Horde_Imap_Client::STATUS_UNSEEN) as $key => $val) {
                     $poll[IMP_Mailbox::formTo($key)] = intval($val['unseen']);
                 }
             } catch (Exception $e) {
                 // Ignore errors in status() calls.
             }
         }
         if (!empty($poll)) {
             $ajax->addTask('poll', $poll);
             $this->_poll = array();
         }
     }
     /* Add quota information. */
     if ($this->_quota && ($quotadata = $injector->getInstance('IMP_Quota_Ui')->quota($this->_quota[0], $this->_quota[1]))) {
         $ajax->addTask('quota', array('m' => $quotadata['message'], 'p' => round($quotadata['percent']), 'l' => $quotadata['percent'] >= 90 ? 'alert' : ($quotadata['percent'] >= 75 ? 'warn' : '')));
         $this->_quota = false;
     }
 }
Пример #10
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)));
     }
 }
Пример #11
0
 /**
  * Redirect the message.
  *
  * Variables used: See the list of variables needed for
  * IMP_Ajax_Application#composeSetup().
  *
  * @return object  An object with the following entries:
  *   - action: (string) 'redirectMessage'.
  *   - success: (integer) 1 on success, 0 on failure.
  */
 public function redirectMessage()
 {
     try {
         list($result, $imp_compose, $headers, ) = $this->_base->composeSetup('sendMessage');
         if (!IMP_Compose::canCompose()) {
             $result->success = 0;
             return $result;
         }
         $res = $imp_compose->sendRedirectMessage($headers['redirect_to']);
         foreach ($res as $val) {
             $subject = $val->headers['Subject'];
             $GLOBALS['notification']->push(empty($subject) ? _("Message redirected successfully.") : sprintf(_("Message \"%s\" redirected successfully."), Horde_String::truncate($subject)), 'horde.success');
             $this->_base->queue->maillog(new IMP_Indices($val->mbox, $val->uid));
         }
     } catch (Horde_Exception $e) {
         $GLOBALS['notification']->push($e);
         $result->success = 0;
     }
     return $result;
 }
Пример #12
0
 /**
  * Add compose javascript variables to the page.
  */
 protected function _addComposeVars($base)
 {
     global $browser, $conf, $injector, $prefs, $registry;
     /* Context menu definitions. */
     $base->js_context['ctx_other'] = new stdClass();
     if (!$prefs->isLocked('request_mdn')) {
         $base->js_context['ctx_other']->rr = _("Read Receipt");
     }
     $base->js_context['ctx_atc'] = new stdClass();
     if (IMP_Compose::canUploadAttachment()) {
         if (!$prefs->isLocked('save_attachments') && (!$prefs->isLocked('save_sent_mail') || $prefs->getValue('save_sent_mail'))) {
             $base->js_context['ctx_atc']->save = _("Save Attachments in Sent Mailbox");
         }
         $atcfile = new stdClass();
         $atcfile->delete = _("Delete");
         $base->js_context['ctx_atcfile'] = $atcfile;
     }
     if ($prefs->getValue('use_pgp') && $prefs->getValue('pgp_public_key')) {
         $base->js_context['ctx_atc']->pgppubkey = _("Attach Personal PGP Public Key");
     }
     if ($registry->hasMethod('contacts/ownVCard')) {
         $base->js_context['ctx_atc']->vcard = _("Attach contact information");
     }
     /* Variables used in compose page. */
     $compose_cursor = $prefs->getValue('compose_cursor');
     $templates_mbox = IMP_Mailbox::getPref(IMP_Mailbox::MBOX_TEMPLATES);
     $base->js_conf += array_filter(array('compose_cursor' => $compose_cursor ? $compose_cursor : 'top', 'rte_avail' => intval($browser->hasFeature('rte')), 'spellcheck' => intval($prefs->getValue('compose_spellcheck')), 'templates_mbox' => $templates_mbox ? $templates_mbox->form_to : null));
     if ($injector->getInstance('IMP_Factory_Imap')->create()->access(IMP_Imap::ACCESS_DRAFTS) && ($drafts_mbox = IMP_Mailbox::getPref(IMP_Mailbox::MBOX_DRAFTS)) && !$drafts_mbox->readonly) {
         $base->js_conf += array_filter(array('auto_save_interval_val' => intval($prefs->getValue('auto_save_drafts')), 'close_draft' => intval($prefs->getValue('close_draft')), 'drafts_mbox' => $drafts_mbox->form_to));
     }
     if ($registry->hasMethod('contacts/search')) {
         $base->js_conf['URI_ABOOK'] = strval(IMP_Basic_Contacts::url()->setRaw(true));
         $base->js_conf['ac_delete'] = strval(Horde_Themes::img('delete-small.png'));
         $base->js_conf['ac_minchars'] = intval($conf['compose']['ac_threshold']) ?: 1;
     }
     if ($prefs->getValue('set_priority')) {
         $base->js_conf['priority'] = array(array('l' => _("High"), 'v' => 'high'), array('l' => _("Normal"), 's' => true, 'v' => 'normal'), array('l' => _("Low"), 'v' => 'low'));
     }
     if (!$prefs->isLocked('default_encrypt')) {
         $encrypt = array();
         foreach ($injector->getInstance('IMP_Compose_Ui')->encryptList(null, true) as $key => $val) {
             $encrypt[] = array('l' => htmlspecialchars($val), 'v' => $key);
         }
         if (!empty($encrypt)) {
             $base->js_conf['encrypt'] = $encrypt;
         }
     }
     /* Gettext strings used in compose page. */
     $base->js_text += array('change_identity' => _("You have edited your signature. Change the identity and lose your changes?"), 'compose_cancel' => _("Cancelling this message will permanently discard its contents and will delete auto-saved drafts.\nAre you sure you want to do this?"), 'compose_close' => _("Compose action completed. You may now safely close this window."), 'dragdropimg_error' => _("Could not add %d file(s) to message: only images are supported."), 'max_atc_size' => _("Your attachment(s) are too large and cannot be uploaded."), 'max_atc_num' => _("You have reached the limit for the number of attachments in this message."), 'nosubject' => _("The message does not have a subject entered.") . "\n" . _("Send message without a subject?"), 'paste_error' => _("Could not paste image as the clipboard data is invalid."), 'replyall' => _("%d recipients"), 'spell_noerror' => _("No spelling errors found."), 'toggle_html' => _("Discard all text formatting information (by converting from HTML to plain text)? This conversion cannot be reversed."), 'uploading' => _("Uploading..."));
 }
Пример #13
0
 /**
  * URL parameters:
  *   - bcc: BCC addresses.
  *   - bcc_json: JSON encoded addresses to send to. Overwrites 'bcc'.
  *   - body: Message body text.
  *   - cc: CC addresses.
  *   - cc_json: JSON encoded addresses to send to. Overwrites 'cc'.
  *   - identity: Force message to use this identity by default.
  *   - popup_link: Compose window generated via a popup link.
  *   - subject: Subject to use.
  *   - type: redirect, reply, reply_auto, reply_all, reply_list,
  *           forward_attach, forward_auto, forward_body, forward_both,
  *           forward_redirect, resume, new, new_to, editasnew, template,
  *           template_edit, template_new
  *   - to: Addresses to send to.
  *   - to_json: JSON encoded addresses to send to. Overwrites 'to'.
  */
 protected function _init()
 {
     global $injector, $notification, $page_output, $prefs;
     $alist = $injector->getInstance('IMP_Dynamic_AddressList');
     $clink = new IMP_Compose_Link($this->vars);
     $addr = array();
     foreach (array('to', 'cc', 'bcc') as $val) {
         $var_name = $val . '_json';
         if (isset($this->vars->{$var_name})) {
             /* Check for JSON encoded information. */
             $addr[$val] = $alist->parseAddressList($this->vars->{$var_name});
         } elseif (isset($clink->args[$val])) {
             /* Non-JSON encoded address information. */
             $addr[$val] = IMP::parseAddressList($clink->args[$val]);
         }
     }
     $subject = isset($clink->args['subject']) ? $clink->args['subject'] : null;
     $identity = $injector->getInstance('IMP_Identity');
     if (!$prefs->isLocked('default_identity') && isset($this->vars->identity)) {
         $identity->setDefault($this->vars->identity);
     }
     /* Init objects. */
     $imp_compose = $injector->getInstance('IMP_Factory_Compose')->create();
     $compose_ajax = new IMP_Ajax_Application_Compose($imp_compose, $this->vars->type);
     $ajax_queue = $injector->getInstance('IMP_Ajax_Queue');
     $ajax_queue->compose($imp_compose);
     $compose_opts = array('title' => _("New Message"));
     switch ($this->vars->type) {
         case 'reply':
         case 'reply_all':
         case 'reply_auto':
         case 'reply_list':
             try {
                 $result = $imp_compose->replyMessage($compose_ajax->reply_map[$this->vars->type], $this->_getContents(), array('to' => isset($addr['to']) ? $addr['to'] : null));
             } catch (IMP_Exception $e) {
                 $notification->push($e, 'horde.error');
                 break;
             }
             $onload = $compose_ajax->getResponse($result);
             switch ($result['type']) {
                 case IMP_Compose::REPLY_SENDER:
                     $compose_opts['title'] = _("Reply");
                     break;
                 case IMP_Compose::REPLY_ALL:
                     $compose_opts['title'] = _("Reply to All");
                     break;
                 case IMP_Compose::REPLY_LIST:
                     $compose_opts['title'] = _("Reply to List");
                     break;
             }
             $compose_opts['title'] .= ': ' . $result['subject'];
             break;
         case 'forward_attach':
         case 'forward_auto':
         case 'forward_body':
         case 'forward_both':
             try {
                 if (count($this->indices) > 1) {
                     if (!in_array($this->vars->type, array('forward_attach', 'forward_auto'))) {
                         $notification->push(_("Multiple messages can only be forwarded as attachments."), 'horde.warning');
                     }
                     $result = $imp_compose->forwardMultipleMessages($this->indices);
                 } else {
                     $result = $imp_compose->forwardMessage($compose_ajax->forward_map[$this->vars->type], $this->_getContents());
                 }
             } catch (IMP_Exception $e) {
                 $notification->push($e, 'horde.error');
                 break;
             }
             $onload = $compose_ajax->getResponse($result);
             $compose_opts['title'] = $result['title'];
             $ajax_queue->attachment($imp_compose, IMP_Compose::FORWARD_ATTACH);
             break;
         case 'forward_redirect':
             try {
                 $imp_compose->redirectMessage($this->indices);
                 $compose_opts['title'] = _("Redirect");
             } catch (IMP_Compose_Exception $e) {
                 $notification->push($e, 'horde.error');
             }
             // Not used in JS
             $onload = new stdClass();
             break;
         case 'editasnew':
         case 'resume':
         case 'template':
         case 'template_edit':
             try {
                 switch ($this->vars->type) {
                     case 'editasnew':
                         $result = $imp_compose->editAsNew($this->indices);
                         break;
                     case 'resume':
                         $result = $imp_compose->resumeDraft($this->indices);
                         $compose_opts['resume'] = true;
                         break;
                     case 'template':
                         $result = $imp_compose->useTemplate($this->indices);
                         break;
                     case 'template_edit':
                         $result = $imp_compose->editTemplate($this->indices);
                         $compose_opts['template'] = true;
                         break;
                 }
                 $onload = $compose_ajax->getResponse($result);
                 $ajax_queue->attachment($imp_compose, $result['type']);
                 $show_editor = $result['format'] == 'html';
             } catch (IMP_Compose_Exception $e) {
                 $notification->push($e);
             }
             break;
         case 'new_to':
             $h = $this->_getContents()->getHeader();
             $f = $h['reply-to'] ?: $h['from'];
             $addr['to'] = $f->getAddressList(true);
             // Fall-through
         // Fall-through
         case 'new':
         case 'template_new':
         default:
             $show_editor = $prefs->getValue('compose_html') && IMP_Compose::canHtmlCompose();
             $onload = $compose_ajax->getBaseResponse();
             $onload->body = isset($clink->args['body']) ? strval($clink->args['body']) : '';
             if ($show_editor) {
                 $onload->format = 'html';
             }
             if ($this->vars->type == 'template_new') {
                 $compose_opts['template'] = true;
             }
             break;
     }
     $compose_opts['redirect'] = $this->vars->type == 'forward_redirect';
     if (isset($onload->addr) || !empty($addr)) {
         foreach (array('to', 'cc', 'bcc') as $val) {
             if (!isset($onload->addr[$val])) {
                 $onload->addr[$val] = array();
             }
             if (isset($addr[$val])) {
                 $tmp = new IMP_Ajax_Addresses($addr[$val]);
                 $onload->addr[$val] = array_merge($onload->addr[$val], $tmp->toAutocompleteArray());
             }
         }
     }
     if (!is_null($subject)) {
         $onload->subject = $subject;
     }
     $this->title = $compose_opts['title'];
     $this->view->compose = $injector->getInstance('IMP_Dynamic_Compose_Common')->compose($this, $compose_opts);
     $page_output->addInlineJsVars(array('ImpCompose.popup_link' => intval($this->vars->popup_link), 'ImpCompose.onload_show' => $onload, 'ImpCompose.tasks' => $injector->getInstance('Horde_Core_Factory_Ajax')->create('imp', $this->vars)->getTasks()));
     Horde::startBuffer();
     $notification->notify(array('listeners' => array('status', 'audio')));
     $this->view->status = Horde::endBuffer();
     $this->_pages[] = 'compose-base';
 }
Пример #14
0
 /**
  * AJAX action: Send a message.
  *
  * See the list of variables needed for
  * IMP_Ajax_Application#composeSetup(). Additional variables used:
  *   - addr_ac: (string) TODO
  *   - encrypt: (integer) The encryption method to use (IMP ENCRYPT
  *              constants).
  *   - html: (integer) In HTML compose mode?
  *   - message: (string) The message text.
  *   - pgp_attach_pubkey: (boolean) True if PGP public key should be
  *                        attached to the message.
  *   - priority: (string) The priority of the message.
  *   - request_read_receipt: (boolean) Add request read receipt header?
  *   - save_attachments_select: (boolean) Whether to save attachments.
  *   - save_sent_mail: (boolean) True if saving sent mail.
  *   - save_sent_mail_mbox: (string) base64url encoded version of sent
  *                          mail mailbox to use.
  *   - vcard_attach: (boolean) Attach user's vCard to the message?
  *
  * @return object  An object with the following entries:
  *   - action: (string) The AJAX action string
  *   - draft_delete: (integer) If set, remove auto-saved drafts.
  *   - encryptjs: (array) Javascript to run after encryption failure.
  *   - flag: (array) See IMP_Ajax_Queue::add().
  *   - identity: (integer) If set, this is the identity that is tied to
  *               the current recipient address.
  *   - success: (integer) 1 on success, 0 on failure.
  */
 public function sendMessage()
 {
     global $injector, $notification, $page_output, $prefs;
     try {
         list($result, $imp_compose, $headers, $identity) = $this->_base->composeSetup('sendMessage');
         if (!IMP_Compose::canCompose()) {
             $result->success = 0;
             return $result;
         }
     } catch (Horde_Exception $e) {
         $notification->push($e);
         $result = new stdClass();
         $result->action = 'sendMessage';
         $result->success = 0;
         return $result;
     }
     $headers['replyto'] = $identity->getValue('replyto_addr');
     $sm_displayed = !$prefs->isLocked(IMP_Mailbox::MBOX_SENT);
     try {
         $imp_compose->buildAndSendMessage($this->vars->message, $headers, $identity, array('encrypt' => $prefs->isLocked('default_encrypt') ? $prefs->getValue('default_encrypt') : $this->vars->encrypt, 'html' => $this->vars->html, 'pgp_attach_pubkey' => $this->vars->pgp_attach_pubkey, 'priority' => $this->vars->priority, 'readreceipt' => $this->vars->request_read_receipt, 'save_sent' => $sm_displayed ? (bool) $this->vars->save_sent_mail : $identity->getValue('save_sent_mail'), 'sent_mail' => $sm_displayed ? isset($this->vars->save_sent_mail_mbox) ? IMP_Mailbox::formFrom($this->vars->save_sent_mail_mbox) : $identity->getValue(IMP_Mailbox::MBOX_SENT) : $identity->getValue(IMP_Mailbox::MBOX_SENT), 'signature' => $this->vars->signature, 'strip_attachments' => isset($this->vars->save_attachments_select) && !$this->vars->save_attachments_select, 'vcard_attach' => $this->vars->vcard_attach ? $identity->getValue('fullname') : null));
         $notification->push(empty($headers['subject']) ? _("Message sent successfully.") : sprintf(_("Message \"%s\" sent successfully."), Horde_String::truncate($headers['subject'])), 'horde.success');
     } catch (IMP_Compose_Exception_Address $e) {
         $this->_handleBadComposeAddr($e);
         $result->success = 0;
         return $result;
     } catch (IMP_Compose_Exception $e) {
         $result->success = 0;
         if (is_null($e->tied_identity)) {
             $notify_level = 'horde.error';
         } else {
             $result->identity = $e->tied_identity;
             $notify_level = 'horde.warning';
         }
         if ($e->encrypt) {
             $imp_ui = $injector->getInstance('IMP_Compose_Ui');
             switch ($e->encrypt) {
                 case 'pgp_symmetric_passphrase_dialog':
                     $imp_ui->passphraseDialog('pgp_symm', $imp_compose->getCacheId());
                     break;
                 case 'pgp_passphrase_dialog':
                     $imp_ui->passphraseDialog('pgp');
                     break;
                 case 'smime_passphrase_dialog':
                     $imp_ui->passphraseDialog('smime');
                     break;
             }
             Horde::startBuffer();
             $page_output->outputInlineScript(true);
             if ($js_inline = Horde::endBuffer()) {
                 $result->encryptjs = array($js_inline);
             }
         } else {
             /* Don't push notification if showing passphrase dialog -
              * passphrase dialog contains the necessary information. */
             $notification->push($e);
         }
         return $result;
     }
     /* Remove any auto-saved drafts. */
     if ($imp_compose->hasDrafts()) {
         $result->draft_delete = 1;
     }
     if ($indices = $imp_compose->getMetadata('indices')) {
         /* Update maillog information. */
         $this->_base->queue->maillog($indices);
     }
     $imp_compose->destroy('send');
     return $result;
 }
Пример #15
0
 /**
  * Convert compose data to/from text/HTML.
  *
  * @param string $data  The message text.
  * @param string $to    Either 'text' or 'html'.
  *
  * @return string  The converted text.
  */
 public function convertComposeText($data, $to)
 {
     switch ($to) {
         case 'html':
             return IMP_Compose::text2html($data);
         case 'text':
             return $GLOBALS['injector']->getInstance('Horde_Core_Factory_TextFilter')->filter($data, 'Html2text', array('wrap' => false));
     }
 }
Пример #16
0
 /**
  * Add base javascript variables to the page.
  */
 protected function _addBaseVars()
 {
     global $prefs, $registry;
     /* Variables used in core javascript files. */
     $this->js_conf = array_filter(array('URI_COMPOSE' => strval(IMP_Dynamic_Compose::url()->setRaw(true)), 'URI_MAILLOG' => strval(IMP_Dynamic_Maillog::url()->setRaw(true)), 'URI_VIEW' => strval(Horde::url('view.php')->add(IMP_Contents_View::addToken())), 'disable_compose' => !IMP_Compose::canCompose(), 'pref_prefix' => hash(version_compare(PHP_VERSION, '5.4', '>=') ? 'fnv132' : 'sha1', $registry->getAuth() . '|' . $_SERVER['SERVER_NAME'])));
     /* Context menu definitions.
      * Keys:
      *   - Begin with '_mbox': A mailbox name container entry
      *   - Begin with '_sep': A separator
      *   - Begin with '_sub': All subitems wrapped in a DIV
      *   - Begin with a '*': No icon
      */
     $context = array('ctx_contacts' => array('_sub1' => new stdClass(), 'new' => _("New Message"), 'add' => _("Add to Address Book"), 'copy' => _("Copy to Clipboard")), 'ctx_reply' => array('reply' => _("To Sender"), 'reply_all' => _("To All"), 'reply_list' => _("To List")));
     if ($registry->hasLink('mail/newEmailFilter')) {
         $context['ctx_contacts']['addfilter'] = _("Create Filter");
     }
     /* Forward context menu. */
     $context['ctx_forward'] = array('attach' => _("As Attachment"), 'body' => _("In Body Text"), 'both' => _("Attachment and Body Text"), '_sep1' => null, 'editasnew' => _("Edit as New"), '_sep2' => null, 'redirect' => _("Redirect"));
     if ($prefs->isLocked('forward_default')) {
         unset($context['ctx_forward']['attach'], $context['ctx_forward']['body'], $context['ctx_forward']['both'], $context['ctx_forward']['_sep1']);
     }
     $this->js_context = $context;
     /* Gettext strings used in core javascript files. */
     $this->js_text = array('emailcopy' => _("Your browser security settings don't permit direct access to the clipboard.") . "\n" . _("You need to either use the keyboard (Ctrl/Cmd + C) or right click on the selected address to access the Copy command."), 'resent' => _("Resent on %s by:"), 'strip_warn' => _("Are you sure you wish to PERMANENTLY delete this attachment?"), 'verify' => _("Verifying..."));
 }
Пример #17
0
 /**
  * Add base javascript variables to the page.
  */
 protected function _addBaseVars()
 {
     global $injector, $page_output, $prefs;
     $imp_imap = $injector->getInstance('IMP_Factory_Imap')->create();
     $code = array('conf' => array_filter(array('allow_folders' => $imp_imap->access(IMP_Imap::ACCESS_FOLDERS), 'disable_compose' => !IMP_Compose::canCompose(), 'flags' => array('deleted' => '\\deleted', 'draft' => '\\draft', 'seen' => '\\seen'), 'mailbox_return' => $prefs->getValue('mailbox_return'), 'qsearchid' => IMP_Mailbox::formTo(IMP_Search::MBOX_PREFIX . IMP_Search::DIMP_QUICKSEARCH), 'refresh_time' => intval($prefs->getValue('refresh_time')))), 'text' => array('exitsearch' => _("Exit Search"), 'folders' => _("Folders"), 'message_0' => _("No messages"), 'message_1' => _("1 message"), 'message_2' => _("%d messages"), 'more_msgs' => _("Load More Messages..."), 'move_nombox' => _("Must enter a non-empty name for the new destination mailbox."), 'new_message' => _("New Message"), 'nofrom' => _("Invalid Address"), 'nosubject' => _("The message does not have a Subject entered.") . "\n" . _("Send message without a Subject?"), 'searchresults' => _("Search Results"), 'subject' => _("Subject")));
     $page_output->addInlineJsVars(array('var IMP' => $code), array('top' => true));
 }
Пример #18
0
 /**
  */
 protected function _init()
 {
     global $conf, $injector, $notification, $page_output, $prefs, $registry, $session;
     $mailbox = $this->indices->mailbox;
     $imp_imap = $mailbox->imp_imap;
     /* 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. */
     $imp_imap->openMailbox($mailbox, Horde_Imap_Client::OPEN_READWRITE);
     /* Make sure we have a valid index. */
     $imp_mailbox = $mailbox->list_ob;
     $imp_mailbox->setIndex($this->indices);
     if (!$imp_mailbox->isValidIndex()) {
         $this->_returnToMailbox(null, 'message_missing');
         return;
     }
     $imp_flags = $injector->getInstance('IMP_Flags');
     $imp_identity = $injector->getInstance('IMP_Identity');
     $imp_message = $injector->getInstance('IMP_Message');
     $imp_ui = $injector->getInstance('IMP_Message_Ui');
     /* Run through action handlers. */
     if ($this->vars->actionID) {
         try {
             $session->getToken($this->vars->token);
         } catch (Horde_Exception $e) {
             $notification->push($e);
             $this->vars->actionID = null;
         }
     }
     $readonly = $mailbox->readonly;
     $peek = false;
     switch ($this->vars->actionID) {
         case 'blacklist':
         case 'whitelist':
             if ($this->vars->actionID == 'blacklist') {
                 $injector->getInstance('IMP_Filter')->blacklistMessage($this->indices);
             } else {
                 $injector->getInstance('IMP_Filter')->whitelistMessage($this->indices);
             }
             break;
         case 'delete_message':
             $imp_message->delete($this->indices, array('mailboxob' => $imp_mailbox));
             if ($prefs->getValue('mailbox_return')) {
                 $this->_returnToMailbox($imp_mailbox->getIndex());
                 return;
             }
             if ($imp_ui->moveAfterAction($mailbox)) {
                 $imp_mailbox->setIndex(1);
             }
             break;
         case 'undelete_message':
             $imp_message->undelete($this->indices);
             break;
         case 'move_message':
         case 'copy_message':
             if (isset($this->vars->targetMbox) && (!$readonly || $this->vars->actionID == 'copy_message')) {
                 if ($this->vars->newMbox) {
                     $targetMbox = IMP_Mailbox::prefFrom($this->vars->targetMbox);
                     $newMbox = true;
                 } else {
                     $targetMbox = IMP_Mailbox::formFrom($this->vars->targetMbox);
                     $newMbox = false;
                 }
                 $imp_message->copy($targetMbox, $this->vars->actionID == 'move_message' ? 'move' : 'copy', $this->indices, array('create' => $newMbox, 'mailboxob' => $imp_mailbox));
                 if ($prefs->getValue('mailbox_return')) {
                     $this->_returnToMailbox($imp_mailbox->getIndex());
                     return;
                 }
             }
             break;
         case 'innocent_report':
         case 'spam_report':
             $res = $injector->getInstance('IMP_Factory_Spam')->create($this->vars->actionID == 'spam_report' ? IMP_Spam::SPAM : IMP_Spam::INNOCENT)->report($this->indices, array('mailbox' => $imp_mailbox));
             switch ($res) {
                 case 1:
                     if ($imp_ui->moveAfterAction($mailbox)) {
                         $imp_mailbox->setIndex(1);
                     }
                     break;
             }
             if ($prefs->getValue('mailbox_return')) {
                 $this->_returnToMailbox($imp_mailbox->getIndex());
                 return;
             }
             break;
         case 'flag_message':
             if (!$readonly && isset($this->vars->flag) && count($this->indices)) {
                 $peek = true;
                 $flag = $imp_flags->parseFormId($this->vars->flag);
                 $imp_message->flag(array($flag['set'] ? 'add' : 'remove' => array($flag['flag'])), $this->indices);
                 if ($prefs->getValue('mailbox_return')) {
                     $this->_returnToMailbox($imp_mailbox->getIndex());
                     return;
                 }
             }
             break;
         case 'add_address':
             try {
                 $contact_link = $injector->getInstance('IMP_Contacts')->addAddress($this->vars->address, $this->vars->name);
                 $notification->push(sprintf(_("Entry \"%s\" was successfully added to the address book"), $contact_link), 'horde.success', array('content.raw'));
             } catch (Horde_Exception $e) {
                 $notification->push($e);
             }
             break;
         case 'strip_all':
         case 'strip_attachment':
             if (!$readonly) {
                 try {
                     $this->indices = new IMP_Indices_Mailbox($this->indices->mailbox, $imp_message->stripPart($this->indices, $this->vars->actionID == 'strip_all' ? null : $this->vars->imapid, array('mailboxob' => $imp_mailbox)));
                     $notification->push(_("Attachment successfully stripped."), 'horde.success');
                 } catch (Horde_Exception $e) {
                     $notification->push($e);
                 }
             }
             break;
     }
     /* We may have done processing that has taken us past the end of the
      * message array, so we will return to the mailbox. */
     if (!$imp_mailbox->isValidIndex()) {
         $this->_returnToMailbox(count($imp_mailbox));
         return;
     }
     /* Now that we are done processing, get the index and array index of
      * the current message. */
     $msg_index = $imp_mailbox[$imp_mailbox->getIndex()];
     /* Parse the message. */
     try {
         $imp_contents = $injector->getInstance('IMP_Factory_Contents')->create(new IMP_Indices($imp_mailbox));
     } catch (IMP_Exception $e) {
         $imp_mailbox->removeMsgs(true);
         $this->_returnToMailbox(null, 'message_missing');
         return;
     }
     /* Get envelope/flag/header information. */
     try {
         /* Need to fetch flags before HEADERTEXT, because SEEN flag might
          * be set before we can grab it. */
         $query = new Horde_Imap_Client_Fetch_Query();
         $query->flags();
         $flags_ret = $imp_imap->fetch($msg_index['m'], $query, array('ids' => $imp_imap->getIdsOb($msg_index['u'])));
         $query = new Horde_Imap_Client_Fetch_Query();
         $query->envelope();
         $fetch_ret = $imp_imap->fetch($msg_index['m'], $query, array('ids' => $imp_imap->getIdsOb($msg_index['u'])));
     } catch (IMP_Imap_Exception $e) {
         $this->_returnToMailbox(null, 'message_missing');
         return;
     }
     $envelope = $fetch_ret->first()->getEnvelope();
     $flags = $flags_ret->first()->getFlags();
     $mime_headers = $peek ? $imp_contents->getHeader() : $imp_contents->getHeaderAndMarkAsSeen();
     /* Get the title/mailbox label of the mailbox page. */
     $page_label = $mailbox->label;
     /* Generate the link to ourselves. */
     $buid = $imp_mailbox->getBuid($msg_index['m'], $msg_index['u']);
     $msgindex = $imp_mailbox->getIndex();
     $message_url = Horde::url('basic.php')->add('page', 'message');
     $token = $session->getToken();
     $self_link = self::url(array('buid' => $buid, 'mailbox' => $mailbox))->add(array('token' => $token, 'start' => $msgindex));
     /* Develop the list of headers to display. */
     $basic_headers = $imp_ui->basicHeaders();
     $display_headers = $msgAddresses = array();
     $date_ob = new IMP_Message_Date($envelope->date);
     if ($format_date = $date_ob->format($date_ob::DATE_LOCAL)) {
         $display_headers['date'] = $format_date;
     }
     /* Build From address links. */
     $display_headers['from'] = $imp_ui->buildAddressLinks($envelope->from, $self_link);
     /* Add country/flag image. */
     if (!empty($envelope->from)) {
         $contacts_img = new IMP_Contacts_Image($envelope->from[0]);
         try {
             $res = $contacts_img->getImage($contacts_img::FLAG);
             $display_headers['from'] .= '&nbsp;' . Horde_Themes_Image::tag($res['url'], array('alt' => $res['desc'], 'fullsrc' => true));
         } catch (IMP_Exception $e) {
         }
     }
     /* Look for Face information. */
     if ($face = $mime_headers->getValue('face')) {
         $display_headers['from'] .= '&nbsp;<img src="' . Horde_Url_Data::create('image/png', base64_decode($face)) . '">';
     }
     /* Build To/Cc/Bcc links. */
     foreach (array('to', 'cc', 'bcc') as $val) {
         $msgAddresses[] = $mime_headers->getValue($val);
         if ($val == 'to' || count($envelope->{$val})) {
             $display_headers[$val] = $imp_ui->buildAddressLinks($envelope->{$val}, $self_link);
         }
     }
     /* Process the subject now. */
     if ($subject = $mime_headers->getValue('subject')) {
         $this->title = sprintf(_("%s: %s"), $page_label, $subject);
         $shortsub = Horde_String::truncate($subject, 100);
     } else {
         $shortsub = _("[No Subject]");
         $this->title = sprintf(_("%s: %s"), $page_label, $shortsub);
     }
     /* See if the priority has been set. */
     switch ($injector->getInstance('IMP_Mime_Headers')->getPriority($mime_headers)) {
         case 'high':
             $basic_headers['priority'] = _("Priority");
             $display_headers['priority'] = '<div class="iconImg msgflags flagHighpriority" title="' . htmlspecialchars(_("High Priority")) . '"></div>&nbsp;' . _("High");
             break;
         case 'low':
             $basic_headers['priority'] = _("Priority");
             $display_headers['priority'] = '<div class="iconImg msgflags flagLowpriority" title="' . htmlspecialchars(_("Low Priority")) . '"></div>&nbsp;' . _("Low");
             break;
     }
     /* Build Reply-To address link. */
     if (!empty($envelope->reply_to) && $envelope->from[0]->bare_address != $envelope->reply_to[0]->bare_address && ($reply_to = $imp_ui->buildAddressLinks($envelope->reply_to, $self_link))) {
         $display_headers['reply-to'] = $reply_to;
     }
     /* Determine if all/list/user-requested headers needed. */
     $all_headers = $this->vars->show_all_headers;
     $user_hdrs = $imp_ui->getUserHeaders();
     /* Check for the presence of mailing list information. */
     $list_info = $imp_ui->getListInformation($mime_headers);
     /* Display all headers or, optionally, the user-specified headers for
      * the current identity. */
     $full_headers = array();
     if ($all_headers) {
         $header_array = $mime_headers->toArray();
         foreach ($header_array as $head => $val) {
             $lc_head = strtolower($head);
             /* Skip the header if we have already dealt with it. */
             if (!isset($display_headers[$lc_head]) && (!in_array($lc_head, array('importance', 'x-priority')) || !isset($display_headers['priority']))) {
                 $full_headers[$lc_head] = $val;
             }
         }
     } elseif (!empty($user_hdrs)) {
         foreach ($user_hdrs as $user_hdr) {
             $user_val = $mime_headers->getValue($user_hdr);
             if (!empty($user_val)) {
                 $full_headers[$user_hdr] = $user_val;
             }
         }
     }
     ksort($full_headers);
     /* For the self URL link, we can't trust the index in the query string
      * as it may have changed if we deleted/copied/moved messages. We may
      * need other stuff in the query string, so we need to do an
      * add/remove of uid info. */
     $selfURL = $mailbox->url(Horde::selfUrlParams()->remove(array('actionID')), $buid)->add('token', $token);
     $headersURL = $selfURL->copy()->remove(array('show_all_headers'));
     /* Generate previous/next links. */
     $prev_msg = $imp_mailbox[$imp_mailbox->getIndex() - 1];
     if ($prev_msg) {
         $prev_url = self::url(array('buid' => $imp_mailbox->getBuid($prev_msg['m'], $prev_msg['u']), 'mailbox' => $mailbox))->setRaw(true);
         $page_output->addLinkTag(array('href' => $prev_url, 'id' => 'prev', 'rel' => 'Previous', 'type' => null));
     } else {
         $prev_url = null;
     }
     $next_msg = $imp_mailbox[$imp_mailbox->getIndex() + 1];
     if ($next_msg) {
         $next_url = self::url(array('buid' => $imp_mailbox->getBuid($next_msg['m'], $next_msg['u']), 'mailbox' => $mailbox))->setRaw(true);
         $page_output->addLinkTag(array('href' => $next_url, 'id' => 'next', 'rel' => 'Next', 'type' => null));
     } else {
         $next_url = null;
     }
     /* Generate the mailbox link. */
     $mailbox_url = $mailbox->url('mailbox')->add('start', $msgindex);
     /* Everything below here is related to preparing the output. */
     $js_vars = array('ImpMessage.text' => array('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", 'spam_report' => _("Are you sure you wish to report this message as spam?"), 'target_mbox' => _("You must select a target mailbox first.")));
     /* Set the status information of the message. */
     $msgAddresses[] = $mime_headers->getValue('from');
     $identity = $match_identity = $imp_identity->getMatchingIdentity($msgAddresses);
     if (is_null($identity)) {
         $identity = $imp_identity->getDefault();
     }
     $flag_parse = $imp_flags->parse(array('flags' => $flags, 'personal' => $match_identity));
     $status = '';
     foreach ($flag_parse as $val) {
         if ($val instanceof IMP_Flag_User) {
             $status .= '<span class="' . $val->css . '" style="' . ($val->bgdefault ? '' : 'background:' . htmlspecialchars($val->bgcolor) . ';') . 'color:' . htmlspecialchars($val->fgcolor) . '">' . htmlspecialchars($val->label) . '</span>';
         } else {
             $status .= $val->span;
         }
     }
     /* If this is a search mailbox, display a link to the parent mailbox
      * of the message in the header. */
     $h_page_label = htmlspecialchars($page_label);
     $header_label = $h_page_label;
     if ($mailbox->search) {
         $header_label .= ' [' . $msg_index['m']->url('mailbox')->link() . $msg_index['m']->display_html . '</a>]';
     }
     /* Prepare the navbar top template. */
     $view = new Horde_View(array('templatePath' => IMP_TEMPLATES . '/basic/message'));
     $view->addHelper('FormTag');
     $view->addHelper('Tag');
     $t_view = clone $view;
     $t_view->buid = $buid;
     $t_view->message_url = $message_url;
     $t_view->mailbox = $mailbox->form_to;
     $t_view->start = $msgindex;
     $t_view->token = $token;
     /* Prepare the navbar navigate template. */
     $n_view = clone $view;
     $n_view->readonly = $readonly;
     $n_view->id = 1;
     if ($mailbox->access_flags) {
         $n_view->mailbox = $mailbox->form_to;
         $args = array('imap' => true, 'mailbox' => $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);
                 $form_unset[] = array('f' => $val->form_unset, 'l' => $val->label);
             }
         }
         $n_view->flaglist_set = $form_set;
         $n_view->flaglist_unset = $form_unset;
     }
     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));
         $iterator = new IMP_Ftree_IteratorFilter($injector->getInstance('IMP_Ftree'));
         $iterator->add($iterator::NONIMAP);
         $n_view->options = new IMP_Ftree_Select(array('heading' => _("This message to"), 'inc_tasklists' => true, 'inc_notepads' => true, 'iterator' => $iterator, 'new_mbox' => true));
     }
     $n_view->back_to = Horde::widget(array('url' => $mailbox_url, 'title' => sprintf(_("Bac_k to %s"), $h_page_label), 'nocheck' => true));
     if ($prev_url) {
         $n_view->prev = Horde::link($prev_url, _("Previous Message"));
         $n_view->prev_img = 'navleftImg';
     } else {
         $n_view->prev_img = 'navleftgreyImg';
     }
     if ($next_url) {
         $n_view->next = Horde::link($next_url, _("Next Message"));
         $n_view->next_img = 'navrightImg';
     } else {
         $n_view->next_img = 'navrightgreyImg';
     }
     /* Prepare the navbar actions template. */
     $a_view = clone $view;
     $compose_params = array('buid' => $buid, 'identity' => $identity, 'mailbox' => IMP_Mailbox::formTo($mailbox));
     if (!$prefs->getValue('compose_popup')) {
         $compose_params['start'] = $msgindex;
     }
     if ($msg_index['m']->access_deletemsgs) {
         if (in_array(Horde_Imap_Client::FLAG_DELETED, $flags)) {
             $a_view->delete = Horde::widget(array('url' => $self_link->copy()->add('actionID', 'undelete_message'), 'title' => _("Undelete"), 'nocheck' => true));
         } else {
             $a_view->delete = Horde::widget(array('url' => $self_link->copy()->add('actionID', 'delete_message'), 'title' => _("_Delete"), 'nocheck' => true));
             if (!$msg_index['m']->is_imap) {
                 $js_vars['ImpMessage.pop3delete'] = _("Are you sure you want to PERMANENTLY delete these messages?");
             }
         }
     }
     $disable_compose = !IMP_Compose::canCompose();
     if (!$disable_compose) {
         $clink_ob = new IMP_Compose_Link();
         $clink = $clink_ob->link()->add($compose_params);
         $a_view->reply = Horde::widget(array('url' => $clink->add(array('actionID' => 'reply_auto')), 'class' => 'horde-hasmenu', 'title' => _("_Reply"), 'nocheck' => true));
         $a_view->reply_sender = Horde::widget(array('url' => $clink->add(array('actionID' => 'reply')), 'title' => _("To Sender"), 'nocheck' => true));
         if ($list_info['reply_list']) {
             $a_view->reply_list = Horde::widget(array('url' => $clink->add(array('actionID' => 'reply_list')), 'title' => _("To _List"), 'nocheck' => true));
         }
         $addr_ob = clone $envelope->to;
         $addr_ob->add($envelope->cc);
         $addr_ob->setIteratorFilter(0, $imp_identity->getAllFromAddresses());
         if (count($addr_ob)) {
             $a_view->show_reply_all = Horde::widget(array('url' => $clink->add(array('actionID' => 'reply_all')), 'title' => _("To _All"), 'nocheck' => true));
         }
         $fwd_locked = $prefs->isLocked('forward_default');
         $a_view->forward = Horde::widget(array('url' => $clink->add(array('actionID' => 'forward_auto')), 'class' => $fwd_locked ? '' : ' horde-hasmenu', 'title' => _("Fo_rward"), 'nocheck' => true));
         if (!$fwd_locked) {
             $a_view->forward_attach = Horde::widget(array('url' => $clink->add(array('actionID' => 'forward_attach')), 'title' => _("As Attachment"), 'nocheck' => true));
             $a_view->forward_body = Horde::widget(array('url' => $clink->add(array('actionID' => 'forward_body')), 'title' => _("In Body Text"), 'nocheck' => true));
             $a_view->forward_both = Horde::widget(array('url' => $clink->add(array('actionID' => 'forward_both')), 'title' => _("Attachment and Body Text"), 'nocheck' => true));
         }
         $a_view->redirect = Horde::widget(array('url' => $clink->add(array('actionID' => 'redirect_compose')), 'title' => _("Redirec_t"), 'nocheck' => true));
         $a_view->editasnew = Horde::widget(array('url' => $clink->add(array('actionID' => 'editasnew')), 'title' => _("Edit as New"), 'nocheck' => true));
     }
     if ($mailbox->access_sortthread) {
         $a_view->show_thread = Horde::widget(array('url' => $mailbox->url(IMP_Basic_Thread::url(), $buid)->add(array('start' => $msgindex)), 'title' => _("_View Thread"), 'nocheck' => true));
     }
     if (!$readonly && $registry->hasMethod('mail/blacklistFrom')) {
         $a_view->blacklist = Horde::widget(array('url' => $self_link->copy()->add('actionID', 'blacklist'), 'title' => _("_Blacklist"), 'nocheck' => true));
     }
     if (!$readonly && $registry->hasMethod('mail/whitelistFrom')) {
         $a_view->whitelist = Horde::widget(array('url' => $self_link->copy()->add('actionID', 'whitelist'), 'title' => _("_Whitelist"), 'nocheck' => true));
     }
     if (!empty($conf['user']['allow_view_source'])) {
         $a_view->view_source = $imp_contents->linkViewJS($imp_contents->getMIMEMessage(), 'view_source', _("_Message Source"), array('css' => '', 'jstext' => _("Message Source"), 'widget' => true));
     }
     if (!$disable_compose && (in_array(Horde_Imap_Client::FLAG_DRAFT, $flags) || $msg_index['m']->drafts)) {
         $a_view->resume = Horde::widget(array('url' => $clink->add(array('actionID' => 'draft')), 'title' => _("Resume"), 'nocheck' => true));
     }
     $imp_params = $mailbox->urlParams($buid);
     $a_view->save_as = Horde::widget(array('url' => IMP_Contents_View::downloadUrl($subject, array_merge(array('actionID' => 'save_message'), $imp_params)), 'title' => _("Sa_ve as"), 'nocheck' => true));
     if ($msg_index['m']->spam_show) {
         $a_view->spam = Horde::widget(array('url' => '#', 'class' => 'spamAction', 'title' => _("Report as Spam"), 'nocheck' => true));
     }
     if ($msg_index['m']->innocent_show) {
         $a_view->innocent = Horde::widget(array('url' => '#', 'class' => 'innocentAction', 'title' => _("Report as Innocent"), 'nocheck' => true));
     }
     if (!$disable_compose) {
         $a_view->redirect = Horde::widget(array('url' => $clink->add(array('actionID' => 'redirect_compose')), 'title' => _("Redirec_t"), 'nocheck' => true));
     }
     $a_view->headers = Horde::widget(array('url' => '#', 'class' => 'horde-hasmenu', 'title' => _("Headers"), 'nocheck' => true));
     if ($all_headers) {
         $a_view->common_headers = Horde::widget(array('url' => $headersURL, 'title' => _("Show Common Headers"), 'nocheck' => true));
     }
     if (!$all_headers) {
         $a_view->all_headers = Horde::widget(array('url' => $headersURL->copy()->add('show_all_headers', 1), 'title' => _("Show All Headers"), 'nocheck' => true));
     }
     if ($list_info['exists']) {
         $a_view->list_headers = Horde::widget(array('onclick' => Horde::popupJs(IMP_Basic_Listinfo::url(array('buid' => $buid, 'mailbox' => $mailbox)), array('urlencode' => true)), 'title' => _("Show Mailing List Information"), 'nocheck' => true));
     }
     $hdrs = array();
     /* Prepare the main message template. */
     if (!$all_headers) {
         foreach ($display_headers as $head => $val) {
             $hdrs[] = array('name' => $basic_headers[$head], 'val' => $val);
         }
     }
     foreach ($full_headers as $head => $val) {
         if (is_array($val)) {
             $hdrs[] = array('name' => $head, 'val' => '<ul style="margin:0;padding-left:15px"><li>' . implode("</li>\n<li>", array_map('htmlspecialchars', $val)) . '</li></ul>');
         } else {
             $hdrs[] = array('name' => $head, 'val' => htmlspecialchars($val));
         }
     }
     /* Determine the fields that will appear in the MIME info entries. */
     $part_info = $part_info_display = array('icon', 'description', 'size');
     $part_info_action = array('download', 'download_zip', 'img_save', 'strip');
     $part_info_bodyonly = array('print');
     $show_parts = isset($this->vars->show_parts) ? $this->vars->show_parts : $prefs->getValue('parts_display');
     $part_info_display = array_merge($part_info_display, $part_info_action, $part_info_bodyonly);
     $contents_mask = IMP_Contents::SUMMARY_BYTES | IMP_Contents::SUMMARY_SIZE | IMP_Contents::SUMMARY_ICON | IMP_Contents::SUMMARY_DESCRIP_LINK | IMP_Contents::SUMMARY_DOWNLOAD | IMP_Contents::SUMMARY_DOWNLOAD_ZIP | IMP_Contents::SUMMARY_IMAGE_SAVE | IMP_Contents::SUMMARY_PRINT;
     /* Do MDN processing now. */
     $mdntext = $imp_ui->MDNCheck(new IMP_Indices($msg_index['m'], $buid), $mime_headers, $this->vars->mdn_confirm) ? strval(new IMP_Mime_Status(array(_("The sender of this message is requesting a notification from you when you have read this message."), sprintf(_("Click %s to send the notification message."), Horde::link($selfURL->copy()->add('mdn_confirm', 1)) . _("HERE") . '</a>')))) : '';
     /* Build body text. This needs to be done before we build the
      * attachment list that lives in the header. */
     $inlineout = $imp_contents->getInlineOutput(array('mask' => $contents_mask, 'part_info_display' => $part_info_display, 'show_parts' => $show_parts));
     /* Build the Attachments menu. */
     $show_atc = false;
     switch ($show_parts) {
         case 'atc':
             $a_view->show_parts_all = Horde::widget(array('url' => $headersURL->copy()->add(array('show_parts' => 'all')), 'title' => _("Show All Parts"), 'nocheck' => true));
             $show_atc = true;
             break;
         case 'all':
             if ($prefs->getValue('strip_attachments')) {
                 $js_vars['ImpMessage.text']['stripwarn'] = _("Are you sure you wish to PERMANENTLY delete this attachment?");
             }
             break;
     }
     if (count($inlineout['atc_parts']) > 2) {
         $a_view->download_all = Horde::widget(array('url' => $imp_contents->urlView($imp_contents->getMIMEMessage(), 'download_all'), 'title' => _("Download All Attachments (in .zip file)"), 'nocheck' => true));
         if ($prefs->getValue('strip_attachments')) {
             $a_view->strip_all = Horde::widget(array('url' => Horde::selfUrlParams()->add(array('actionID' => 'strip_all', 'token' => $token)), 'class' => 'stripAllAtc', 'title' => _("Strip All Attachments"), 'nocheck' => true));
             $js_vars['ImpMessage.text']['stripallwarn'] = _("Are you sure you want to PERMANENTLY delete all attachments?");
         }
         $show_atc = true;
     }
     if ($show_atc) {
         $a_view->atc = Horde::widget(array('url' => '#', 'class' => 'horde-hasmenu', 'title' => _("Attachments"), 'nocheck' => true));
     }
     /* Show attachment information in headers? 'atc_parts' will be empty if
      * 'parts_display' pref is 'none'. */
     if (!empty($inlineout['atc_parts'])) {
         if ($show_parts == 'all') {
             $val = $imp_contents->getTree()->getTree(true);
         } else {
             $tmp = array();
             foreach ($inlineout['atc_parts'] as $id) {
                 $summary = $imp_contents->getSummary($id, $contents_mask);
                 $tmp[] = '<tr>';
                 foreach ($part_info as $val) {
                     $tmp[] = '<td>' . $summary[$val] . '</td>';
                 }
                 $tmp[] = '<td>';
                 foreach ($part_info_action as $val) {
                     $tmp[] = $summary[$val];
                 }
                 $tmp[] = '</td></tr>';
             }
             $val = '<table>' . implode('', $tmp) . '</table>';
         }
         $hdrs[] = array('class' => 'msgheaderParts', 'name' => $show_parts == 'all' ? _("Parts") : _("Attachments"), 'val' => $val);
     }
     $m_view = clone $view;
     $m_view->label = $shortsub;
     $m_view->headers = $hdrs;
     $m_view->msgtext = $mdntext . $inlineout['msgtext'];
     $subinfo = new IMP_View_Subinfo(array('mailbox' => $mailbox));
     $subinfo->label = $header_label;
     $subinfo->value = sprintf(_("(%d of %d)"), $msgindex, count($imp_mailbox)) . $status;
     $injector->getInstance('Horde_View_Topbar')->subinfo = $subinfo->render();
     /* Output message page now. */
     $page_output->addInlineJsVars($js_vars, array('top' => true));
     $page_output->addScriptFile('scriptaculous/effects.js', 'horde');
     $page_output->addScriptFile('hordecore.js', 'horde');
     $page_output->addScriptFile('message.js');
     $page_output->addScriptFile('stripe.js', 'horde');
     $page_output->addScriptPackage('IMP_Script_Package_Imp');
     if (!empty($conf['tasklist']['use_notepad']) || !empty($conf['tasklist']['use_tasklist'])) {
         $page_output->addScriptPackage('Horde_Core_Script_Package_Dialog');
     }
     $page_output->noDnsPrefetch();
     Horde::startBuffer();
     foreach ($injector->getInstance('IMP_Maillog')->getLog(new IMP_Maillog_Message($this->indices, array('mdn'))) as $val) {
         $notification->push($val->message, 'imp.' . $val->action);
     }
     $this->output = Horde::endBuffer();
     $this->output .= $t_view->render('navbar_top') . $n_view->render('navbar_navigate') . $a_view->render('navbar_actions') . $m_view->render('message') . $a_view->render('navbar_actions');
     $n_view->id = 2;
     $n_view->isbottom = true;
     $this->output .= $n_view->render('navbar_navigate');
 }
Пример #19
0
 /**
  * @throws IMP_Exception
  */
 protected function _init()
 {
     global $injector, $notification, $page_output;
     if (!$this->indices) {
         throw new IMP_Exception(_("No message index given."));
     }
     $page_output->addScriptFile('message.js');
     $page_output->addScriptFile('external/CustomElements.js');
     $page_output->addScriptFile('external/time-elements.js');
     $page_output->addScriptFile('textarearesize.js', 'horde');
     $page_output->addScriptFile('toggle_quotes.js', 'horde');
     $page_output->addScriptPackage('IMP_Script_Package_Imp');
     $page_output->addThemeStylesheet('message.css');
     $page_output->addThemeStylesheet('message_view.css');
     $js_vars = array();
     switch ($this->vars->actionID) {
         case 'strip_attachment':
             try {
                 $this->indices = new IMP_Indices_Mailbox($this->indices->mailbox, $this->indices->stripPart($this->vars->id));
                 $js_vars['-ImpMessage.strip'] = 1;
                 $notification->push(_("Attachment successfully stripped."), 'horde.success');
             } catch (IMP_Exception $e) {
                 $notification->push($e);
             }
             break;
     }
     try {
         $show_msg = new IMP_Contents_Message($this->indices);
         $msg_res = $show_msg->showMessage();
     } catch (IMP_Exception $e) {
         $notification->notify(array('listeners' => array('status', 'audio')));
         echo Horde::wrapInlineScript(array('parent.close()'));
         exit;
     }
     /* Add 'maillog' and 'poll' data to the AJAX queue. */
     $ajax_queue = $injector->getInstance('IMP_Ajax_Queue');
     $ajax_queue->maillog($this->indices);
     $ajax_queue->poll($this->indices->mailbox);
     list(, $buid) = $this->indices->buids->getSingle();
     /* Need to be dynamically added, since formatting needs to be applied
      * via javascript. */
     foreach (array('from', 'to', 'cc', 'bcc') as $val) {
         if ($tmp = $show_msg->getAddressHeader($val)) {
             $js_vars['ImpMessage.' . $val] = $tmp;
         }
     }
     if ($resent = $show_msg->getResentData()) {
         $resent_js = array();
         foreach ($resent as $val) {
             $resent_js[] = array('date' => $val['date']->format($val['date']::DATE_LOCAL), 'from' => $show_msg->getAddressHeader($val['from']));
         }
         $js_vars['ImpMessage.resent'] = $resent_js;
     }
     if (isset($msg_res['log'])) {
         $js_vars['ImpMessage.log'] = $msg_res['log'];
     }
     $list_info = $show_msg->contents->getListInformation();
     if (!empty($list_info['exists'])) {
         $js_vars['ImpMessage.reply_list'] = true;
         $this->view->listinfo = Horde::popupJs(IMP_Basic_Listinfo::url(array('buid' => $buid, 'mailbox' => $this->indices->mailbox)), array('urlencode' => true));
     }
     $js_vars['ImpMessage.buid'] = $buid;
     $js_vars['ImpMessage.mbox'] = $this->indices->mailbox->form_to;
     if (isset($msg_res['atc'])) {
         $js_vars['ImpMessage.msg_atc'] = $msg_res['atc'];
         $this->js_text['atc_downloadall'] = _("Download All (%s)");
     }
     if (isset($msg_res['md'])) {
         $js_vars['ImpMessage.msg_md'] = $msg_res['md'];
     }
     $js_vars['ImpMessage.tasks'] = $injector->getInstance('Horde_Core_Factory_Ajax')->create('imp', $this->vars)->getTasks();
     $page_output->addInlineJsVars($js_vars);
     if (isset($msg_res['js'])) {
         $page_output->addInlineScript(array_filter($msg_res['js']), true);
     }
     $this->_pages[] = 'message';
     $subject = $show_msg->getSubject();
     $this->view->subject = isset($subject['subjectlink']) ? $subject['subjectlink'] : $subject['subject'];
     $this->title = $subject['title'];
     /* Determine if compose mode is disabled. */
     if (IMP_Compose::canCompose()) {
         $this->view->qreply = $injector->getInstance('IMP_Dynamic_Compose_Common')->compose($this, array('title' => _("Message") . ': ' . $subject['subject']));
         $this->_pages[] = 'qreply';
         $this->js_conf['qreply'] = 1;
     }
     $page_output->noDnsPrefetch();
     $this->view->show_delete = $this->indices->mailbox->access_deletemsgs;
     list($real_mbox, ) = $this->indices->getSingle();
     $this->view->show_innocent = $real_mbox->innocent_show;
     $this->view->show_spam = $real_mbox->spam_show;
     $this->view->show_view_all = empty($msg_res['onepart']);
     $this->view->show_view_source = $injector->getInstance('Horde_Core_Perms')->hasAppPermission('view_msg_source');
     $this->view->save_as = $show_msg->getSaveAs();
     if ($date = $show_msg->getDateOb()) {
         $this->view->datestamp = $date->format($date::DATE_ISO_8601);
         $this->view->fulldate = $date->format($date::DATE_FORCE);
         $this->view->localdate = $date->format($date::DATE_LOCAL);
         $this->view->addHelper('Text');
     }
     if ($this->view->user_hdrs = $show_msg->getUserHeaders()) {
         $this->view->addHelper('Text');
     }
     $this->view->msgtext = $msg_res['msgtext'];
     Horde::startBuffer();
     $notification->notify(array('listeners' => array('status', 'audio')));
     $this->view->status = Horde::endBuffer();
     $this->view->title = $this->title;
 }
Пример #20
0
 /**
  * Helper for html2Text() and text2Html().
  *
  * @internal
  */
 protected function _convertText($mode)
 {
     global $injector;
     $compose = null;
     $result = new stdClass();
     $result->text = array();
     foreach (json_decode($this->vars->data, true) as $key => $val) {
         $tmp = null;
         if (empty($val['changed'])) {
             if (!$compose) {
                 $compose = $this->_base->initCompose();
             }
             switch ($compose->compose->replyType()) {
                 case IMP_Compose::FORWARD_BODY:
                 case IMP_Compose::FORWARD_BOTH:
                     $data = $compose->compose->forwardMessageText($compose->contents, array('format' => $mode));
                     $tmp = $data['body'];
                     break;
                 case IMP_Compose::REPLY_ALL:
                 case IMP_Compose::REPLY_LIST:
                 case IMP_Compose::REPLY_SENDER:
                     $data = $compose->compose->replyMessageText($compose->contents, array('format' => $mode));
                     $tmp = $data['body'];
                     break;
             }
         }
         if (is_null($tmp)) {
             switch ($mode) {
                 case 'html':
                     $tmp = IMP_Compose::text2html($val['text']);
                     break;
                 case 'text':
                     $tmp = $injector->getInstance('Horde_Core_Factory_TextFilter')->filter($val['text'], 'Html2text', array('wrap' => false));
                     break;
             }
         }
         $result->text[$key] = $tmp;
     }
     return $result;
 }
Пример #21
0
 /**
  * @throws IMP_Exception
  */
 protected function _init()
 {
     global $conf, $injector, $notification, $page_output;
     if (!$this->indices) {
         throw new IMP_Exception(_("No message index given."));
     }
     $page_output->addScriptFile('message-dimp.js');
     $page_output->addScriptFile('textarearesize.js', 'horde');
     $page_output->addScriptFile('toggle_quotes.js', 'horde');
     $page_output->addScriptPackage('IMP_Script_Package_Imp');
     $js_vars = array();
     switch ($this->vars->actionID) {
         case 'strip_attachment':
             try {
                 $this->indices = new IMP_Indices_Mailbox($this->indices->mailbox, $injector->getInstance('IMP_Message')->stripPart($this->indices, $this->vars->id));
                 $js_vars['-DimpMessage.strip'] = 1;
                 $notification->push(_("Attachment successfully stripped."), 'horde.success');
             } catch (IMP_Exception $e) {
                 $notification->push($e);
             }
             break;
     }
     try {
         $show_msg = new IMP_Ajax_Application_ShowMessage($this->indices);
         $msg_res = $show_msg->showMessage(array('headers' => array_diff(array_keys($injector->getInstance('IMP_Message_Ui')->basicHeaders()), array('subject')), 'preview' => false));
     } catch (IMP_Exception $e) {
         $notification->notify(array('listeners' => array('status', 'audio')));
         echo Horde::wrapInlineScript(array('parent.close()'));
         exit;
     }
     $ajax_queue = $injector->getInstance('IMP_Ajax_Queue');
     $ajax_queue->poll($this->indices->mailbox);
     list(, $buid) = $this->indices->buids->getSingle();
     foreach (array('from', 'to', 'cc', 'bcc', 'replyTo', 'log') as $val) {
         if (!empty($msg_res[$val])) {
             $js_vars['DimpMessage.' . $val] = $msg_res[$val];
         }
     }
     if (!empty($msg_res['list_info']['exists'])) {
         $js_vars['DimpMessage.reply_list'] = true;
         $this->view->listinfo = Horde::popupJs(IMP_Basic_Listinfo::url(array('buid' => $buid, 'mailbox' => $this->indices->mailbox)), array('urlencode' => true));
     }
     $js_vars['DimpMessage.buid'] = $buid;
     $js_vars['DimpMessage.mbox'] = $this->indices->mailbox->form_to;
     $js_vars['DimpMessage.tasks'] = $injector->getInstance('Horde_Core_Factory_Ajax')->create('imp', $this->vars)->getTasks();
     $page_output->addInlineJsVars($js_vars);
     if (isset($msg_res['js'])) {
         $page_output->addInlineScript(array_filter($msg_res['js']), true);
     }
     $this->_pages[] = 'message';
     /* Determine if compose mode is disabled. */
     if (IMP_Compose::canCompose()) {
         $this->view->qreply = $injector->getInstance('IMP_Dynamic_Compose_Common')->compose($this, array('title' => _("Message") . ': ' . $msg_res['subject']));
         $this->_pages[] = 'qreply';
         $this->js_conf['qreply'] = 1;
     }
     $page_output->noDnsPrefetch();
     $this->view->show_delete = $this->indices->mailbox->access_deletemsgs;
     list($real_mbox, ) = $this->indices->getSingle();
     $this->view->show_innocent = $real_mbox->innocent_show;
     $this->view->show_spam = $real_mbox->spam_show;
     $this->view->show_view_all = empty($msg_res['onepart']);
     $this->view->show_view_source = !empty($conf['user']['allow_view_source']);
     $this->view->save_as = $msg_res['save_as'];
     $this->view->subject = isset($msg_res['subjectlink']) ? $msg_res['subjectlink'] : $msg_res['subject'];
     $hdrs = array();
     foreach ($msg_res['headers'] as $val) {
         $hdrs[] = array_filter(array('id' => isset($val['id']) ? 'msgHeader' . $val['id'] : null, 'label' => $val['name'], 'val' => $val['value']));
     }
     $this->view->hdrs = $hdrs;
     if (isset($msg_res['atc_label'])) {
         $this->view->atc_label = $msg_res['atc_label'];
         if (isset($msg_res['atc_list'])) {
             $this->view->atc_list = $msg_res['atc_list'];
         } else {
             $this->view->atc_list = array();
         }
         if (isset($msg_res['atc_download'])) {
             $this->view->atc_download = $msg_res['atc_download'];
         }
     } else {
         $this->view->atc_list = array();
     }
     $this->view->msgtext = $msg_res['msgtext'];
     Horde::startBuffer();
     $notification->notify(array('listeners' => array('status', 'audio')));
     $this->view->status = Horde::endBuffer();
     $this->title = $msg_res['title'];
     $this->view->title = $this->title;
 }
Пример #22
0
 /**
  */
 protected function _init()
 {
     global $browser, $injector, $notification, $page_output, $prefs, $registry, $session;
     /* Mailto link handler: redirect based on current view. */
     if ($this->vars->actionID == 'mailto_link') {
         switch ($registry->getView()) {
             case Horde_Registry::VIEW_DYNAMIC:
                 IMP_Dynamic_Compose::url()->add($_GET)->redirect();
                 exit;
             case Horde_Registry::VIEW_MINIMAL:
                 IMP_Minimal_Compose::url()->add($_GET)->redirect();
                 exit;
         }
     }
     /* The message headers and text. */
     $header = array();
     $msg = '';
     $redirect = $resume = $spellcheck = false;
     $oldrtemode = $rtemode = null;
     /* Is this a popup window? */
     if ($isPopup = $prefs->getValue('compose_popup') || $this->vars->popup) {
         $page_output->topbar = $page_output->sidebar = false;
     }
     /* Set the current identity. */
     $identity = $injector->getInstance('IMP_Identity');
     if (!$prefs->isLocked('default_identity') && !is_null($this->vars->identity)) {
         $identity->setDefault($this->vars->identity);
     }
     if ($this->vars->actionID) {
         switch ($this->vars->actionID) {
             case 'draft':
             case 'editasnew':
             case 'forward_attach':
             case 'forward_auto':
             case 'forward_body':
             case 'forward_both':
             case 'fwd_digest':
             case 'mailto':
             case 'mailto_link':
             case 'reply':
             case 'reply_all':
             case 'reply_auto':
             case 'reply_list':
             case 'redirect_compose':
             case 'template':
             case 'template_edit':
             case 'template_new':
                 /* These are all safe actions that might be invoked without a
                  * token. */
                 break;
             default:
                 try {
                     $session->checkToken($this->vars->compose_requestToken);
                 } catch (Horde_Exception $e) {
                     $notification->push($e);
                     $this->vars->actionID = null;
                 }
         }
     }
     /* Check for duplicate submits. */
     if ($reload = $this->vars->compose_formToken) {
         try {
             $session->checkNonce($reload);
         } catch (Horde_Exception $e) {
             $notification->push(_("You have already submitted this page."), 'horde.error');
             $this->vars->actionID = null;
         }
     }
     /* Determine if compose mode is disabled. */
     $compose_disable = !IMP_Compose::canCompose();
     /* Determine if mailboxes are readonly. */
     $draft = IMP_Mailbox::getPref(IMP_Mailbox::MBOX_DRAFTS);
     $readonly_drafts = $draft && $draft->readonly;
     $sent_mail = $identity->getValue(IMP_Mailbox::MBOX_SENT);
     if (!$sent_mail) {
         $readonly_sentmail = $save_sent_mail = false;
     } elseif ($sent_mail->readonly) {
         $readonly_sentmail = true;
         $save_sent_mail = false;
     } else {
         $readonly_sentmail = false;
         $save_sent_mail = $reload ? (bool) $this->vars->save_sent_mail : true;
     }
     /* Initialize the IMP_Compose:: object. */
     $imp_compose = $injector->getInstance('IMP_Factory_Compose')->create($this->vars->composeCache);
     /* Init objects. */
     $imp_imap = $injector->getInstance('IMP_Factory_Imap')->create();
     $imp_ui = new IMP_Compose_Ui();
     /* Determine the composition type - text or HTML.
        $rtemode is null if browser does not support it. */
     if ($session->get('imp', 'rteavail')) {
         if ($prefs->isLocked('compose_html')) {
             $rtemode = $prefs->getValue('compose_html');
         } else {
             $rtemode = $this->vars->rtemode;
             if (is_null($rtemode)) {
                 $rtemode = $prefs->getValue('compose_html');
             } else {
                 $rtemode = intval($rtemode);
                 $oldrtemode = intval($this->vars->oldrtemode);
             }
         }
     }
     /* Update the file attachment information. */
     $attach_upload = $imp_compose->canUploadAttachment();
     if ($attach_upload) {
         /* Only notify if we are reloading the compose screen. */
         $notify = !in_array($this->vars->actionID, array('send_message', 'save_draft'));
         $deleteList = Horde_Util::getPost('delattachments', array());
         /* Update the attachment information. */
         foreach ($imp_compose as $key => $val) {
             if (!in_array($key, $deleteList)) {
                 $val->getPart()->setDescription($this->vars->filter('file_description_' . $key));
                 $imp_compose[$key] = $val;
             }
         }
         /* Delete attachments. */
         foreach ($deleteList as $val) {
             if ($notify) {
                 $notification->push(sprintf(_("Deleted attachment \"%s\"."), $imp_compose[$val]->getPart()->getName(true)), 'horde.success');
             }
             unset($imp_compose[$val]);
         }
         /* Add attachments. */
         for ($i = 1, $fcount = count($_FILES); $i <= $fcount; ++$i) {
             if (isset($_FILES['upload_' . $i]) && strlen($_FILES['upload_' . $i]['name'])) {
                 try {
                     $atc_ob = $imp_compose->addAttachmentFromUpload('upload_' . $i);
                     if ($atc_ob[0] instanceof IMP_Compose_Exception) {
                         throw $atc_ob[0];
                     }
                     if ($notify) {
                         $notification->push(sprintf(_("Added \"%s\" as an attachment."), $atc_ob[0]->getPart()->getName()), 'horde.success');
                     }
                 } catch (IMP_Compose_Exception $e) {
                     /* Any error will cancel the current action. */
                     $this->vars->actionID = null;
                     $notification->push($e, 'horde.error');
                 }
             }
         }
     }
     /* Get message priority. */
     $priority = $this->vars->get('priority', 'normal');
     /* Request read receipt? */
     $request_read_receipt = (bool) $this->vars->request_read_receipt;
     /* Run through the action handlers. */
     $this->title = _("New Message");
     switch ($this->vars->actionID) {
         case 'mailto':
             try {
                 $contents = $this->_getContents();
             } catch (IMP_Exception $e) {
                 $notification->push($e, 'horde.error');
                 break;
             }
             $imp_headers = $contents->getHeader();
             $header['to'] = '';
             if ($this->vars->mailto) {
                 $header['to'] = $imp_headers->getValue('to');
             }
             if (empty($header['to'])) {
                 ($header['to'] = strval($imp_headers->getOb('from'))) || ($header['to'] = strval($imp_headers->getOb('reply-to')));
             }
             break;
         case 'mailto_link':
             $clink = new IMP_Compose_Link($this->vars);
             if (isset($clink->args['body'])) {
                 $msg = $clink->args['body'];
             }
             foreach (array('to', 'cc', 'bcc', 'subject') as $val) {
                 if (isset($clink->args[$val])) {
                     $header[$val] = $clink->args[$val];
                 }
             }
             break;
         case 'draft':
         case 'editasnew':
         case 'template':
         case 'template_edit':
             try {
                 switch ($this->vars->actionID) {
                     case 'draft':
                         $result = $imp_compose->resumeDraft($this->indices);
                         $resume = true;
                         break;
                     case 'editasnew':
                         $result = $imp_compose->editAsNew($this->indices);
                         break;
                     case 'template':
                         $result = $imp_compose->useTemplate($this->indices);
                         break;
                     case 'template_edit':
                         $result = $imp_compose->editTemplate($this->indices);
                         $this->vars->template_mode = true;
                         break;
                 }
                 if (!is_null($rtemode)) {
                     $rtemode = $result['format'] == 'html';
                 }
                 $msg = $result['body'];
                 $header = array_merge($header, $this->_convertToHeader($result));
                 if (!is_null($result['identity']) && $result['identity'] != $identity->getDefault() && !$prefs->isLocked('default_identity')) {
                     $identity->setDefault($result['identity']);
                     $sent_mail = $identity->getValue(IMP_Mailbox::MBOX_SENT);
                 }
                 $priority = $result['priority'];
                 $request_read_receipt = $result['readreceipt'];
             } catch (IMP_Compose_Exception $e) {
                 $notification->push($e);
             }
             break;
         case 'reply':
         case 'reply_all':
         case 'reply_auto':
         case 'reply_list':
             try {
                 $contents = $this->_getContents();
             } catch (IMP_Exception $e) {
                 $notification->push($e, 'horde.error');
                 break;
             }
             $reply_map = array('reply' => IMP_Compose::REPLY_SENDER, 'reply_all' => IMP_Compose::REPLY_ALL, 'reply_auto' => IMP_Compose::REPLY_AUTO, 'reply_list' => IMP_Compose::REPLY_LIST);
             $reply_msg = $imp_compose->replyMessage($reply_map[$this->vars->actionID], $contents, array('to' => $this->vars->to));
             $msg = $reply_msg['body'];
             $header = $this->_convertToHeader($reply_msg);
             $format = $reply_msg['format'];
             switch ($reply_msg['type']) {
                 case IMP_Compose::REPLY_SENDER:
                     $this->vars->actionID = 'reply';
                     $this->title = _("Reply:");
                     break;
                 case IMP_Compose::REPLY_ALL:
                     if ($this->vars->actionID == 'reply_auto') {
                         $recip_list = $imp_compose->recipientList($header);
                         if (!empty($recip_list['list'])) {
                             $replyauto_all = count($recip_list['list']);
                         }
                     }
                     $this->vars->actionID = 'reply_all';
                     $this->title = _("Reply to All:");
                     break;
                 case IMP_Compose::REPLY_LIST:
                     if ($this->vars->actionID == 'reply_auto') {
                         $replyauto_list = true;
                         if (($parse_list = $injector->getInstance('Horde_ListHeaders')->parse('list-id', $contents->getHeader()->getValue('list-id'))) && !is_null($parse_list->label)) {
                             $replyauto_list_id = $parse_list->label;
                         }
                     }
                     $this->vars->actionID = 'reply_list';
                     $this->title = _("Reply to List:");
                     break;
             }
             if (!empty($reply_msg['lang'])) {
                 $reply_lang = array_values($reply_msg['lang']);
             }
             $this->title .= ' ' . $header['subject'];
             if (!is_null($rtemode)) {
                 $rtemode = $rtemode || $format == 'html';
             }
             break;
         case 'replyall_revert':
         case 'replylist_revert':
             try {
                 $reply_msg = $imp_compose->replyMessage(IMP_Compose::REPLY_SENDER, $imp_compose->getContentsOb());
                 $header = $this->_convertToHeader($reply_msg);
             } catch (IMP_Exception $e) {
                 $notification->push($e, 'horde.error');
             }
             break;
         case 'forward_attach':
         case 'forward_auto':
         case 'forward_body':
         case 'forward_both':
             $fwd_map = array('forward_attach' => IMP_Compose::FORWARD_ATTACH, 'forward_auto' => IMP_Compose::FORWARD_AUTO, 'forward_body' => IMP_Compose::FORWARD_BODY, 'forward_both' => IMP_Compose::FORWARD_BOTH);
             try {
                 $fwd_msg = $imp_compose->forwardMessage($fwd_map[$this->vars->actionID], $this->_getContents());
             } catch (IMP_Exception $e) {
                 $notification->push($e, 'horde.error');
                 break;
             }
             $msg = $fwd_msg['body'];
             $header = $this->_convertToHeader($fwd_msg);
             $format = $fwd_msg['format'];
             $rtemode = $rtemode || !is_null($rtemode) && $format == 'html';
             $this->title = $fwd_msg['title'];
             break;
         case 'redirect_compose':
             try {
                 $imp_compose->redirectMessage($this->indices);
                 $redirect = true;
                 $this->title = ngettext("Redirect", "Redirect Messages", count($this->indices));
             } catch (IMP_Compose_Exception $e) {
                 $notification->push($e, 'horde.error');
             }
             break;
         case 'redirect_send':
             try {
                 $num_msgs = $imp_compose->sendRedirectMessage($this->vars->to);
                 $imp_compose->destroy('send');
                 if ($isPopup) {
                     if ($prefs->getValue('compose_confirm')) {
                         $notification->push(ngettext("Message redirected successfully.", "Messages redirected successfully", count($num_msgs)), 'horde.success');
                         $this->_popupSuccess();
                         return;
                     }
                     echo Horde::wrapInlineScript(array('window.close();'));
                 } else {
                     $notification->push(ngettext("Message redirected successfully.", "Messages redirected successfully", count($num_msgs)), 'horde.success');
                     $this->_mailboxReturnUrl()->redirect();
                 }
                 exit;
             } catch (Horde_Exception $e) {
                 $notification->push($e);
                 $this->vars->actionID = 'redirect_compose';
             }
             break;
         case 'auto_save_draft':
         case 'save_draft':
         case 'save_template':
         case 'send_message':
             // Drafts readonly is handled below.
             if ($compose_disable && $this->vars->actionID == 'send_message') {
                 break;
             }
             try {
                 $header['from'] = strval($identity->getFromLine(null, $this->vars->from));
             } catch (Horde_Exception $e) {
                 $header['from'] = '';
                 $notification->push($e);
                 break;
             }
             $header['to'] = $this->vars->to;
             $header['cc'] = $this->vars->cc;
             $header['bcc'] = $this->vars->bcc;
             $header['subject'] = strval($this->vars->subject);
             $message = strval($this->vars->message);
             /* Save the draft. */
             switch ($this->vars->actionID) {
                 case 'auto_save_draft':
                 case 'save_draft':
                 case 'save_template':
                     if (!$readonly_drafts || $this->vars->actionID == 'save_template') {
                         $save_opts = array('html' => $rtemode, 'priority' => $priority, 'readreceipt' => $request_read_receipt);
                         try {
                             switch ($this->vars->actionID) {
                                 case 'save_template':
                                     $result = $imp_compose->saveTemplate($header, $message, $save_opts);
                                     break;
                                 default:
                                     $result = $imp_compose->saveDraft($header, $message, $save_opts);
                                     break;
                             }
                             /* Closing draft if requested by preferences. */
                             switch ($this->vars->actionID) {
                                 case 'save_draft':
                                     if ($isPopup) {
                                         if ($prefs->getValue('close_draft')) {
                                             $imp_compose->destroy('save_draft');
                                             echo Horde::wrapInlineScript(array('window.close();'));
                                             exit;
                                         }
                                         $notification->push($result, 'horde.success');
                                     } else {
                                         $notification->push($result, 'horde.success');
                                         if ($prefs->getValue('close_draft')) {
                                             $imp_compose->destroy('save_draft');
                                             $this->_mailboxReturnUrl()->redirect();
                                         }
                                     }
                                     break;
                                 case 'save_template':
                                     if ($isPopup) {
                                         echo Horde::wrapInlineScript(array('window.close();'));
                                         exit;
                                     }
                                     $notification->push($result, 'horde.success');
                                     $this->_mailboxReturnUrl()->redirect();
                                     break;
                             }
                         } catch (IMP_Compose_Exception $e) {
                             if ($this->vars->actionID == 'save_draft') {
                                 $notification->push($e);
                             }
                         }
                     }
                     if ($this->vars->actionID == 'auto_save_draft') {
                         $r = new stdClass();
                         $r->requestToken = $session->getToken();
                         $r->formToken = $session->getNonce();
                         $response = new Horde_Core_Ajax_Response_HordeCore($r);
                         $response->sendAndExit();
                     }
                     break;
                 default:
                     $header['replyto'] = $identity->getValue('replyto_addr');
                     if ($this->vars->sent_mail) {
                         $sent_mail = IMP_Mailbox::formFrom($this->vars->sent_mail);
                     }
                     try {
                         $imp_compose->buildAndSendMessage($message, $header, $identity, array('encrypt' => $prefs->isLocked('default_encrypt') ? $prefs->getValue('default_encrypt') : $this->vars->encrypt_options, 'html' => $rtemode, 'pgp_attach_pubkey' => $this->vars->pgp_attach_pubkey, 'priority' => $priority, 'save_sent' => $save_sent_mail, 'sent_mail' => $sent_mail, 'signature' => $this->vars->signature, 'strip_attachments' => !$this->vars->save_attachments_select, 'readreceipt' => $request_read_receipt, 'vcard_attach' => $this->vars->vcard ? $identity->getValue('fullname') : null));
                         $imp_compose->destroy('send');
                         if ($isPopup) {
                             if ($prefs->getValue('compose_confirm')) {
                                 $notification->push(_("Message sent successfully."), 'horde.success');
                                 $this->_popupSuccess();
                                 return;
                             }
                             echo Horde::wrapInlineScript(array('window.close();'));
                         } else {
                             $notification->push(_("Message sent successfully."), 'horde.success');
                             $this->_mailboxReturnUrl()->redirect();
                         }
                         exit;
                     } catch (IMP_Compose_Exception $e) {
                         $code = $e->getCode();
                         $notification->push($e->getMessage(), strpos($code, 'horde.') === 0 ? $code : 'horde.error');
                         /* Switch to tied identity. */
                         if (!is_null($e->tied_identity)) {
                             $identity->setDefault($e->tied_identity);
                             $notification->push(_("Your identity has been switched to the identity associated with the current recipient address. The identity will not be checked again during this compose action."));
                         }
                         switch ($e->encrypt) {
                             case 'pgp_symmetric_passphrase_dialog':
                                 $imp_ui->passphraseDialog('pgp_symm', $imp_compose->getCacheId());
                                 break;
                             case 'pgp_passphrase_dialog':
                                 $imp_ui->passphraseDialog('pgp');
                                 break;
                             case 'smime_passphrase_dialog':
                                 $imp_ui->passphraseDialog('smime');
                                 break;
                         }
                     }
                     break;
             }
             break;
         case 'fwd_digest':
             if (count($this->indices)) {
                 try {
                     $res = $imp_compose->forwardMultipleMessages($this->indices);
                     $header['subject'] = $res['subject'];
                     $fwd_msg = array('type' => IMP_Compose::FORWARD_ATTACH);
                 } catch (IMP_Compose_Exception $e) {
                     $notification->push($e, 'horde.error');
                 }
             }
             break;
         case 'cancel_compose':
         case 'discard_compose':
             $imp_compose->destroy($this->vars->actionID == 'cancel_compose' ? 'cancel' : 'discard');
             if ($isPopup) {
                 echo Horde::wrapInlineScript(array('window.close();'));
             } else {
                 $this->_mailboxReturnUrl()->redirect();
             }
             exit;
         case 'template_new':
             $this->vars->template_mode = true;
             break;
     }
     /* Get the message cache ID. */
     $composeCacheID = filter_var($imp_compose->getCacheId(), FILTER_SANITIZE_STRING);
     /* Attach autocompleters to the compose form elements. */
     if ($redirect) {
         $imp_ui->attachAutoCompleter(array('to'));
     } else {
         $imp_ui->attachAutoCompleter(array('to', 'cc', 'bcc'));
         $spellcheck = $imp_ui->attachSpellChecker();
         $page_output->addScriptFile('ieescguard.js', 'horde');
     }
     $max_attach = $imp_compose->additionalAttachmentsAllowed();
     /* Get the URL to use for the cancel action. If the attachments cache
      * is not empty, or this is the resume drafts page, we must reload
      * this page and delete the attachments and/or the draft message. */
     if ($isPopup) {
         if ($resume || count($imp_compose)) {
             $cancel_url = self::url()->setRaw(true)->add(array('actionID' => 'cancel_compose', 'compose_requestToken' => $session->getToken(), 'composeCache' => $composeCacheID, 'popup' => 1));
             $discard_url = clone $cancel_url;
             $discard_url->add('actionID', 'discard_compose');
         } else {
             $cancel_url = $discard_url = '';
         }
     } elseif ($resume || count($imp_compose)) {
         $cancel_url = $this->_mailboxReturnUrl(self::url()->setRaw(true))->setRaw(true)->add(array('actionID' => 'cancel_compose', 'compose_requestToken' => $session->getToken(), 'composeCache' => $composeCacheID));
         $discard_url = clone $cancel_url;
         $discard_url->add('actionID', 'discard_compose');
     } else {
         $cancel_url = $discard_url = $this->_mailboxReturnUrl(false)->setRaw(true);
     }
     /* Grab any data that we were supplied with. */
     if (!strlen($msg)) {
         $msg = $this->vars->get('message', strval($this->vars->body));
         if ($browser->hasQuirk('double_linebreak_textarea')) {
             $msg = preg_replace('/(\\r?\\n){3}/', '$1', $msg);
         }
         $msg = "\n" . $msg;
     }
     if (isset($this->vars->signature)) {
         $signature = $this->vars->signature;
         if ($browser->hasQuirk('double_linebreak_textarea')) {
             $signature = preg_replace('/(\\r?\\n){3}/', '$1', $signature);
         }
         $signatureChanged = $signature != $identity->getSignature($oldrtemode ? 'html' : 'text');
     } else {
         $signatureChanged = false;
     }
     /* Convert from Text -> HTML or vice versa if RTE mode changed. */
     if (!is_null($oldrtemode) && $oldrtemode != $rtemode) {
         $msg = $imp_ui->convertComposeText($msg, $rtemode ? 'html' : 'text');
         if ($signatureChanged) {
             $signature = $imp_ui->convertComposeText($signature, $rtemode ? 'html' : 'text');
         }
     }
     /* If this is the first page load for this compose item, add auto BCC
      * addresses. */
     if (!$reload && !$resume) {
         $header['bcc'] = strval($identity->getBccAddresses());
     }
     foreach (array('to', 'cc', 'bcc') as $val) {
         if (!isset($header[$val])) {
             $header[$val] = $this->vars->{$val};
         }
     }
     if (!isset($header['subject'])) {
         $header['subject'] = $this->vars->subject;
     }
     /* If PGP encryption is set by default, and we have a recipient list
      * on first load, make sure we have public keys for all recipients. */
     $encrypt_options = $prefs->isLocked('default_encrypt') ? $prefs->getValue('default_encrypt') : $this->vars->encrypt_options;
     if ($prefs->getValue('use_pgp') && !$prefs->isLocked('default_encrypt') && $prefs->getValue('pgp_reply_pubkey')) {
         $default_encrypt = $prefs->getValue('default_encrypt');
         if (!$reload && in_array($default_encrypt, array(IMP_Crypt_Pgp::ENCRYPT, IMP_Crypt_Pgp::SIGNENC))) {
             $addrs = $imp_compose->recipientList($header);
             if (!empty($addrs['list'])) {
                 $imp_pgp = $injector->getInstance('IMP_Crypt_Pgp');
                 try {
                     foreach ($addrs['list'] as $val) {
                         $imp_pgp->getPublicKey(strval($val));
                     }
                 } catch (Horde_Exception $e) {
                     $notification->push(_("PGP encryption cannot be used by default as public keys cannot be found for all recipients."), 'horde.warning');
                     $encrypt_options = $default_encrypt == IMP_Crypt_Pgp::ENCRYPT ? IMP::ENCRYPT_NONE : IMP_Crypt_Pgp::SIGN;
                 }
             }
         }
     }
     /* Define some variables used in the javascript code. */
     $js_vars = array('ImpComposeBase.editor_on' => $rtemode, 'ImpCompose.auto_save' => intval($prefs->getValue('auto_save_drafts')), 'ImpCompose.cancel_url' => strval($cancel_url), 'ImpCompose.cursor_pos' => $rtemode ? null : $prefs->getValue('compose_cursor'), 'ImpCompose.discard_url' => strval($discard_url), 'ImpCompose.max_attachments' => $max_attach === true ? null : $max_attach, 'ImpCompose.popup' => intval($isPopup), 'ImpCompose.redirect' => intval($redirect), 'ImpCompose.reloaded' => intval($reload), 'ImpCompose.sm_check' => intval(!$prefs->isLocked(IMP_Mailbox::MBOX_SENT)), 'ImpCompose.spellcheck' => intval($spellcheck && $prefs->getValue('compose_spellcheck')), 'ImpCompose.text' => array('cancel' => _("Cancelling this message will permanently discard its contents.") . "\n" . _("Are you sure you want to do this?"), 'change_identity' => _("You have edited your signature. Change the identity and lose your changes?"), 'discard' => _("Doing so will discard this message permanently."), 'file' => _("File"), 'nosubject' => _("The message does not have a Subject entered.") . "\n" . _("Send message without a Subject?"), 'recipient' => _("You must specify a recipient.")));
     /* Set up the base view now. */
     $view = $injector->createInstance('Horde_View');
     $view->addHelper('FormTag');
     $view->addHelper('Horde_Core_View_Helper_Accesskey');
     $view->addHelper('Horde_Core_View_Helper_Help');
     $view->addHelper('Horde_Core_View_Helper_Image');
     $view->addHelper('Horde_Core_View_Helper_Label');
     $view->addHelper('Tag');
     $view->allow_compose = !$compose_disable;
     $view->post_action = self::url();
     $blank_url = new Horde_Url('#');
     if ($redirect) {
         /* Prepare the redirect template. */
         $view->cacheid = $composeCacheID;
         $view->title = $this->title;
         $view->token = $session->getToken();
         if ($registry->hasMethod('contacts/search')) {
             $view->abook = $blank_url->copy()->link(array('class' => 'widget', 'id' => 'redirect_abook', 'title' => _("Address Book")));
             $js_vars['ImpCompose.redirect_contacts'] = strval(IMP_Basic_Contacts::url()->add(array('to_only' => 1))->setRaw(true));
         }
         $view->input_value = $header['to'];
         $this->output = $view->render('basic/compose/redirect');
     } else {
         /* Prepare the compose template. */
         $view->file_upload = $attach_upload;
         $hidden = array('actionID' => '', 'attachmentAction' => '', 'compose_formToken' => $session->getNonce(), 'compose_requestToken' => $session->getToken(), 'composeCache' => $composeCacheID, 'composeHmac' => $imp_compose->getHmac(), 'oldrtemode' => $rtemode, 'rtemode' => $rtemode, 'user' => $registry->getAuth());
         if ($attach_upload) {
             $hidden['MAX_FILE_SIZE'] = $session->get('imp', 'file_upload');
         }
         foreach (array('page', 'start', 'popup', 'template_mode') as $val) {
             $hidden[$val] = $this->vars->{$val};
         }
         $view->hidden = $hidden;
         $view->tabindex = 1;
         $view->title = $this->title;
         if (!$this->vars->template_mode) {
             $view->send_msg = true;
             $view->save_draft = $imp_imap->access(IMP_Imap::ACCESS_DRAFTS) && !$readonly_drafts;
         }
         $view->resume = $resume;
         $view->di_locked = $prefs->isLocked('default_identity');
         if ($view->di_locked) {
             $view->fromaddr_locked = $prefs->isLocked('from_addr');
             try {
                 $view->from = $identity->getFromLine(null, $this->vars->from);
             } catch (Horde_Exception $e) {
             }
         } else {
             $select_list = $identity->getSelectList();
             $view->last_identity = $identity->getDefault();
             if (count($select_list) > 1) {
                 $view->count_select_list = true;
                 $t_select_list = array();
                 foreach ($select_list as $key => $select) {
                     $t_select_list[] = array('label' => $select, 'selected' => $key == $identity->getDefault(), 'value' => $key);
                 }
                 $view->select_list = $t_select_list;
             } else {
                 $view->identity_default = $identity->getDefault();
                 $view->identity_text = $select_list[0];
             }
         }
         $view->signature = $identity->hasSignature(true);
         $addr_array = array('to' => _("_To"), 'cc' => _("_Cc"), 'bcc' => _("_Bcc"));
         $address_array = array();
         foreach ($addr_array as $val => $label) {
             $address_array[] = array('id' => $val, 'label' => $label, 'val' => $header[$val]);
         }
         $view->addr = $address_array;
         $view->subject = $header['subject'];
         if ($prefs->getValue('set_priority')) {
             $view->set_priority = true;
             $priorities = array('high' => _("High"), 'normal' => _("Normal"), 'low' => _("Low"));
             $priority_option = array();
             foreach ($priorities as $key => $val) {
                 $priority_option[] = array('label' => $val, 'selected' => $priority == $key, 'val' => $key);
             }
             $view->pri_opt = $priority_option;
         }
         $compose_options = array();
         if ($registry->hasMethod('contacts/search')) {
             $compose_options[] = array('url' => $blank_url->copy()->link(array('class' => 'widget', 'id' => 'addressbook_popup')), 'img' => Horde_Themes_Image::tag('addressbook_browse.png'), 'label' => _("Address Book"));
             $js_vars['ImpCompose.contacts_url'] = strval(IMP_Basic_Contacts::url()->setRaw(true));
         }
         if ($spellcheck) {
             $compose_options[] = array('url' => $blank_url->copy()->link(array('class' => 'widget', 'id' => 'spellcheck')), 'img' => '', 'label' => '');
         }
         if ($attach_upload) {
             $url = new Horde_Url('#attachments');
             $compose_options[] = array('url' => $url->link(array('class' => 'widget')), 'img' => Horde_Themes_Image::tag('attachment.png'), 'label' => _("Attachments"));
         }
         $view->compose_options = $compose_options;
         if ($imp_imap->access(IMP_Imap::ACCESS_FOLDERS) && !$prefs->isLocked('save_sent_mail')) {
             $view->ssm = true;
             if ($readonly_sentmail) {
                 $notification->push(sprintf(_("Cannot save sent-mail message to \"%s\" as that mailbox is read-only.", $sent_mail->display), 'horde.warning'));
             }
             $view->ssm_selected = $reload ? $save_sent_mail : $sent_mail && $identity->saveSentmail();
             if ($this->vars->sent_mail) {
                 $sent_mail = IMP_Mailbox::formFrom($this->vars->sent_mail);
             }
             if (!$prefs->isLocked(IMP_Mailbox::MBOX_SENT)) {
                 $iterator = new IMP_Ftree_IteratorFilter($injector->getInstance('IMP_Ftree'));
                 $iterator->add($iterator::NONIMAP);
                 $iterator->mboxes = array('INBOX');
                 $ssm_options = array('abbrev' => false, 'basename' => true, 'iterator' => $iterator, 'selected' => $sent_mail);
                 /* Check to make sure the sent-mail mailbox is created -
                  * it needs to exist to show up in drop-down list. */
                 if ($sent_mail) {
                     $sent_mail->create();
                 }
                 $view->ssm_mboxes = new IMP_Ftree_Select($ssm_options);
             } else {
                 if ($sent_mail) {
                     $sent_mail = '&quot;' . $sent_mail->display_html . '&quot;';
                 }
                 $view->ssm_mbox = $sent_mail;
             }
         }
         $view->rrr_selected = $prefs->isLocked('request_mdn') ? null : $prefs->getValue('request_mdn') == 'always' || $request_read_receipt;
         if (!is_null($rtemode) && !$prefs->isLocked('compose_html')) {
             $view->compose_html = true;
             $view->html_switch = $blank_url->copy()->link(array('id' => 'rte_toggle', 'title' => _("Switch Composition Method")));
             $view->rtemode = $rtemode;
         }
         if (isset($replyauto_all)) {
             $view->replyauto_all = $replyauto_all;
         } elseif (isset($replyauto_list)) {
             $view->replyauto_list = true;
             if (isset($replyauto_list_id)) {
                 $view->replyauto_list_id = $replyauto_list_id;
             }
         }
         if (isset($reply_lang)) {
             $view->reply_lang = implode(',', $reply_lang);
         }
         $view->message = $msg;
         if ($signatureChanged) {
             $view->signatureContent = $signature;
         }
         if ($prefs->getValue('use_pgp') || $prefs->getValue('use_smime')) {
             if ($prefs->isLocked('default_encrypt')) {
                 $view->use_encrypt = false;
             } else {
                 $view->use_encrypt = true;
                 $view->encrypt_options = $imp_ui->encryptList($encrypt_options);
             }
             if ($prefs->getValue('use_pgp') && $prefs->getValue('pgp_public_key')) {
                 $view->pgp_options = true;
                 $view->pgp_attach_pubkey = $reload ? $this->vars->pgp_attach_pubkey : $prefs->getValue('pgp_attach_pubkey');
             }
         }
         if ($registry->hasMethod('contacts/ownVCard')) {
             $view->vcard = true;
             $view->attach_vcard = $this->vars->vcard;
         }
         if ($attach_upload) {
             $view->attach_size = IMP::numberFormat($imp_compose->maxAttachmentSize(), 0);
             $view->maxattachmentnumber = !$max_attach;
             $save_attach = $prefs->getValue('save_attachments');
             if ($view->ssm && !$prefs->isLocked('save_attachments')) {
                 $view->show_link_save_attach = true;
                 $view->attach_options = array(array('label' => _("Save attachments with message in sent-mail mailbox?"), 'name' => 'save_attachments_select', 'val' => $reload ? $this->vars->save_attachments_select : $save_attach == 'always'));
             }
             if (count($imp_compose)) {
                 $view->numberattach = true;
                 $atc = array();
                 $v = $injector->getInstance('IMP_Factory_MimeViewer');
                 foreach ($imp_compose as $data) {
                     $mime = $data->getPart();
                     $type = $mime->getType();
                     $entry = array('name' => $mime->getName(true), 'icon' => $v->getIcon($type), 'number' => $data->id, 'type' => $type, 'size' => $mime->getSize(), 'description' => $mime->getDescription(true));
                     if (!(isset($fwd_msg) && $fwd_msg['type'] != IMP_Compose::FORWARD_BODY) && $type != 'application/octet-stream') {
                         $entry['name'] = $data->viewUrl()->link(array('class' => 'link', 'target' => 'compose_preview_window', 'title' => _("Preview"))) . htmlspecialchars($entry['name']) . '</a>';
                     }
                     $atc[] = $entry;
                 }
                 $view->atc = $atc;
             }
         }
         $this->output = $view->render('basic/compose/compose');
     }
     $page_output->addScriptPackage('IMP_Script_Package_ComposeBase');
     $page_output->addScriptFile('compose.js');
     $page_output->addScriptFile('editor.js');
     $page_output->addScriptFile('imp.js');
     $page_output->addInlineJsVars($js_vars);
     if (!$redirect) {
         $imp_ui->addIdentityJs();
     }
     if ($rtemode && !$redirect) {
         $page_output->addScriptPackage('IMP_Script_Package_Editor');
     }
 }