IMP_Contents_Message::showMessage PHP Method

showMessage() public method

Create the object used to display the message.
public showMessage ( ) : array
return array Array with the following keys: - atc: (object) Attachment information. - download: (string) The URL for the download all action. - label: (string) The attachment label. - list: (array) Attachment information. - md: (array) Metadata. - msgtext: (string) The text of the message. - onepart: (boolean) True if message only contains one part.
    public function showMessage()
    {
        global $prefs, $registry, $session;
        $result = array();
        // Create message text and attachment list.
        $result['msgtext'] = '';
        $show_parts = $prefs->getValue('parts_display');
        /* Do MDN processing now. */
        switch ($registry->getView()) {
            case $registry::VIEW_DYNAMIC:
                if ($this->_indices->mdnCheck($this->_loadHeaders())) {
                    $status = new IMP_Mime_Status(null, array(_("The sender of this message is requesting notification from you when you have read this message."), Horde::link('#', '', '', '', '', '', '', array('id' => 'send_mdn_link')) . _("Click to send the notification message.") . '</a>'));
                    $status->domid('sendMdnMessage');
                    $result['msgtext'] .= strval($status);
                }
        }
        /* Build body text. This needs to be done before we build the
         * attachment list. */
        $session->close();
        $inlineout = $this->getInlineOutput();
        $session->start();
        $result['md'] = $inlineout['metadata'];
        $result['msgtext'] .= $inlineout['msgtext'];
        if ($inlineout['one_part']) {
            $result['onepart'] = true;
        }
        if (count($inlineout['atc_parts']) || $show_parts == 'all' && count($inlineout['display_ids']) > 2) {
            $result['atc']['label'] = $show_parts == 'all' ? _("Parts") : sprintf(ngettext("%d Attachment", "%d Attachments", count($inlineout['atc_parts'])), count($inlineout['atc_parts']));
            if (count($inlineout['atc_parts']) > 1) {
                $result['atc']['download'] = strval($this->contents->urlView($this->contents->getMIMEMessage(), 'download_all')->setRaw(true));
            }
        }
        /* Show attachment information in headers? */
        if (!empty($inlineout['atc_parts'])) {
            $partlist = array();
            $contents_mask = IMP_Contents::SUMMARY_DESCRIP | IMP_Contents::SUMMARY_DESCRIP_LINK | IMP_Contents::SUMMARY_DOWNLOAD | IMP_Contents::SUMMARY_ICON | IMP_Contents::SUMMARY_SIZE;
            $part_info = array('icon', 'description', 'size', 'download', 'description_raw', 'download_url');
            if ($show_parts == 'all') {
                array_unshift($part_info, 'id');
            }
            foreach ($inlineout['atc_parts'] as $id) {
                $summary = $this->contents->getSummary($id, $contents_mask);
                $tmp = array();
                foreach ($part_info as $val) {
                    if (isset($summary[$val])) {
                        $tmp[$val] = $summary[$val] instanceof Horde_Url ? strval($summary[$val]->setRaw(true)) : $summary[$val];
                    }
                }
                $partlist[] = array_filter($tmp);
            }
            $result['atc']['list'] = $partlist;
        }
        return $result;
    }

Usage Example

