Branch 'kolab-syncroton-2.2' - 2 commits - config/main.inc.php.dist lib/kolab_sync_backend.php lib/kolab_sync_data.php

Aleksander Machniak machniak at kolabsys.com
Fri Jan 24 12:23:07 CET 2014


 config/main.inc.php.dist   |   42 ++++++++----
 lib/kolab_sync_backend.php |  149 +++++++++++++++++++++++++++++++++++----------
 lib/kolab_sync_data.php    |    1 
 3 files changed, 147 insertions(+), 45 deletions(-)

New commits:
commit ea4620ecf234ddb5f85487f88a674e05d3cbf5d8
Author: Aleksander Machniak <alec at alec.pl>
Date:   Fri Jan 24 12:20:54 2014 +0100

    Add option (activesync_init_subscriptions) to define which folders
    should be subscribed for synchronization on device init (#2794)

diff --git a/config/main.inc.php.dist b/config/main.inc.php.dist
index ba6ca08..2ebe75d 100644
--- a/config/main.inc.php.dist
+++ b/config/main.inc.php.dist
@@ -63,3 +63,19 @@ $config['activesync_ping_timeout'] = 60;
 // We start detecting changes n seconds since the last sync of a folder
 // Default: 180
 $config['activesync_quiet_time'] = 180;
+
+// When a device is reqistered, by default a set of folders are
+// subscribed for syncronization, i.e. INBOX and personal folders with
+// defined folder type:
+//     mail.drafts, mail.wastebasket, mail.sentitems, mail.outbox,
+//     event, event.default,
+//     contact, contact.default,
+//     task, task.default
+// This default set can be extended by adding following values:
+//     1 - all subscribed folders in personal namespace
+//     2 - all folders in personal namespace
+//     4 - all subscribed folders in other users namespace
+//     8 - all folders in other users namespace
+//    16 - all subscribed folders in shared namespace
+//    32 - all folders in shared namespace
+$config['activesync_init_subscriptions'] = 0;
diff --git a/lib/kolab_sync_backend.php b/lib/kolab_sync_backend.php
index 1b85e06..e280c4c 100644
--- a/lib/kolab_sync_backend.php
+++ b/lib/kolab_sync_backend.php
@@ -398,37 +398,8 @@ class kolab_sync_backend
             // Update local cache
             $this->root_meta['DEVICE'][$id] = $device;
 
-            // Subscribe to default folders
-            $foldertypes = kolab_storage::folders_typedata();
-
-            if (!empty($foldertypes)) {
-                $types = array(
-                    'mail.drafts',
-                    'mail.wastebasket',
-                    'mail.sentitems',
-                    'mail.outbox',
-                    'event.default',
-                    'contact.default',
-                    'task.default',
-                    'event',
-                    'contact',
-                    'task'
-                );
-
-                $foldertypes = array_intersect($foldertypes, $types);
-
-                // get default folders
-                foreach ($foldertypes as $folder => $type) {
-                    // only personal folders
-                    if ($this->storage->folder_namespace($folder) == 'personal') {
-                        $flag = preg_match('/^(event|task)/', $type) ? 2 : 1;
-                        $this->folder_set($folder, $id, $flag);
-                    }
-                }
-            }
-
-            // INBOX always exists
-            $this->folder_set('INBOX', $id, 1);
+            // subscribe default set of folders
+            $this->device_init_subscriptions($id);
         }
 
         return $result;
@@ -535,6 +506,122 @@ class kolab_sync_backend
         return $result;
     }
 
