Page MenuHomePhorge

D5406.1775243708.diff
No OneTemporary

Authored By
Unknown
Size
7 KB
Referenced Files
None
Subscribers
None

D5406.1775243708.diff

diff --git a/plugins/kolab_activesync/config.inc.php.dist b/plugins/kolab_activesync/config.inc.php.dist
--- a/plugins/kolab_activesync/config.inc.php.dist
+++ b/plugins/kolab_activesync/config.inc.php.dist
@@ -2,7 +2,3 @@
// The page with Activesync clients configuration manual
$config['activesync_setup_url'] = 'https://kb.kolab.org/?s=activesync';
-
-// Force a subscription state per devicetype (lowercase) and folder
-// States can be: 0 => not subscribed, 1 => subscribed, 2 => subscribed with alarm
-$config['activesync_force_subscriptions'] = ['windowsoutlook15' => ['INBOX' => 1, 'Sent' => 1, 'Trash' => 1, 'Calendar' => 1, 'Contacts' => 1, 'Tasks' => 1]];
diff --git a/plugins/kolab_activesync/kolab_activesync_ui.php b/plugins/kolab_activesync/kolab_activesync_ui.php
--- a/plugins/kolab_activesync/kolab_activesync_ui.php
+++ b/plugins/kolab_activesync/kolab_activesync_ui.php
@@ -29,7 +29,6 @@
private $rc;
private $plugin;
- private $force_subscriptions = [];
private $skin_path;
public const SETUP_URL = 'https://kb.kolabenterprise.com/documentation/setting-up-an-activesync-client';
@@ -42,7 +41,6 @@
$skin_path = $this->plugin->local_skin_path() . '/';
$this->skin_path = 'plugins/kolab_activesync/' . $skin_path;
- $this->force_subscriptions = $this->rc->config->get('activesync_force_subscriptions', []);
$this->plugin->include_stylesheet($skin_path . 'config.css');
}
@@ -98,15 +96,6 @@
return $table->show($attrib);
}
- private function is_protected($folder, $devicetype)
- {
- $devicetype = strtolower($devicetype);
- if (array_key_exists($devicetype, $this->force_subscriptions)) {
- return array_key_exists($folder, $this->force_subscriptions[$devicetype]);
- }
- return false;
- }
-
public function folder_subscriptions($attrib = [])
{
if (empty($attrib['id'])) {
@@ -116,8 +105,6 @@
// group folders by type (show only known types)
$use_fieldsets = rcube_utils::get_boolean($attrib['use-fieldsets'] ?? '');
$imei = $this->device['deviceid'];
- $devicetype = strtolower($this->device['devicetype'] ?? 'unknown');
- $device_force_subscriptions = $this->force_subscriptions[$devicetype] ?? [];
$html = null;
foreach (['mail', 'contact', 'event', 'task', 'note'] as $type) {
@@ -128,9 +115,7 @@
$f = $folder[0];
$subscribed = 0;
- if ($device_force_subscriptions && array_key_exists($f, $device_force_subscriptions)) {
- $subscribed = intval($device_force_subscriptions[$f]);
- } elseif (!empty($subscriptions[$f])) {
+ if (!empty($subscriptions[$f])) {
$subscribed = (int) $subscriptions[$f][0];
}
@@ -219,7 +204,7 @@
$table->add_row();
- $disabled = $this->is_protected($folder, $this->device['devicetype'] ?? 'unknown');
+ $disabled = $this->plugin->engine->is_protected($folder, $this->device['devicetype'] ?? 'unknown');
$table->add('subscription checkbox-cell', $checkbox_sync->show(
$subscribed > 0 ? $folder_value : null,
@@ -277,7 +262,7 @@
$name .= " ($_name)";
}
- $disabled = $this->is_protected($folder_name, $device['devicetype'] ?? 'unknown');
+ $disabled = $this->plugin->engine->is_protected($folder_name, $device['devicetype'] ?? 'unknown');
$flag = $subscriptions[$id] ?? 0;
$table->add_row();
diff --git a/plugins/libkolab/config.inc.php.dist b/plugins/libkolab/config.inc.php.dist
--- a/plugins/libkolab/config.inc.php.dist
+++ b/plugins/libkolab/config.inc.php.dist
@@ -94,3 +94,7 @@
'timeout' => 30,
);
*/
+
+// Force a subscription state per devicetype (lowercase) and folder
+// States can be: 0 => not subscribed, 1 => subscribed, 2 => subscribed with alarm
+$config['activesync_force_subscriptions'] = ['windowsoutlook15' => ['INBOX' => 1, 'Sent' => 1, 'Trash' => 1, 'Calendar' => 1, 'Contacts' => 1, 'Addressbook' => 1, 'Tasks' => 1, '/dav/calendars/user/.*/Default' => 1, '/dav/addressbooks/user/.*/Default' => 1]];
diff --git a/plugins/libkolab/lib/kolab_subscriptions.php b/plugins/libkolab/lib/kolab_subscriptions.php
--- a/plugins/libkolab/lib/kolab_subscriptions.php
+++ b/plugins/libkolab/lib/kolab_subscriptions.php
@@ -33,6 +33,7 @@
private $folders_list;
private $folders_type;
private $icache = [];
+ private $protected_folders = [];
/**
* Object constructor
@@ -42,6 +43,7 @@
public function __construct($dav_url = null)
{
$this->rc = rcube::get_instance();
+ $this->protected_folders = $this->rc->config->get('activesync_force_subscriptions', []);
if ($dav_url) {
$this->dav = new kolab_storage_dav($dav_url);
@@ -107,6 +109,36 @@
return $result;
}
+ /**
+ * Getter for folders subscription flag on protected folders
+ *
+ * @return string|false false if not set, otherwise the flag.
+ */
+ private function get_forced_flag($folder, $devicetype)
+ {
+ $forcedFolders = $this->protected_folders[strtolower($devicetype)] ?? [];
+
+ foreach ($forcedFolders as $idx => $flag) {
+ if (preg_match("|$idx|", $folder)) {
+ return $flag;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Check if a folder is protected by a forced subscription setting
+ *
+ * @param string $folder Folder
+ * @param string $devicetype Device type
+ *
+ * @return bool True if protected
+ */
+ public function is_protected($folder, $devicetype)
+ {
+ return $this->get_forced_flag($folder, $devicetype) !== false;
+ }
+
/**
* Get folder subscriptions
*
@@ -123,10 +155,10 @@
$result = $this->get_subscriptions($deviceid, $type);
+ $devicetype = $this->imei_to_type($deviceid);
+ $folders = $this->list_folders($type);
// Verify if subscribed folders still exist
if (!empty($result)) {
- $folders = $this->list_folders($type);
-
foreach ($result as $idx => $flag) {
reset($folders);
foreach ($folders as $folder) {
@@ -149,6 +181,20 @@
}
}
+ // Insert existing folders that match the forced folders set, that aren't already in the result set
+ // TODO: Because of the regex support in protected_folders we end up doing a lot of comparisons (count(folders) * count(protected_folders)),
+ // and can't use a map instead.
+ foreach ($folders as $folder) {
+ $folderPath = $folder[0];
+ if (array_key_exists($folderPath, $result)) {
+ continue;
+ }
+ if (($flag = $this->get_forced_flag($folder[0], $devicetype)) !== false) {
+ $folder[0] = $flag;
+ $result[$folderPath] = $folder;
+ }
+ }
+
return $result ?? [];
}
@@ -482,6 +528,29 @@
return $this->icache["deviceid:{$userid}:{$imei}"] = $db->fetch_array($result)[0] ?? null;
}
+ /**
+ * Get syncroton device type from IMEI identifier
+ *
+ * @param string $imei IMEI identifier
+ *
+ * @return string|null Syncroton device identifier
+ */
+ private function imei_to_type($imei)
+ {
+ $userid = $this->rc->user->ID;
+
+ if (isset($this->icache["devicetype:{$userid}:{$imei}"])) {
+ return $this->icache["devicetype:{$userid}:{$imei}"];
+ }
+
+ $db = $this->rc->get_dbh();
+ $table = $db->table_name('syncroton_device');
+
+ $result = $db->query("SELECT devicetype FROM {$table} WHERE `owner_id` = ? AND `deviceid` = ?", $userid, $imei);
+
+ return $this->icache["devicetype:{$userid}:{$imei}"] = $db->fetch_array($result)[0] ?? null;
+ }
+
/**
* IMAP folder properties for list_folders/list_subscriptions output
*/

File Metadata

Mime Type
text/plain
Expires
Fri, Apr 3, 7:15 PM (10 h, 45 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18825899
Default Alt Text
D5406.1775243708.diff (7 KB)

Event Timeline