Example #1
0
File: Zip.php Project: horde/horde
 /**
  * Return the rendered information about the Horde_Mime_Part object.
  *
  * @return array  See parent::render().
  * @throws Horde_Exception
  */
 protected function _renderInfo()
 {
     $charset = $this->getConfigParam('charset');
     $contents = $this->_mimepart->getContents();
     if (!$this->getConfigParam('zip')) {
         $this->setConfigParam('zip', Horde_Compress::factory('Zip'));
     }
     $zipInfo = $this->getConfigParam('zip')->decompress($contents, array('action' => Horde_Compress_Zip::ZIP_LIST));
     $fileCount = count($zipInfo);
     $name = $this->_mimepart->getName(true);
     if (empty($name)) {
         $name = Horde_Mime_Viewer_Translation::t("unnamed");
     }
     $monospace = $this->getConfigParam('monospace');
     $text = '<table><tr><td align="left"><span ' . ($monospace ? 'class="' . $monospace . '">' : 'style="font-family:monospace">') . $this->_textFilter(Horde_Mime_Viewer_Translation::t("Archive Name") . ': ' . $name . "\n" . Horde_Mime_Viewer_Translation::t("Archive File Size") . ': ' . strlen($contents) . " bytes\n" . sprintf(Horde_Mime_Viewer_Translation::ngettext("File Count: %d file", "File Count: %d files", $fileCount), $fileCount) . "\n\n" . str_repeat(' ', 15) . Horde_String::pad(Horde_Mime_Viewer_Translation::t("Attributes"), 10, ' ', STR_PAD_LEFT) . Horde_String::pad(Horde_Mime_Viewer_Translation::t("Size"), 10, ' ', STR_PAD_LEFT) . Horde_String::pad(Horde_Mime_Viewer_Translation::t("Modified Date"), 19, ' ', STR_PAD_LEFT) . Horde_String::pad(Horde_Mime_Viewer_Translation::t("Method"), 10, ' ', STR_PAD_LEFT) . Horde_String::pad(Horde_Mime_Viewer_Translation::t("Ratio"), 10, ' ', STR_PAD_LEFT) . "\n", 'Space2html', array('charset' => $charset, 'encode' => true, 'encode_all' => true)) . str_repeat('-', 74) . "\n";
     foreach ($zipInfo as $key => $val) {
         $ratio = empty($val['size']) ? 0 : 100 * ($val['csize'] / $val['size']);
         $val['name'] = Horde_String::pad(Horde_String::truncate($val['name'], 15), 15, ' ', STR_PAD_RIGHT);
         $val['attr'] = Horde_String::pad($val['attr'], 10, ' ', STR_PAD_LEFT);
         $val['size'] = Horde_String::pad($val['size'], 10, ' ', STR_PAD_LEFT);
         $val['date'] = Horde_String::pad(strftime("%d-%b-%Y %H:%M", $val['date']), 19, ' ', STR_PAD_LEFT);
         $val['method'] = Horde_String::pad($val['method'], 10, ' ', STR_PAD_LEFT);
         $val['ratio'] = Horde_String::pad(sprintf("%1.1f%%", $ratio), 10, ' ', STR_PAD_LEFT);
         reset($val);
         while (list($k, $v) = each($val)) {
             $val[$k] = $this->_textFilter($v, 'Space2html', array('charset' => $charset, 'encode' => true, 'encode_all' => true));
         }
         if (!is_null($this->_callback)) {
             $val = call_user_func($this->_callback, $key, $val);
         }
         $text .= $val['name'] . $val['attr'] . $val['size'] . $val['date'] . $val['method'] . $val['ratio'] . "\n";
     }
     return $this->_renderReturn(nl2br($text . str_repeat('-', 74) . "\n</span></td></tr></table>"), 'text/html; charset=' . $charset);
 }
Example #2
0
 /**
  */
 public function display(Horde_Core_Prefs_Ui $ui)
 {
     global $injector, $page_output, $prefs;
     $page_output->addScriptFile('hordecore.js', 'horde');
     $page_output->addScriptFile('prefs/searches.js');
     $p_css = new Horde_Themes_Element('prefs.css');
     $page_output->addStylesheet($p_css->fs, $p_css->uri);
     $imp_search = $injector->getInstance('IMP_Search');
     $fout = $vout = array();
     $view = new Horde_View(array('templatePath' => IMP_TEMPLATES . '/prefs'));
     $view->addHelper('FormTag');
     $view->addHelper('Tag');
     $view->addHelper('Text');
     $vfolder_locked = $prefs->isLocked('vfolder');
     $iterator = IMP_Search_IteratorFilter::create(IMP_Search_IteratorFilter::DISABLED | IMP_Search_IteratorFilter::VFOLDER);
     foreach ($iterator as $val) {
         if (!$val->prefDisplay) {
             continue;
         }
         $editable = !$vfolder_locked && $imp_search->isVFolder($val, true);
         $m_url = $val->enabled ? $val->mbox_ob->url('mailbox')->link() : null;
         $vout[] = array('description' => Horde_String::truncate($val->querytext, 200), 'edit' => $editable ? $imp_search->editUrl($val) : null, 'enabled' => $val->enabled, 'enabled_locked' => $vfolder_locked, 'key' => $val->id, 'label' => $val->label, 'm_url' => $m_url);
     }
     $view->vfolders = $vout;
     $filter_locked = $prefs->isLocked('filter');
     $iterator = IMP_Search_IteratorFilter::create(IMP_Search_IteratorFilter::DISABLED | IMP_Search_IteratorFilter::FILTER);
     foreach ($iterator as $val) {
         if (!$val->prefDisplay) {
             continue;
         }
         $editable = !$filter_locked && $imp_search->isFilter($val, true);
         $fout[] = array('description' => Horde_String::truncate($val->querytext, 200), 'edit' => $editable ? $imp_search->editUrl($val) : null, 'enabled' => $val->enabled, 'enabled_locked' => $filter_locked, 'key' => $val->id, 'label' => $val->label);
     }
     $view->filters = $fout;
     if (empty($fout) && empty($vout)) {
         $view->nosearches = true;
     } else {
         $GLOBALS['page_output']->addInlineJsVars(array('ImpSearchesPrefs.confirm_delete_filter' => _("Are you sure you want to delete this filter?"), 'ImpSearchesPrefs.confirm_delete_vfolder' => _("Are you sure you want to delete this virtual folder?")));
     }
     return $view->render('searches');
 }
Example #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');
     }
 }
Example #4
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';
 }
