mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-07-10 15:08:28 +03:00
Move to plugin #385
This commit is contained in:
parent
86ac71ea2e
commit
9789a2509f
13 changed files with 197 additions and 67 deletions
|
|
@ -97,7 +97,6 @@ capath = ""
|
|||
client_cert = ""
|
||||
|
||||
[capa]
|
||||
contacts = On
|
||||
quota = On
|
||||
search = On
|
||||
search_adv = On
|
||||
|
|
@ -304,7 +303,6 @@ cookie_default_secure = Off
|
|||
check_new_messages = On
|
||||
replace_env_in_configuration = ""
|
||||
boundary_prefix = ""
|
||||
kolab_enabled = Off
|
||||
dev_email = ""
|
||||
dev_password = ""
|
||||
|
||||
|
|
|
|||
|
|
@ -92,6 +92,8 @@ export class AppUser extends AbstractApp {
|
|||
|
||||
addShortcut('escape,enter', '', dropdownsDetectVisibility);
|
||||
addEventListener('click', dropdownsDetectVisibility);
|
||||
|
||||
this.folderList = FolderUserStore.folderList;
|
||||
}
|
||||
|
||||
refresh() {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import { koComputable } from 'External/ko';
|
|||
import { SettingsGet } from 'Common/Globals';
|
||||
import { i18n, trigger as translatorTrigger } from 'Common/Translator';
|
||||
import { ContactUserStore } from 'Stores/User/Contact';
|
||||
import { FolderUserStore } from 'Stores/User/Folder';
|
||||
import Remote from 'Remote/User/Fetch';
|
||||
|
||||
export class UserSettingsContacts /*extends AbstractViewSettings*/ {
|
||||
|
|
@ -49,33 +48,5 @@ export class UserSettingsContacts /*extends AbstractViewSettings*/ {
|
|||
Password: ContactUserStore.syncPass()
|
||||
})
|
||||
);
|
||||
|
||||
this.kolabContactFolder = ko.observable(SettingsGet('KolabContactFolder'));
|
||||
this.kolabContactFolder.subscribe(value =>
|
||||
Remote.saveSettings(null, { KolabContactFolder: value })
|
||||
);
|
||||
this.showKolab = FolderUserStore.allowKolab();
|
||||
this.folderSelectList = koComputable(() => {
|
||||
const
|
||||
aResult = [{
|
||||
id: '',
|
||||
name: '',
|
||||
}],
|
||||
foldersWalk = folders => {
|
||||
folders.forEach(oItem => {
|
||||
if ('contact' === oItem.kolabType()) {
|
||||
aResult.push({
|
||||
id: oItem.fullName,
|
||||
name: oItem.fullName
|
||||
});
|
||||
}
|
||||
if (oItem.subFolders.length) {
|
||||
foldersWalk(oItem.subFolders());
|
||||
}
|
||||
});
|
||||
};
|
||||
foldersWalk(FolderUserStore.folderList());
|
||||
return aResult;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace RainLoop\Providers\AddressBook;
|
||||
|
||||
use RainLoop\Providers\AddressBook\Classes\Contact;
|
||||
use RainLoop\Providers\AddressBook\Classes\Property;
|
||||
use RainLoop\Providers\AddressBook\Enumerations\PropertyType;
|
||||
|
||||
class KolabAddressBook implements AddressBookInterface
|
||||
class KolabAddressBook implements \RainLoop\Providers\AddressBook\AddressBookInterface
|
||||
{
|
||||
use CardDAV;
|
||||
use \RainLoop\Providers\AddressBook\CardDAV;
|
||||
|
||||
protected
|
||||
$oImapClient,
|
||||
|
|
@ -24,7 +24,7 @@ class KolabAddressBook implements AddressBookInterface
|
|||
|
||||
protected function ImapClient() : \MailSo\Imap\ImapClient
|
||||
{
|
||||
if (!$this->oImapClient /*&&\RainLoop\Api::Config()->Get('labs', 'kolab_enabled', false)*/) {
|
||||
if (!$this->oImapClient) {
|
||||
$this->oImapClient = $this->MailClient()->ImapClient();
|
||||
}
|
||||
return $this->oImapClient;
|
||||
|
|
@ -78,9 +78,9 @@ class KolabAddressBook implements AddressBookInterface
|
|||
return $xCard;
|
||||
}
|
||||
|
||||
protected function MessageAsContact(\MailSo\Mail\Message $oMessage) : ?Classes\Contact
|
||||
protected function MessageAsContact(\MailSo\Mail\Message $oMessage) : ?Contact
|
||||
{
|
||||
$oContact = new Classes\Contact;
|
||||
$oContact = new Contact;
|
||||
$oContact->IdContact = $oMessage->Uid();
|
||||
// $oContact->Display = isset($aItem['display']) ? (string) $aItem['display'] : '';
|
||||
$oContact->Changed = $oMessage->HeaderTimeStampInUTC();
|
||||
|
|
@ -88,12 +88,12 @@ class KolabAddressBook implements AddressBookInterface
|
|||
$oFrom = $oMessage->From();
|
||||
if ($oFrom) {
|
||||
$oMail = $oFrom[0];
|
||||
$oProperty = new Classes\Property(PropertyType::EMAIl, $oMail->GetEmail());
|
||||
$oProperty = new Property(PropertyType::EMAIl, $oMail->GetEmail());
|
||||
$oContact->Properties[] = $oProperty;
|
||||
$oProperty = new Classes\Property(PropertyType::FULLNAME, $oMail->GetDisplayName());
|
||||
// $oProperty = new Classes\Property(PropertyType::FULLNAME, $oMail->ToString());
|
||||
$oProperty = new Property(PropertyType::FULLNAME, $oMail->GetDisplayName());
|
||||
// $oProperty = new Property(PropertyType::FULLNAME, $oMail->ToString());
|
||||
$oContact->Properties[] = $oProperty;
|
||||
// $oProperty = new Classes\Property(PropertyType::NICK_NAME, $oMail->GetDisplayName());
|
||||
// $oProperty = new Property(PropertyType::NICK_NAME, $oMail->GetDisplayName());
|
||||
// $oContact->Properties[] = $oProperty;
|
||||
}
|
||||
|
||||
|
|
@ -129,7 +129,7 @@ class KolabAddressBook implements AddressBookInterface
|
|||
return false;
|
||||
}
|
||||
|
||||
public function ContactSave(string $sEmail, Classes\Contact $oContact) : bool
|
||||
public function ContactSave(string $sEmail, Contact $oContact) : bool
|
||||
{
|
||||
// TODO
|
||||
// $emails = $oContact->GetEmails();
|
||||
|
|
@ -237,7 +237,7 @@ class KolabAddressBook implements AddressBookInterface
|
|||
|
||||
if (!\strlen($oParams->sFolderName)) {
|
||||
// return [];
|
||||
throw new ClientException(Notifications::CantGetMessageList);
|
||||
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::CantGetMessageList);
|
||||
}
|
||||
|
||||
$this->ImapClient();
|
||||
|
|
@ -254,13 +254,13 @@ class KolabAddressBook implements AddressBookInterface
|
|||
catch (\Throwable $oException)
|
||||
{
|
||||
throw $oException;
|
||||
throw new ClientException(Notifications::CantGetMessageList, $oException);
|
||||
throw new \RainLoop\Exceptions\ClientException(\RainLoop\Notifications::CantGetMessageList, $oException);
|
||||
}
|
||||
|
||||
return $aResult;
|
||||
}
|
||||
|
||||
public function GetContactByID(string $sEmail, $mID, bool $bIsStrID = false) : ?Classes\Contact
|
||||
public function GetContactByID(string $sEmail, $mID, bool $bIsStrID = false) : ?Contact
|
||||
{
|
||||
if ($bIsStrID) {
|
||||
$oMessage = null;
|
||||
20
plugins/kolab/LICENSE
Normal file
20
plugins/kolab/LICENSE
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 RainLoop Team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
89
plugins/kolab/index.php
Normal file
89
plugins/kolab/index.php
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
|
||||
class KolabPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||
{
|
||||
const
|
||||
NAME = 'Kolab',
|
||||
VERSION = '0.1',
|
||||
RELEASE = '2022-05-13',
|
||||
CATEGORY = 'Security',
|
||||
DESCRIPTION = 'Get contacts suggestions from Kolab.',
|
||||
REQUIRED = '2.15.4';
|
||||
|
||||
public function Init() : void
|
||||
{
|
||||
// \RainLoop\Api::Config()->Set('contacts', 'enable', true);
|
||||
if (\RainLoop\Api::Config()->Get('contacts', 'enable', false)) {
|
||||
$this->addHook('filter.app-data', 'FilterAppData');
|
||||
$this->addHook('main.fabrica', 'MainFabrica');
|
||||
|
||||
$this->addJs('js/settings.js');
|
||||
$this->addTemplate('templates/KolabSettings.html');
|
||||
$this->addJsonHook('KolabFolder', 'DoKolabFolder');
|
||||
}
|
||||
}
|
||||
|
||||
public function Supported() : string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
private function Account() : \RainLoop\Model\Account
|
||||
{
|
||||
return \RainLoop\Api::Actions()->getAccountFromToken();
|
||||
}
|
||||
|
||||
private function SettingsProvider() : \RainLoop\Providers\Settings
|
||||
{
|
||||
return \RainLoop\Api::Actions()->SettingsProvider(true);
|
||||
}
|
||||
|
||||
private function Settings() : \RainLoop\Settings
|
||||
{
|
||||
return $this->SettingsProvider()->Load($this->Account());
|
||||
}
|
||||
|
||||
public function DoKolabFolder() : array
|
||||
{
|
||||
// \error_log(\print_r($this->Manager()->Actions()->GetActionParams(), 1));
|
||||
$sValue = $this->jsonParam('contact');
|
||||
$oSettings = $this->Settings();
|
||||
if (\is_string($sValue)) {
|
||||
$oSettings->SetConf('KolabContactFolder', $sValue);
|
||||
$this->SettingsProvider()->Save($this->Account(), $oSettings);
|
||||
}
|
||||
return $this->jsonResponse(__FUNCTION__, true);
|
||||
}
|
||||
|
||||
public function FilterAppData($bAdmin, &$aResult) : void
|
||||
{
|
||||
// if ImapClient->IsSupported('METADATA')
|
||||
if (\is_array($aResult) && !empty($aResult['Auth'])) {
|
||||
$aResult['Capa']['Kolab'] = true;
|
||||
$aResult['KolabContactFolder'] = (string) $this->Settings()->GetConf('KolabContactFolder', '');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $mResult
|
||||
*/
|
||||
public function MainFabrica(string $sName, &$mResult)
|
||||
{
|
||||
/*
|
||||
if ('suggestions' === $sName) {
|
||||
if (!\is_array($mResult)) {
|
||||
$mResult = array();
|
||||
}
|
||||
// $sFolder = \trim($this->Config()->Get('plugin', 'mailbox', ''));
|
||||
// if ($sFolder) {
|
||||
require_once __DIR__ . '/KolabContactsSuggestions.php';
|
||||
$mResult[] = new KolabContactsSuggestions();
|
||||
// }
|
||||
}
|
||||
*/
|
||||
if ('address-book' === $sName) {
|
||||
require_once __DIR__ . '/KolabAddressBook.php';
|
||||
$mResult = new KolabAddressBook();
|
||||
}
|
||||
}
|
||||
}
|
||||
54
plugins/kolab/js/settings.js
Normal file
54
plugins/kolab/js/settings.js
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
(rl => {
|
||||
|
||||
const getFolders = type => {
|
||||
const
|
||||
aResult = [{
|
||||
id: '',
|
||||
name: '',
|
||||
}],
|
||||
foldersWalk = folders => {
|
||||
folders.forEach(oItem => {
|
||||
if (type === oItem.kolabType()) {
|
||||
aResult.push({
|
||||
id: oItem.fullName,
|
||||
name: oItem.fullName
|
||||
});
|
||||
}
|
||||
if (oItem.subFolders.length) {
|
||||
foldersWalk(oItem.subFolders());
|
||||
}
|
||||
});
|
||||
};
|
||||
foldersWalk(rl.app.folderList());
|
||||
return aResult;
|
||||
};
|
||||
|
||||
|
||||
class KolabSettings /* extends AbstractViewSettings */
|
||||
{
|
||||
constructor() {
|
||||
this.contactFolder = ko.observable(rl.settings.get('KolabContactFolder'));
|
||||
// rl.app.FolderUserStore.hasCapability('METADATA');
|
||||
this.contactFolder.subscribe(value => {
|
||||
rl.pluginRemoteRequest(()=>{}, 'KolabFolder', {
|
||||
contact: value
|
||||
});
|
||||
});
|
||||
this.contactFoldersList = ko.computed(() => getFolders('contact'), {'pure':true});
|
||||
// this.eventFoldersList = ko.computed(() => getFolders('event'), {'pure':true});
|
||||
// this.taskFoldersList = ko.computed(() => getFolders('task'), {'pure':true});
|
||||
// this.noteFoldersList = ko.computed(() => getFolders('note'), {'pure':true});
|
||||
// this.fileFoldersList = ko.computed(() => getFolders('file'), {'pure':true});
|
||||
// this.journalFoldersList = ko.computed(() => getFolders('journal'), {'pure':true});
|
||||
// this.configFoldersList = ko.computed(() => getFolders('configuration'), {'pure':true});
|
||||
}
|
||||
}
|
||||
|
||||
rl.addSettingsViewModel(
|
||||
KolabSettings,
|
||||
'KolabSettings',
|
||||
'Kolab',
|
||||
'kolab'
|
||||
);
|
||||
|
||||
})(window.rl);
|
||||
12
plugins/kolab/templates/KolabSettings.html
Normal file
12
plugins/kolab/templates/KolabSettings.html
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
<div class="b-settings-kolab form-horizontal">
|
||||
<div class="legend">Kolab</div>
|
||||
<div class="form-horizontal">
|
||||
|
||||
<div class="control-group">
|
||||
<label data-i18n="KOLAB/CONTACTS_FOLDER"></label>
|
||||
<select data-bind="options: contactFoldersList, value: contactFolder,
|
||||
optionsText: 'name', optionsValue: 'id'"></select>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -249,7 +249,6 @@ class Actions
|
|||
case 'address-book':
|
||||
// Providers\AddressBook\AddressBookInterface
|
||||
$mResult = new Providers\AddressBook\PdoAddressBook();
|
||||
// $mResult = new Providers\AddressBook\KolabAddressBook();
|
||||
break;
|
||||
case 'identities':
|
||||
case 'suggestions':
|
||||
|
|
@ -498,10 +497,9 @@ class Actions
|
|||
{
|
||||
if (null === $this->oAddressBookProvider) {
|
||||
$oDriver = null;
|
||||
if ($this->GetCapa(Enumerations\Capa::CONTACTS)) {
|
||||
if ($this->oConfig->Get('contacts', 'enable', false) || $bForceEnable) {
|
||||
$oDriver = $this->fabrica('address-book', $oAccount);
|
||||
}
|
||||
// if ($bForceEnable || $this->oConfig->Get('contacts', 'enable', false)) {
|
||||
if ($bForceEnable || $this->GetCapa(Enumerations\Capa::CONTACTS)) {
|
||||
$oDriver = $this->fabrica('address-book', $oAccount);
|
||||
}
|
||||
|
||||
$this->oAddressBookProvider = new Providers\AddressBook($oDriver);
|
||||
|
|
@ -731,7 +729,6 @@ class Actions
|
|||
'ContactsAutosave' => (bool) $oConfig->Get('defaults', 'contacts_autosave', true),
|
||||
'HideUnsubscribed' => false,
|
||||
'MainEmail' => '',
|
||||
'KolabContactFolder' => '',
|
||||
'UserBackgroundName' => '',
|
||||
'UserBackgroundHash' => ''
|
||||
);
|
||||
|
|
@ -829,7 +826,6 @@ class Actions
|
|||
$aResult['HideUnsubscribed'] = (bool)$oSettingsLocal->GetConf('HideUnsubscribed', $aResult['HideUnsubscribed']);
|
||||
$aResult['UseThreads'] = (bool)$oSettingsLocal->GetConf('UseThreads', $aResult['UseThreads']);
|
||||
$aResult['ReplySameFolder'] = (bool)$oSettingsLocal->GetConf('ReplySameFolder', $aResult['ReplySameFolder']);
|
||||
$aResult['KolabContactFolder'] = (string)$oSettingsLocal->GetConf('KolabContactFolder', $aResult['KolabContactFolder']);
|
||||
}
|
||||
|
||||
if ($oConfig->Get('login', 'determine_user_language', true)) {
|
||||
|
|
@ -1154,11 +1150,11 @@ class Actions
|
|||
'AdditionalAccounts' => (bool) $oConfig->Get('webmail', 'allow_additional_accounts', false),
|
||||
'AttachmentThumbnails' => (bool) $oConfig->Get('interface', 'show_attachment_thumbnail', true),
|
||||
'AttachmentsActions' => (bool) $oConfig->Get('capa', 'attachments_actions', false),
|
||||
'Contacts' => (bool) $oConfig->Get('capa', 'contacts', true),
|
||||
'Contacts' => (bool) $oConfig->Get('contacts', 'enable', false),
|
||||
'DangerousActions' => (bool) $oConfig->Get('capa', 'dangerous_actions', true),
|
||||
'GnuPG' => (bool) $oConfig->Get('security', 'openpgp', false) && \SnappyMail\PGP\GnuPG::isSupported(),
|
||||
'Identities' => (bool) $oConfig->Get('webmail', 'allow_additional_identities', false),
|
||||
'Kolab' => (bool) $oConfig->Get('labs', 'kolab_enabled', false) /* && ImapClient->IsSupported('METADATA')*/,
|
||||
'Kolab' => false, // See Kolab plugin
|
||||
'MessageActions' => (bool) $oConfig->Get('capa', 'message_actions', true),
|
||||
'OpenPGP' => (bool) $oConfig->Get('security', 'openpgp', false),
|
||||
'Prefetch' => (bool) $oConfig->Get('labs', 'allow_prefetch', false),
|
||||
|
|
|
|||
|
|
@ -345,7 +345,6 @@ trait User
|
|||
$this->setSettingsFromParams($oSettingsLocal, 'UseThreads', 'bool');
|
||||
$this->setSettingsFromParams($oSettingsLocal, 'ReplySameFolder', 'bool');
|
||||
$this->setSettingsFromParams($oSettingsLocal, 'HideUnsubscribed', 'bool');
|
||||
$this->setSettingsFromParams($oSettingsLocal, 'KolabContactFolder', 'string');
|
||||
|
||||
return $this->DefaultResponse(__FUNCTION__,
|
||||
$this->SettingsProvider()->Save($oAccount, $oSettings) &&
|
||||
|
|
|
|||
|
|
@ -208,7 +208,6 @@ class Application extends \RainLoop\Config\AbstractConfig
|
|||
),
|
||||
|
||||
'capa' => array(
|
||||
'contacts' => array(true),
|
||||
'quota' => array(true),
|
||||
'search' => array(true),
|
||||
'search_adv' => array(true),
|
||||
|
|
@ -400,7 +399,6 @@ Enables caching in the system'),
|
|||
'check_new_messages' => array(true),
|
||||
'replace_env_in_configuration' => array(''),
|
||||
'boundary_prefix' => array(''),
|
||||
'kolab_enabled' => array(false),
|
||||
'dev_email' => array(''),
|
||||
'dev_password' => array('')
|
||||
),
|
||||
|
|
|
|||
|
|
@ -21,5 +21,4 @@ class Capa
|
|||
const ATTACHMENTS_ACTIONS = 'AttachmentsActions';
|
||||
const DANGEROUS_ACTIONS = 'DangerousActions';
|
||||
const AUTOLOGOUT = 'AutoLogout';
|
||||
const KOLAB = 'Kolab';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,11 +40,3 @@
|
|||
spellcheck="false" data-bind="value: syncPass">
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-horizontal" data-bind="visible: showKolab">
|
||||
<div class="legend">Kolab</div>
|
||||
<div class="control-group">
|
||||
<label data-i18n="KOLAB/CONTACTS_FOLDER"></label>
|
||||
<select data-bind="options: folderSelectList, value: kolabContactFolder,
|
||||
optionsText: 'name', optionsValue: 'id'"></select>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue