summaryrefslogtreecommitdiff
path: root/lib/kolab_sync_data_email.php
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2013-01-17 12:56:01 (GMT)
committerAleksander Machniak <alec@alec.pl>2013-01-17 12:56:01 (GMT)
commit2bec11daf4ffe957a156199d7a3ce279615472c4 (patch)
treedc5c0a8d87acb2f3f851997cd5f8747110d14a62 /lib/kolab_sync_data_email.php
parentf191c1b177119bfed98a01841e6a01abd38edcd4 (diff)
downloadkolab-syncroton-2bec11daf4ffe957a156199d7a3ce279615472c4.tar.gz
Fix detection of changes in email messages (e.g. \Seen flag update) (Bug #1169)
Diffstat (limited to 'lib/kolab_sync_data_email.php')
-rw-r--r--lib/kolab_sync_data_email.php53
1 files changed, 44 insertions, 9 deletions
diff --git a/lib/kolab_sync_data_email.php b/lib/kolab_sync_data_email.php
index 769d472..6a67b34 100644
--- a/lib/kolab_sync_data_email.php
+++ b/lib/kolab_sync_data_email.php
@@ -751,10 +751,12 @@ class kolab_sync_data_email extends kolab_sync_data implements Syncroton_Data_ID
// convert filter into one IMAP search string
foreach ($filter as $idx => $filter_item) {
if (is_array($filter_item)) {
- // @TODO
- // convert 'changed' entries into IMAP search string
- // for now we just return empty result
- return $result_type == self::RESULT_COUNT ? 0 : array();
+ // This is a request for changes since list time
+ // we'll use HIGHESTMODSEQ value from the last Sync
+ if ($filter_item[0] == 'changed' && $filter_item[1] == '>') {
+ $modseq = (array) $this->backend->modseq_get($this->device->id, $folderid, $filter_item[2]);
+ $modseq_data = array();
+ }
}
else {
$filter_str .= ' ' . $filter_item;
@@ -765,15 +767,43 @@ class kolab_sync_data_email extends kolab_sync_data implements Syncroton_Data_ID
// no sorting for best performance
$sort_by = null;
- foreach ($folders as $folderid) {
- $foldername = $this->backend->folder_id2name($folderid, $this->device->deviceid);
+ foreach ($folders as $folder_id) {
+ $foldername = $this->backend->folder_id2name($folder_id, $this->device->deviceid);
if ($foldername === null) {
continue;
}
-// $this->storage->set_folder($foldername);
- $this->storage->folder_sync($foldername);
+ $this->storage->set_folder($foldername);
+
+ // Syncronize folder (if it wasn't synced in this request already)
+ if ($this->lastsync_folder != $foldername
+ || $this->lastsync_time < time() - Syncroton_Registry::getPingTimeout()
+ ) {
+ $this->storage->folder_sync($foldername);
+ }
+
+ $this->lastsync_folder = $foldername;
+ $this->lastsync_time = time();
+
+ // We're in "get changes" mode
+ if (isset($modseq_data)) {
+ $folder_data = $this->storage->folder_data($foldername);
+ if ($folder_data['HIGHESTMODSEQ']) {
+ $modseq_data[$foldername] = $folder_data['HIGHESTMODSEQ'];
+ if ($modseq_data[$foldername] != $modseq[$foldername]) {
+ $modseq_update = true;
+ }
+ }
+
+ // If previous HIGHESTMODSEQ doesn't exist we can't get changes
+ // We can only get folder's HIGHESTMODSEQ value and store it for the next try
+ if (empty($modseq) || empty($modseq[$foldername])) {
+ continue;
+ }
+
+ $filter_str .= " MODSEQ " . ($modseq[$foldername] + 1);
+ }
$search = $this->storage->search_once($foldername, $filter_str);
@@ -789,7 +819,7 @@ class kolab_sync_data_email extends kolab_sync_data implements Syncroton_Data_ID
case self::RESULT_UID:
if ($uids = $search->get()) {
foreach ($uids as $idx => $uid) {
- $uids[$idx] = $this->createMessageId($folderid, $uid);
+ $uids[$idx] = $this->createMessageId($folder_id, $uid);
}
$result = array_merge($result, $uids);
}
@@ -804,6 +834,11 @@ class kolab_sync_data_email extends kolab_sync_data implements Syncroton_Data_ID
}
}
+ if (!empty($modseq_update)) {
+ $this->backend->modseq_set($this->device->id, $folderid,
+ $this->syncTimeStamp, $modseq_data);
+ }
+
return $result;
}