Example #5
0
 /**
  * Parses a vEvent into the message properties.
  *
  * @param Horde_Icalendar_Vevent $vevent  The vEvent to parse.
  * @param string $method                  The method (e.g., 'REQUEST').
  *
  * @throws Horde_ActiveSync_Exception
  */
 protected function _parsevEvent($vevent, $method = 'REQUEST')
 {
     if ($method == 'REQUEST') {
         $this->responserequested = '1';
     } else {
         $this->responserequested = '0';
     }
     try {
         $organizer = parse_url($vevent->getAttribute('ORGANIZER'));
         $this->organizer = $organizer['path'];
     } catch (Horde_Icalendar_Exception $e) {
     }
     try {
         $this->globalobjid = Horde_Mapi::createGoid($vevent->getAttribute('UID'));
         $this->starttime = new Horde_Date($vevent->getAttribute('DTSTART'));
         $this->endtime = new Horde_Date($vevent->getAttribute('DTEND'));
     } catch (Horde_Exception $e) {
         throw new Horde_ActiveSync_Exception($e);
     }
     try {
         $this->dtstamp = new Horde_Date($vevent->getAttribute('DTSTAMP'));
     } catch (Horde_Exception $e) {
     }
     try {
         $this->location = Horde_String::truncate($vevent->getAttribute('LOCATION'), 255);
     } catch (Horde_Icalendar_Exception $e) {
     }
     try {
         $class = $vevent->getAttribute('CLASS');
         if (!is_array($class)) {
             $this->sensitivity = $class == 'PRIVATE' ? Horde_ActiveSync_Message_Appointment::SENSITIVITY_PRIVATE : ($class == 'CONFIDENTIAL' ? Horde_ActiveSync_Message_Appointment::SENSITIVITY_CONFIDENTIAL : ($class == 'PERSONAL' ? Horde_ActiveSync_Message_Appointment::SENSITIVITY_PERSONAL : Horde_ActiveSync_Message_Appointment::SENSITIVITY_NORMAL));
         }
     } catch (Horde_Icalendar_Exception $e) {
     }
     try {
         $status = $vevent->getAttribute('STATUS');
         if (!is_array($status)) {
             $status = Horde_String::upper($status);
             $this->busystatus = $status == 'TENTATIVE' ? Horde_ActiveSync_Message_Appointment::BUSYSTATUS_TENTATIVE : ($status == 'CONFIRMED' ? Horde_ActiveSync_Message_Appointment::BUSYSTATUS_BUSY : Horde_ActiveSync_Message_Appointment::BUSYSTATUS_FREE);
         }
     } catch (Horde_Icalendar_Exception $e) {
     }
     // vCalendar 1.0 alarms
     try {
         $alarm = $vevent->getAttribute('AALARM');
         if (!is_array($alarm) && intval($alarm)) {
             $this->reminder = intval($this->starttime->timestamp() - $alarm);
         }
     } catch (Horde_Icalendar_Exception $e) {
     }
     // vCalendar 2.0 alarms
     foreach ($vevent->getComponents() as $alarm) {
         if (!$alarm instanceof Horde_Icalendar_Valarm) {
             continue;
         }
         try {
             $trigger = $alarm->getAttribute('TRIGGER');
             $triggerParams = $alarm->getAttribute('TRIGGER', true);
         } catch (Horde_Icalendar_Exception $e) {
             continue;
         }
         if (isset($triggerParams['VALUE']) && $triggerParams['VALUE'] == 'DATE-TIME') {
             if (isset($triggerParams['RELATED']) && $triggerParams['RELATED'] == 'END') {
                 $this->reminder = intval($this->endtime->timestamp() - $trigger);
             } else {
                 $this->reminder = intval($this->starttime->timestamp() - $trigger);
             }
         } else {
             $this->reminder = -intval($trigger);
         }
     }
 }
Example #6
0
 /**
  * Imports an event parsed from a string.
  *
  * @param string $text      The text to parse into an event
  * @param string $calendar  The calendar into which the event will be
  *                          imported.  If 'null', the user's default
  *                          calendar will be used.
  *
  * @return array  The UID of all events that were added.
  * @throws Kronolith_Exception
  */
 public function quickAdd($text, $calendar = null)
 {
     $text = trim($text);
     if (strpos($text, "\n") !== false) {
         list($title, $description) = explode($text, "\n", 2);
     } else {
         $title = $text;
         $description = '';
     }
     $title = trim($title);
     $description = trim($description);
     $dateParser = Horde_Date_Parser::factory(array('locale' => $GLOBALS['language']));
     $r = $dateParser->parse($title, array('return' => 'result'));
     if (!($d = $r->guess())) {
         throw new Horde_Exception(sprintf(_("Cannot parse event description \"%s\""), Horde_String::truncate($text)));
     }
     $title = $r->untaggedText();
     $kronolith_driver = self::getDriver(null, $calendar);
     $event = $kronolith_driver->getEvent();
     $event->initialized = true;
     $event->title = $title;
     $event->description = $description;
     $event->start = $d;
     $event->end = $d->add(array('hour' => 1));
     $event->save();
     return $event;
 }
