Try to determine the MIME part that carries the object of the specified type.
public static matchMimePartToObjectType ( Horde_Mime_Part $structure, string $type ) : string | boolean | ||
$structure | Horde_Mime_Part | A structural representation of the mime message. |
$type | string | The object type. |
리턴 | string | boolean | The MIME ID of the message part carrying the object of the specified type or false if such a part was not identified within the message. |
/** * Store the modified object in 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 writer. * @param Horde_Mime_Part $structure The MIME message structure of the object. * * @return boolean|string The return value of the append operation. * @throws Horde_Kolab_Storage_Object_Exception */ public function save(Horde_Kolab_Storage_Object_Writer $data) { list($headers, $body) = $this->_getDriver()->fetchComplete($this->_getFolder(), $this->getBackendId()); $mime_id = Horde_Kolab_Storage_Object_MimeType::matchMimePartToObjectType($body, $this->getType()); if ($mime_id === false) { throw new Horde_Kolab_Storage_Object_Exception(sprintf('Missing expected mime type (%s) in object "%s" in folder "%s"!', Horde_Kolab_Storage_Object_MimeType::getMimeTypeFromObjectType($this->getType()), $this->getBackendId(), $this->_getFolder())); } $this->_content = $body->getPart($mime_id)->getContents(array('stream' => true)); $body->alterPart($mime_id, $this->createFreshKolabPart($data->save($this))); $body->buildMimeIds(); // Update attachments. if (isset($this['_attachments'])) { foreach ($this['_attachments'] as $name => $attachment) { foreach ($body->getParts() as $part) { if ($part->getName() === $name) { $body->removePart($part->getMimeId()); break; } } if (!is_null($attachment)) { $part = new Horde_Mime_Part(); $part->setType($attachment['type']); $part->setContents($attachment['content']); $part->setName($name); $body->addPart($part); } $body->buildMimeIds(); } } $this->_mime_part_id = Horde_Kolab_Storage_Object_MimeType::matchMimePartToObjectType($body, $this->getType()); $old_uid = $this->getBackendId(); // Save message. $result = $this->_appendMessage($body, $headers); $this->_getDriver()->deleteMessages($this->_getFolder(), array($old_uid)); $this->_getDriver()->expunge($this->_getFolder()); return $result; }
public function testNoMatchToObjectType() { $this->assertFalse(Horde_Kolab_Storage_Object_MimeType::matchMimePartToObjectType($this->getMultipartMimeMessage('dummy/dummy'), 'event')); }