getSummary() public method

Get summary info for a MIME ID.
public getSummary ( string $id, integer $mask ) : array
$id string The MIME ID.
$mask integer A bitmask indicating what information to return:
Always output:
  'type' = MIME type

IMP_Contents::SUMMARY_BYTES
  Output: parts = 'bytes'

IMP_Contents::SUMMARY_SIZE
  Output: parts = 'size'

IMP_Contents::SUMMARY_ICON
IMP_Contents::SUMMARY_ICON_RAW
  Output: parts = 'icon'

IMP_Contents::SUMMARY_DESCRIP
  Output: parts = 'description_raw'

IMP_Contents::SUMMARY_DESCRIP_LINK
  Output: parts = 'description'

IMP_Contents::SUMMARY_DOWNLOAD
  Output: parts = 'download', 'download_url'

IMP_Contents::SUMMARY_IMAGE_SAVE
  Output: parts = 'img_save'

IMP_Contents::SUMMARY_PRINT
IMP_Contents::SUMMARY_PRINT_STUB
  Output: parts = 'print'

IMP_Contents::SUMMARY_STRIP
  Output: parts = 'strip'
return array An array with the requested information.
Exemplo n.º 1
0
 /**
  * Generate inline message display.
  *
  * @param array $options  Options:
  *   - mask: (integer) The mask needed for a getSummary() call.
  *   - mimeid: (string) Restrict output to this MIME ID (and children).
  *
  * @return array  See getInlineOutput().
  */
 protected function _getInlineOutput(array $options)
 {
     global $prefs, $registry;
     $atc_parts = $display_ids = $i = $metadata = $msgtext = $wrap_ids = array();
     $text_out = '';
     $view = $registry->getView();
     $contents_mask = isset($options['mask']) ? $options['mask'] : 0;
     $mimeid_filter = isset($options['mimeid']) ? new Horde_Mime_Id($options['mimeid']) : null;
     $show_parts = $prefs->getValue('parts_display');
     foreach ($this->contents->getMIMEMessage()->partIterator() as $part) {
         $mime_id = $part->getMimeId();
         $i[] = $mime_id;
         if (isset($display_ids[$mime_id]) || isset($atc_parts[$mime_id])) {
             continue;
         }
         if ($mimeid_filter && (strval($mimeid_filter) != $mime_id && !$mimeid_filter->isChild($mime_id))) {
             continue;
         }
         if (!($render_mode = $this->contents->canDisplay($mime_id, IMP_Contents::RENDER_INLINE_AUTO))) {
             if (IMP_Mime_Attachment::isAttachment($part)) {
                 if ($show_parts == 'atc') {
                     $atc_parts[$mime_id] = 1;
                 }
                 if ($contents_mask) {
                     $msgtext[$mime_id] = array('text' => $this->_formatSummary($this->contents->getSummary($mime_id, $contents_mask), true));
                 }
             }
             continue;
         }
         $render_part = $this->contents->renderMIMEPart($mime_id, $render_mode);
         if ($show_parts == 'atc' && IMP_Mime_Attachment::isAttachment($part) && (empty($render_part) || !($render_mode & IMP_Contents::RENDER_INLINE))) {
             $atc_parts[$mime_id] = 1;
         }
         if (empty($render_part)) {
             if ($contents_mask && IMP_Mime_Attachment::isAttachment($part)) {
                 $msgtext[$mime_id] = array('text' => $this->_formatSummary($this->contents->getSummary($mime_id, $contents_mask), true));
             }
             continue;
         }
         reset($render_part);
         while (list($id, $info) = each($render_part)) {
             $display_ids[$id] = 1;
             if (empty($info)) {
                 continue;
             }
             $part_text = $contents_mask && empty($info['nosummary']) ? $this->_formatSummary($this->contents->getSummary($id, $contents_mask), !empty($info['attach'])) : '';
             if (empty($info['attach'])) {
                 if (isset($info['status'])) {
                     if (!is_array($info['status'])) {
                         $info['status'] = array($info['status']);
                     }
                     $render_issues = array();
                     foreach ($info['status'] as $val) {
                         if (in_array($view, $val->views)) {
                             if ($val instanceof IMP_Mime_Status_RenderIssue) {
                                 $render_issues[] = $val;
                             } else {
                                 $part_text .= strval($val);
                             }
                         }
                     }
                     if (!empty($render_issues)) {
                         $render_issues_ob = new IMP_Mime_Status_RenderIssue_Display();
                         $render_issues_ob->addIssues($render_issues);
                         $part_text .= strval($render_issues_ob);
                     }
                 }
                 $part_text .= '<div class="mimePartData">' . $info['data'] . '</div>';
             } elseif ($show_parts == 'atc') {
                 $atc_parts[$id] = 1;
             }
             $msgtext[$id] = array('text' => $part_text, 'wrap' => empty($info['wrap']) ? null : $info['wrap']);
             if (isset($info['metadata'])) {
                 /* Format: array(identifier, ...[data]...) */
                 $metadata = array_merge($metadata, $info['metadata']);
             }
         }
     }
     if (!empty($msgtext)) {
         uksort($msgtext, 'strnatcmp');
     }
     reset($msgtext);
     while (list($id, $part) = each($msgtext)) {
         while (!empty($wrap_ids)) {
             $id_ob = new Horde_Mime_Id(end($wrap_ids));
             if ($id_ob->isChild($id)) {
                 break;
             }
             array_pop($wrap_ids);
             $text_out .= '</div>';
         }
         if (!empty($part['wrap'])) {
             $text_out .= '<div class="' . $part['wrap'] . '" impcontentsmimeid="' . $id . '">';
             $wrap_ids[] = $id;
         }
         $text_out .= '<div class="mimePartBase"' . (empty($part['wrap']) ? ' impcontentsmimeid="' . $id . '"' : '') . '>' . $part['text'] . '</div>';
     }
     $text_out .= str_repeat('</div>', count($wrap_ids));
     if (!strlen($text_out)) {
         $text_out = strval(new IMP_Mime_Status(null, _("There are no parts that can be shown inline.")));
     }
     $atc_parts = $show_parts == 'all' ? $i : array_keys($atc_parts);
     return array('atc_parts' => $atc_parts, 'display_ids' => array_keys($display_ids), 'metadata' => $metadata, 'msgtext' => $text_out, 'one_part' => count($i) === 1);
 }