Example #7
0
 /**
  * Redirect the message.
  *
  * Variables used:
  *   - composeCache: (string) The IMP_Compose cache identifier.
  *   - redirect_to: (string) The address(es) to redirect to.
  *
  * @return object  An object with the following entries:
  *   - action: (string) 'redirectMessage'.
  *   - success: (integer) 1 on success, 0 on failure.
  */
 public function redirectMessage()
 {
     $result = new stdClass();
     $result->action = 'redirectMessage';
     $result->success = 1;
     try {
         $imp_compose = $GLOBALS['injector']->getInstance('IMP_Factory_Compose')->create($this->vars->composeCache);
         $res = $imp_compose->sendRedirectMessage($this->vars->redirect_to);
         foreach ($res as $val) {
             $subject = $val->headers->getValue('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;
 }
Example #8
0
        $realname = $currFile->getFileName();
        $mimeType = Horde_Mime_Magic::filenameToMIME($realname);
        $currFile->mimeType = $mimeType;
        if (Horde_String::lower(Horde_String::substr($realname, 0, 6)) == 'readme') {
            $readmes[] = $currFile;
        }
        $icon = $injector->getInstance('Horde_Core_Factory_MimeViewer')->getIcon($mimeType);
        $author = Chora::showAuthorName($lg->getAuthor());
        $filerev = $lg->getRevision();
        $date = $lg->getDate();
        $log = $lg->getMessage();
        $attic = $currFile->isDeleted();
        $fileName = $where . ($attic ? '/' . 'Attic' : '') . '/' . $realname;
        $name = $injector->getInstance('Horde_Core_Factory_TextFilter')->filter($realname, 'space2html', array('encode' => true, 'encode_all' => true));
        $url = Chora::url('browsefile', $fileName, $branchArgs);
        $readableDate = Chora::readableTime($date);
        if ($log) {
            $shortLog = Horde_String::truncate(str_replace("\n", ' ', trim($log)), $conf['options']['shortLogLength']);
        }
        require CHORA_TEMPLATES . '/directory/file.inc';
    }
    echo '</tbody>';
}
echo '</table>';
if ($readmes) {
    $readmeCollection = new Chora_Readme_Collection($readmes);
    $readmeFile = $readmeCollection->chooseReadme();
    $readmeRenderer = new Chora_Renderer_File_Html($injector->createInstance('Horde_View'), $readmeFile, $readmeFile->getRevision());
    echo $readmeRenderer->render();
}
$page_output->footer();
Example #9
0
 /**
  */
 protected function _init()
 {
     global $injector, $notification, $page_output, $registry, $session;
     $imp_mailbox = $this->indices->mailbox->list_ob;
     switch ($mode = $this->vars->get('mode', 'thread')) {
         case 'thread':
             /* THREAD MODE: Make sure we have a valid index. */
             list($m, $u) = $this->indices->getSingle();
             $imp_indices = $imp_mailbox->getFullThread($u, $m);
             break;
         default:
             /* MSGVIEW MODE: Make sure we have a valid list of messages. */
             $imp_indices = $this->indices;
             break;
     }
     if (!count($imp_indices)) {
         $notification->push(_("Could not load message."), 'horde.error');
         $this->indices->mailbox->url('mailbox')->redirect();
     }
     /* Run through action handlers. */
     switch ($this->vars->actionID) {
         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;
     }
     $msgs = $tree = array();
     $subject = '';
     $page_label = $this->indices->mailbox->label;
     $imp_ui = $injector->getInstance('IMP_Message_Ui');
     $query = new Horde_Imap_Client_Fetch_Query();
     $query->envelope();
     /* Force images to show in HTML data. */
     $injector->getInstance('IMP_Images')->alwaysShow = true;
     $multiple = count($imp_indices) > 1;
     foreach ($imp_indices as $ob) {
         $imp_imap = $ob->mbox->imp_imap;
         $fetch_res = $imp_imap->fetch($ob->mbox, $query, array('ids' => $imp_imap->getIdsOb($ob->uids)));
         foreach ($ob->uids as $idx) {
             $envelope = $fetch_res[$idx]->getEnvelope();
             /* Get the body of the message. */
             $curr_msg = $curr_tree = array();
             $contents = $injector->getInstance('IMP_Factory_Contents')->create($ob->mbox->getIndicesOb($idx));
             $mime_id = $contents->findBody();
             if ($contents->canDisplay($mime_id, IMP_Contents::RENDER_INLINE)) {
                 $ret = $contents->renderMIMEPart($mime_id, IMP_Contents::RENDER_INLINE);
                 $ret = reset($ret);
                 $curr_msg['body'] = $ret['data'];
                 if (!empty($ret['js'])) {
                     $page_output->addInlineScript($ret['js'], true);
                 }
             } else {
                 $curr_msg['body'] = '<em>' . _("There is no text that can be displayed inline.") . '</em>';
             }
             $curr_msg['idx'] = $idx;
             /* Get headers for the message. */
             $date_ob = new IMP_Message_Date($envelope->date);
             $curr_msg['date'] = $date_ob->format($date_ob::DATE_LOCAL);
             if ($this->indices->mailbox->special_outgoing) {
                 $curr_msg['addr_to'] = true;
                 $curr_msg['addr'] = _("To:") . ' ' . $imp_ui->buildAddressLinks($envelope->to, Horde::selfUrlParams());
                 $addr = _("To:") . ' ' . htmlspecialchars($envelope->to[0]->label, ENT_COMPAT, 'UTF-8');
             } else {
                 $from = $envelope->from;
                 $curr_msg['addr_to'] = false;
                 $curr_msg['addr'] = $imp_ui->buildAddressLinks($from, Horde::selfUrlParams());
                 $addr = htmlspecialchars($from[0]->label, ENT_COMPAT, 'UTF-8');
             }
             $subject_header = htmlspecialchars($envelope->subject, ENT_COMPAT, 'UTF-8');
             switch ($mode) {
                 case 'thread':
                     if (empty($subject)) {
                         $subject = preg_replace('/^re:\\s*/i', '', $subject_header);
                     }
                     $curr_msg['link'] = $multiple ? Horde::widget(array('url' => '#display', 'title' => _("Thread List"), 'nocheck' => true)) : '';
                     $curr_tree['subject'] = $imp_mailbox->getThreadOb($imp_mailbox->getArrayIndex($fetch_res[$idx]->getUid(), $ob->mbox) + 1)->img;
                     break;
                 default:
                     $curr_msg['link'] = Horde::widget(array('url' => '#display', 'title' => _("Back to Multiple Message View Index"), 'nocheck' => true));
                     $curr_tree['subject'] = '';
                     break;
             }
             switch ($registry->getView()) {
                 case $registry::VIEW_BASIC:
                     $curr_msg['link'] .= ' | ' . Horde::widget(array('url' => $this->indices->mailbox->url('message', $idx), 'title' => _("Go to Message"), 'nocheck' => true)) . ' | ' . Horde::widget(array('url' => $this->indices->mailbox->url('mailbox')->add(array('start' => $imp_mailbox->getArrayIndex($idx))), 'title' => sprintf(_("Bac_k to %s"), $page_label)));
                     break;
             }
             $curr_tree['subject'] .= Horde::link('#i' . $idx) . Horde_String::truncate($subject_header, 60) . '</a> (' . $addr . ')';
             $msgs[] = $curr_msg;
             $tree[] = $curr_tree;
         }
     }
     /* Flag messages as seen. */
     $injector->getInstance('IMP_Message')->flag(array('add' => array(Horde_Imap_Client::FLAG_SEEN)), $imp_indices);
     $view = new Horde_View(array('templatePath' => IMP_TEMPLATES . '/thread'));
     if ($mode == 'thread') {
         $view->subject = $subject;
         $view->thread = true;
         switch ($registry->getView()) {
             case $registry::VIEW_BASIC:
                 $uid_list = $imp_indices[strval($this->indices->mailbox)];
                 $delete_link = $this->indices->mailbox->url('mailbox')->add(array('actionID' => 'delete_messages', 'indices' => strval($imp_indices), 'token' => $session->getToken(), 'start' => $imp_mailbox->getArrayIndex(end($uid_list))));
                 $view->delete = Horde::link($delete_link, _("Delete Thread"), null, null, null, null, null, array('id' => 'threaddelete'));
                 $page_output->addInlineScript(array('$("threaddelete").observe("click", function(e) { if (!window.confirm(' . json_encode(_("Are you sure you want to delete all messages in this thread?")) . ')) { e.stop(); } })'), true);
                 break;
         }
     } else {
         $view->subject = sprintf(_("%d Messages"), count($msgs));
     }
     $view->messages = $msgs;
     $view->tree = $tree;
     $page_output->addScriptFile('stripe.js', 'horde');
     $page_output->addScriptFile('toggle_quotes.js', 'horde');
     $page_output->noDnsPrefetch();
     $this->output = $view->render('thread');
     switch ($registry->getView()) {
         case $registry::VIEW_DYNAMIC:
             $page_output->topbar = $page_output->sidebar = false;
             $this->header_params = array('html_id' => 'htmlAllowScroll');
             break;
     }
     $this->title = $mode == 'thread' ? _("Thread View") : _("Multiple Message View");
 }
Example #10
0
 /**
  * Add mail message(s) from the mail server as a message/rfc822
  * attachment.
  *
  * @param IMP_Indices $indices  An indices object.
  *
  * @return string  Subject string.
  *
  * @throws IMP_Exception
  */
 public function attachImapMessage($indices)
 {
     if (!count($indices)) {
         return false;
     }
     $attached = 0;
     foreach ($indices as $ob) {
         foreach ($ob->uids as $idx) {
             ++$attached;
             $contents = $GLOBALS['injector']->getInstance('IMP_Factory_Contents')->create(new IMP_Indices($ob->mbox, $idx));
             $headerob = $contents->getHeader();
             $part = new Horde_Mime_Part();
             $part->setCharset('UTF-8');
             $part->setType('message/rfc822');
             $part->setName(_("Forwarded Message"));
             $part->setContents($contents->fullMessageText(array('stream' => true)), array('usestream' => true));
             // Throws IMP_Compose_Exception.
             $this->addAttachmentFromPart($part);
             $part->clearContents();
         }
     }
     if ($attached > 1) {
         return 'Fwd: ' . sprintf(_("%u Forwarded Messages"), $attached);
     }
     if ($name = $headerob['Subject']) {
         $name = Horde_String::truncate($name, 80);
     } else {
         $name = _("[No Subject]");
     }
     return 'Fwd: ' . strval(new Horde_Imap_Client_Data_BaseSubject($name, array('keepblob' => true)));
 }
<li>
  <a href="<?php 
echo $entry->link() == '' ? 'http://www.horde.org' : HordeWeb_Utils::wrapLink($entry->link());
?>
"><?php 
echo $entry->title();
?>
</a>
  <div class="description"><?php 
echo Horde_String::truncate(strip_tags($entry->description()), 180);
?>
</div>
</li>
Example #12
0
 /**
  * URL Parameters:
  *   - a: (string) Action ID.
  *   - checkbox: TODO
  *   - p: (integer) Page.
  *   - search: (sring) The search string
  *   - start: (integer) Start.
  *   - t: (string) Token.
  */
 protected function _init()
 {
     global $injector, $notification, $prefs, $session;
     $imp_imap = $this->indices->mailbox->imp_imap;
     $imp_search = $injector->getInstance('IMP_Search');
     /* Determine if mailbox is readonly. */
     $readonly = $this->indices->mailbox->readonly;
     /* Get the base URL for this page. */
     $mailbox_url = self::url(array('mailbox' => $this->indices->mailbox));
     /* Perform message actions (via advanced UI). */
     switch ($this->vars->checkbox) {
         // 'd' = delete message
         // 'u' = undelete message
         case 'd':
         case 'u':
             $imp_message = $injector->getInstance('IMP_Message');
             if ($this->vars->checkbox == 'd') {
                 try {
                     $session->checkToken($this->vars->t);
                     $imp_message->delete($this->indices);
                 } catch (Horde_Exception $e) {
                     $notification->push($e);
                 }
             } else {
                 $imp_message->undelete($this->indices);
             }
             break;
             // 'rs' = report spam
             // 'ri' = report innocent
         // 'rs' = report spam
         // 'ri' = report innocent
         case 'rs':
         case 'ri':
             $injector->getInstance('IMP_Factory_Spam')->create($this->vars->checkbox == 'rs' ? IMP_Spam::SPAM : IMP_Spam::INNOCENT)->report($this->indices);
             break;
     }
     /* Run through the action handlers. */
     switch ($this->vars->a) {
         // 'm' = message missing
         case 'm':
             $notification->push(_("There was an error viewing the requested message."), 'horde.error');
             break;
             // 'e' = expunge mailbox
         // 'e' = expunge mailbox
         case 'e':
             $injector->getInstance('IMP_Message')->expungeMailbox(array(strval($this->indices->mailbox) => 1));
             break;
             // 'ds' = do search
         // 'ds' = do search
         case 'ds':
             if (!empty($this->vars->search) && $this->indices->mailbox->access_search) {
                 /* Create the search query and reset the global mailbox
                  * variable. */
                 $q_ob = $imp_search->createQuery(array(new IMP_Search_Element_Text($this->vars->search, false)), array('mboxes' => array($this->indices->mailbox)));
                 /* Need to re-calculate these values. */
                 $this->indices->mailbox = IMP_Mailbox::get($q_ob);
                 $readonly = $this->indices->mailbox->readonly;
                 $mailbox_url = self::url(array('mailbox' => $this->indices->mailbox));
             }
             break;
     }
     /* Build the list of messages in the mailbox. */
     $imp_mailbox = $this->indices->mailbox->list_ob;
     $pageOb = $imp_mailbox->buildMailboxPage($this->vars->p, $this->vars->start);
     /* Generate page title. */
     $this->title = $this->indices->mailbox->display;
     /* Modify title for display on page. */
     if ($pageOb['msgcount']) {
         $this->title .= ' (';
         if ($imp_imap->access(IMP_Imap::ACCESS_UNSEEN)) {
             $unseen = $imp_mailbox->unseenMessages(Horde_Imap_Client::SEARCH_RESULTS_COUNT);
             $this->title .= sprintf(_("%d unseen"), $unseen) . '/';
         }
         $this->title .= sprintf(_("%d total"), $pageOb['msgcount']) . ')';
     }
     if ($pageOb['pagecount'] > 1) {
         $this->title .= ' - ' . sprintf(_("%d of %d"), $pageOb['page'], $pageOb['pagecount']);
     }
     if ($readonly) {
         $this->title .= ' [' . _("Read-Only") . ']';
     }
     $this->view->title = $this->title;
     /* Build the array of message information. */
     $imp_ui = new IMP_Mailbox_Ui($this->indices->mailbox);
     $mbox_info = $imp_mailbox->getMailboxArray(range($pageOb['begin'], $pageOb['end']), array('headers' => true));
     $msgs = array();
     while (list(, $ob) = each($mbox_info['overview'])) {
         /* Initialize the header fields. */
         $msg = array('buid' => $imp_mailbox->getBuid($ob['mailbox'], $ob['uid']), 'status' => '', 'subject' => trim($imp_ui->getSubject($ob['envelope']->subject)));
         /* Format the from header. */
         $getfrom = $imp_ui->getFrom($ob['envelope']);
         $msg['from'] = $getfrom['from'];
         /* Get flag information. */
         $flag_parse = $injector->getInstance('IMP_Flags')->parse(array('flags' => $ob['flags'], 'headers' => $ob['headers'], 'personal' => $ob['envelope']->to));
         foreach ($flag_parse as $val) {
             if ($abbrev = $val->abbreviation) {
                 $msg['status'] .= $abbrev;
             } elseif ($val instanceof IMP_Flag_User) {
                 $msg['subject'] = '*' . Horde_String::truncate($val->label, 8) . '* ' . $msg['subject'];
             }
         }
         /* Generate the target link. */
         if ($this->indices->mailbox->templates) {
             $compose = 't';
         } elseif ($this->indices->mailbox->draft || in_array(Horde_Imap_Client::FLAG_DRAFT, $ob['flags'])) {
             $compose = 'd';
         } else {
             $msg['target'] = IMP_Minimal_Message::url(array('buid' => $msg['buid'], 'mailbox' => $this->indices->mailbox));
         }
         if (!isset($msg['target'])) {
             $clink = new IMP_Compose_Link();
             $msg['target'] = $clink->link()->add(array('a' => $compose, 'buid' => $msg['buid'], 'bodypart' => 1, 'mailbox' => $this->indices->mailbox));
         }
         $msgs[] = $msg;
     }
     $this->view->msgs = $msgs;
     $mailbox = $mailbox_url->copy()->add('p', $pageOb['page']);
     $menu = array(array(_("Refresh"), $mailbox));
     $search_mbox = $this->indices->mailbox->search;
     /* Determine if we are going to show the Purge Deleted link. */
     if (!$prefs->getValue('use_trash') && !$this->indices->mailbox->vinbox && $this->indices->mailbox->access_expunge) {
         $menu[] = array(_("Purge Deleted"), $mailbox->copy()->add('a', 'e'));
     }
     /* Add search link. */
     if ($this->indices->mailbox->access_search) {
         if ($search_mbox) {
             $mboxes = $imp_search[strval($this->indices->mailbox)]->mboxes;
             $orig_mbox = IMP_Mailbox::get(reset($mboxes));
             $menu[] = array(sprintf(_("New Search in %s"), $orig_mbox->label), IMP_Minimal_Search::url(array('mailbox' => $orig_mbox)));
         } else {
             $menu[] = array(_("Search"), IMP_Minimal_Search::url(array('mailbox' => $this->indices->mailbox)));
         }
     }
     /* Generate page links. */
     if ($pageOb['page'] != 1) {
         $menu[] = array(_("First Page"), $mailbox_url->copy()->add('p', 1));
         $menu[] = array(_("Previous Page"), $mailbox_url->copy()->add('p', $pageOb['page'] - 1));
     }
     if ($pageOb['page'] != $pageOb['pagecount']) {
         $menu[] = array(_("Next Page"), $mailbox_url->copy()->add('p', $pageOb['page'] + 1));
         $menu[] = array(_("Last Page"), $mailbox_url->copy()->add('p', $pageOb['pagecount']));
     }
     $this->view->menu = $this->getMenu('mailbox', $menu);
     $this->view->checkbox = $mailbox_url->copy()->add('p', $pageOb['page']);
     $this->view->delete = $this->indices->mailbox->access_deletemsgs;
     $this->view->t = $session->getToken();
     $this->_pages[] = 'mailbox';
     $this->_pages[] = 'menu';
 }
Example #13
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;
 }
