From 11fe4cd222efe6bf9b5e2ae465d8620255962a99 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Mon, 15 Mar 2010 15:06:06 -0600 Subject: [PATCH] Add preference to allow viewing of all inline parts by default (MIMP) --- imp/config/prefs.php.dist | 13 +++- imp/docs/CHANGES | 1 + imp/lib/Ui/Message.php | 75 ++++++++++++++----- imp/lib/Views/ShowMessage.php | 6 +- imp/message-mimp.php | 83 ++++++++-------------- imp/message.php | 6 +- imp/templates/message/message-mimp.html | 10 ++- .../message/{download-mimp.html => part-mimp.html} | 7 +- 8 files changed, 128 insertions(+), 73 deletions(-) rename imp/templates/message/{download-mimp.html => part-mimp.html} (59%) diff --git a/imp/config/prefs.php.dist b/imp/config/prefs.php.dist index 8dc7df026..eabbce5c9 100644 --- a/imp/config/prefs.php.dist +++ b/imp/config/prefs.php.dist @@ -204,7 +204,8 @@ $prefGroups['mimp'] = array( 'column' => _("Other Options"), 'label' => _("Minimalist View Options"), 'desc' => _("Configure options for the minimalist view."), - 'members' => array('mimp_preview_msg', 'mimp_download_confirm') + 'members' => array('mimp_preview_msg', 'mimp_download_confirm', + 'mimp_inline_all') ); $prefGroups['standard'] = array( @@ -1635,12 +1636,22 @@ $_prefs['mimp_preview_msg'] = array( $_prefs['mimp_download_confirm'] = array( 'value' => 0, + // Locked by default 'locked' => true, 'shared' => false, 'type' => 'number', 'desc' => _("Only show download confirmation page if message part is greater than this size, in bytes. Set to 0 to always require the confirmation page.") ); +$_prefs['mimp_inline_all'] = array( + 'value' => 0, + // Locked by default + 'locked' => true, + 'shared' => false, + 'type' => 'checkbox', + 'desc' => _("Show all inline parts by default in message view? If unchecked, will treat all but the first viewable inline part as attachments.") +); + // End Minimalist View Options // Standard View Options diff --git a/imp/docs/CHANGES b/imp/docs/CHANGES index 7b2596f39..e096bcda1 100644 --- a/imp/docs/CHANGES +++ b/imp/docs/CHANGES @@ -2,6 +2,7 @@ v5.0-git -------- +[mms] Add preference to allow viewing of all inline parts by default (MIMP). [mms] Add hook to alter composed message details before sending. [mms] DIMP now honors the 'allow_resume_all' configuration option. [mms] Remove 'sort_limit' configuration option. diff --git a/imp/lib/Ui/Message.php b/imp/lib/Ui/Message.php index 548abf365..d46275f44 100644 --- a/imp/lib/Ui/Message.php +++ b/imp/lib/Ui/Message.php @@ -458,14 +458,22 @@ class IMP_Ui_Message } /** - * Output inline message display for the imp and dimp views. + * Generate inline message display. * - * @param object $imp_contents The IMP_Contents object containing the - * message data. - * @param integer $contents_mask The mask needed for a - * IMP_Contents::getSummary() call. - * @param array $part_info_display The list of summary fields to display. - * @param string $show_parts The value of the 'parts_display' pref. + * @param object $imp_contents The IMP_Contents object containing the + * message data. + * @param array $options Additional options: + *
+     * 'display_mask' - (integer) The mask of display view type to render
+     *                  inline (DEFAULT: IMP_Contents::RENDER_INLINE_AUTO).
+     * 'mask' - (integer) The mask needed for a IMP_Contents::getSummary()
+     *          call.
+     * 'no_inline_all' - (boolean) If true, only display first inline part.
+     *                   Subsequent inline parts will be treated as
+     *                   attachments.
+     * 'part_info_display' - (array) The list of summary fields to display.
+     * 'show_parts' - (string) The value of the 'parts_display' pref.
+     * 
* * @return array An array with the following keys: *
@@ -475,13 +483,26 @@ class IMP_Ui_Message
      * 'msgtext' - (string) The rendered HTML code.
      * 
*/ - public function getInlineOutput($imp_contents, $contents_mask, - $part_info_display, $show_parts) + public function getInlineOutput($imp_contents, $options = array()) { $atc_parts = $display_ids = $js_onload = $wrap_ids = array(); $msgtext = ''; $parts_list = $imp_contents->getContentTypeMap(); + $contents_mask = isset($options['mask']) + ? $options['mask'] + : 0; + $display_mask = isset($options['display_mask']) + ? $options['display_mask'] + : IMP_Contents::RENDER_INLINE_AUTO; + $no_inline_all = !empty($options['no_inline_all']); + $part_info_display = isset($options['part_info_display']) + ? $options['part_info_display'] + : array(); + $show_parts = isset($options['show_parts']) + ? $options['show_parts'] + : $GLOBALS['prefs']->getValue('parts_display'); + if ($show_parts == 'all') { $atc_parts = array_keys($parts_list); } @@ -491,13 +512,15 @@ class IMP_Ui_Message continue; } - if (!($render_mode = $imp_contents->canDisplay($mime_id, IMP_Contents::RENDER_INLINE | IMP_Contents::RENDER_INFO))) { + if (!($render_mode = $imp_contents->canDisplay($mime_id, $display_mask))) { if ($imp_contents->isAttachment($mime_type)) { if ($show_parts == 'atc') { $atc_parts[] = $mime_id; } - $msgtext .= $this->formatSummary($imp_contents->getSummary($mime_id, $contents_mask), $part_info_display, true); + if ($contents_mask) { + $msgtext .= $this->formatSummary($imp_contents->getSummary($mime_id, $contents_mask), $part_info_display, true); + } } continue; } @@ -512,13 +535,20 @@ class IMP_Ui_Message if (empty($render_part)) { if ($imp_contents->isAttachment($mime_type)) { - $msgtext .= $this->formatSummary($imp_contents->getSummary($mime_id, $contents_mask), $part_info_display, true); + if ($contents_mask) { + $msgtext .= $this->formatSummary($imp_contents->getSummary($mime_id, $contents_mask), $part_info_display, true); + } } continue; } reset($render_part); while (list($id, $info) = each($render_part)) { + if ($no_inline_all === 1) { + $atc_parts[] = $id; + continue; + } + $display_ids[] = $id; if (empty($info)) { @@ -537,20 +567,33 @@ class IMP_Ui_Message } if (empty($info['attach'])) { - $msgtext .= $this->formatSummary($imp_contents->getSummary($id, $contents_mask), $part_info_display) . - $this->formatStatusMsg($info['status']) . - '
' . $info['data'] . '
'; + if ($contents_mask) { + $msgtext .= $this->formatSummary($imp_contents->getSummary($id, $contents_mask), $part_info_display) . + $this->formatStatusMsg($info['status']) . + '
' . $info['data'] . '
'; + } else { + if ($msgtext && !empty($options['sep'])) { + $msgtext .= $options['sep']; + } + $msgtext .= $info['data']; + } } else { if ($show_parts == 'atc') { $atc_parts[] = $id; } - $msgtext .= $this->formatSummary($imp_contents->getSummary($id, $contents_mask), $part_info_display, true); + if ($contents_mask) { + $msgtext .= $this->formatSummary($imp_contents->getSummary($id, $contents_mask), $part_info_display, true); + } } if (isset($info['js'])) { $js_onload = array_merge($js_onload, $info['js']); } + + if ($no_inline_all) { + $no_inline_all = 1; + } } } diff --git a/imp/lib/Views/ShowMessage.php b/imp/lib/Views/ShowMessage.php index 8237f80b5..74b5e42b1 100644 --- a/imp/lib/Views/ShowMessage.php +++ b/imp/lib/Views/ShowMessage.php @@ -262,7 +262,11 @@ class IMP_Views_ShowMessage /* Build body text. This needs to be done before we build the * attachment list. */ - $inlineout = $imp_ui->getInlineOutput($imp_contents, $contents_mask, $part_info_display, $show_parts); + $inlineout = $imp_ui->getInlineOutput($imp_contents, array( + 'mask' => $contents_mask, + 'part_info_display' => $part_info_display, + 'show_parts' => $show_parts + )); $result['js'] = array_merge($result['js'], $inlineout['js_onload']); $result['msgtext'] .= $inlineout['msgtext']; diff --git a/imp/message-mimp.php b/imp/message-mimp.php index ee1807f07..e1adb8f2e 100644 --- a/imp/message-mimp.php +++ b/imp/message-mimp.php @@ -75,7 +75,7 @@ case 'ri': $msg_delete = (IMP_Spam::reportSpam(array($index_array['mailbox'] => array($index_array['uid'])), $vars->a == 'rs' ? 'spam' : 'innocent') === 1); break; -// 'c' = confirm download +// 'pa' = part action // Need to build message information, so don't do action until below. } @@ -139,20 +139,29 @@ $self_link = IMP::generateIMPUrl('message-mimp.php', $imp_mbox['mailbox'], $uid, $t = $injector->createInstance('Horde_Template'); $t->setOption('gettext', true); -/* Output download confirmation screen. */ -if (($vars->a == 'c') && isset($vars->atc)) { - $summary = $imp_contents->getSummary($vars->atc, IMP_Contents::SUMMARY_SIZE | IMP_Contents::SUMMARY_DESCRIP_NOLINK_NOHTMLSPECCHARS | IMP_Contents::SUMMARY_DOWNLOAD_NOJS); +/* Output part action screen. */ +if (($vars->a == 'pa') && + (isset($vars->atc) || isset($vars->id))) { + if (isset($vars->atc)) { + $summary = $imp_contents->getSummary($vars->atc, IMP_Contents::SUMMARY_SIZE | IMP_Contents::SUMMARY_DESCRIP_NOLINK_NOHTMLSPECCHARS | IMP_Contents::SUMMARY_DOWNLOAD_NOJS); - $title = _("Verify Download"); + $title = _("Download Attachment"); + + $t->set('descrip', $summary['description']); + $t->set('download', $summary['download']); + $t->set('size', $summary['size']); + $t->set('type', $summary['type']); + } else { + $title = _("View Attachment"); + + $data = $imp_contents->renderMIMEPart($vars->id, $imp_contents->canDisplay($vars->id, IMP_Contents::RENDER_INLINE | IMP_Contents::RENDER_INFO)); + $t->set('view_data', $data ? $data : _("This part is empty.")); + } - $t->set('descrip', $summary['description']); - $t->set('download', $summary['download']); $t->set('self_link', $self_link); - $t->set('size', $summary['size']); - $t->set('type', $summary['type']); require IMP_TEMPLATES . '/common-header.inc'; - echo $t->fetch(IMP_TEMPLATES . '/message/download-mimp.html'); + echo $t->fetch(IMP_TEMPLATES . '/message/part-mimp.html'); exit; } @@ -231,46 +240,13 @@ foreach ($flag_parse as $val) { } /* Create the body of the message. */ -$parts_list = $imp_contents->getContentTypeMap(); -$atc_parts = $display_ids = array(); -$body_shown = false; -$msg_text = ''; - -foreach ($parts_list as $mime_id => $mime_type) { - if (in_array($mime_id, $display_ids, true)) { - continue; - } - - if ($body_shown || - !($render_mode = $imp_contents->canDisplay($mime_id, IMP_Contents::RENDER_INLINE | IMP_Contents::RENDER_INFO))) { - if ($imp_contents->isAttachment($mime_type)) { - $atc_parts[] = $mime_id; - } - continue; - } - - $render_part = $imp_contents->renderMIMEPart($mime_id, $render_mode); - if (($render_mode & IMP_Contents::RENDER_INLINE) && empty($render_part)) { - /* This meant that nothing was rendered - allow this part to appear - * in the attachment list instead. */ - $atc_parts[] = $mime_id; - continue; - } - - while (list($id, $info) = each($render_part)) { - if ($body_shown) { - $atc_parts[] = $id; - continue; - } - - if (empty($info)) { - continue; - } +$inlineout = $imp_ui->getInlineOutput($imp_contents, array( + 'display_mask' => IMP_Contents::RENDER_INLINE, + 'no_inline_all' => !$prefs->getValue('mimp_inline_all'), + 'sep' => '

' +)); - $body_shown = true; - $msg_text = $info['data']; - } -} +$msg_text = $inlineout['msgtext']; /* Display the first 250 characters, or display the entire message? */ if ($prefs->getValue('mimp_preview_msg') && @@ -352,7 +328,7 @@ foreach ($display_headers as $head => $val) { $t->set('hdrs', $hdrs); $atc = array(); -foreach ($atc_parts as $key) { +foreach ($inlineout['atc_parts'] as $key) { $summary = $imp_contents->getSummary($key, IMP_Contents::SUMMARY_BYTES | IMP_Contents::SUMMARY_SIZE | IMP_Contents::SUMMARY_DESCRIP_NOLINK_NOHTMLSPECCHARS | IMP_Contents::SUMMARY_DOWNLOAD_NOJS); $tmp = array( @@ -365,10 +341,14 @@ foreach ($atc_parts as $key) { /* Preference: if set, only show download confirmation screen if * attachment over a certain size. */ $tmp['download'] = ($summary['bytes'] > $prefs->getValue('mimp_download_confirm')) - ? $self_link->copy()->add(array('a' => 'c', 'atc' => $key)) + ? $self_link->copy()->add(array('a' => 'pa', 'atc' => $key)) : $summary['download']; } + if ($imp_contents->canDisplay($key, IMP_Contents::RENDER_INLINE_AUTO)) { + $tmp['view'] = $self_link->copy()->add(array('a' => 'pa', 'id' => $key)); + } + $atc[] = $tmp; } $t->set('atc', $atc); @@ -379,4 +359,3 @@ $t->set('title', ($status ? $status . ' | ' : '') . $display_headers['subject'] require IMP_TEMPLATES . '/common-header.inc'; IMP::status(); echo $t->fetch(IMP_TEMPLATES . '/message/message-mimp.html'); - diff --git a/imp/message.php b/imp/message.php index 28529eb2b..e7203bc85 100644 --- a/imp/message.php +++ b/imp/message.php @@ -598,7 +598,11 @@ if ($imp_ui->MDNCheck($imp_mbox['mailbox'], $uid, $mime_headers, $vars->mdn_conf /* Build body text. This needs to be done before we build the attachment list * that lives in the header. */ -$inlineout = $imp_ui->getInlineOutput($imp_contents, $contents_mask, $part_info_display, $show_parts); +$inlineout = $imp_ui->getInlineOutput($imp_contents, array( + 'mask' => $contents_mask, + 'part_info_display' => $part_info_display, + 'show_parts' => $show_parts +)); /* Build the Attachments menu. */ $a_template->set('atc', Horde::widget('#', _("Attachments"), 'widget hasmenu', '', '', _("Attachments"), true)); diff --git a/imp/templates/message/message-mimp.html b/imp/templates/message/message-mimp.html index cb8453c57..fcf107342 100644 --- a/imp/templates/message/message-mimp.html +++ b/imp/templates/message/message-mimp.html @@ -5,7 +5,15 @@
: [Show All]
-
Attachment: []
+
+ Attachment: () + + [View] + + + [Download] + +

diff --git a/imp/templates/message/download-mimp.html b/imp/templates/message/part-mimp.html similarity index 59% rename from imp/templates/message/download-mimp.html rename to imp/templates/message/part-mimp.html index 0975f1fd7..322349b80 100644 --- a/imp/templates/message/download-mimp.html +++ b/imp/templates/message/part-mimp.html @@ -1,8 +1,13 @@ + + +

- Click to verify download of attachment: + Download attachment: []

+ +

Return to message view

-- 2.11.0