Skip to content

Commit

Permalink
Implement _getMailmapChanges for Mongo driver.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrubinsk committed Oct 16, 2013
1 parent e48b6da commit 9d4093c
Showing 1 changed file with 41 additions and 21 deletions.
62 changes: 41 additions & 21 deletions framework/ActiveSync/lib/Horde/ActiveSync/State/Mongo.php
Expand Up @@ -1235,33 +1235,53 @@ protected function _havePIMChanges()
}

/**
* Determines if a specific email change originated from the client. Used to
* avoid mirroring back client initiated changes.
* Return all available mailMap changes for the current folder.
*
* @param string $id The object id.
* @param array $flags An array of item flags.
* @param string $type The type of change;
* A Horde_ActiveSync::CHANGE_TYPE_* constant.
* @param array $changes The chagnes array
*
* @return boolean True if changes is due to an incoming client change.
* @return array An array of hashes, each in the form of
* {uid} => array(
* Horde_ActiveSync::CHANGE_TYPE_FLAGS => true|false,
* Horde_ActiveSync::CHANGE_TYPE_DELETE => true|false
* )
*/
protected function _isPIMChange($id, $flags, $type)
protected function _getMailMapChanges(array $changes)
{
$this->_logger->info(sprintf(
'_isPIMChange: %s, %s, %s',
$id, print_r($flags, true), $type));
if ($type == Horde_ActiveSync::CHANGE_TYPE_FLAGS) {
if ($this->_isPIMChangeQuery($id, $flags['read'], 'sync_read')) {
return true;
}
if ($this->_isPIMChangeQuery($id, $flags['flagged'], 'sync_flagged')) {
return true;
}
$ids = array();
foreach ($changes as $change) {
$ids[] = strval($change['id']);
}
$query = array(
'sync_folderid' => $this->_collection['id'],
'sync_devid' => $this->_deviceInfo->id,
'sync_user' => $this->_deviceInfo->user,
'message_uid' => array('$in' => $ids)
);
Horde::debug($query);
$rows = $this->_db->mailmap->find(
$query,
array('message_uid', 'sync_read', 'sync_flagged', 'sync_deleted')
);

return false;
} else {
return $this->_isPIMChangeQuery($id, true, 'sync_deleted');
$results = array();
foreach ($rows as $row) {
foreach ($changes as $change) {
if ($change['id'] == $row['message_uid']) {
if ($change['type'] == Horde_ActiveSync::CHANGE_TYPE_FLAGS) {
$results[$row['message_uid']][$change['type']] =
(!is_null($row['sync_read']) && $row['sync_read'] == $change['flags']['read']) ||
(!is_null($row['sync_flagged'] && $row['sync_flagged'] == $change['flags']['flagged']));
continue 2;
} elseif ($change['type'] == Horde_ActiveSync::CHANGE_TYPE_DELETE) {
$results[$row['message_uid']][$change['type']] =
!is_null($row['sync_deleted']) && $row['sync_deleted'] == $change['flags']['deleted'];
continue 2;
}
}
}
}

return $results;
}

/**
Expand Down

0 comments on commit 9d4093c

Please sign in to comment.