/** * Get an IMAP message and retrieve the Kolab Format object. * * @param int $id The message to retrieve. * @param string $mime_type The mime type of the part to retrieve. * @param boolean $parse_headers Should the heades be Mime parsed? * @param array $formats The list of possible format parts. * * @return array|PEAR_Error An array that list the Kolab XML * object text, the mime ID of the part * with the XML object, the Mime parsed * message and the Mime parsed headers if * requested. */ function parseMessage($id, $mime_type, $parse_headers = true, $formats = array('XML')) { $raw_headers = $this->_driver->getMessageHeader($this->_path, $id); if (is_a($raw_headers, 'PEAR_Error')) { return PEAR::raiseError(sprintf(Horde_Kolab_Storage_Translation::t("Failed retrieving the message with ID %s. Original error: %s."), $id, $raw_headers->getMessage())); } $body = $this->_driver->getMessageBody($this->_path, $id); if (is_a($body, 'PEAR_Error')) { return PEAR::raiseError(sprintf(Horde_Kolab_Storage_Translation::t("Failed retrieving the message with ID %s. Original error: %s."), $id, $body->getMessage())); } //@todo: not setting "forcemime" means the subparts get checked too. Seems incorrect. $mime_message = Horde_Mime_Part::parseMessage($raw_headers . "\r" . $body, array('forcemime' => true)); $parts = $mime_message->contentTypeMap(); $mime_headers = false; $xml = false; // Read in a Kolab event object, if one exists $part_ids['XML'] = array_search($mime_type, $parts); if ($part_ids['XML'] !== false) { if ($parse_headers) { $mime_headers = Horde_Mime_Headers::parseHeaders($raw_headers); $mime_headers->setEOL("\r\n"); } $part = $mime_message->getPart($part_ids['XML']); //@todo: Check what happened to this call //$part->transferDecodeContents(); $xml = $part->getContents(); } $alternate_formats = array_diff(array('XML'), $formats); if (!empty($alternate_formats)) { foreach ($alternate_formats as $type) { $part_ids[$type] = false; } foreach ($mime_message->getParts() as $part) { $params = $part->getDispositionParameters(); foreach ($alternate_formats as $type) { if (isset($params['x-kolab-format']) && $params['x-kolab-format'] == $type) { $part_ids[$type] = $part->getMimeId(); } } } } $result = array($xml, $part_ids, $mime_message, $mime_headers); return $result; }
/** * Retrieves a complete message. * * @param string $folder The folder to fetch the messages from. * @param array $uid The message UID. * * @return array The message encapsuled as an array that contains a * Horde_Mime_Headers and a Horde_Mime_Part object. */ public function fetchComplete($folder, $uid) { $query = new Horde_Imap_Client_Fetch_Query(); $query->fullText(); try { $ret = $this->getBackend()->fetch($folder, $query, array('ids' => new Horde_Imap_Client_Ids($uid))); if (!isset($ret[$uid])) { throw new Horde_Kolab_Storage_Exception(sprintf(Horde_Kolab_Storage_Translation::t("Failed fetching message %s in folder %s."), $uid, $folder)); } $msg = $ret[$uid]->getFullMsg(); } catch (Horde_Imap_Client_Exception_ServerResponse $e) { throw new Horde_Kolab_Storage_Exception($e->details); } catch (Horde_Imap_Client_Exception $e) { throw new Horde_Kolab_Storage_Exception($e); } return array(Horde_Mime_Headers::parseHeaders($msg), Horde_Mime_Part::parseMessage($msg)); }
/** * Expunges messages in the current folder. * * @return mixed True or a PEAR error in case of an error. */ public function expunge($folder) { $this->getBackend()->expunge($this->encodePath($folder)); if ($this->getBackend()->errornum != 0) { throw new Horde_Kolab_Storage_Exception(sprintf(Horde_Kolab_Storage_Translation::t("Failed expunging folder %s.") . ' ' . Horde_Kolab_Storage_Translation::t("Error: %s"), $folder, $this->getBackend()->error)); } }
/** * Modify an existing object. * * @param array $object The array that holds the updated object data. * @param boolean $raw True if the data to be stored has been provided in * raw format. * * @return string The new backend ID of the modified object or true in case * the backend does not support this return value. * * @throws Horde_Kolab_Storage_Exception In case an error occured while * saving the data. */ public function modify($object, $raw = false) { if (!isset($object['uid'])) { throw new Horde_Kolab_Storage_Exception('The provided object data contains no ID value!'); } try { $obid = $this->getBackendId($object['uid']); } catch (Horde_Kolab_Storage_Exception $e) { throw new Horde_Kolab_Storage_Exception(sprintf(Horde_Kolab_Storage_Translation::t('The message with ID %s does not exist. This probably means that the Kolab object has been modified by somebody else since you retrieved the object from the backend. Original error: %s'), $object['uid'], $e->getMessage())); } if ($raw === false) { $writer = new Horde_Kolab_Storage_Object_Writer_Format(new Horde_Kolab_Format_Factory(), array('version' => $this->_version)); } else { $writer = new Horde_Kolab_Storage_Object_Writer_Raw(); } // Mark removed attachments as to-be-deleted. $oldObject = $this->getObject($object['uid']); $oldAttachments = isset($oldObject['inline-attachments']) ? $oldObject['inline-attachments'] : array(); if ($oldObject['picture']) { $oldAttachments[] = $oldObject['picture']; } $newAttachments = isset($object['inline-attachments']) ? $object['inline-attachments'] : array(); if (isset($object['picture'])) { $newAttachments[] = $object['picture']; } $attachments = isset($object['_attachments']) ? $object['_attachments'] : array(); foreach (array_diff($oldAttachments, $newAttachments) as $attachment) { $attachments[$attachment] = null; } $object['_attachments'] = $attachments; if (!$object instanceof Horde_Kolab_Storage_Object) { $object_array = $object; $object = $oldObject; $object->setData($object_array); } $object->setDriver($this->_driver); $result = $object->save($writer); // Filter out removed attachments so that they won't be synchronized. $object['_attachments'] = array_filter($object['_attachments']); if ($result === true) { $params = array(); } else { $params = array('changes' => array(Horde_Kolab_Storage_Folder_Stamp::ADDED => array($result => $object), Horde_Kolab_Storage_Folder_Stamp::DELETED => array($obid => $object['uid']))); } $this->synchronize($params); return $result; }
/** * Generates a new MIME messages that will wrap a Kolab groupware object. * * @return Horde_Mime_Part The new MIME message. */ protected function createEnvelope() { $envelope = new Horde_Mime_Part(); $envelope->setName('Kolab Groupware Data'); $envelope->setType('multipart/mixed'); $description = new Horde_Mime_Part(); $description->setName('Kolab Groupware Information'); $description->setType('text/plain'); $description->setDisposition('inline'); $description->setCharset('utf-8'); $description->setContents(sprintf(Horde_Kolab_Storage_Translation::t("This is a Kolab Groupware object. To view this object you will need an email client that understands the Kolab Groupware format. For a list of such email clients please visit %s"), 'http://www.kolab.org/content/kolab-clients'), array('encoding' => 'quoted-printable')); $envelope->addPart($description); return $envelope; }
/** * Create a namespace handler. * * @param string $type The namespace type. * @param string $user The current user. * @param array $params The parameters for the namespace. * * @return Horde_Kolab_Storage_Folder_Namespace The namespace handler. */ public function createNamespace($type, $user, array $params = array()) { $class = 'Horde_Kolab_Storage_Folder_Namespace_' . Horde_String::ucfirst($type); if (!class_exists($class)) { throw new Horde_Kolab_Storage_Exception(sprintf(Horde_Kolab_Storage_Translation::t('Invalid "namespace" type "%s"!'), $type)); } return new $class($user, $params); }
/** * Returns the plural translation of a message. * * @param string $singular The singular version to translate. * @param string $plural The plural version to translate. * @param integer $number The number that determines singular vs. plural. * * @return string The string translation, or the original string if no * translation exists. */ public static function ngettext($singular, $plural, $number) { self::$_domain = 'Horde_Kolab_Storage'; self::$_directory = '@data_dir@' == '@' . 'data_dir' . '@' ? __DIR__ . '/../../../../locale' : '@data_dir@/Horde_Kolab_Storage/locale'; return parent::ngettext($singular, $plural, $number); }
/** * Save an object. * * @param array $object The array that holds the data object. * @param string $old_object_id The id of the object if it existed before. * * @return boolean True on success. * * @throws Horde_Kolab_Storage_Exception In case the given old object id * is invalid or an error occured * while saving the data. */ public function save($object, $old_object_id = null) { // update existing kolab object if ($old_object_id != null) { // check if object really exists if (!$this->objectUidExists($old_object_id)) { throw new Horde_Kolab_Storage_Exception(sprintf(Horde_Kolab_Storage_Translation::t("Old object %s does not exist."), $old_object_id)); } // get the storage ID $id = $this->getStorageId($old_object_id); if ($id === false) { throw new Horde_Kolab_Storage_Exception(sprintf(Horde_Kolab_Storage_Translation::t("Old object %s does not map to a uid."), $old_object_id)); } $old_object = $this->getObject($old_object_id); } else { $id = null; $old_object = null; } $this->_folder->saveObject($object, $this->_data_version, $this->_object_type, $id, $old_object); $this->synchronize($old_object_id); return true; }
/** * Expunges messages in the current folder. * * @param string $folder The folder to append the message(s) to. Either * in UTF7-IMAP or UTF-8. * * @return mixed True or a PEAR error in case of an error. */ public function expunge($folder) { $this->select($folder); $result = @imap_expunge($this->getBackend()); if (!$result) { throw new Horde_Kolab_Storage_Exception(sprintf(Horde_Kolab_Storage_Translation::t("Failed expunging folder %s.") . ' ' . Horde_Kolab_Storage_Translation::t("Error: %s"), $folder, imap_last_error())); } }
/** * Triggers a URL. * * @param string $url The URL to be triggered. * * @return boolean|PEAR_Error True if successfull. */ private function triggerUrl($url) { global $conf; if (!empty($conf['kolab']['no_triggering'])) { return true; } $options['method'] = 'GET'; $options['timeout'] = 5; $options['allowRedirects'] = true; if (isset($conf['http']['proxy']) && !empty($conf['http']['proxy']['proxy_host'])) { $options = array_merge($options, $conf['http']['proxy']); } $http = new HTTP_Request($url, $options); $http->setBasicAuth($GLOBALS['registry']->getAuth(), $GLOBALS['registry']->getAuthCredential('password')); @$http->sendRequest(); if ($http->getResponseCode() != 200) { return PEAR::raiseError(sprintf(Horde_Kolab_Storage_Translation::t("Unable to trigger URL %s. Response: %s"), $url, $http->getResponseCode())); } return true; }