Skip to content

Commit

Permalink
Merge branch 'master' into horde_5_2
Browse files Browse the repository at this point in the history
  • Loading branch information
mrubinsk committed Nov 10, 2013
2 parents 2be676e + d7d8dcf commit 87bd34f
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 36 deletions.
3 changes: 3 additions & 0 deletions framework/ActiveSync/doc/Horde/ActiveSync/TODO
Expand Up @@ -26,4 +26,7 @@ BC BREAKING (i.e., Horde 6).
places. (Some client commands are sent using the CLASS, some using the
FOLDER_TYPE).

- Clean up and refactor the folder creation/editing/deleting methods in the
backend. They need to be normalized in accepting/returning the same objects
now that we support multiple folders per non-email collection.

31 changes: 24 additions & 7 deletions framework/ActiveSync/lib/Horde/ActiveSync/Connector/Importer.php
Expand Up @@ -303,13 +303,15 @@ public function importMessageMove(array $uids, $dst)
* @param string $parent The parent folder id.
* @param integer $type The EAS Folder type. @since 2.9.0
*
* @return string The new serverid if successful.
*
* @todo Horde 6 - This should take and return a Horde_ActiveSync_Message_Folder object.
* @return Horde_ActiveSync_Message_Folder The new serverid if successful.
*/
public function importFolderChange($uid, $displayname, $parent = Horde_ActiveSync::FOLDER_ROOT, $type = null)
{
// TODO: BC HACK. For now, we need to convert the uid -> folderid.
$this->_logger->info(sprintf(
'[%s] Horde_ActiveSync_Connector_Importer::importFolderChange(%s, %s, %s, %s)',
$this->_procid, $uid, $displayname, $parent, $type));

// Convert the uids to serverids.
$collections = $this->_as->getCollectionsObject();
if (!empty($parent)) {
$parent_sid = $collections->getBackendIdForFolderUid($parent);
Expand All @@ -319,18 +321,33 @@ public function importFolderChange($uid, $displayname, $parent = Horde_ActiveSyn
if (!empty($uid)) {
$folderid = $collections->getBackendIdForFolderUid($uid);
} else {
// New folder.
$folderid = false;
}

// Perform the creation in the backend.
try {
$new_uid = $this->_as->driver->changeFolder($folderid, $displayname, $parent_sid, $uid, $type);
$results = $this->_as->driver->changeFolder(
$folderid, $displayname, $parent_sid, $uid, $type);
} catch (Horde_ActiveSync_Exception $e) {
$this->_logger->err($e->getMessage());
throw $e;
}

// @todo Horde 6 this should always return an object.
if ($results instanceof Horde_ActiveSync_Message_Folder) {
$folderid = $results->_serverid;
$uid = $results->serverid;
} else {
// Need to build a message folder object here for BC reasons.
$serverid = $results;
$results = $this->_as->messageFactory('Folder');
$results->serverid = $serverid;
$results->_serverid = $folderid;
}

$change = array();
$change['id'] = $new_uid;
$change['id'] = $uid;
$change['folderid'] = $folderid;
$change['mod'] = $displayname;
$change['parent'] = $parent;
Expand All @@ -339,7 +356,7 @@ public function importFolderChange($uid, $displayname, $parent = Horde_ActiveSyn
$change,
Horde_ActiveSync::CHANGE_ORIGIN_PIM);

return $new_uid;
return $results;
}

/**
Expand Down
10 changes: 9 additions & 1 deletion framework/ActiveSync/lib/Horde/ActiveSync/Driver/Base.php
Expand Up @@ -468,8 +468,16 @@ abstract public function deleteFolder($id, $parent = Horde_ActiveSync::FOLDER_RO
* @param string $id The server's folder id
* @param string $displayname The new display name.
* @param string $parent The folder's parent, if needed.
* @param string $uid The existing folder uid, if this is an edit.
* @since 2.9.0 (@todo Look at this for H6. It's
* here now to save an extra DB lookup for data
* we already have.)
* @param integer $type The EAS Folder type. @since 2.9.0
*
* @return Horde_ActiveSync_Message_Folder
* @throws Horde_ActiveSync_Exception
*/
abstract public function changeFolder($id, $displayname, $parent);
abstract public function changeFolder($id, $displayname, $parent, $uid = null, $type = null);

/**
* Move message
Expand Down
13 changes: 11 additions & 2 deletions framework/ActiveSync/lib/Horde/ActiveSync/Imap/Adapter.php
Expand Up @@ -93,7 +93,9 @@ public function appendMessage($folderid, $msg, array $flags = array())
* @param string $name The new mailbox name.
* @param string $parent The parent mailbox, if any.
*
* @throws Horde_ActiveSync_Exception, Horde_ActiveSync_Exception_FolderExists
* @return string The new serverid for the mailbox. This is the UTF-8 name
* of the mailbox. @since 2.9.0
* @throws Horde_ActiveSync_Exception, Horde_ActiveSync_Exception_FolderExists
*/
public function createMailbox($name, $parent = null)
{
Expand All @@ -112,6 +114,8 @@ public function createMailbox($name, $parent = null)
}
throw new Horde_ActiveSync_Exception($e);
}

return $mbox->utf8;
}

