Skip to content

Commit

Permalink
Don't descend into message/rfc822 parts while iterating.
Browse files Browse the repository at this point in the history
Prevents EAS clients from showing each part within the rfc822 part
as a separate attachment.
  • Loading branch information
mrubinsk committed Sep 17, 2015
1 parent eee4e6b commit c0ca138
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
6 changes: 4 additions & 2 deletions framework/ActiveSync/lib/Horde/ActiveSync/Imap/Message.php
Expand Up @@ -291,8 +291,10 @@ public function getMessageBodyDataObject(array $options = array())
public function getAttachments($version)
{
$ret = array();
$map = $this->basePart->contentTypeMap();
foreach ($map as $id => $type) {
$iterator = new Horde_ActiveSync_Mime_Iterator($this->_basePart->base);
foreach ($iterator as $part) {
$type = $part->getType();
$id = $part->getMimeId();
if ($this->isAttachment($id, $type)) {
if ($type != 'application/ms-tnef' || (!$mime_part = $this->_decodeTnefData($id))) {
$mime_part = $this->getMimePart($id, array('nocontents' => true));
Expand Down
18 changes: 17 additions & 1 deletion framework/ActiveSync/lib/Horde/ActiveSync/Mime/Iterator.php
Expand Up @@ -107,6 +107,20 @@ protected function _isAttachment($part)
}
}

/**
* Return whether or not to allow recursion into a mime part when iterating
* all of the parts. So far, only disallows this for message/rfc822 parts
* to prevent each mime part of the rfc822 part to display as an attachment.
*
* @param Horde_Mime_Part $part The part to check.
*
* @return boolean True is we can descend into the part. False otherwise.
*/
protected function _allowRecursion($part)
{
return !in_array($part->getType(), array('message/rfc822'));
}

/* RecursiveIterator methods. */

/**
Expand Down Expand Up @@ -137,13 +151,15 @@ public function next()

$out = $this->_state->current->getPartByIndex($this->_state->index++);
if ($out) {
if ($this->_ignoreAttachments && $this->_isAttachment($out)) {
if (($this->_ignoreAttachments && $this->_isAttachment($out)) ||
!$this->_allowRecursion($this->_state->current)) {
return $this->next();
}
$this->_state->recurse[] = array(
$this->_state->current,
$this->_state->index
);

$this->_state->current = $out;
$this->_state->index = 0;
} elseif ($tmp = array_pop($this->_state->recurse)) {
Expand Down

0 comments on commit c0ca138

Please sign in to comment.