Skip to content

Commit

Permalink
Move list information generation into IMP_Contents
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed Jan 14, 2015
1 parent f44ea92 commit 698c3c1
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 58 deletions.
35 changes: 14 additions & 21 deletions imp/lib/Ajax/Application/ShowMessage.php
Expand Up @@ -22,6 +22,13 @@
*/
class IMP_Ajax_Application_ShowMessage
{
/**
* Contents object.
*
* @var IMP_Contents
*/
public $contents;

/**
* Default list of part info elements to display.
*
Expand All @@ -31,13 +38,6 @@ class IMP_Ajax_Application_ShowMessage
'icon', 'description', 'size', 'download'
);

/**
* Contents object.
*
* @var IMP_Contents
*/
protected $_contents;

/**
* Envelope object.
*
Expand Down Expand Up @@ -98,12 +98,11 @@ public function __construct(IMP_Indices $indices, $peek = false)
throw new Exception();
}

$imp_contents = $injector->getInstance('IMP_Factory_Contents')->create($indices);
$this->contents = $injector->getInstance('IMP_Factory_Contents')->create($indices);
} catch (Exception $e) {
throw new IMP_Exception(_("Requested message not found."));
}

$this->_contents = $imp_contents;
$this->_envelope = $ob->getEnvelope();
$this->_indices = $indices;
$this->_peek = $peek;
Expand All @@ -129,7 +128,6 @@ public function __construct(IMP_Indices $indices, $peek = false)
* - from: (array) The From addresses.
* - headers: (array; FULL): An array of user-defined headers.
* - js: (array) Javascript code to run on display.
* - list_info: (array; FULL) List information.
* - localdate: (string) The date formatted to the user's timezone.
* - md: (array) Metadata.
* - msgtext: (string) The text of the message.
Expand Down Expand Up @@ -267,8 +265,8 @@ public function showMessage($args)
? _("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(),
$result['atc']['download'] = strval($this->contents->urlView(
$this->contents->getMIMEMessage(),
'download_all'
)->setRaw(true));
}
Expand All @@ -291,7 +289,7 @@ public function showMessage($args)
$part_info[] = 'description_raw';
$part_info[] = 'download_url';

$summary = $this->_contents->getSummary($id, $contents_mask);
$summary = $this->contents->getSummary($id, $contents_mask);
$tmp = array();
foreach ($part_info as $val) {
if (isset($summary[$val])) {
Expand Down Expand Up @@ -327,11 +325,6 @@ public function showMessage($args)
}

$result['save_as'] = strval($result['save_as']->setRaw(true));
} else {
$list_info = $imp_ui->getListInformation($this->_headers);
if (!empty($list_info['exists'])) {
$result['list_info'] = $list_info;
}
}

/* Add changed flag information. */
Expand Down Expand Up @@ -414,7 +407,7 @@ public function getInlineOutput($mimeid = null)
$part_info_display[] = 'print';

$inline_ob = new IMP_Contents_InlineOutput();
return $inline_ob->getInlineOutput($this->_contents, array(
return $inline_ob->getInlineOutput($this->contents, array(
'mask' => $contents_mask,
'mimeid' => $mimeid,
'part_info_display' => $part_info_display
Expand Down Expand Up @@ -479,8 +472,8 @@ protected function _loadHeaders()
{
if (!isset($this->_headers)) {
$this->_headers = $this->_peek
? $this->_contents->getHeader()
: $this->_contents->getHeaderAndMarkAsSeen();
? $this->contents->getHeader()
: $this->contents->getHeaderAndMarkAsSeen();
}
}

Expand Down
2 changes: 1 addition & 1 deletion imp/lib/Compose.php
Expand Up @@ -1933,7 +1933,7 @@ public function replyMessage($type, $contents, array $opts = array())

/* We might need $list_info in the reply_all section. */
$list_info = in_array($type, array(self::REPLY_AUTO, self::REPLY_LIST))
? $injector->getInstance('IMP_Message_Ui')->getListInformation($h)
? $contents->getListInformation()
: null;

if (!is_null($list_info) && !empty($list_info['reply_list'])) {
Expand Down
41 changes: 41 additions & 0 deletions imp/lib/Contents.php
Expand Up @@ -1379,4 +1379,45 @@ public function getViewCache()
return $this->_viewcache;
}

/**
* Returns mailing list information for the message.
*
* @return array An array with 2 elements:
* <pre>
* - exists: (boolean) True if this is a mailing list message.
* - reply_list: (string) If non-null, the e-mail address to use to post
* to the list.
* </pre>
*/
public function getListInformation()
{
global $injector;

$headers = $this->getHeader();
$lh = $injector->getInstance('Horde_ListHeaders');
$ret = array(
'exists' => false,
'reply_list' => null
);

if ($lh->listHeadersExist($headers)) {
$ret['exists'] = true;

/* See if the List-Post header provides an e-mail address for the
* list. */
if ($val = $headers['List-Post']) {
foreach ($lh->parse('list-post', $val->value) as $val2) {
if ($val2 instanceof Horde_ListHeaders_NoPost) {
break;
} elseif (stripos($val2->url, 'mailto:') === 0) {
$ret['reply_list'] = substr($val2->url, 7);
break;
}
}
}
}

return $ret;
}

}
4 changes: 3 additions & 1 deletion imp/lib/Dynamic/Message.php
Expand Up @@ -87,7 +87,9 @@ protected function _init()
$js_vars['ImpMessage.' . $val] = $msg_res[$val];
}
}
if (!empty($msg_res['list_info']['exists'])) {

$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(
Expand Down
32 changes: 0 additions & 32 deletions imp/lib/Message/Ui.php
Expand Up @@ -39,36 +39,4 @@ public function basicHeaders()
);
}

/**
* Returns e-mail information for a mailing list.
*
* @param Horde_Mime_Headers $headers A Horde_Mime_Headers object.
*
* @return array An array with 2 elements: 'exists' and 'reply_list'.
*/
public function getListInformation($headers)
{
$lh = $GLOBALS['injector']->getInstance('Horde_ListHeaders');
$ret = array('exists' => false, 'reply_list' => null);

if ($lh->listHeadersExist($headers)) {
$ret['exists'] = true;

/* See if the List-Post header provides an e-mail address for the
* list. */
if ($val = $headers['List-Post']) {
foreach ($lh->parse('list-post', $val->value) as $val2) {
if ($val2 instanceof Horde_ListHeaders_NoPost) {
break;
} elseif (stripos($val2->url, 'mailto:') === 0) {
$ret['reply_list'] = substr($val2->url, 7);
break;
}
}
}
}

return $ret;
}

}
7 changes: 4 additions & 3 deletions imp/lib/Mime/Viewer/Plain.php
Expand Up @@ -60,7 +60,9 @@ protected function _impRender($inline)
{
global $injector, $prefs, $registry;

$cache = $this->getConfigParam('imp_contents')->getViewCache();
$contents = $this->getConfigParam('imp_contents');

$cache = $contents->getViewCache();
$mime_id = $this->_mimepart->getMimeId();

if (isset($cache->plain[$mime_id])) {
Expand Down Expand Up @@ -120,8 +122,7 @@ protected function _impRender($inline)
(($show == 'thread') && ($injector->getInstance('Horde_Variables')->page == 'thread')));
if (!$hideBlocks &&
in_array($show, array('list', 'listthread'))) {
$header = $this->getConfigParam('imp_contents')->getHeader();
$list_info = $injector->getInstance('IMP_Message_Ui')->getListInformation($header);
$list_info = $contents->getListInformation();
$hideBlocks = $list_info['exists'];
}
}
Expand Down

0 comments on commit 698c3c1

Please sign in to comment.