Example #1
0
 /**
  * @throws IMP_Exception
  */
 protected function _init()
 {
     global $injector, $notification, $page_output;
     if (!$this->indices) {
         throw new IMP_Exception(_("No message index given."));
     }
     $page_output->addScriptFile('message.js');
     $page_output->addScriptFile('external/CustomElements.js');
     $page_output->addScriptFile('external/time-elements.js');
     $page_output->addScriptFile('textarearesize.js', 'horde');
     $page_output->addScriptFile('toggle_quotes.js', 'horde');
     $page_output->addScriptPackage('IMP_Script_Package_Imp');
     $page_output->addThemeStylesheet('message.css');
     $page_output->addThemeStylesheet('message_view.css');
     $js_vars = array();
     switch ($this->vars->actionID) {
         case 'strip_attachment':
             try {
                 $this->indices = new IMP_Indices_Mailbox($this->indices->mailbox, $this->indices->stripPart($this->vars->id));
                 $js_vars['-ImpMessage.strip'] = 1;
                 $notification->push(_("Attachment successfully stripped."), 'horde.success');
             } catch (IMP_Exception $e) {
                 $notification->push($e);
             }
             break;
     }
     try {
         $show_msg = new IMP_Contents_Message($this->indices);
         $msg_res = $show_msg->showMessage();
     } catch (IMP_Exception $e) {
         $notification->notify(array('listeners' => array('status', 'audio')));
         echo Horde::wrapInlineScript(array('parent.close()'));
         exit;
     }
     /* Add 'maillog' and 'poll' data to the AJAX queue. */
     $ajax_queue = $injector->getInstance('IMP_Ajax_Queue');
     $ajax_queue->maillog($this->indices);
     $ajax_queue->poll($this->indices->mailbox);
     list(, $buid) = $this->indices->buids->getSingle();
     /* Need to be dynamically added, since formatting needs to be applied
      * via javascript. */
     foreach (array('from', 'to', 'cc', 'bcc') as $val) {
         if ($tmp = $show_msg->getAddressHeader($val)) {
             $js_vars['ImpMessage.' . $val] = $tmp;
         }
     }
     if ($resent = $show_msg->getResentData()) {
         $resent_js = array();
         foreach ($resent as $val) {
             $resent_js[] = array('date' => $val['date']->format($val['date']::DATE_LOCAL), 'from' => $show_msg->getAddressHeader($val['from']));
         }
         $js_vars['ImpMessage.resent'] = $resent_js;
     }
     if (isset($msg_res['log'])) {
         $js_vars['ImpMessage.log'] = $msg_res['log'];
     }
     $list_info = $show_msg->contents->getListInformation();
     if (!empty($list_info['exists'])) {
         $js_vars['ImpMessage.reply_list'] = true;
         $this->view->listinfo = Horde::popupJs(IMP_Basic_Listinfo::url(array('buid' => $buid, 'mailbox' => $this->indices->mailbox)), array('urlencode' => true));
     }
     $js_vars['ImpMessage.buid'] = $buid;
     $js_vars['ImpMessage.mbox'] = $this->indices->mailbox->form_to;
     if (isset($msg_res['atc'])) {
         $js_vars['ImpMessage.msg_atc'] = $msg_res['atc'];
         $this->js_text['atc_downloadall'] = _("Download All (%s)");
     }
     if (isset($msg_res['md'])) {
         $js_vars['ImpMessage.msg_md'] = $msg_res['md'];
     }
     $js_vars['ImpMessage.tasks'] = $injector->getInstance('Horde_Core_Factory_Ajax')->create('imp', $this->vars)->getTasks();
     $page_output->addInlineJsVars($js_vars);
     if (isset($msg_res['js'])) {
         $page_output->addInlineScript(array_filter($msg_res['js']), true);
     }
     $this->_pages[] = 'message';
     $subject = $show_msg->getSubject();
     $this->view->subject = isset($subject['subjectlink']) ? $subject['subjectlink'] : $subject['subject'];
     $this->title = $subject['title'];
     /* Determine if compose mode is disabled. */
     if (IMP_Compose::canCompose()) {
         $this->view->qreply = $injector->getInstance('IMP_Dynamic_Compose_Common')->compose($this, array('title' => _("Message") . ': ' . $subject['subject']));
         $this->_pages[] = 'qreply';
         $this->js_conf['qreply'] = 1;
     }
     $page_output->noDnsPrefetch();
     $this->view->show_delete = $this->indices->mailbox->access_deletemsgs;
     list($real_mbox, ) = $this->indices->getSingle();
     $this->view->show_innocent = $real_mbox->innocent_show;
     $this->view->show_spam = $real_mbox->spam_show;
     $this->view->show_view_all = empty($msg_res['onepart']);
     $this->view->show_view_source = $injector->getInstance('Horde_Core_Perms')->hasAppPermission('view_msg_source');
     $this->view->save_as = $show_msg->getSaveAs();
     if ($date = $show_msg->getDateOb()) {
         $this->view->datestamp = $date->format($date::DATE_ISO_8601);
         $this->view->fulldate = $date->format($date::DATE_FORCE);
         $this->view->localdate = $date->format($date::DATE_LOCAL);
         $this->view->addHelper('Text');
     }
     if ($this->view->user_hdrs = $show_msg->getUserHeaders()) {
         $this->view->addHelper('Text');
     }
     $this->view->msgtext = $msg_res['msgtext'];
     Horde::startBuffer();
     $notification->notify(array('listeners' => array('status', 'audio')));
     $this->view->status = Horde::endBuffer();
     $this->view->title = $this->title;
 }
All Usage Examples Of IMP_Contents_Message::showMessage