/**
Expand Down Expand Up @@ -657,6 +661,8 @@ public function queryMailbox($query)
* @param string $new The new mailbox name.
* @param string $parent The parent mailbox, if any.
*
* @return string The new serverid for the mailbox.
* @since 2.9.0
* @throws Horde_ActiveSync_Exception
*/
public function renameMailbox($old, $new, $parent = null)
Expand All @@ -671,14 +677,17 @@ public function renameMailbox($old, $new, $parent = null)
$ns = $this->_defaultNamespace();
$new = $parent . $ns['delimiter'] . $new;
}
$new_mbox = new Horde_Imap_Client_Mailbox($new);
try {
$imap->renameMailbox(
new Horde_Imap_Client_Mailbox($old),
new Horde_Imap_Client_Mailbox($new)
$new_mbox
);
} catch (Horde_Imap_Client_Exception $e) {
throw new Horde_ActiveSync_Exception($e);
}

return $new_mbox->utf8;
}

/**
Expand Down
41 changes: 18 additions & 23 deletions framework/ActiveSync/lib/Horde/ActiveSync/Request/FolderCreate.php
Expand Up @@ -43,8 +43,18 @@ class Horde_ActiveSync_Request_FolderCreate extends Horde_ActiveSync_Request_Bas
const STATUS_SUCCESS = 1;
const STATUS_ERROR = 6;
const STATUS_KEYMISM = 9;

/**
* Handle request
* Handle request.
*
* Notes: For FOLDERCREATE requests or non-email collections, the parent
* seems to be set to the root of that collection type and the EAS type is
* included. For new root email folders, the parent is set to ROOT.
* For FOLDERCHANGE requests, the type is NOT included so the backend must
* be able to determine the folder type given the folder's id only. Also,
* the parent element does not seem to be transmitted by the clients I
* have tested, so even though it is included when creating the new
* folder, it is NOT included when edting that same folder. *sigh*
*
* @return boolean
*/
Expand Down Expand Up @@ -84,10 +94,10 @@ protected function _handle()
throw new Horde_ActiveSync_Exception('Protocol Error');
}

