IMP_Contents::_buildMessage PHP Method

_buildMessage() protected method

Builds the "virtual" Horde_Mime_Part object by checking for embedded parts.
protected _buildMessage ( array $parts = null )
$parts array The parts list to process.
    protected function _buildMessage($parts = null)
    {
        global $injector;
        if (is_null($parts)) {
            if ($this->_build) {
                return;
            }
            $this->_build = true;
            $parts = array();
            foreach ($this->_message->partIterator() as $val) {
                $parts[] = $val->getMimeId();
            }
            $first_id = reset($parts);
        } else {
            $first_id = null;
        }
        $last_id = null;
        $to_process = array();
        $mv_factory = $injector->getInstance('IMP_Factory_MimeViewer');
        foreach ($parts as $id) {
            if (!is_null($last_id) && strpos($id, $last_id) === 0) {
                continue;
            }
            $last_id = null;
            $mime_part = $this->getMimePart($id, array('nocontents' => true));
            if (!$mime_part) {
                continue;
            }
            $viewer = $mv_factory->create($mime_part, array('contents' => $this));
            if ($viewer->embeddedMimeParts() && ($mime_part = $this->getMimePart($id))) {
                $viewer->setMIMEPart($mime_part);
                $new_part = $viewer->getEmbeddedMimeParts();
                if (!is_null($new_part)) {
                    $mime_part[] = $new_part;
                    $mime_part->buildMimeIds($id);
                    $this->_embedded[] = $new_part->getMimeId();
                    foreach ($new_part->partIterator() as $val) {
                        $to_process[] = $val->getMimeId();
                    }
                    $last_id = $id;
                }
            }
        }
        if (!empty($to_process)) {
            $this->_buildMessage($to_process);
        }
    }