Skip to content

Commit

Permalink
Seperate the folder changes from the message changes for clarity.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrubinsk committed May 5, 2015
1 parent fbdd5e9 commit f65780b
Showing 1 changed file with 140 additions and 120 deletions.
260 changes: 140 additions & 120 deletions framework/ActiveSync/lib/Horde/ActiveSync/Connector/Exporter.php
Expand Up @@ -151,147 +151,167 @@ public function setChanges($changes, $collection)
public function sendNextChange()
{
if (empty($this->_currentCollection)) {
if ($this->_step < count($this->_changes)) {
return $this->_sendNextFolderSyncChange();
} else {
return $this->_sendNextChange();
}
}

/**
* Sends the next message change to the client.
*
* @return @see self::sendNextChange()
*/
protected function _sendNextChange()
{
if ($this->_step < count($this->_changes)) {
$change = $this->_changes[$this->_step];

// Ignore this change, no UID value, keep trying until we get a
// good entry or we run out of entries.
while (empty($change['id']) && $this->_step < count($this->_changes) - 1) {
$this->_logger->err('Missing UID value for an entry in: ' . $this->_currentCollection['id']);
$this->_step++;
$change = $this->_changes[$this->_step];
}

// Actually export the change by calling the appropriate
// method to output the correct wbxml for this change.
if (empty($change['ignore'])) {
switch($change['type']) {
case Horde_ActiveSync::CHANGE_TYPE_CHANGE:
// Folder add/change.
if ($folder = $this->_as->driver->getFolder($change['serverid'])) {
// @TODO BC HACK. Need to ensure we have a _serverid here.
// REMOVE IN H6.
if (empty($folder->_serverid)) {
$folder->_serverid = $folder->serverid;
}
$stat = $this->_as->driver->statFolder(
try {
$message = $this->_as->driver->getMessage(
$this->_currentCollection['serverid'],
$change['id'],
$folder->parentid,
$folder->displayname,
$folder->_serverid,
$folder->type);
$this->folderChange($folder);
} else {
$this->_currentCollection);
$message->flags = (isset($change['flags'])) ? $change['flags'] : 0;
$this->messageChange($change['id'], $message);
} catch (Horde_Exception_NotFound $e) {
$this->_logger->err(sprintf(
'[%s] Message gone or error reading message from server: %s',
$this->_procid, $e->getMessage()));
$this->_as->state->updateState($change['type'], $change);
$this->_step++;
return $e;
} catch (Horde_ActiveSync_Exception $e) {
$this->_logger->err(sprintf(
'[%s] Error stating %s: ignoring.',
$this->_procid, $change['id']));
$stat = array('id' => $change['id'], 'mod' => $change['id'], 0);
'[%s] Unknown backend error skipping message: %s',
$this->_procid,
$e->getMessage()));
$this->_as->state->updateState($change['type'], $change);
$this->_step++;
return $e;
}
// Update the state.
$this->_as->state->updateState(
Horde_ActiveSync::CHANGE_TYPE_FOLDERSYNC, $stat);
break;

case Horde_ActiveSync::CHANGE_TYPE_DELETE:
$this->folderDeletion($change['id']);
$this->_as->state->updateState(
Horde_ActiveSync::CHANGE_TYPE_DELETE, $change);
$this->messageDeletion($change['id']);
break;
}
$this->_step++;
return true;
} else {
return false;
}
} else {
if ($this->_step < count($this->_changes)) {
$change = $this->_changes[$this->_step];

// Ignore this change, no UID value, keep trying until we get a
// good entry or we run out of entries.
while (empty($change['id']) && $this->_step < count($this->_changes) - 1) {
$this->_logger->err('Missing UID value for an entry in: ' . $this->_currentCollection['id']);
$this->_step++;
$change = $this->_changes[$this->_step];
}
case Horde_ActiveSync::CHANGE_TYPE_SOFTDELETE:
$this->messageDeletion($change['id'], true);
break;

// Actually export the change by calling the appropriate
// method to output the correct wbxml for this change.
if (empty($change['ignore'])) {
switch($change['type']) {
case Horde_ActiveSync::CHANGE_TYPE_CHANGE:
try {
$message = $this->_as->driver->getMessage(
$this->_currentCollection['serverid'],
$change['id'],
$this->_currentCollection);
$message->flags = (isset($change['flags'])) ? $change['flags'] : 0;
$this->messageChange($change['id'], $message);
} catch (Horde_Exception_NotFound $e) {
$this->_logger->err(sprintf(
'[%s] Message gone or error reading message from server: %s',
$this->_procid, $e->getMessage()));
$this->_as->state->updateState($change['type'], $change);
$this->_step++;
return $e;
} catch (Horde_ActiveSync_Exception $e) {
$this->_logger->err(sprintf(
'[%s] Unknown backend error skipping message: %s',
$this->_procid,
$e->getMessage()));
$this->_as->state->updateState($change['type'], $change);
$this->_step++;
return $e;
}
break;

case Horde_ActiveSync::CHANGE_TYPE_DELETE:
$this->messageDeletion($change['id']);
break;

case Horde_ActiveSync::CHANGE_TYPE_SOFTDELETE:
$this->messageDeletion($change['id'], true);
break;

case Horde_ActiveSync::CHANGE_TYPE_FLAGS:
// Read flag.
$message = Horde_ActiveSync::messageFactory('Mail');
$message->flags = Horde_ActiveSync::CHANGE_TYPE_CHANGE;
$message->read = isset($change['flags']['read']) ? $change['flags']['read'] : false;

// "Flagged" flag.
if (isset($change['flags']['flagged']) && $this->_as->device->version >= Horde_ActiveSync::VERSION_TWELVE) {
$flag = Horde_ActiveSync::messageFactory('Flag');
$flag->flagstatus = $change['flags']['flagged'] == 1
? Horde_ActiveSync_Message_Flag::FLAG_STATUS_ACTIVE
: Horde_ActiveSync_Message_Flag::FLAG_STATUS_CLEAR;
$message->flag = $flag;
}
case Horde_ActiveSync::CHANGE_TYPE_FLAGS:
// Read flag.
$message = Horde_ActiveSync::messageFactory('Mail');
$message->flags = Horde_ActiveSync::CHANGE_TYPE_CHANGE;
$message->read = isset($change['flags']['read']) ? $change['flags']['read'] : false;

// "Flagged" flag.
if (isset($change['flags']['flagged']) && $this->_as->device->version >= Horde_ActiveSync::VERSION_TWELVE) {
$flag = Horde_ActiveSync::messageFactory('Flag');
$flag->flagstatus = $change['flags']['flagged'] == 1
? Horde_ActiveSync_Message_Flag::FLAG_STATUS_ACTIVE
: Horde_ActiveSync_Message_Flag::FLAG_STATUS_CLEAR;
$message->flag = $flag;
}

// Categories
if (!empty($change['categories']) && $this->_as->device->version > Horde_ActiveSync::VERSION_TWELVEONE) {
$message->categories = $change['categories'];
}
// Categories
if (!empty($change['categories']) && $this->_as->device->version > Horde_ActiveSync::VERSION_TWELVEONE) {
$message->categories = $change['categories'];
}

// Verbs
if ($this->_as->device->version >= Horde_ActiveSync::VERSION_FOURTEEN) {
if (isset($change['flags'][Horde_ActiveSync::CHANGE_REPLY_STATE])) {
$message->lastverbexecuted = Horde_ActiveSync_Message_Mail::VERB_REPLY_SENDER;
$message->lastverbexecutiontime = new Horde_Date($change['flags'][Horde_ActiveSync::CHANGE_REPLY_STATE]);
} elseif (isset($change['flags'][Horde_ActiveSync::CHANGE_REPLYALL_STATE])) {
$message->lastverbexecuted = Horde_ActiveSync_Message_Mail::VERB_REPLY_ALL;
$message->lastverbexecutiontime = new Horde_Date($change['flags'][Horde_ActiveSync::CHANGE_REPLYALL_STATE]);
} elseif (isset($change['flags'][Horde_ActiveSync::CHANGE_FORWARD_STATE])) {
$message->lastverbexecuted = Horde_ActiveSync_Message_Mail::VERB_FORWARD;
$message->lastverbexecutiontime = new Horde_Date($change['flags'][Horde_ActiveSync::CHANGE_FORWARD_STATE]);
}
// Verbs
if ($this->_as->device->version >= Horde_ActiveSync::VERSION_FOURTEEN) {
if (isset($change['flags'][Horde_ActiveSync::CHANGE_REPLY_STATE])) {
$message->lastverbexecuted = Horde_ActiveSync_Message_Mail::VERB_REPLY_SENDER;
$message->lastverbexecutiontime = new Horde_Date($change['flags'][Horde_ActiveSync::CHANGE_REPLY_STATE]);
} elseif (isset($change['flags'][Horde_ActiveSync::CHANGE_REPLYALL_STATE])) {
$message->lastverbexecuted = Horde_ActiveSync_Message_Mail::VERB_REPLY_ALL;
$message->lastverbexecutiontime = new Horde_Date($change['flags'][Horde_ActiveSync::CHANGE_REPLYALL_STATE]);
} elseif (isset($change['flags'][Horde_ActiveSync::CHANGE_FORWARD_STATE])) {
$message->lastverbexecuted = Horde_ActiveSync_Message_Mail::VERB_FORWARD;
$message->lastverbexecutiontime = new Horde_Date($change['flags'][Horde_ActiveSync::CHANGE_FORWARD_STATE]);
}
}

// Export it.
$this->messageChange($change['id'], $message);
break;
// Export it.
$this->messageChange($change['id'], $message);
break;

case Horde_ActiveSync::CHANGE_TYPE_MOVE:
$this->messageMove($change['id'], $change['parent']);
break;
}
case Horde_ActiveSync::CHANGE_TYPE_MOVE:
$this->messageMove($change['id'], $change['parent']);
break;
}
}

// Update the state.
$this->_as->state->updateState($change['type'], $change);
$this->_step++;
return true;
} else {
return false;
}
}

/**
* Sends the next folder change to the client.
*
* @return @see self::sendNextChange()
*/
protected function _sendNextFolderSyncChange()
{
if ($this->_step < count($this->_changes)) {
$change = $this->_changes[$this->_step];
switch($change['type']) {
case Horde_ActiveSync::CHANGE_TYPE_CHANGE:
// Folder add/change.
if ($folder = $this->_as->driver->getFolder($change['serverid'])) {
// @TODO BC HACK. Need to ensure we have a _serverid here.
// REMOVE IN H6.
if (empty($folder->_serverid)) {
$folder->_serverid = $folder->serverid;
}
$stat = $this->_as->driver->statFolder(
$change['id'],
$folder->parentid,
$folder->displayname,
$folder->_serverid,
$folder->type);
$this->folderChange($folder);
} else {
$this->_logger->err(sprintf(
'[%s] Error stating %s: ignoring.',
$this->_procid, $change['id']));
$stat = array('id' => $change['id'], 'mod' => $change['id'], 0);
}
// Update the state.
$this->_as->state->updateState($change['type'], $change);
$this->_step++;
return true;
} else {
return false;
$this->_as->state->updateState(
Horde_ActiveSync::CHANGE_TYPE_FOLDERSYNC, $stat);
break;

case Horde_ActiveSync::CHANGE_TYPE_DELETE:
$this->folderDeletion($change['id']);
$this->_as->state->updateState(
Horde_ActiveSync::CHANGE_TYPE_DELETE, $change);
break;
}
$this->_step++;
return true;
} else {
return false;
}
}

Expand Down

0 comments on commit f65780b

Please sign in to comment.