// ServerID
$serverid = false;
// Server_uid (the EAS uid for this collection).
$server_uid = false;
if ($this->_decoder->getElementStartTag(Horde_ActiveSync::FOLDERHIERARCHY_SERVERENTRYID)) {
$serverid = $this->_decoder->getElementContent();
$server_uid = $this->_decoder->getElementContent();
if (!$this->_decoder->getElementEndTag()) {
throw new Horde_ActiveSync_Exception('Protocol Error');
}
Expand Down Expand Up @@ -135,7 +145,7 @@ protected function _handle()
$importer->init($this->_state);
if (!$delete) {
try {
$serverid = $importer->importFolderChange($serverid, $displayname, $parentid, $type);
$folder = $importer->importFolderChange($server_uid, $displayname, $parentid, $type);
} catch (Horde_ActiveSync_Exception $e) {
$this->_logger->err($e->getMessage());
if ($e->getCode() == Horde_ActiveSync_Exception::UNSUPPORTED) {
Expand All @@ -146,7 +156,7 @@ protected function _handle()
}
} else {
try {
$importer->importFolderDeletion($serverid);
$importer->importFolderDeletion($server_uid);
} catch (Horde_ActiveSync_Exception $e) {
$status = self::STATUS_ERROR;
}
Expand All @@ -155,15 +165,7 @@ protected function _handle()

$this->_encoder->startWBXML();
if ($create) {
// @TODO: Horde 6 - pass a H_AS_Message_Folder object to the importFolderChange()
// method so we can delegate the _serverid creation to the backend like
// it should be.
if ($status == self::STATUS_SUCCESS) {
$folder = $this->_activeSync->messageFactory('Folder');
$folder->serverid = $serverid;
$folder->displayname = $displayname;
$folder->type = $type;
$folder->_serverid = $displayname;
$collections->updateFolderInHierarchy($folder);
$collections->save();
}
Expand All @@ -180,18 +182,12 @@ protected function _handle()
$this->_encoder->endTag();

$this->_encoder->startTag(Horde_ActiveSync::FOLDERHIERARCHY_SERVERENTRYID);
$this->_encoder->content($serverid);
$this->_encoder->content($folder->serverid);
$this->_encoder->endTag();
}

$this->_encoder->endTag();
} elseif ($update) {
// @TODO: See note above about H6.
$folder = $this->_activeSync->messageFactory('Folder');
$folder->serverid = $serverid;
$folder->displayname = $displayname;
$folder->type = $type;
$folder->_serverid = $displayname;
$collections->updateFolderInHierarchy($folder, true);
$collections->save();

Expand All @@ -207,8 +203,7 @@ protected function _handle()

$this->_encoder->endTag();
} elseif ($delete) {
// @TODO: See note about H6
$collections->deleteFolderFromHierarchy($serverid);
$collections->deleteFolderFromHierarchy($server_uid);
$this->_encoder->startTag(self::FOLDERDELETE);

$this->_encoder->startTag(Horde_ActiveSync::FOLDERHIERARCHY_STATUS);
Expand Down
Expand Up @@ -144,8 +144,9 @@ protected function _handle()
switch ($element[Horde_ActiveSync_Wbxml::EN_TAG]) {
case SYNC_ADD:
case SYNC_MODIFY:
$serverid = $importer->importFolderChange(
$new_server = $importer->importFolderChange(
$folder->serverid, $folder->displayname);
$serverid = $new_server->serverid;
if (!in_array($serverid, $seenfolders)) {
$seenfolders[] = $serverid;
$collections->updateFolderInHierarchy($folder);
Expand Down
5 changes: 3 additions & 2 deletions framework/ActiveSync/lib/Horde/ActiveSync/State/Mongo.php
Expand Up @@ -1263,7 +1263,7 @@ protected function _getPIMChangeTS(array $changes)
empty($rows['errmsg']) ? '' : $rows['errmsg']));
}
$results = array();
foreach ($rows as $row) {
foreach ($rows['result'] as $row) {
$results[$row['_id']] = $row['max'];
}

Expand All @@ -1286,10 +1286,11 @@ protected function _havePIMChanges()
$c = $this->_collection['class'] == Horde_ActiveSync::CLASS_EMAIL ?
$this->_db->HAS_mailmap :
$this->_db->HAS_map;

$query = array(
'sync_devid' => $this->_deviceInfo->id,
'sync_user' => $this->_deviceInfo->user,
'sync_folderid' => $this->_collection['id']
'sync_folderid' => $this->_collection['serverid']
);
try {
return (bool)$c->find($query, array('_id'))->count();
Expand Down

0 comments on commit 87bd34f

Please sign in to comment.