Example #14
0
 /**
  * Return data for costobjects, optionally filtered by client_ids.
  *
  * @param mixed $client_ids  A client id or an array of client ids to
  *                           filter cost obejcts by.
  *
  * @return array  An array of cost objects data.
  */
 public static function getCostObjectType($client_ids = null)
 {
     $elts = array('' => _("--- No Cost Object ---"));
     $counter = 0;
     foreach (self::getCostObjects($client_ids) as $category) {
         Horde_Array::arraySort($category['objects'], 'name');
         $elts['category%' . $counter++] = sprintf('--- %s ---', $category['category']);
         foreach ($category['objects'] as $object) {
             $name = Horde_String::truncate($object['name'], 80);
             $hours = 0.0;
             $filter = array('costobject' => $object['id']);
             if (!empty($GLOBALS['conf']['time']['sum_billable_only'])) {
                 $filter['billable'] = true;
             }
             $result = $GLOBALS['injector']->getInstance('Hermes_Driver')->getHours($filter, array('hours'));
             foreach ($result as $entry) {
                 if (!empty($entry['hours'])) {
                     $hours += $entry['hours'];
                 }
             }
             /* Show summary of hours versus estimate for this
              * deliverable. */
             if (empty($object['estimate'])) {
                 $name .= sprintf(_(" (%0.2f hours)"), $hours);
             } else {
                 $name .= sprintf(_(" (%d%%, %0.2f of %0.2f hours)"), (int) ($hours / $object['estimate'] * 100), $hours, $object['estimate']);
             }
             $elts[$object['id']] = $name;
         }
     }
     return $elts;
 }
