Skip to content

Commit

Permalink
Use new Horde_Mime features
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed Feb 26, 2015
1 parent 1db1a68 commit b31f842
Show file tree
Hide file tree
Showing 14 changed files with 103 additions and 115 deletions.
6 changes: 3 additions & 3 deletions imp/lib/Compose.php
Original file line number Diff line number Diff line change
Expand Up @@ -3153,9 +3153,9 @@ protected function _getMessageText($contents, array $options = array())
if (!is_null($pgp)) {
$msg = '';
$pgp->buildMimeIds();
foreach ($pgp->contentTypeMap() as $key => $val) {
if (strpos($val, 'text/') === 0) {
$msg .= $pgp[$key]->getContents();
foreach ($pgp->partIterator() as $val) {
if ($val->getPrimaryType() === 'text') {
$msg .= $val->getContents();
}
}
}
Expand Down
35 changes: 16 additions & 19 deletions imp/lib/Contents.php
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ public function getSummary($id, $mask = 0)
$part['type'] = $mime_type;

/* Is this part an attachment? */
$is_atc = $this->isAttachment($mime_type);
$is_atc = $this->isAttachment($mime_part);

/* Get bytes/size information. */
if (($mask & self::SUMMARY_BYTES) ||
Expand Down Expand Up @@ -1012,12 +1012,14 @@ public function linkViewJS($mime_part, $actionID, $text,
* downloaded by itself (i.e. all the data needed to view the part is
* contained within the download data).
*
* @param string $mime_type The MIME type.
* @param Horde_Mime_Part $part The MIME part.
*
* @return boolean True if an attachment.
*/
public function isAttachment($mime_type)
public function isAttachment(Horde_Mime_Part $part)
{
$mime_type = $part->getType();

switch ($mime_type) {
case 'application/ms-tnef':
return false;
Expand Down Expand Up @@ -1052,7 +1054,10 @@ protected function _buildMessage($parts = null)
return;
}
$this->_build = true;
$parts = array_keys($this->_message->contentTypeMap());
$parts = array();
foreach ($this->_message->partIterator() as $val) {
$parts[] = $val->getMimeId();
}
$first_id = reset($parts);
} else {
$first_id = null;
Expand Down Expand Up @@ -1089,7 +1094,9 @@ protected function _buildMessage($parts = null)
$mime_part->addPart($new_part);
$mime_part->buildMimeIds($id);
$this->_embedded[] = $new_part->getMimeId();
$to_process = array_merge($to_process, array_keys($new_part->contentTypeMap()));
foreach ($new_part->partIterator() as $val) {
$to_process[] = $val->getMimeId();
}
$last_id = $id;
}
}
Expand Down Expand Up @@ -1146,18 +1153,6 @@ public function canDisplay($part, $mask, $type = null)
return 0;
}

/**
* Returns the Content-Type map for the entire message, regenerating
* embedded parts if needed.
*
* @return array See Horde_Mime_Part::contentTypeMap().
*/
public function getContentTypeMap()
{
$this->_buildMessage();
return $this->_message->contentTypeMap();
}

/**
* Returns the MIME part tree of the message.
*
Expand Down Expand Up @@ -1225,9 +1220,11 @@ public function downloadAllList()
{
$ret = array();

foreach ($this->getContentTypeMap() as $key => $val) {
$this->_buildMessage();

foreach ($this->_message->partIterator() as $val) {
if ($this->isAttachment($val)) {
$ret[] = $key;
$ret[] = $val->getMimeId();
}
}

Expand Down
18 changes: 10 additions & 8 deletions imp/lib/Contents/InlineOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ public function getInlineOutput(IMP_Contents $contents,
{
global $prefs, $registry;

$atc_parts = $display_ids = $metadata = $msgtext = $wrap_ids = array();
$parts_list = $contents->getContentTypeMap();
$atc_parts = $display_ids = $i = $metadata = $msgtext = $wrap_ids = array();
$text_out = '';
$view = $registry->getView();

Expand All @@ -67,7 +66,10 @@ public function getInlineOutput(IMP_Contents $contents,
? $options['show_parts']
: $prefs->getValue('parts_display');

foreach ($parts_list as $mime_id => $mime_type) {
foreach ($contents->getMIMEMessage()->partIterator() as $part) {
$mime_id = $part->getMimeId();
$i[] = $mime_id;

if (isset($display_ids[$mime_id]) ||
isset($atc_parts[$mime_id])) {
continue;
Expand All @@ -80,7 +82,7 @@ public function getInlineOutput(IMP_Contents $contents,
}

if (!($render_mode = $contents->canDisplay($mime_id, $display_mask))) {
if ($contents->isAttachment($mime_type)) {
if ($contents->isAttachment($part)) {
if ($show_parts == 'atc') {
$atc_parts[$mime_id] = 1;
}
Expand All @@ -96,15 +98,15 @@ public function getInlineOutput(IMP_Contents $contents,

$render_part = $contents->renderMIMEPart($mime_id, $render_mode);
if (($show_parts == 'atc') &&
$contents->isAttachment($mime_type) &&
$contents->isAttachment($part) &&
(empty($render_part) ||
!($render_mode & $contents::RENDER_INLINE))) {
$atc_parts[$mime_id] = 1;
}

if (empty($render_part)) {
if ($contents_mask &&
$contents->isAttachment($mime_type)) {
$contents->isAttachment($part)) {
$msgtext[$mime_id] = array(
'text' => $this->_formatSummary($contents, $mime_id, $contents_mask, $part_info_display, true)
);
Expand Down Expand Up @@ -202,15 +204,15 @@ public function getInlineOutput(IMP_Contents $contents,
}

$atc_parts = ($show_parts == 'all')
? array_keys($parts_list)
? $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($parts_list) == 1)
'one_part' => (count($i) === 1)
);
}

Expand Down
16 changes: 1 addition & 15 deletions imp/lib/Flag/System/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,9 @@ public function matchHeader(Horde_Mime_Headers $data)
*/
public function matchStructure(Horde_Mime_Part $data)
{
return $this->_matchStructure(array($data));
}

/**
* Recursively search message for Content-Disposition of 'attachment'
*
* @param Horde_Mime_Part $data MIME part.
*
* @return boolean True if the part is an attachment.
*/
private function _matchStructure($data)
{
foreach ($data as $val) {
foreach ($data->partIterator() as $val) {
if ($val->getDisposition() === 'attachment') {
return true;
} elseif ($this->_matchStructure($val->getParts())) {
return true;
}
}

Expand Down
29 changes: 16 additions & 13 deletions imp/lib/Mime/Viewer/Alternative.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,7 @@ protected function _renderInline()
protected function _IMPrender($inline)
{
$base_id = $this->_mimepart->getMimeId();
$full_subparts = $this->_mimepart->contentTypeMap();

$display_ids = $ret = array();

$prefer_plain = ($GLOBALS['prefs']->getValue('alternative_display') == 'text');

/* Look for a displayable part. RFC: show the LAST choice that can be
Expand All @@ -77,16 +74,18 @@ protected function _IMPrender($inline)
* one viewable part, we will display all viewable subparts of that
* alternative. */
$imp_contents = $this->getConfigParam('imp_contents');
foreach ($full_subparts as $mime_id => $type) {
$ret[$mime_id] = null;
if ((strcmp($base_id, $mime_id) !== 0) &&
$imp_contents->canDisplay($mime_id, $inline ? IMP_Contents::RENDER_INLINE : IMP_Contents::RENDER_FULL) &&
foreach ($this->_mimepart->partIterator() as $val) {
$id = $val->getMimeId();
$ret[$id] = null;

if ((strcmp($base_id, $id) !== 0) &&
$imp_contents->canDisplay($id, $inline ? IMP_Contents::RENDER_INLINE : IMP_Contents::RENDER_FULL) &&
/* Show HTML if $prefer_plain is false-y or if
* alternative_display is not 'html'. */
(!$prefer_plain ||
(($type != 'text/html') &&
(strpos($type, 'text/') === 0)))) {
$display_ids[strval($mime_id)] = true;
(($val->getType() != 'text/html') &&
($val->getPrimaryType() != 'text')))) {
$display_ids[strval($id)] = true;
}
}

Expand All @@ -109,7 +108,7 @@ protected function _IMPrender($inline)
end($display_ids);
$curr_id = key($display_ids);
while (!is_null($curr_id) && (strcmp($base_id, $curr_id) !== 0)) {
if (isset($full_subparts[$curr_id])) {
if (array_key_exists($curr_id, $ret)) {
$disp_id = $curr_id;
}

Expand All @@ -123,10 +122,14 @@ protected function _IMPrender($inline)
* are rendered. Parts not rendered will be marked as not being
* handled by this viewer (Bug #9365). */
$render_part = $this->_mimepart->getPart($disp_id);
$need_render = $subparts = $render_part->contentTypeMap();
foreach ($render_part->partIterator() as $val) {
$id = $val->getMimeId();
$need_render[$id] = $subparts[$id] = true;
}

/* Track whether there is at least one viewable (non-empty) part. */
$viewable = false;
$viewable_ret = $ret;

foreach (array_keys($subparts) as $val) {
if (isset($display_ids[$val]) && isset($need_render[$val])) {
Expand Down Expand Up @@ -166,7 +169,7 @@ protected function _IMPrender($inline)
* viewable part that exists in the message. */
if (!$viewable) {
$id_ob = new Horde_Mime_Id($disp_id);
if (isset($full_subparts[$id_ob->idArithmetic($id_ob::ID_NEXT)])) {
if (array_key_exists($id_ob->idArithmetic($id_ob::ID_NEXT), $viewable_ret)) {
$ret[$disp_id] = array(
'data' => '',
'status' => new IMP_Mime_Status(
Expand Down
17 changes: 10 additions & 7 deletions imp/lib/Mime/Viewer/Appledouble.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,11 @@ protected function _IMPrender($inline)
* means to download. */

/* Display the resource fork download link. */
$mime_id = $this->_mimepart->getMimeId();
$parts_list = array_keys($this->_mimepart->contentTypeMap());
reset($parts_list);
$applefile_id = next($parts_list);
$iterator = $this->_mimepart->partIterator();
$iterator->rewind();
$mime_id = $iterator->current()->getMimeId();
$iterator->next();
$applefile_id = $iterator->current()->getMimeId();

$id_ob = new Horde_Mime_Id($applefile_id);
$data_id = $id_ob->idArithmetic($id_ob::ID_NEXT);
Expand All @@ -110,9 +111,11 @@ protected function _IMPrender($inline)
$ret = $this->getConfigParam('imp_contents')->renderMIMEPart($data_id, $disp);
}

foreach ($parts_list as $val) {
if (!isset($ret[$val]) && (strcmp($val, $data_id) !== 0)) {
$ret[$val] = (strcmp($val, $mime_id) === 0)
foreach ($iterator as $ob) {
$id = $ob->getMimeId();

if (!isset($ret[$id]) && (strcmp($id, $data_id) !== 0)) {
$ret[$id] = (strcmp($id, $mime_id) === 0)
? array(
'data' => '',
'status' => $status,
Expand Down
7 changes: 3 additions & 4 deletions imp/lib/Mime/Viewer/Externalbody.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,10 @@ protected function _getEmbeddedMimeParts()
$base_part = $imp_contents->getMIMEMessage();
$cid = $this->_mimepart->getContentId();

foreach (array_keys($base_part->contentTypeMap(true)) as $key) {
if (($part = $base_part->getPart($key)) &&
($part->getContentId() == $cid) &&
foreach ($base_part->partIterator() as $part) {
if (($part->getContentId() == $cid) &&
($part->getType() != 'message/external-body') &&
($full_part = $imp_contents->getMimePart($key))) {
($full_part = $imp_contents->getMimePart($part->getMimeId()))) {
$full_part = clone $full_part;
$full_part->setMimeId($this->_mimepart->getMimeId());
// TODO: Add headers from referring body part.
Expand Down
11 changes: 6 additions & 5 deletions imp/lib/Mime/Viewer/Mdn.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ protected function _renderInline()
protected function _renderInfo()
{
$mdn_id = $this->_mimepart->getMimeId();
$parts = array_keys($this->_mimepart->contentTypeMap());

$status = new IMP_Mime_Status(
$this->_mimepart,
Expand All @@ -79,8 +78,10 @@ protected function _renderInfo()
* (3) Original message (optional) */

/* Get the human readable message. */
reset($parts);
$part1_id = next($parts);
$iterator = $this->_mimepart->partIterator();
$iterator->rewind();
$iterator->next();
$part1_id = $iterator->current()->getMimeId();
$id_ob = new Horde_Mime_Id($part1_id);

/* Ignore the technical details.
Expand All @@ -107,8 +108,8 @@ protected function _renderInfo()
)
);

foreach (array_keys($part->contentTypeMap()) as $key) {
$ret[$key] = null;
foreach ($part->partIterator() as $val) {
$ret[$val->getMimeId()] = null;
}
}

Expand Down
16 changes: 10 additions & 6 deletions imp/lib/Mime/Viewer/Pgp.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,11 @@ protected function _getEmbeddedMimeParts()
}

$imp_contents = $this->getConfigParam('imp_contents');
$partlist = array_keys($this->_mimepart->contentTypeMap());
$base_id = reset($partlist);
$version_id = next($partlist);
$iterator = $this->_mimepart->partIterator();
$iterator->rewind();
$base_id = $iterator->current()->getMimeId();
$iterator->next();
$version_id = $iterator->current()->getMimeId();

$id_ob = new Horde_Mime_Id($version_id);
$data_id = $id_ob->idArithmetic($id_ob::ID_NEXT);
Expand Down Expand Up @@ -396,9 +398,11 @@ protected function _outputPGPSigned()
{
global $conf, $injector, $prefs, $session;

$partlist = array_keys($this->_mimepart->contentTypeMap());
$base_id = reset($partlist);
$signed_id = next($partlist);
$iterator = $this->_mimepart->partIterator();
$iterator->rewind();
$base_id = $iterator->current()->getMimeId();
$iterator->next();
$signed_id = $iterator->current()->getMimeId();

$id_ob = new Horde_Mime_Id($signed_id);
$sig_id = $id_ob->idArithmetic($id_ob::ID_NEXT);
Expand Down
5 changes: 4 additions & 1 deletion imp/lib/Mime/Viewer/Related.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ protected function _IMPrender($inline)
}

$data_id = null;
$ret = array_fill_keys(array_keys($this->_mimepart->contentTypeMap()), null);
$ret = array();
foreach ($this->_mimepart->partIterator() as $val) {
$ret[$val->getMimeId()] = null;
}

foreach (array_keys($render) as $val) {
$ret[$val] = $render[$val];
Expand Down

0 comments on commit b31f842

Please sign in to comment.