protected function _convertToRelated(Horde_Domhtml $html, Horde_Mime_Part $part)
{
$r_part = false;
foreach ($this as $atc) {
if ($atc->related) {
$r_part = true;
break;
}
}
if (!$r_part) {
return $part;
}
/* Create new multipart/related part. */
$related = new Horde_Mime_Part();
$related->setType('multipart/related');
/* Get the CID for the 'root' part. Although by default the first part
* is the root part (RFC 2387 [3.2]), we may as well be explicit and
* put the CID in the 'start' parameter. */
$related->setContentTypeParameter('start', $part->setContentId());
$related[] = $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)) {
list($attr_name, $atc_id) = explode(';', $node->getAttribute(self::RELATED_ATTR));
/* If attachment can't be found, ignore. */
if ($r_atc = $this[$atc_id]) {
if ($r_atc->linked) {
$attr = strval($r_atc->link_url);
} else {
$related_part = $r_atc->getPart(true);
$attr = 'cid:' . $related_part->setContentId();
$add[] = $related_part;
}
$node->setAttribute($attr_name, $attr);
}
$node->removeAttribute(self::RELATED_ATTR);
}
}
foreach (array_reverse($add) as $val) {
$related[] = $val;
}
return $related;
}