Example #15
0
    }
    ?>
    <?php 
    echo $this->redirectUrl->add('b', $bookmark->id)->link(array('target' => $this->target)) . $this->h($bookmark->title ? $bookmark->title : $bookmark->url);
    ?>
</a>
    <small>
      <?php 
    echo $this->h($bookmark->url);
    ?>
      <?php 
    if (strlen($bookmark->description)) {
        ?>
      &mdash;
      <?php 
        echo $this->h(Horde_String::truncate($bookmark->description, 200));
        ?>
      <?php 
    }
    ?>
    </small>
    <ul class="horde-tags">
     <?php 
    natcasesort($bookmark->tags);
    ?>
     <?php 
    foreach ($bookmark->tags as $tag) {
        $url = $GLOBALS['injector']->getInstance('Trean_TagBrowser')->addTagLink($tag);
        ?>
     <li><a href="<?php 
        echo $url;
Example #16
0
 /**
  * URL Parameters:
  * <pre>
  *   - criteria_form: (string) JSON representation of the search query.
  *   - edit_query: (integer) If true, edit a search query (contained in
  *                 'mailbox' parameter).
  *   - edit_query_filter: (string) The name of the filter being edited.
  *   - edit_query_vfolder: (string) The name of the virtual folder being
  *                         edited.
  *   - mailbox: (string) Mailbox parameter.
  *   - mailbox_list: (array) A list of mailboxes to process (base64url
  *                   encoded) If empty, uses 'mailbox' parameter.
  *   - mboxes_form: (string) JSON representation of the list of mailboxes
  *                  for the query. Hash containing 2 keys: mbox &
  *                  subfolder. Both values are base64url encoded.
  *   - search_label: (string) The label to use when saving the search.
  *   - search_type: (string) The type of saved search ('filter',
  *                 'vfolder'). If empty, the search should not be saved.
  *   - subfolder: (boolean) If set, search mailbox will default to
  *                subfolder search.
  * </pre>
  */
 protected function _init()
 {
     global $injector, $notification, $page_output, $prefs, $registry;
     /* Define the criteria list. */
     $criteria = array('from' => array('label' => _("From"), 'type' => 'header'), 'recip' => array('label' => _("Recipients (To/Cc/Bcc)"), 'type' => 'header'), 'to' => array('label' => _("To"), 'type' => 'header'), 'cc' => array('label' => _("Cc"), 'type' => 'header'), 'bcc' => array('label' => _("Bcc"), 'type' => 'header'), 'subject' => array('label' => _("Subject"), 'type' => 'header'), 'customhdr' => array('label' => _("Custom Header"), 'type' => 'customhdr'), 'body' => array('label' => _("Body"), 'type' => 'text'), 'text' => array('label' => _("Entire Message"), 'type' => 'text'), 'date_range' => array('label' => _("Date"), 'type' => 'date'), 'older' => array('label' => _("Older Than"), 'type' => 'within'), 'younger' => array('label' => _("Younger Than"), 'type' => 'within'), 'size_smaller' => array('label' => _("Size (KB) <"), 'type' => 'size'), 'size_larger' => array('label' => _("Size (KB) >"), 'type' => 'size'));
     $filters = array('bulk' => array('label' => _("Bulk Messages"), 'type' => 'filter'), 'attach' => array('label' => _("Contains Attachment(s)"), 'type' => 'filter'), 'mailinglist' => array('label' => _("Mailing List Messages"), 'type' => 'filter'), 'personal' => array('label' => _("Personal Messages"), 'type' => 'filter'));
     /* Define some constants. */
     $constants = array('within' => array('d' => IMP_Search_Element_Within::INTERVAL_DAYS, 'm' => IMP_Search_Element_Within::INTERVAL_MONTHS, 'y' => IMP_Search_Element_Within::INTERVAL_YEARS));
     if (isset($this->vars->mailbox_list)) {
         if (is_array($this->vars->mailbox_list)) {
             $default_mailbox = IMP_Mailbox::get('INBOX');
             $search_mailbox = IMP_Mailbox::formFrom($this->vars->mailbox_list);
         } else {
             $default_mailbox = IMP_Mailbox::formFrom($this->vars->mailbox_list);
             $search_mailbox = array($default_mailbox);
         }
     } elseif (isset($this->vars->mailbox)) {
         $default_mailbox = IMP_Mailbox::formFrom($this->vars->mailbox);
         $search_mailbox = array($default_mailbox);
     } else {
         $default_mailbox = IMP_Mailbox::get('INBOX');
         $search_mailbox = array($default_mailbox);
     }
     /* Check that searching is allowed. */
     if (!$injector->getInstance('IMP_Factory_Imap')->create()->access(IMP_Imap::ACCESS_SEARCH)) {
         $default_mailbox->url('mailbox')->redirect();
     }
     $imp_flags = $injector->getInstance('IMP_Flags');
     $imp_search = $injector->getInstance('IMP_Search');
     $dynamic_view = $registry->getView() == Horde_Registry::VIEW_DYNAMIC;
     $js_vars = array();
     /* Generate the search query if 'criteria_form' is present in the form
      * data. */
     if ($this->vars->criteria_form) {
         $c_list = array();
         foreach (json_decode($this->vars->criteria_form) as $val) {
             switch ($val->t) {
                 case 'from':
                 case 'to':
                 case 'cc':
                 case 'bcc':
                 case 'subject':
                     $c_list[] = new IMP_Search_Element_Header($val->v, $val->t, $val->n);
                     break;
                 case 'recip':
                     $c_list[] = new IMP_Search_Element_Recipient($val->v, $val->n);
                     break;
                 case 'customhdr':
                     $c_list[] = new IMP_Search_Element_Header($val->v->s, $val->v->h, $val->n);
                     break;
                 case 'body':
                 case 'text':
                     $c_list[] = new IMP_Search_Element_Text($val->v, $val->t == 'body', $val->n);
                     break;
                 case 'date_range':
                     $c_list[] = new IMP_Search_Element_Daterange($val->b ? new DateTime($val->b) : 0, $val->e ? new DateTime($val->e) : 0, $val->n);
                     break;
                 case 'older':
                 case 'younger':
                     $c_list[] = new IMP_Search_Element_Within($val->v->v, $constants['within'][$val->v->l], $val->t == 'older');
                     break;
                 case 'size_smaller':
                 case 'size_larger':
                     $c_list[] = new IMP_Search_Element_Size($val->v, $val->t == 'size_larger');
                     break;
                 case 'or':
                     $c_list[] = new IMP_Search_Element_Or();
                     break;
                 case 'bulk':
                     $c_list[] = new IMP_Search_Element_Bulk($val->n);
                     break;
                 case 'attach':
                     $c_list[] = new IMP_Search_Element_Attachment($val->n);
                     break;
                 case 'mailinglist':
                     $c_list[] = new IMP_Search_Element_Mailinglist($val->n);
                     break;
                 case 'personal':
                     $c_list[] = new IMP_Search_Element_Personal($val->n);
                     break;
                 case 'flag':
                     /* Flag search. */
                     $formdata = $imp_flags->parseFormId(rawurldecode($val->v));
                     $c_list[] = new IMP_Search_Element_Flag($formdata['flag'], $formdata['set'] && !$val->n);
                     break;
             }
         }
         $redirect_dynamic = true;
         $redirect_target = false;
         switch ($this->vars->search_type) {
             case 'filter':
                 $q_ob = $imp_search->createQuery($c_list, array('id' => IMP_Mailbox::formFrom($this->vars->edit_query_filter), 'label' => $this->vars->search_label, 'type' => IMP_Search::CREATE_FILTER));
                 if ($this->vars->edit_query_filter) {
                     $notification->push(sprintf(_("Filter \"%s\" edited successfully."), $this->vars->search_label), 'horde.success');
                     $redirect_dynamic = false;
                     $redirect_target = 'prefs';
                 } else {
                     $notification->push(sprintf(_("Filter \"%s\" created succesfully."), $this->vars->search_label), 'horde.success');
                 }
                 break;
             case 'vfolder':
                 $form = json_decode($this->vars->mboxes_form);
                 $q_ob = $imp_search->createQuery($c_list, array('id' => IMP_Mailbox::formFrom($this->vars->edit_query_vfolder), 'label' => $this->vars->search_label, 'mboxes' => IMP_Mailbox::formFrom($form->mbox), 'subfolders' => IMP_Mailbox::formFrom($form->subfolder), 'type' => IMP_Search::CREATE_VFOLDER));
                 if ($this->vars->edit_query_vfolder) {
                     $notification->push(sprintf(_("Virtual Folder \"%s\" edited successfully."), $this->vars->search_label), 'horde.success');
                     $redirect_target = 'prefs';
                 } else {
                     $notification->push(sprintf(_("Virtual Folder \"%s\" created succesfully."), $this->vars->search_label), 'horde.success');
                     $redirect_target = 'mailbox';
                 }
                 break;
             default:
                 $form = json_decode($this->vars->mboxes_form);
                 $q_ob = $imp_search->createQuery($c_list, array('mboxes' => IMP_Mailbox::formFrom($form->mbox), 'subfolders' => IMP_Mailbox::formFrom($form->subfolder)));
                 $redirect_target = 'mailbox';
                 break;
         }
         /* Redirect to the mailbox page. */
         if ($redirect_target) {
             if ($dynamic_view && $redirect_dynamic) {
                 echo '<html><head>' . Horde::wrapInlineScript(array('window.parent.DimpBase.go("mbox", "' . $q_ob->mbox_ob->form_to . '")')) . '</head></html>';
                 exit;
             }
             switch ($redirect_target) {
                 case 'mailbox':
                     $q_ob->mbox_ob->url('mailbox')->redirect();
                     break;
                 case 'prefs':
                     $registry->getServiceLink('prefs', 'imp')->add('group', 'searches')->redirect();
                     break;
             }
             exit;
         }
     }
     /* Prepare the search view. */
     $view = new Horde_View(array('templatePath' => IMP_TEMPLATES . '/search'));
     $view->addHelper('Text');
     $view->addHelper('Tag');
     $view->addHelper('FormTag');
     $view->action = self::url();
     /* Determine if we are editing a search query. */
     $q_ob = $default_mailbox->getSearchOb();
     if ($this->vars->edit_query && $default_mailbox->search) {
         if ($default_mailbox->vfolder) {
             if (!$default_mailbox->editvfolder) {
                 $notification->push(_("Built-in Virtual Folders cannot be edited."), 'horde.error');
                 $registry->getServiceLink('prefs', 'imp')->add('group', 'searches')->redirect();
             }
             $view->edit_query = true;
             $view->edit_query_vfolder = $default_mailbox->form_to;
         } elseif ($imp_search->isFilter($q_ob)) {
             if (!$imp_search->isFilter($q_ob, true)) {
                 $notification->push(_("Built-in Filters cannot be edited."), 'horde.error');
                 $registry->getServiceLink('prefs', 'imp')->add('group', 'searches')->redirect();
             }
             $view->edit_query = true;
             $view->edit_query_filter = $default_mailbox->form_to;
         }
         if ($view->edit_query) {
             $view->search_label = $q_ob->label;
             $js_vars['ImpSearch.prefsurl'] = strval($registry->getServiceLink('prefs', 'imp')->add('group', 'searches')->setRaw(true));
         }
     } else {
         /* Process list of recent searches. */
         $iterator = IMP_Search_IteratorFilter::create(IMP_Search_IteratorFilter::QUERY);
         $rs = array();
         foreach ($iterator as $val) {
             $rs[$val->formid] = array('c' => $val->criteria, 'f' => array('m' => IMP_Mailbox::formTo($val->all ? array(IMP_Search_Query::ALLSEARCH) : array_map('strval', $val->mbox_list)), 's' => IMP_Mailbox::formTo(array_map('strval', $val->subfolder_list))), 'l' => Horde_String::truncate($val->querytext));
         }
         if (!empty($rs)) {
             $js_vars['ImpSearch.i_recent'] = $rs;
         }
         $s_mboxes = IMP_Mailbox::formTo($search_mailbox);
         $js_vars['ImpSearch.i_mboxes'] = array('m' => $this->vars->subfolder ? array() : $s_mboxes, 's' => $this->vars->subfolder ? $s_mboxes : array());
     }
     if ($default_mailbox->search) {
         $js_vars['ImpSearch.i_criteria'] = $q_ob->criteria;
         $js_vars['ImpSearch.i_mboxes'] = array('m' => IMP_Mailbox::formTo($q_ob->all ? array(IMP_Search_Query::ALLSEARCH) : $q_ob->mbox_list), 's' => IMP_Mailbox::formTo($q_ob->subfolder_list));
     }
     /* Create the criteria list. */
     $c_list = $types = array();
     foreach ($criteria as $key => $val) {
         $c_list[] = array('l' => $val['label'], 'v' => $key);
         $types[$key] = $val['type'];
     }
     $view->clist = $c_list;
     /* Create the filter list. These are all-or-nothing searches. */
     $f_list = array();
     foreach ($filters as $key => $val) {
         $f_list[] = array('l' => $val['label'], 'v' => $key);
         $types[$key] = 'filter';
     }
     $view->filterlist = $f_list;
     /* Create the flag list. */
     $flist = $imp_flags->getList(array('imap' => true, 'mailbox' => $default_mailbox));
     $flag_set = array();
     foreach ($flist as $val) {
         $flag_set[] = array('l' => $val->label, 'v' => rawurlencode($val->form_set));
         $types[rawurlencode($val->form_set)] = 'flag';
     }
     $view->flist = $flag_set;
     /* Generate master mailbox list. */
     $mbox_list = array();
     if (!$view->edit_query_filter) {
         $js_vars['ImpSearch.allsearch'] = IMP_Mailbox::formTo(IMP_Search_Query::ALLSEARCH);
         $ob = $injector->getInstance('IMP_Search_Ui')->getSearchMboxList();
         $mbox_list = $ob->mbox_list;
         $view->subscribe = $prefs->getValue('subscribe');
         $view->tree = $ob->tree->getTree();
     }
     /* Prepare the topbar. */
     if (!$dynamic_view) {
         $injector->getInstance('Horde_View_Topbar')->subinfo = $injector->getInstance('IMP_View_Subinfo')->render();
     }
     Horde_Core_Ui_JsCalendar::init();
     $page_output->addScriptFile('hordecore.js', 'horde');
     $page_output->addScriptFile('horde.js', 'horde');
     $page_output->addScriptFile('search.js');
     $page_output->addInlineJsVars(array_merge($js_vars, array('ImpSearch.data' => array('constants' => $constants, 'dynamic_view' => $dynamic_view, 'inbox' => IMP_Mailbox::get('INBOX')->form_to, 'mbox_list' => $mbox_list, 'months' => Horde_Core_Ui_JsCalendar::months(), 'searchmbox' => $default_mailbox->form_to, 'types' => $types), 'ImpSearch.text' => array('and' => _("and"), 'customhdr' => _("Custom Header:"), 'datereset' => _("Date Reset"), 'dateselection' => _("Date Selection"), 'flag' => _("Flag:"), 'loading' => _("Loading..."), 'need_criteria' => _("Please select at least one search criteria."), 'need_date' => _("Need at least one date in the date range search."), 'need_mbox' => _("Please select at least one mailbox to search."), 'need_label' => _("Saved searches require a label."), 'not_match' => _("Do NOT Match"), 'or' => _("OR"), 'search_all' => _("Search All Mailboxes"), 'search_term' => _("Search Term:"), 'subfolder_search' => _("Search all subfolders?"), 'to' => _("to")))), array('onload' => true));
     if ($dynamic_view) {
         if (!$this->vars->edit_query) {
             $view->return_mailbox_val = sprintf(_("Return to %s"), $default_mailbox->display_html);
         }
         $page_output->topbar = $page_output->sidebar = false;
         $this->header_params = array('html_id' => 'htmlAllowScroll');
     }
     $this->title = _("Search");
     $this->output = $view->render('search');
 }
Example #17
0
 /**
  * Get the list of Hermes-only deliverables for the requested client.
  *  - c:   The client id
  *  - id:  The optional deliverable id, if requesting a specific deliverable.
  */
 public function listDeliverables()
 {
     global $injector;
     if (!empty($this->vars->id)) {
         $params = array('id' => $this->vars->id);
         return array_values($injector->getInstance('Hermes_Driver')->listDeliverables($params));
     }
     // Only poll Hermes' deliverables if we have a client id since they
     // are ALWAYS tied to a client. Otherwise, just return the list of
     // external cost objects.
     $client_id = !empty($this->vars->c) ? $this->vars->c : null;
     if (!empty($client_id)) {
         $objs = array_values($injector->getInstance('Hermes_Driver')->listDeliverables(array('client_id' => $client_id)));
         foreach ($objs as &$obj) {
             $obj['id'] = 'hermes:' . $obj['id'];
             $obj['hours'] = 0;
             foreach ($injector->getInstance('Hermes_Driver')->getHours(array('costobject' => $obj['id'])) as $slice) {
                 $obj['hours'] += $slice['hours'];
             }
         }
         return $objs;
     }
     $elts = array();
     foreach (Hermes::getCostObjects($client_id, true) as $category) {
         Horde_Array::arraySort($category['objects'], 'name');
         foreach ($category['objects'] as $object) {
             $hours = 0;
             foreach ($injector->getInstance('Hermes_Driver')->getHours(array('costobject' => $object['id'])) as $slice) {
                 $hours += $slice['hours'];
             }
             $elts[] = array('id' => $object['id'], 'client_id' => false, 'name' => sprintf('%s (%s)', htmlspecialchars(Horde_String::truncate($object['name'], 80)), htmlspecialchars($category['category'])), 'parent' => empty($object['parent']) ? 0 : $object['parent'], 'estimate' => empty($object['estimate']) ? 0 : $object['estimate'], 'active' => true, 'is_external' => true, 'hours' => $hours);
         }
     }
     return array_values($elts);
 }
Example #18
0
 /**
  * Reports a list of messages as innocent/spam.
  *
  * @param IMP_Indices $indices  An indices object.
  * @param array $opts           Additional options:
  *   - mailboxob: (IMP_Mailbox_List) Update this mailbox list object.
  *                DEFAULT: No update.
  *
  * @return integer  1 if messages have been deleted, 2 if messages have
  *                  been moved.
  */
 public function report(IMP_Indices $indices, array $opts = array())
 {
     global $injector, $notification, $prefs;
     /* Abort immediately if spam reporting has not been enabled, or if
      * there are no messages. */
     if (empty($this->_drivers) || !count($indices)) {
         return 0;
     }
     $imp_contents = $injector->getInstance('IMP_Factory_Contents');
     $report_count = 0;
     foreach ($indices as $ob) {
         try {
             $ob->mbox->uidvalid;
         } catch (IMP_Exception $e) {
             continue;
         }
         foreach ($ob->uids as $idx) {
             try {
                 $contents = $imp_contents->create($ob->mbox->getIndicesOb($idx));
             } catch (IMP_Exception $e) {
                 continue;
             }
             $report_flag = false;
             foreach ($this->_drivers as $val) {
                 if ($val->report($contents, $this->_action)) {
                     $report_flag = true;
                 }
             }
             if ($report_flag) {
                 ++$report_count;
             }
         }
     }
     if (!$report_count) {
         return 0;
     }
     /* Report what we've done. */
     if ($report_count == 1) {
         $hdrs = $contents->getHeader();
         if ($subject = $hdrs->getValue('subject')) {
             $subject = Horde_String::truncate($subject, 30);
         } elseif ($from = $hdrs->getValue('from')) {
             $from = Horde_String::truncate($from, 30);
         } else {
             $subject = '[' . _("No Subject") . ']';
         }
         switch ($this->_action) {
             case self::INNOCENT:
                 $msg = $subject ? sprintf(_("The message \"%s\" has been reported as innocent."), $subject) : sprintf(_("The message from \"%s\" has been reported as innocent."), $from);
                 break;
             case self::SPAM:
                 $msg = $subject ? sprintf(_("The message \"%s\" has been reported as spam."), $subject) : sprintf(_("The message from \"%s\" has been reported as spam."), $from);
                 break;
         }
     } else {
         switch ($this->_action) {
             case self::INNOCENT:
                 $msg = sprintf(_("%d messages have been reported as innocent."), $report_count);
                 break;
             case self::SPAM:
                 $msg = sprintf(_("%d messages have been reported as spam."), $report_count);
                 break;
         }
     }
     $notification->push($msg, 'horde.message');
     $mbox_args = array();
     if (isset($opts['mailboxob'])) {
         $mbox_args['mailboxob'] = $opts['mailboxob'];
     }
     /* Run post-reporting hook. */
     try {
         $injector->getInstance('Horde_Core_Hooks')->callHook('post_spam', 'imp', array($this->_action == self::SPAM ? 'spam' : 'innocent', $indices));
     } catch (Horde_Exception_HookNotSet $e) {
     }
     /* Delete/move message after report. */
     switch ($this->_action) {
         case self::INNOCENT:
             /* Always flag messages as NotJunk. */
             $imp_message = $injector->getInstance('IMP_Message');
             $imp_message->flag(array('add' => array(Horde_Imap_Client::FLAG_NOTJUNK), 'remove' => array(Horde_Imap_Client::FLAG_JUNK)), $indices);
             if (($result = $prefs->getValue('move_innocent_after_report')) && !$imp_message->copy('INBOX', 'move', $indices, $mbox_args)) {
                 $result = 0;
             }
             break;
         case self::SPAM:
             /* Always flag messages as Junk. */
             $imp_message = $injector->getInstance('IMP_Message');
             $imp_message->flag(array('add' => array(Horde_Imap_Client::FLAG_JUNK), 'remove' => array(Horde_Imap_Client::FLAG_NOTJUNK)), $indices);
             switch ($result = $prefs->getValue('delete_spam_after_report')) {
                 case 1:
                     $msg_count = $imp_message->delete($indices, $mbox_args);
                     if ($msg_count === false) {
                         $result = 0;
                     } else {
                         if ($msg_count == 1) {
                             $notification->push(_("The message has been deleted."), 'horde.message');
                         } else {
                             $notification->push(sprintf(_("%d messages have been deleted."), $msg_count), 'horde.message');
                         }
                     }
                     break;
                 case 2:
                     if ($targetMbox = IMP_Mailbox::getPref(IMP_Mailbox::MBOX_SPAM)) {
                         if (!$imp_message->copy($targetMbox, 'move', $indices, array_merge($mbox_args, array('create' => true)))) {
                             $result = 0;
                         }
                     } else {
                         $notification->push(_("Could not move message to spam mailbox - no spam mailbox defined in preferences."), 'horde.error');
                         $result = 0;
                     }
                     break;
             }
             break;
     }
     return $result;
 }
Example #19
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');
 }
