Try to determine the MIME part that carries an object matching based on the message headers.
public static matchMimePartToHeaderType ( Horde_Mime_Part $structure, Horde_Mime_Headers $headers ) : string | boolean | ||
$structure | Horde_Mime_Part | A structural representation of the mime message. |
$headers | Horde_Mime_Headers | The message headers. |
return | string | boolean | The MIME ID of the message part carrying an object matching the message headers or false if such a part was not identified within the message. |
/** * Loads the object from the backend. * * @param string $backend_id The object ID within the * backend. * @param Horde_Kolab_Storage_Folder $folder The folder to retrieve * the data object from. * @param Horde_Kolab_Storage_Object_Writer $data The data parser. * @param Horde_Mime_Part $structure The MIME message * structure of the object. */ public function load($backend_id, Horde_Kolab_Storage_Folder $folder, Horde_Kolab_Storage_Object_Writer $data, Horde_Mime_Part $structure = null) { $this->_folder = $folder->getPath(); $this->_backend_id = $backend_id; $result = Horde_Kolab_Storage_Object_MimeType::matchMimePartToFolderType($structure, $folder->getType()); /* No object content matching the folder type: Try fetching the header * and look for a Kolab type deviating from the folder type. */ if ($result === false || $result[0] === false) { $result = Horde_Kolab_Storage_Object_MimeType::matchMimePartToHeaderType($structure, $this->getHeaders()); /* Seems to have no Kolab data part: mark invalid. */ if ($result === false || $result[0] === false) { $this->_type = self::TYPE_INVALID; $this->addParseError(self::ERROR_MISSING_KOLAB_PART); return; } } $this->_type = $result[1]; $mime_part = $structure->getPart($result[0]); if (empty($mime_part)) { $this->_type = self::TYPE_INVALID; $this->addParseError(self::ERROR_MISSING_KOLAB_PART); return; } $this->_mime_part_id = $result[0]; $mime_part->setContents($this->getContent()); $result = $data->load($mime_part->getContents(array('stream' => true)), $this); if ($result instanceof Exception) { $this->addParseError(self::ERROR_INVALID_KOLAB_PART, $result->getMessage()); } else { foreach ($structure->getParts() as $part) { if ($part->getMimeId() == $this->_mime_part_id || !$part->getName()) { continue; } $this->_data['_attachments'][$part->getName()] = array('type' => $part->getType(), 'content' => $this->_getDriver()->fetchBodypart($this->_getFolder(), $this->getBackendId(), $part->getMimeId())); } } $this->_structure = $structure; }
public function testUndefinedKolabTypeHeader() { $headers = new Horde_Mime_Headers(); $this->assertFalse(Horde_Kolab_Storage_Object_MimeType::matchMimePartToHeaderType($this->getMultipartMimeMessage('test/test'), $headers)); }