/usr/share/horde/mnemo/lib/Driver/Kolab.php is in php-horde-mnemo 4.2.12-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 | <?php
/**
* Horde Mnemo driver for the Kolab_Storage backend.
*
* Copyright 2004-2016 Horde LLC (http://www.horde.org/)
*
* See the enclosed file LICENSE for license information (ASL). If you
* did not receive this file, see http://www.horde.org/licenses/apache.
*
* @author Gunnar Wrobel <wrobel@pardus.de>
* @author Thomas Jarosch <thomas.jarosch@intra2net.com>
* @author Stuart Binge <omicron@mighty.co.za>
* @since Mnemo 2.0
* @package Mnemo
*/
class Mnemo_Driver_Kolab extends Mnemo_Driver
{
/**
* The Kolab_Storage backend.
*
* @var Horde_Kolab_Storage
*/
private $_kolab;
/**
* The current notepad.
*
* @var Horde_Kolab_Storage_Data
*/
private $_data;
/**
* Construct a new Kolab storage object.
*
* @param string $notepad The name of the notepad to load/save notes from.
* @param array $params The connection parameters
*
* @throws InvalidArguementException
*/
public function __construct($notepad, $params = array())
{
if (empty($params['storage'])) {
throw new InvalidArgumentException('Missing required storage handler.');
}
$this->_notepad = $notepad;
$this->_kolab = $params['storage'];
}
/**
* Retrieves all of the notes of the current notepad from the backend.
*
* @throws Mnemo_Exception
*/
public function retrieve()
{
$this->_memos = array();
try {
$note_list = $this->_getData()->getObjects();
} catch (Horde_Kolab_Storage_Exception $e) {
throw new Mnemo_Exception($e);
}
if (empty($note_list)) {
return;
}
foreach ($note_list as $note) {
$this->_memos[Horde_Url::uriB64Encode($note['uid'])] = $this->_buildNote($note);
}
}
/**
* Retrieves one note from the backend.
*
* @param string $noteId The ID of the note to retrieve.
* @param string $passphrase A passphrase with which this note was
* supposed to be encrypted.
*
* @return array The array of note attributes.
* @throws Mnemo_Exception
* @throws Horde_Exception_NotFound
*/
public function get($noteId, $passphrase = null)
{
try {
$uid = Horde_Url::uriB64Decode($noteId);
if ($this->_getData()->objectIdExists($uid)) {
$note = $this->_getData()->getObject($uid);
return $this->_buildNote($note, $passphrase);
} else {
throw new Horde_Exception_NotFound();
}
} catch (Horde_Kolab_Storage_Exception $e) {
throw new Mnemo_Exception($e);
}
}
/**
* Retrieves one note from the backend by UID.
*
* @param string $uid The UID of the note to retrieve.
* @param string $passphrase A passphrase with which this note was
* supposed to be encrypted.
*
* @return array The array of note attributes.
* @throws Mnemo_Exception
* @throws Horde_Exception_NotFound
*/
public function getByUID($uid, $passphrase = null)
{
//@todo: search across notepads
// HACK: Use default notepad if no notepad is set.
// ActiveSync does not work without this
// as we don't search across all notepads yet.
if (empty($this->_notepad)) {
$this->_notepad = Mnemo::getDefaultNotepad();
}
return $this->get(Horde_Url::uriB64Encode($uid), $passphrase);
}
/**
* Adds a note to the backend storage.
*
* @param string $noteId The ID of the new note.
* @param string $desc The first line of the note.
* @param string $body The whole note body.
* @param string $tags The tags of the note.
*
* @return string The unique ID of the new note.
* @throws Mnemo_Exception
*/
protected function _add($noteId, $desc, $body, $tags)
{
$object = $this->_buildObject($noteId, $desc, $body, $tags);
try {
$this->_getData()->create($object);
} catch (Horde_Kolab_Storage_Exception $e) {
throw new Mnemo_Exception($e);
}
return $object['uid'];
}
/**
* Modifies an existing note.
*
* @param string $noteId The note to modify.
* @param string $desc The first line of the note.
* @param string $body The whole note body.
* @param string $tags The tags of the note.
*
* @return string The note's UID.
* @throws Mnemo_Exception
*/
protected function _modify($noteId, $desc, $body, $tags)
{
$object = $this->_buildObject($noteId, $desc, $body, $tags);
try {
$this->_getData()->modify($object);
} catch (Horde_Kolab_Storage_Exception $e) {
throw new Mnemo_Exception($e);
}
return $object['uid'];
}
/**
* Converts a note hash to a Kolab hash.
*
* @param string $noteId The note to modify.
* @param string $desc The first line of the note.
* @param string $body The whole note body.
* @param string $tags The tags of the note.
*
* @return object The Kolab hash.
*/
protected function _buildObject($noteId, $desc, $body, $tags)
{
$uid = Horde_Url::uriB64Decode($noteId);
$object = array(
'uid' => $uid,
'summary' => $desc,
'body' => $body,
);
$object['categories'] = $GLOBALS['injector']
->getInstance('Mnemo_Tagger')
->split($tags);
usort($object['categories'], 'strcoll');
return $object;
}
/**
* Moves a note to a new notepad.
*
* @param string $noteId The note to move.
* @param string $newNotepad The new notepad.
*
* @return string The note's UID.
* @throws Mnemo_Exception
*/
protected function _move($noteId, $newNotepad)
{
$uid = Horde_Url::uriB64Decode($noteId);
try {
$this->_getData()->move(
$uid,
$GLOBALS['mnemo_shares']->getShare($newNotepad)->get('folder')
);
$this->_getDataForNotepad($newNotepad)->synchronize();
} catch (Horde_Kolab_Storage_Exception $e) {
throw new Mnemo_Exception($e);
}
return $uid;
}
/**
* Deletes a note permanently.
*
* @param array $note The note to delete.
*
* @return string The note's UID.
* @throws Mnemo_Exception
*/
protected function _delete($noteId)
{
$uid = Horde_Url::uriB64Decode($noteId);
try {
$this->_getData()->delete($uid);
} catch (Horde_Kolab_Storage_Exception $e) {
throw new Mnemo_Exception($e);
}
return $uid;
}
/**
* Deletes all notes from the current notepad.
*
* @return array An array of uids that have been removed.
* @throws Mnemo_Exception
*/
protected function _deleteAll()
{
try {
$uids = $this->_getData()->getObjectIds();
$this->_getData()->deleteAll();
} catch (Horde_Kolab_Storage_Exception $e) {
throw new Mnemo_Exception($e);
}
return $uids;
}
/**
* Return the Kolab data handler for the current notepad.
*
* @return Horde_Kolab_Storage_Data The data handler.
*/
protected function _getData()
{
if (empty($this->_notepad)) {
throw new LogicException(
'The notepad has been left undefined but is required!'
);
}
if ($this->_data === null) {
$this->_data = $this->_getDataForNotepad($this->_notepad);
}
return $this->_data;
}
/**
* Return the Kolab data handler for the specified notepad.
*
* @param string $notepad The notepad name.
*
* @return Horde_Kolab_Storage_Data The data handler.
*/
protected function _getDataForNotepad($notepad)
{
try {
return $this->_kolab->getData(
$GLOBALS['mnemo_shares']->getShare($notepad)->get('folder'),
'note'
);
} catch (Horde_Kolab_Storage_Exception $e) {
throw new Mnemo_Exception(
sprintf(
_("Failed retrieving Kolab data for notepad %s: %s"),
$notepad,
$e->getMessage()
)
);
}
}
/**
* Build a note based on data array
*
* @param array $note The data for the note
* @param string $passphrase A passphrase for decrypting a note
*
* @return array The converted data array representing the note
*/
protected function _buildNote($note, $passphrase = null)
{
$encrypted = false;
$body = $note['body'];
$id = Horde_Url::uriB64Encode($note['uid']);
if (strpos($body, '-----BEGIN PGP MESSAGE-----') === 0) {
$encrypted = true;
if (empty($passphrase)) {
$passphrase = Mnemo::getPassphrase($id);
}
if (empty($passphrase)) {
$body = new Mnemo_Exception(_("This note has been encrypted."), Mnemo::ERR_NO_PASSPHRASE);
} else {
try {
$body = $this->_decrypt($body, $passphrase)->message;
} catch (Mnemo_Exception $e) {
$body = $e;
}
Mnemo::storePassphrase($id, $passphrase);
}
}
$tagger = $GLOBALS['injector']->getInstance('Mnemo_Tagger');
$tags = $tagger->getTags($note['uid'], 'note');
if (!empty($note['categories'])) {
usort($tags, 'strcoll');
if (array_diff($note['categories'], $tags)) {
$tagger->replaceTags(
$note['uid'],
$note['categories'],
$GLOBALS['registry']->getAuth(),
'note'
);
}
$tags = $note['categories'];
}
$result = array(
'memolist_id' => $this->_notepad,
'memo_id' => $id,
'uid' => $note['uid'],
'tags' => $tags,
'desc' => $note['summary'],
'encrypted' => $encrypted,
'body' => $body,
);
if (!empty($note['creation-date'])) {
$result['created'] = new Horde_Date($note['creation-date']);
}
if (!empty($note['last-modification-date'])) {
$result['modified'] = new Horde_Date($note['last-modification-date']);
}
return $result;
}
/**
* Generates a local note ID.
*
* @return string A new note ID.
*/
protected function _generateId()
{
return Horde_Url::uriB64Encode($this->_getData()->generateUid());
}
}
|