Skip to content

Commit

Permalink
Catch MDN messages with broken format
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed Mar 18, 2015
1 parent 80eaf12 commit d81d7b2
Showing 1 changed file with 37 additions and 19 deletions.
56 changes: 37 additions & 19 deletions imp/lib/Mime/Viewer/Mdn.php
Expand Up @@ -63,14 +63,6 @@ protected function _renderInline()
*/
protected function _renderInfo()
{
$mdn_id = $this->_mimepart->getMimeId();

$status = new IMP_Mime_Status(
$this->_mimepart,
_("A message you have sent has resulted in a return notification from the recipient.")
);
$status->icon('info_icon.png', _("Info"));

/* RFC 3798 [3]: There are three parts to a delivery status
* multipart/report message:
* (1) Human readable message
Expand All @@ -80,7 +72,40 @@ protected function _renderInfo()
/* Get the human readable message. */
$iterator = $this->_mimepart->partIterator(false);
$iterator->rewind();
$part1_id = $iterator->current()->getMimeId();
$ret = $this->_parseMdn($iterator->current());

$status = new IMP_Mime_Status(
$this->_mimepart,
_("A message you have sent has resulted in a return notification from the recipient.")
);
$status->icon('info_icon.png', _("Info"));

$ret[$this->_mimepart->getMimeId()] = array(
'data' => '',
'status' => $status,
'type' => 'text/html; charset=' . $this->getConfigParam('charset'),
'wrap' => 'mimePartWrap'
);

return $ret;
}

/**
* Parse the MDN part.
*
* @param Horde_Mime_Part $part MDN part.
*
* @return array See parent::render().
*/
protected function _parseMdn($part)
{
$ret = array();

if (!$part) {
return $ret;
}

$part1_id = $part->getMimeId();
$id_ob = new Horde_Mime_Id($part1_id);

/* Ignore the technical details.
Expand All @@ -92,10 +117,10 @@ protected function _renderInfo()
$imp_contents = $this->getConfigParam('imp_contents');
$part3_id = $id_ob->idArithmetic($id_ob::ID_NEXT);

if ($part = $imp_contents->getMimePart($part3_id)) {
if ($part2 = $imp_contents->getMimePart($part3_id)) {
$status->addText(
$imp_contents->linkViewJS(
$part,
$part2,
'view_attach',
_("View the text of the sent message."),
array(
Expand All @@ -107,18 +132,11 @@ protected function _renderInfo()
)
);

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

$ret[$mdn_id] = array(
'data' => '',
'status' => $status,
'type' => 'text/html; charset=' . $this->getConfigParam('charset'),
'wrap' => 'mimePartWrap'
);

return $ret;
}

Expand Down

0 comments on commit d81d7b2

Please sign in to comment.