summaryrefslogtreecommitdiff
path: root/lib/kolab_sync_data_email.php
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2012-09-12 13:23:47 (GMT)
committerAleksander Machniak <alec@alec.pl>2012-09-12 13:23:47 (GMT)
commitb9a488314de4423bb5525828409f8cde271151ea (patch)
tree01ab6a460d860941ae192df06e4b636a4a78e286 /lib/kolab_sync_data_email.php
parent9c1bfe24c4de02ded9141a222414e91d4b1049aa (diff)
downloadkolab-syncroton-b9a488314de4423bb5525828409f8cde271151ea.tar.gz
Update Syncroton, update code for API changes
Diffstat (limited to 'lib/kolab_sync_data_email.php')
-rw-r--r--lib/kolab_sync_data_email.php97
1 files changed, 62 insertions, 35 deletions
diff --git a/lib/kolab_sync_data_email.php b/lib/kolab_sync_data_email.php
index cebfdfb..a041d7f 100644
--- a/lib/kolab_sync_data_email.php
+++ b/lib/kolab_sync_data_email.php
@@ -336,7 +336,7 @@ class kolab_sync_data_email extends kolab_sync_data implements Syncroton_Data_ID
/**
* Returns properties of a message for Search response
*
- * @param string $longId Message identifier
+ * @param string $longId Message identifier
* @param array $options Search options
*
* @return Syncroton_Model_Email Email object
@@ -787,17 +787,16 @@ class kolab_sync_data_email extends kolab_sync_data implements Syncroton_Data_ID
/**
* ActiveSync Search handler
*
- * @param array $query Search query parameters
- * @param array $options Search options
+ * @param Syncroton_Model_StoreRequest $store Search query
*
- * @return array List of Syncroton_Model_StoreResponseResult objects
+ * @return Syncroton_Model_StoreResponse Complete Search response
*/
- public function search($query, $options)
+ public function search(Syncroton_Model_StoreRequest $store)
{
- list ($folders, $search_str) = $this->parse_search_query($query, $options);
+ list($folders, $search_str) = $this->parse_search_query($store);
if (empty($search_str)) {
- return array();
+ throw new Exception('Empty/invalid search request');
}
$result = array();
@@ -838,48 +837,76 @@ class kolab_sync_data_email extends kolab_sync_data implements Syncroton_Data_ID
}
}
- return array_values($result);
+ $result = array_values($result);
+ $response = new Syncroton_Model_StoreResponse();
+
+ // Calculate requested range
+ $start = (int) $store->options['range'][0];
+ $limit = (int) $store->options['range'][1] + 1;
+ $total = count($result);
+ $response->total = $total;
+
+ // Get requested chunk of data set
+ if ($total) {
+ if ($start > $total) {
+ $start = $total;
+ }
+ if ($limit > $total) {
+ $limit = max($start+1, $total);
+ }
+ if ($start > 0 || $limit < $total) {
+ $result = array_slice($result, $start, $limit-$start);
+ }
+
+ $response->range = array($start, $start + count($result) - 1);
+ }
+
+ // Build result array, convert to ActiveSync format
+ foreach ($result as $idx => $rec) {
+ $rec->properties = $this->getSearchEntry($rec->longId, $store->options);
+ $response->result[] = $rec;
+ unset($result[$idx]);
+ }
+
+ return $response;
}
/**
* Converts ActiveSync search parameters into IMAP search string
*/
- protected function parse_search_query($query, $options)
+ protected function parse_search_query($store)
{
- if (empty($query)) {
- return array();
- }
-
+ $options = $store->options;
+ $query = $store->query;
$search_str = '';
$folders = array();
- if (!is_array($query)) {
- $search = $query;
+ if (empty($query) || !is_array($query)) {
+ return array();
}
- else {
- if (isset($query['and']['freeText']) && strlen($query['and']['freeText'])) {
- $search = $query['and']['freeText'];
- }
- if (!empty($query['and']['collections'])) {
- foreach ($query['and']['collections'] as $collection) {
- $folders = array_merge($folders, $this->extractFolders($collection));
- }
- }
+ if (isset($query['and']['freeText']) && strlen($query['and']['freeText'])) {
+ $search = $query['and']['freeText'];
+ }
- if (!empty($query['and']['greaterThan'])
- && !empty($query['and']['greaterThan']['dateReceived'])
- && !empty($query['and']['greaterThan']['value'])
- ) {
- $search_str .= ' SINCE ' . $query['and']['greaterThan']['value']->format('d-M-Y');
+ if (!empty($query['and']['collections'])) {
+ foreach ($query['and']['collections'] as $collection) {
+ $folders = array_merge($folders, $this->extractFolders($collection));
}
+ }
- if (!empty($query['and']['lessThan'])
- && !empty($query['and']['lessThan']['dateReceived'])
- && !empty($query['and']['lessThan']['value'])
- ) {
- $search_str .= ' BEFORE ' . $query['and']['lessThan']['value']->format('d-M-Y');
- }
+ if (!empty($query['and']['greaterThan'])
+ && !empty($query['and']['greaterThan']['dateReceived'])
+ && !empty($query['and']['greaterThan']['value'])
+ ) {
+ $search_str .= ' SINCE ' . $query['and']['greaterThan']['value']->format('d-M-Y');
+ }
+
+ if (!empty($query['and']['lessThan'])
+ && !empty($query['and']['lessThan']['dateReceived'])
+ && !empty($query['and']['lessThan']['value'])
+ ) {
+ $search_str .= ' BEFORE ' . $query['and']['lessThan']['value']->format('d-M-Y');
}
if ($search !== null) {