Skip to content

Commit

Permalink
Abstract inline part display generation
Browse files Browse the repository at this point in the history
Also allow part display generation to be restricted by MIME ID.
  • Loading branch information
slusarz committed Nov 8, 2014
1 parent 618afd7 commit 97166ba
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 27 deletions.
76 changes: 50 additions & 26 deletions imp/lib/Ajax/Application/ShowMessage.php
Expand Up @@ -22,6 +22,15 @@
*/
class IMP_Ajax_Application_ShowMessage
{
/**
* Default list of part info elements to display.
*
* @var array
*/
public $part_info = array(
'icon', 'description', 'size', 'download'
);

/**
* Contents object.
*
Expand Down Expand Up @@ -253,27 +262,9 @@ public function showMessage($args)

// Create message text and attachment list.
$result['msgtext'] = '';
$part_info = $this->part_info;
$show_parts = $prefs->getValue('parts_display');

switch ($registry->getView()) {
case $registry::VIEW_MINIMAL:
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_PRINT_STUB;
break;
}

$part_info = $part_info_display = array('icon', 'description', 'size', 'download');
$part_info_display[] = 'print';

list($mbox, $uid) = $this->_indices->getSingle();

/* Do MDN processing now. */
Expand All @@ -292,12 +283,7 @@ public function showMessage($args)
/* Build body text. This needs to be done before we build the
* attachment list. */
$session->close();
$inline_ob = new IMP_Contents_InlineOutput();
$inlineout = $inline_ob->getInlineOutput($this->_contents, array(
'mask' => $contents_mask,
'part_info_display' => $part_info_display,
'show_parts' => $show_parts
));
$inlineout = $this->getInlineOutput();
$session->start();

$result['md'] = $inlineout['metadata'];
Expand Down Expand Up @@ -325,7 +311,7 @@ public function showMessage($args)
}

foreach ($inlineout['atc_parts'] as $id) {
$contents_mask |= IMP_Contents::SUMMARY_DESCRIP |
$contents_mask = IMP_Contents::SUMMARY_DESCRIP_LINK |
IMP_Contents::SUMMARY_DOWNLOAD |
IMP_Contents::SUMMARY_ICON |
IMP_Contents::SUMMARY_SIZE;
Expand Down Expand Up @@ -421,4 +407,42 @@ public function getAddressHeader($header, $limit = 50)
return $out;
}

/**
* Get the inline display output for a message.
*
* @param string $mimeid Restrict output to this MIME ID (and children).
*
* @return array See IMP_Contents_InlineOutput#getInlineOutput().
*/
public function getInlineOutput($mimeid = null)
{
global $registry;

switch ($registry->getView()) {
case $registry::VIEW_MINIMAL:
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_PRINT_STUB;
break;
}

$part_info = $part_info_display = $this->part_info;
$part_info_display[] = 'print';

$inline_ob = new IMP_Contents_InlineOutput();
return $inline_ob->getInlineOutput($this->_contents, array(
'mask' => $contents_mask,
'mimeid' => $mimeid,
'part_info_display' => $part_info_display
));
}

}
13 changes: 12 additions & 1 deletion imp/lib/Contents/InlineOutput.php
Expand Up @@ -30,6 +30,7 @@ class IMP_Contents_InlineOutput
* - display_mask: (integer) The mask of display view type to render
* inline (DEFAULT: RENDER_INLINE_AUTO).
* - mask: (integer) The mask needed for a getSummary() call.
* - mimeid: (string) Restrict output to this MIME ID (and children).
* - part_info_display: (array) The list of summary fields to display.
* - show_parts: (string) The value of the 'parts_display' pref.
*
Expand All @@ -56,6 +57,9 @@ public function getInlineOutput(IMP_Contents $contents,
$display_mask = isset($options['display_mask'])
? $options['display_mask']
: $contents::RENDER_INLINE_AUTO;
$mimeid_filter = isset($options['mimeid'])
? new Horde_Mime_Id($options['mimeid'])
: null;
$part_info_display = isset($options['part_info_display'])
? $options['part_info_display']
: array();
Expand All @@ -69,6 +73,12 @@ public function getInlineOutput(IMP_Contents $contents,
continue;
}

if ($mimeid_filter &&
((strval($mimeid_filter) != $mime_id) &&
!$mimeid_filter->isChild($mime_id))) {
continue;
}

if (!($render_mode = $contents->canDisplay($mime_id, $display_mask))) {
if ($contents->isAttachment($mime_type)) {
if ($show_parts == 'atc') {
Expand Down Expand Up @@ -176,7 +186,8 @@ public function getInlineOutput(IMP_Contents $contents,
$wrap_ids[] = $id;
}

$text_out .= '<div class="mimePartBase">' . $part['text'] . '</div>';
$text_out .= '<div class="mimePartBase" impcontentsmimeid="' .
$id . '">' . $part['text'] . '</div>';
}

$text_out .= str_repeat('</div>', count($wrap_ids));
Expand Down

0 comments on commit 97166ba

Please sign in to comment.