1: <?php
2: /**
3: * A modifiable message object.
4: *
5: * PHP version 5
6: *
7: * @category Kolab
8: * @package Kolab_Storage
9: * @author Gunnar Wrobel <wrobel@pardus.de>
10: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
11: * @link http://pear.horde.org/index.php?package=Kolab_Storage
12: */
13:
14: /**
15: * A modifiable message object.
16: *
17: * Copyright 2011-2012 Horde LLC (http://www.horde.org/)
18: *
19: * See the enclosed file COPYING for license information (LGPL). If you
20: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
21: *
22: * @category Kolab
23: * @package Kolab_Storage
24: * @author Gunnar Wrobel <wrobel@pardus.de>
25: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
26: * @link http://pear.horde.org/index.php?package=Kolab_Storage
27: */
28: class Horde_Kolab_Storage_Data_Modifiable
29: {
30: /**
31: * Constructor.
32: *
33: * @param Horde_Kolab_Storage_Driver $driver The backend driver.
34: * @param string $folder The folder this object belongs to.
35: * @param array $object The MIME parsed message elements.
36: */
37: public function __construct($driver, $folder, $object)
38: {
39: $this->_driver = $driver;
40: $this->_folder = $folder;
41: $this->_object = $object;
42: }
43:
44: public function getStructure()
45: {
46: return $this->_object[1];
47: }
48:
49: public function setPart($mime_id, $new_part)
50: {
51: $part = $this->_object[1]->getPart(0);
52: if (!empty($part)) {
53: $part->setContents('');
54: }
55: $this->_object[1]->alterPart($mime_id, $new_part);
56: $this->_object[1]->buildMimeIds();
57: }
58:
59: public function store()
60: {
61: $result = $this->_driver->appendMessage(
62: $this->_folder,
63: $this->_object[1]->toString(
64: array(
65: 'canonical' => true,
66: 'stream' => true,
67: 'headers' => $this->_object[0]
68: )
69: )
70: );
71: if (is_object($result) || $result === false || $result === null) {
72: throw new Horde_Kolab_Storage_Exception(
73: 'Unexpected return value when modifying an object!'
74: );
75: }
76: return $result;
77: }
78: }