Exemplo n.º 2
0
 /**
  * Create the object used to display the message.
  *
  * @param array $args  Configuration parameters:
  *   - headers: (array) The headers desired in the returned headers array
  *              (only used with non-preview view).
  *   - preview: (boolean) Is this the preview view?
  *
  * @return array  Array with the following keys:
  *   - atc_download: The download all link
  *   - atc_label: The label to use for Attachments
  *   - atc_list: The list (HTML code) of attachments
  *   - bcc (FULL): The Bcc addresses
  *   - cc: The CC addresses
  *   - fulldate (FULL): The full canonical date.
  *   - from: The From addresses
  *   - headers (FULL): An array of headers (not including basic headers)
  *   - js: Javascript code to run on display
  *   - list_info (FULL): List information.
  *   - localdate (PREVIEW): The date formatted to the user's timezone
  *   - md: Metadata
  *   - msgtext: The text of the message
  *   - onepart: True if message only contains one part.
  *   - replyTo (FULL): The Reply-to addresses
  *   - save_as: The save link
  *   - subject: The subject
  *   - subjectlink: The subject with linked URLs/email addresses (defaults
  *                  to 'subject')
  *   - title (FULL): The title of the page
  *   - to: The To addresses
  *
  * @throws IMP_Exception
  */
 public function showMessage($args)
 {
     global $injector, $page_output, $prefs, $registry, $session;
     $preview = !empty($args['preview']);
     $result = array();
     $mime_headers = $this->_peek ? $this->_contents->getHeader() : $this->_contents->getHeaderAndMarkAsSeen();
     $headers = array();
     $imp_ui = $injector->getInstance('IMP_Message_Ui');
     /* Develop the list of Headers to display now. Deal with the 'basic'
      * header information first since there are various manipulations
      * done to them. */
     $basic_headers = $imp_ui->basicHeaders();
     if (empty($args['headers'])) {
         $args['headers'] = array('from', 'date', 'to', 'cc', 'bcc');
     }
     $headers_list = array_intersect_key($basic_headers, array_flip($args['headers']));
     /* Build From/To/Cc/Bcc/Reply-To links. */
     foreach (array('from', 'to', 'cc', 'bcc', 'reply-to') as $val) {
         if (isset($headers_list[$val]) && (!$preview || $val != 'reply-to')) {
             if ($tmp = $this->getAddressHeader($val)) {
                 $result[$val] = $tmp;
             }
             if ($preview) {
                 unset($headers_list[$val]);
             }
         }
     }
     /* Build the rest of the headers. */
     foreach ($headers_list as $head => $str) {
         if ($val = $mime_headers->getValue($head)) {
             if ($head == 'date') {
                 /* Add local time to date header. */
                 $date_ob = new IMP_Message_Date($this->_envelope->date);
                 $val = htmlspecialchars($date_ob->format($date_ob::DATE_LOCAL));
                 if ($preview) {
                     $result['localdate'] = $val;
                 } else {
                     $result['fulldate'] = $date_ob->format($date_ob::DATE_FORCE);
                 }
             } elseif (!$preview) {
                 $val = htmlspecialchars($val);
             }
             if (!$preview) {
                 $headers[$head] = array('id' => Horde_String::ucfirst($head), 'name' => $str, 'value' => $val);
             }
         }
     }
     if (empty($result['reply-to']) || $result['from']['addr'][0]->b == $result['reply-to']['addr'][0]->b) {
         unset($result['reply-to'], $headers['reply-to']);
     }
     /* JS requires camelized name for reply-to. */
     if (!$preview && isset($headers['reply-to'])) {
         $result['replyTo'] = $result['reply-to'];
         $headers['reply-to']['id'] = 'ReplyTo';
         unset($result['reply-to']);
     }
     /* Maillog information. */
     $ajax_queue = $injector->getInstance('IMP_Ajax_Queue');
     $ajax_queue->maillog($this->_indices);
     if (!$preview) {
         /* Display the user-specified headers for the current identity. */
         $user_hdrs = $imp_ui->getUserHeaders();
         foreach ($user_hdrs as $user_hdr) {
             $user_val = $mime_headers->getValue($user_hdr);
             if (!empty($user_val)) {
                 if (!is_array($user_val)) {
                     $user_val = array($user_val);
                 }
                 foreach ($user_val as $val) {
                     $headers[] = array('name' => $user_hdr, 'value' => htmlspecialchars($val));
                 }
             }
         }
         $result['headers'] = array_values($headers);
     }
     /* Process the subject. */
     $subject = $mime_headers->getValue('subject');
     if ($subject) {
         $text_filter = $injector->getInstance('Horde_Core_Factory_TextFilter');
         $filtered_subject = preg_replace("/\\b\\s+\\b/", ' ', IMP::filterText($subject));
         $result['subject'] = $text_filter->filter($filtered_subject, 'text2html', array('parselevel' => Horde_Text_Filter_Text2html::NOHTML));
         $subjectlink = $text_filter->filter($filtered_subject, 'text2html', array('parselevel' => Horde_Text_Filter_Text2html::MICRO));
         if ($subjectlink != $result['subject']) {
             $result['subjectlink'] = $subjectlink;
         }
         if (!$preview) {
             $result['title'] = $subject;
         }
     } else {
         $result['subject'] = _("[No Subject]");
         if (!$preview) {
             $result['title'] = _("[No Subject]");
         }
     }
     // Create message text and attachment list.
     $result['msgtext'] = '';
     $show_parts = $prefs->getValue('parts_display');
     switch ($registry->getView()) {
         case $registry::VIEW_SMARTMOBILE:
             $contents_mask = 0;
             break;
         default:
             $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_PRINT_STUB;
             break;
     }
     $part_info = $part_info_display = array('icon', 'description', 'size', 'download', 'download_zip');
     $part_info_display[] = 'print';
     list($mbox, $uid) = $this->_indices->getSingle();
     /* Do MDN processing now. */
     switch ($registry->getView()) {
         case $registry::VIEW_DYNAMIC:
             if ($imp_ui->MDNCheck(new IMP_Indices($mbox, $uid), $mime_headers)) {
                 $status = new IMP_Mime_Status(array(_("The sender of this message is requesting notification from you when you have read this message."), sprintf(_("Click %s to send the notification message."), Horde::link('#', '', '', '', '', '', '', array('id' => 'send_mdn_link')) . _("HERE") . '</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->_contents->getInlineOutput(array('mask' => $contents_mask, 'part_info_display' => $part_info_display, 'show_parts' => $show_parts));
     $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']) > 2) {
             $result['atc_download'] = Horde::link($this->_contents->urlView($this->_contents->getMIMEMessage(), 'download_all')) . '[' . _("Save All") . ']</a>';
         }
     }
     /* Show attachment information in headers? */
     if (!empty($inlineout['atc_parts'])) {
         $partlist = array();
         if ($show_parts == 'all') {
             array_unshift($part_info, 'id');
         }
         foreach ($inlineout['atc_parts'] as $id) {
             $contents_mask |= IMP_Contents::SUMMARY_DESCRIP | IMP_Contents::SUMMARY_DOWNLOAD | IMP_Contents::SUMMARY_ICON | IMP_Contents::SUMMARY_SIZE;
             $part_info[] = 'description_raw';
             $part_info[] = 'download_url';
             $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;
     }
     $result['save_as'] = IMP_Contents_View::downloadUrl(htmlspecialchars_decode($result['subject']), array_merge(array('actionID' => 'save_message'), $mbox->urlParams($uid)));
     if ($preview) {
         /* Need to grab cached inline scripts. */
         Horde::startBuffer();
         $page_output->outputInlineScript(true);
         if ($js_inline = Horde::endBuffer()) {
             $result['js'] = array($js_inline);
         }
         $result['save_as'] = strval($result['save_as']->setRaw(true));
     } else {
         $list_info = $imp_ui->getListInformation($mime_headers);
         if (!empty($list_info['exists'])) {
             $result['list_info'] = $list_info;
         }
     }
     /* Add changed flag information. */
     if (!$this->_peek && $mbox->is_imap) {
         $status = $mbox->imp_imap->status($mbox, Horde_Imap_Client::STATUS_PERMFLAGS);
         if (in_array(Horde_Imap_Client::FLAG_SEEN, $status['permflags'])) {
             $ajax_queue->flag(array(Horde_Imap_Client::FLAG_SEEN), true, $this->_indices);
         }
     }
     return array_filter($result);
 }