diff --git a/imp/lib/Compose.php b/imp/lib/Compose.php index def4e877b35..ea0e2348cc7 100644 --- a/imp/lib/Compose.php +++ b/imp/lib/Compose.php @@ -2617,6 +2617,11 @@ protected function _convertToRelated(Horde_Domhtml $html, $related->setContentTypeParameter('start', $part->setContentId()); $related->addPart($part); + /* HTML iteration is from child->parent, so need to gather related + * parts and add at end after sorting to generate a more sensible + * attachment list. */ + $add = array(); + foreach ($html as $node) { if (($node instanceof DOMElement) && $node->hasAttribute(self::RELATED_ATTR)) { @@ -2628,7 +2633,7 @@ protected function _convertToRelated(Horde_Domhtml $html, } else { $related_part = $r_atc->getPart(true); $attr = 'cid:' . $related_part->setContentId(); - $related->addPart($related_part); + $add[] = $related_part; } $node->setAttribute($attr_name, $attr); @@ -2636,6 +2641,8 @@ protected function _convertToRelated(Horde_Domhtml $html, } } + array_map(array($related, 'addPart'), array_reverse($add)); + return $related; }