Example #20
0
File: Csv.php Project: horde/horde
 /**
  * Takes all necessary actions for the given import step, parameters and
  * form values and returns the next necessary step.
  *
  * @param integer $action  The current step. One of the IMPORT_* constants.
  * @param array $param     An associative array containing needed
  *                         parameters for the current step. Keys for this
  *                         driver:
  *   - check_charset: (boolean) Do some checks to see if the correct
  *                    charset has been provided. Throws charset exception
  *                    on error.
  *   - import_mapping: TODO
  *
  * @return mixed  Either the next step as an integer constant or imported
  *                data set after the final step.
  * @throws Horde_Data_Exception
  * @throws Horde_Data_Exception_Charset
  */
 public function nextStep($action, array $param = array())
 {
     switch ($action) {
         case Horde_Data::IMPORT_FILE:
             parent::nextStep($action, $param);
             /* Move uploaded file so that we can read it again in the next
                step after the user gave some format details. */
             $file_name = $_FILES['import_file']['tmp_name'];
             if (($file_data = file_get_contents($file_name)) === false) {
                 throw new Horde_Data_Exception(Horde_Data_Translation::t("The uploaded file could not be saved."));
             }
             /* Do charset checking now, if requested. */
             if (isset($param['check_charset'])) {
                 $charset = isset($this->_vars->charset) ? Horde_String::lower($this->_vars->charset) : 'utf-8';
                 switch ($charset) {
                     case 'utf-8':
                         $error = !Horde_String::validUtf8($file_data);
                         break;
                     default:
                         $error = $file_data != Horde_String::convertCharset(Horde_String::convertCharset($file_data, $charset, 'UTF-8'), 'UTF-8', $charset);
                         break;
                 }
                 if ($error) {
                     $e = new Horde_Data_Exception_Charset(Horde_Data_Translation::t("Incorrect charset given for the data."));
                     $e->badCharset = $charset;
                     throw $e;
                 }
             }
             $this->storage->set('charset', $this->_vars->charset);
             $this->storage->set('file_data', $file_data);
             /* Read the file's first two lines to show them to the user. */
             $first_lines = '';
             if ($fp = @fopen($file_name, 'r')) {
                 for ($line_no = 1, $line = fgets($fp); $line_no <= 3 && $line; $line_no++, $line = fgets($fp)) {
                     $line = Horde_String::convertCharset($line, $this->_vars->charset, 'UTF-8');
                     $first_lines .= Horde_String::truncate($line);
                     if (Horde_String::length($line) > 100) {
                         $first_lines .= "\n";
                     }
                 }
             }
             $this->storage->set('first_lines', $first_lines);
             /* Import the first line to guess the number of fields. */
             if ($first_lines) {
                 rewind($fp);
                 $line = self::getCsv($fp);
                 if ($line) {
                     $this->storage->set('fields', count($line));
                 }
             }
             return Horde_Data::IMPORT_CSV;
         case Horde_Data::IMPORT_CSV:
             $this->storage->set('header', $this->_vars->header);
             $import_mapping = array();
             if (isset($param['import_mapping'])) {
                 $import_mapping = $param['import_mapping'];
             }
             $file_name = Horde_Util::getTempFile('import');
             file_put_contents($file_name, $this->storage->get('file_data'));
             $this->storage->set('data', $this->importFile($file_name, $this->_vars->header, $this->_vars->sep, $this->_vars->quote, $this->_vars->fields, $import_mapping, $this->storage->get('charset'), $this->storage->get('crlf')));
             $this->storage->set('map');
             return Horde_Data::IMPORT_MAPPED;
         default:
             return parent::nextStep($action, $param);
     }
 }