+    /**
+     * Subscribe default set of folders on device registration
+     */
+    private function device_init_subscriptions($deviceid)
+    {
+        // INBOX always exists
+        $this->folder_set('INBOX', $deviceid, 1);
+
+        $supported_types = array(
+            'mail.drafts',
+            'mail.wastebasket',
+            'mail.sentitems',
+            'mail.outbox',
+            'event.default',
+            'contact.default',
+            'task.default',
+            'event',
+            'contact',
+            'task'
+        );
+
+        // This default set can be extended by adding following values:
+        $modes = array(
+            'SUB_PERSONAL' => 1, // all subscribed folders in personal namespace
+            'ALL_PERSONAL' => 2, // all folders in personal namespace
+            'SUB_OTHER'    => 4, // all subscribed folders in other users namespace
+            'ALL_OTHER'    => 8, // all folders in other users namespace
+            'SUB_SHARED'   => 16, // all subscribed folders in shared namespace
+            'ALL_SHARED'   => 32, // all folders in shared namespace
+        );
+
+        $rcube   = rcube::get_instance();
+        $config  = $rcube->config;
+        $mode    = (int) $config->get('activesync_init_subscriptions');
+        $folders = array();
+
+        // Subscribe to default folders
+        $foldertypes = kolab_storage::folders_typedata();
+
+        if (!empty($foldertypes)) {
+            $_foldertypes = array_intersect($foldertypes, $supported_types);
+
+            // get default folders
+            foreach ($_foldertypes as $folder => $type) {
+                // only personal folders
+                if ($this->storage->folder_namespace($folder) == 'personal') {
+                    $flag = preg_match('/^(event|task)/', $type) ? 2 : 1;
+                    $this->folder_set($folder, $deviceid, $flag);
+                    $folders[] = $folder;
+                }
+            }
+        }
+
+        // we're in default mode, exit
+        if (!$mode) {
+            return;
+        }
+
+        // below we support additionally all mail folders
+        $supported_types[] = 'mail';
+        $supported_types[] = 'mail.junkemails';
+
+        // get configured special folders
+        $special_folders = array();
+        $map             = array(
+            'drafts' => 'mail.drafts',
+            'junk'   => 'mail.junkemails',
+            'sent'   => 'mail.sentitems',
+            'trash'  => 'mail.wastebasket',
+        );
+
+        foreach ($map as $folder => $type) {
+            if ($folder = $config->get($folder . '_mbox')) {
+                $special_folders[$folder] = $type;
+            }
+        }
+
+        // get folders list(s)
+        if (($mode & $modes['ALL_PERSONAL']) || ($mode & $modes['ALL_OTHER']) || ($mode & $modes['ALL_SHARED'])) {
+            $all_folders        = $this->storage->list_folders();
+            if (($mode & $modes['SUB_PERSONAL']) || ($mode & $modes['SUB_OTHER']) || ($mode & $modes['SUB_SHARED'])) {
+                $subscribed_folders = $this->storage->list_folders_subscribed();
+            }
+        }
+        else {
+            $all_folders = $this->storage->list_folders_subscribed();
+        }
+
+        foreach ($all_folders as $folder) {
+            // folder already subscribed
+            if (in_array($folder, $folders)) {
+                continue;
+            }
+
+            $type = $foldertypes[$folder] ?: 'mail';
+            if ($type == 'mail' && isset($special_folders[$folder])) {
+                $type == $special_folders[$folder];
+            }
+
+            if (!in_array($type, $supported_types)) {
+                continue;
+            }
+
+            $ns = strtoupper($this->storage->folder_namespace($folder));
+
+            // subscribe the folder according to configured mode
+            // and folder namespace/subscription status
+            if (($mode & $modes["ALL_$ns"])
+                || (($mode & $modes["SUB_$ns"])
+                    && (!isset($subscribed_folders) || in_array($folder, $subscribed_folders)))
+            ) {
+                $flag = preg_match('/^(event|task)/', $type) ? 2 : 1;
+                $this->folder_set($folder, $deviceid, $flag);
+            }
+        }
+    }
 
     /**
      * Helper method to decode saved IMAP metadata
diff --git a/lib/kolab_sync_data.php b/lib/kolab_sync_data.php
index bff7105..b09bf68 100644
--- a/lib/kolab_sync_data.php
+++ b/lib/kolab_sync_data.php
@@ -879,7 +879,6 @@ abstract class kolab_sync_data implements Syncroton_Data_IData
             }
         }
 
-
         return $folders;
     }
 


commit d679d8a3d12c98527ae0af1ea9fe1bdc837664ea
Author: Aleksander Machniak <alec at alec.pl>
Date:   Fri Jan 24 08:51:27 2014 +0100

    s/$rcmail_config/$config/

diff --git a/config/main.inc.php.dist b/config/main.inc.php.dist
index a57c4e6..ba6ca08 100644
--- a/config/main.inc.php.dist
+++ b/config/main.inc.php.dist
@@ -3,37 +3,37 @@
 // This file lists all ActiveSync-related configuration options
 
 // Enables ActiveSync protocol debuging
-$rcmail_config['activesync_debug'] = true;
+$config['activesync_debug'] = true;
 
 // Enables logging to a separate directory for every user/device
-$rcmail_config['activesync_user_log'] = false;
+$config['activesync_user_log'] = false;
 
 // Enable per-user debugging only if /var/log/syncroton/<username>/ folder exists
-$rcmail_config['activesync_user_debug'] = false;
+$config['activesync_user_debug'] = false;
 
 // If specified all ActiveSync-related logs will be saved to this file
 // Note: This doesn't change Roundcube Framework log locations
-$rcmail_config['activesync_log_file'] = null;
+$config['activesync_log_file'] = null;
 
 // Type of ActiveSync cache. Supported values: 'db', 'apc' and 'memcache'.
 // Note: This is only for some additional data like timezones mapping.
-$rcmail_config['activesync_cache'] = 'db';
+$config['activesync_cache'] = 'db';
 
 // lifetime of ActiveSync cache
 // possible units: s, m, h, d, w
-$rcmail_config['activesync_cache_ttl'] = '1d';
+$config['activesync_cache_ttl'] = '1d';
 
 // Type of ActiveSync Auth cache. Supported values: 'db', 'apc' and 'memcache'.
 // Note: This is only for username canonification map.
-$rcmail_config['activesync_auth_cache'] = 'db';
+$config['activesync_auth_cache'] = 'db';
 
 // lifetime of ActiveSync Auth cache
 // possible units: s, m, h, d, w
-$rcmail_config['activesync_auth_cache_ttl'] = '1d';
+$config['activesync_auth_cache_ttl'] = '1d';
 
 // List of global addressbooks (GAL)
 // Note: If empty 'autocomplete_addressbooks' setting will be used
-$rcmail_config['activesync_addressbooks'] = array();
+$config['activesync_addressbooks'] = array();
 
 // ActiveSync => Roundcube contact fields map for GAL search
 /* Default: array(
@@ -50,16 +50,16 @@ $rcmail_config['activesync_addressbooks'] = array();
        'title'         => 'jobtitle',
 );
 */
-$rcmail_config['activesync_gal_fieldmap'] = null;
+$config['activesync_gal_fieldmap'] = null;
 
 // List of Roundcube plugins
 // WARNING: Not all plugins used in Roundcube can be listed here
-$rcmail_config['activesync_plugins'] = array();
+$config['activesync_plugins'] = array();
 
 // Defines for how many seconds we'll sleep between every
 // action for detecting changes in folders. Default: 60
-$rcmail_config['activesync_ping_timeout'] = 60;
+$config['activesync_ping_timeout'] = 60;
 
 // We start detecting changes n seconds since the last sync of a folder
 // Default: 180
-$rcmail_config['activesync_quiet_time'] = 180;
+$config['activesync_quiet_time'] = 180;




More information about the commits mailing list