Skip to content

Commit

Permalink
Support collection deletion, if API support is present.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrubinsk committed Nov 11, 2013
1 parent ae6d6fe commit 24c7202
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 6 deletions.
56 changes: 56 additions & 0 deletions framework/Core/lib/Horde/Core/ActiveSync/Connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,62 @@ public function changeFolder($class, $id, $name)
}
}

/**
* Delete a folder.
*
* @param string $class The EAS collection class.
* @param string $id The folder id
*
* @since 2.12.0
*/
public function deleteFolder($class, $id)
{
global $registry, $prefs;

if ($prefs->getValue('activesync_multiplex')) {
throw new Horde_ActiveSync_Exception(
'Deleting collections not supported with multiplexed collections',
Horde_ActiveSync_Exception::UNSUPPORTED
);
}

switch ($class) {
case Horde_ActiveSync::CLASS_TASKS:
$registry->tasks->deleteTasklist($id);
break;

case Horde_ActiveSync::CLASS_CONTACTS:
if (!$registry->hasMethod('contacts/deleteAddressbook')) {
throw new Horde_ActiveSync_Exception(
'Deleting addressbooks not supported by the contacts API.',
Horde_ActiveSync_Exception::UNSUPPORTED
);
}
$registry->contacts->deleteAddressbook($id);
break;

case Horde_ActiveSync::CLASS_CALENDAR:
if (!$registry->hasMethod('calendar/deleteCalendar')) {
throw new Horde_ActiveSync_Exception(
'Deleting calendars not supported by the calendar API.',
Horde_ActiveSync_Exception::UNSUPPORTED
);
}
$registry->calendar->deleteCalendar($id);
break;
case Horde_ActiveSync::CLASS_NOTES :
if (!$registry->hasMethod('notes/deleteNotepad')) {
throw new Horde_ActiveSync_Exception(
'Deleting notepads not supported by the notes API.',
Horde_ActiveSync_Exception::UNSUPPORTED
);
}
$registry->notes->deleteNotpad($id);
break;
}

}

/**
* Clear the authentication and destroy the current session.
*/
Expand Down
37 changes: 31 additions & 6 deletions framework/Core/lib/Horde/Core/ActiveSync/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -717,15 +717,40 @@ public function changeFolder($id, $displayname, $parent, $uid = null, $type = nu
* Delete a folder on the server.
*
* @param string $id The server's folder id.
* @param string $parent The folder's parent, if needed.
* @param string $parent The folder's parent, if needed. @deprecated
*/
public function deleteFolder($id, $parent = Horde_ActiveSync::FOLDER_ROOT)
{
try {
$this->_imap->deleteMailbox($id);
} catch (Horde_ActiveSync_Exception $e) {
$this->_logger->err($e->getMessage());
throw $e;
$this->_logger->info(sprintf(
'[%s] Horde_Core_ActiveSync_Driver::deleteFolder(%s)',
getmypid(), $id));

$parts = $this->_parseFolderId($id);
if (is_array($parts)) {
$folder_class = $parts[self::FOLDER_PART_CLASS];
$folder_id = $parts[self::FOLDER_PART_ID];
} else {
$folder_class = $parts;
$folder_id = $id;
}

switch ($folder_class) {
case Horde_ActiveSync::CLASS_EMAIL;
case Horde_ActiveSync::FOLDER_TYPE_USER_MAIL:
try {
$this->_logger->info($folder_id);
$this->_imap->deleteMailbox($folder_id);
} catch (Horde_ActiveSync_Exception $e) {
$this->_logger->err($e->getMessage());
throw $e;
}
break;

case Horde_ActiveSync::CLASS_TASKS:
case Horde_ActiveSync::CLASS_CALENDAR:
case Horde_ActiveSync::CLASS_CONTACTS:
case Horde_ActiveSync::CLASS_NOTES:
$this->_connector->deleteFolder($folder_class, $folder_id);
}
}

Expand Down

0 comments on commit 24c7202

Please sign in to comment.