Example #21
0
 /**
  * Generate the preview text.
  *
  * @return array  Array with the following keys:
  *   - cut: (boolean) Was the preview text cut?
  *   - text: (string) The preview text.
  */
 public function generatePreview()
 {
     // For preview generation, don't go through overhead of scanning for
     // embedded parts. Necessary evil, or else very large parts (e.g
     // 5 MB+ text parts) will take ages to scan.
     $oldbuild = $this->_build;
     $this->_build = true;
     $mimeid = $this->findBody();
     if (is_null($mimeid)) {
         $this->_build = $oldbuild;
         return array('cut' => false, 'text' => '');
     }
     $maxlen = empty($GLOBALS['conf']['msgcache']['preview_size']) ? $GLOBALS['prefs']->getValue('preview_maxlen') : $GLOBALS['conf']['msgcache']['preview_size'];
     // Retrieve 3x the size of $maxlen of bodytext data. This should
     // account for any content-encoding & HTML tags.
     $pmime = $this->getMIMEPart($mimeid, array('length' => $maxlen * 3));
     $ptext = Horde_String::convertCharset($pmime->getContents(), $pmime->getCharset(), 'UTF-8');
     if ($pmime->getType() == 'text/html') {
         $ptext = $GLOBALS['injector']->getInstance('Horde_Core_Factory_TextFilter')->filter($ptext, 'Html2text');
     }
     $this->_build = $oldbuild;
     if (Horde_String::length($ptext) > $maxlen) {
         return array('cut' => true, 'text' => Horde_String::truncate($ptext, $maxlen));
     }
     return array('cut' => false, 'text' => $ptext);
 }