Support contact undelete with new storage classes; only list undeleted imap objects

This commit is contained in:
Thomas Bruederli 2012-03-14 13:57:02 +01:00
parent fc1439c7bd
commit edaad9b47c
4 changed files with 57 additions and 48 deletions

View file

@ -632,55 +632,22 @@ class rcube_kolab_contacts extends rcube_addressbook
if (!is_array($ids))
$ids = explode(',', $ids);
$count = 0;
$uids = array();
/*
TODO: re-implement this using kolab_storage_folder::undelete();
$imap_uids = $_SESSION['kolab_delete_uids'];
// convert contact IDs into IMAP UIDs
foreach ($ids as $id)
if ($uid = $imap_uids[$id])
$uids[] = $uid;
if (!empty($uids)) {
$session = &Horde_Kolab_Session::singleton();
$imap = &$session->getImap();
if (is_object($imap) && is_a($imap, 'PEAR_Error')) {
$error = $imap;
$count = 0;
foreach ($ids as $id) {
$uid = $this->_id2uid($id);
if ($this->storagefolder->undelete($uid)) {
$count++;
}
else {
$result = $imap->select($this->imap_folder);
if (is_object($result) && is_a($result, 'PEAR_Error')) {
$error = $result;
}
else {
$result = $imap->undeleteMessages(implode(',', $uids));
if (is_object($result) && is_a($result, 'PEAR_Error')) {
$error = $result;
}
else {
$this->_connect();
$this->storagefolder->synchronize();
}
}
}
if ($error) {
raise_error(array(
'code' => 600, 'type' => 'php',
'file' => __FILE__, 'line' => __LINE__,
'message' => "Error undeleting a contact object(s) from the Kolab server:" . $error->getMessage()),
'message' => "Error undeleting a contact object $uid from the Kolab server"),
true, false);
}
$rcmail = rcmail::get_instance();
$rcmail->session->remove('kolab_delete_uids');
}
*/
return count($uids);
return $count;
}

View file

@ -217,7 +217,7 @@ class kolab_format_contact extends kolab_format
$this->obj->setPhoto('','');
}
// handle spouse, children, profession, initials, pgppublickey, etc.
// TODO: handle spouse, children, profession, initials, pgppublickey, etc.
// cache this data
$this->data = $object;

View file

@ -62,7 +62,7 @@ class kolab_storage
/**
* Get a list of storage folders for the given data type
*
* @param string Data type to list folders for (contact,event,task,note)
* @param string Data type to list folders for (contact,distribution-list,event,task,note)
*
* @return array List of Kolab_Folder objects (folder names in UTF7-IMAP)
*/
@ -94,6 +94,31 @@ class kolab_storage
}
/**
* Getter for a single Kolab object, identified by its UID.
* This will search all folders storing objects of the given type.
*
* @param string Object UID
* @param string Object type (contact,distribution-list,event,task,note)
* @return array The Kolab object represented as hash array or false if not found
*/
public static function get_object($uid, $type)
{
$folder = null;
foreach ((array)self::$imap->list_folders('', '*', $type) as $foldername) {
if (!$folder)
$folder = new kolab_storage_folder($foldername, self::$imap);
else
$folder->set_folder($foldername);
if ($object = $folder->get_object($uid))
return $object;
}
return false;
}
/**
*
*/

View file

@ -52,8 +52,20 @@ class kolab_storage_folder
*/
function __construct($name, $imap = null)
{
$this->name = $name;
$this->imap = is_object($imap) ? $imap : rcmail::get_instance()->get_storage();
$this->imap->set_options(array('skip_deleted' => false));
$this->set_folder($name);
}
/**
* Set the IMAP folder name this instance connects to
*
* @param string The folder name/path
*/
public function set_folder($name)
{
$this->name = $name;
$this->imap->set_folder($this->name);
$metadata = $this->imap->get_metadata($this->name, array(kolab_storage::CTYPE_KEY));
@ -146,7 +158,7 @@ class kolab_storage_folder
// search by object type
$ctype = self::KTYPE_PREFIX . $type;
$index = $this->imap->search_once($this->name, 'HEADER X-Kolab-Type ' . $ctype);
$index = $this->imap->search_once($this->name, 'UNDELETED HEADER X-Kolab-Type ' . $ctype);
return $index->count();
}
@ -163,7 +175,7 @@ class kolab_storage_folder
// search by object type
$ctype = self::KTYPE_PREFIX . $type;
$search = 'HEADER X-Kolab-Type ' . $ctype;
$search = 'UNDELETED HEADER X-Kolab-Type ' . $ctype;
$index = $this->imap->search_once($this->name, $search);
$results = array();
@ -194,7 +206,7 @@ class kolab_storage_folder
if ($msguid && ($object = $this->read_object($msguid)))
return $object;
return array('uid' => $uid);
return false;
}
@ -380,7 +392,12 @@ class kolab_storage_folder
*/
public function undelete($uid)
{
// TODO: implement this
if ($msguid = $this->uid2msguid($uid)) {
if ($this->imap->set_flag($msguid, 'UNDELETED', $this->name)) {
return $msguid;
}
}
return false;
}