diff --git a/dev/Stores/User/Contact.js b/dev/Stores/User/Contact.js index ec1f1b4e6..863759787 100644 --- a/dev/Stores/User/Contact.js +++ b/dev/Stores/User/Contact.js @@ -1,6 +1,5 @@ import ko from 'ko'; import { SettingsGet } from 'Common/Globals'; -import { pInt } from 'Common/Utils'; import { koComputable, addObservablesTo, koArrayWithDestroy } from 'External/ko'; import Remote from 'Remote/User/Fetch'; @@ -51,16 +50,14 @@ ContactUserStore.sync = fResultFunc => { }; ContactUserStore.init = () => { - let value = !!SettingsGet('ContactsSyncIsAllowed'); - ContactUserStore.allowSync(value); - if (value) { - ContactUserStore.syncMode(SettingsGet('ContactsSyncMode')); - ContactUserStore.syncUrl(SettingsGet('ContactsSyncUrl')); - ContactUserStore.syncUser(SettingsGet('ContactsSyncUser')); - ContactUserStore.syncPass(SettingsGet('ContactsSyncPassword')); + let config = SettingsGet('ContactsSync'); + ContactUserStore.allowSync(!!config); + if (config) { + ContactUserStore.syncMode(config.Mode); + ContactUserStore.syncUrl(config.Url); + ContactUserStore.syncUser(config.User); + ContactUserStore.syncPass(config.Password); setTimeout(ContactUserStore.sync, 10000); - value = pInt(SettingsGet('ContactsSyncInterval')); - value = 5 <= value ? (320 >= value ? value : 320) : 20; - setInterval(ContactUserStore.sync, value * 60000 + 5000); + setInterval(ContactUserStore.sync, config.Interval * 60000 + 5000); } }; diff --git a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php index 0cdcf7767..9d9600c62 100644 --- a/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php +++ b/snappymail/v/0.0.0/app/libraries/RainLoop/Actions.php @@ -686,12 +686,6 @@ class Actions 'MailToEmail' => '', 'ContactsIsAllowed' => $this->AddressBookProvider($oAccount)->IsActive(), - 'ContactsSyncIsAllowed' => (bool)$oConfig->Get('contacts', 'allow_sync', false), - 'ContactsSyncInterval' => (int)$oConfig->Get('contacts', 'sync_interval', 20), - 'ContactsSyncMode' => 0, - 'ContactsSyncUrl' => '', - 'ContactsSyncUser' => '', - 'ContactsSyncPassword' => '', 'ViewHTML' => (bool) $oConfig->Get('defaults', 'view_html', true), 'ShowImages' => (bool) $oConfig->Get('defaults', 'show_images', false), @@ -739,14 +733,15 @@ class Actions ) ); - if ($aResult['ContactsIsAllowed'] && $aResult['ContactsSyncIsAllowed']) { - $mData = $this->getContactsSyncData($oAccount); - if (\is_array($mData)) { - $aResult['ContactsSyncMode'] = isset($mData['Mode']) ? $mData['Mode'] : 0; - $aResult['ContactsSyncUrl'] = isset($mData['Url']) ? \trim($mData['Url']) : ''; - $aResult['ContactsSyncUser'] = isset($mData['User']) ? \trim($mData['User']) : ''; - $aResult['ContactsSyncPassword'] = static::APP_DUMMY; - } + if ($aResult['ContactsIsAllowed'] && $oConfig->Get('contacts', 'allow_sync', false)) { + $aData = $this->getContactsSyncData($oAccount) ?: [ + 'Mode' => 0, + 'Url' => '', + 'User' => '' + ]; + $aData['Password'] = $aData['Password'] ? static::APP_DUMMY : ''; + $aData['Interval'] = \max(20, \min(320, (int) $oConfig->Get('contacts', 'sync_interval', 20))); + $aResult['ContactsSync'] = $aData; } $sToken = Utils::GetCookie(self::AUTH_MAILTO_TOKEN_KEY); diff --git a/snappymail/v/0.0.0/app/libraries/snappymail/upgrade.php b/snappymail/v/0.0.0/app/libraries/snappymail/upgrade.php index dc86c76c2..80e4d8bc6 100644 --- a/snappymail/v/0.0.0/app/libraries/snappymail/upgrade.php +++ b/snappymail/v/0.0.0/app/libraries/snappymail/upgrade.php @@ -132,7 +132,7 @@ abstract class Upgrade if ($aData) { $oActions->setContactsSyncData($oAccount, $aData); return array( - 'Enable' => isset($aData['Enable']) ? !!$aData['Enable'] : false, + 'Mode' => empty($aData['Enable']) ? 0 : 1, 'Url' => isset($aData['Url']) ? \trim($aData['Url']) : '', 'User' => isset($aData['User']) ? \trim($aData['User']) : '', 'Password' => isset($aData['Password']) ? $aData['Password'] : ''