mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-25 10:09:20 +03:00
Merge 721a849254 into c154d23cfe
This commit is contained in:
commit
bc7cd52657
10 changed files with 469 additions and 5 deletions
207
plugins/nextcloud/NextcloudAddressBook.php
Normal file
207
plugins/nextcloud/NextcloudAddressBook.php
Normal file
|
|
@ -0,0 +1,207 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use RainLoop\Providers\AddressBook\Classes\Contact;
|
||||||
|
|
||||||
|
class NextcloudAddressBook implements \RainLoop\Providers\AddressBook\AddressBookInterface
|
||||||
|
{
|
||||||
|
use RainLoop\Providers\AddressBook\CardDAV;
|
||||||
|
|
||||||
|
private const SETTINGS_KEY = 'nextcloudAddressBookUri';
|
||||||
|
|
||||||
|
private string $defaultUri;
|
||||||
|
private string $defaultName;
|
||||||
|
private string $defaultDescription;
|
||||||
|
private bool $ignoreSystemAddressBook;
|
||||||
|
private $contactsManager;
|
||||||
|
|
||||||
|
function __construct(string $defaultUri = 'webmail', string $defaultName = 'WebMail', string $defaultDescription = 'Recipients from snappymail', bool $ignoreSystemAddressBook = true)
|
||||||
|
{
|
||||||
|
$this->defaultUri = $defaultUri;
|
||||||
|
$this->defaultName = $defaultName;
|
||||||
|
$this->defaultDescription = $defaultDescription;
|
||||||
|
$this->ignoreSystemAddressBook = $ignoreSystemAddressBook;
|
||||||
|
|
||||||
|
$this->GetSavedAddressBookKey();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getContactsManager()
|
||||||
|
{
|
||||||
|
if ($this->contactsManager == null) {
|
||||||
|
$this->contactsManager = \OC::$server->getContactsManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->contactsManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function GetSavedAddressBookKey() : string
|
||||||
|
{
|
||||||
|
if ($this->ignoreSystemAddressBook) {
|
||||||
|
foreach ($this->getContactsManager()->getUserAddressBooks() as $addressBook) {
|
||||||
|
if ($addressBook->isSystemAddressBook()) {
|
||||||
|
$this->getContactsManager()->unregisterAddressBook($addressBook);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$uid = \OC::$server->getUserSession()->getUser()->getUID();
|
||||||
|
$cardDavBackend = \OC::$server->get(\OCA\DAV\CardDAV\CardDavBackend::class);
|
||||||
|
$principalUri = 'principals/users/' . $uid;
|
||||||
|
$uri = $this->GetSavedUri();
|
||||||
|
$addressBookId = $cardDavBackend->getAddressBooksByUri($principalUri, $uri);
|
||||||
|
|
||||||
|
if ($addressBookId === null) {
|
||||||
|
return $cardDavBackend->createAddressBook($principalUri, $uri, array_filter([
|
||||||
|
'{DAV:}displayname' => $this->defaultName,
|
||||||
|
'{urn:ietf:params:xml:ns:carddav}addressbook-description' => $this->defaultDescription,
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $addressBookId['id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function IsSupported() : bool
|
||||||
|
{
|
||||||
|
// Maybe just return true, contacts app is just a frontend
|
||||||
|
// return \OC::$server->getAppManager()->isEnabledForUser('contacts');
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function SetEmail(string $sEmail) : bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function Sync() : bool
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function Export(string $sType = 'vcf') : bool
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function ContactSave(Contact $oContact) : bool
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function DeleteContacts(array $aContactIds) : bool
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function DeleteAllContacts(string $sEmail) : bool
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function GetContacts(int $iOffset = 0, int $iLimit = 20, string $sSearch = '', int &$iResultCount = 0) : array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function GetContactByEmail(string $sEmail) : ?Contact
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function GetContactByID($mID, bool $bIsStrID = false) : ?Contact
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function GetSuggestions(string $sSearch, int $iLimit = 20) : array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function GetEmailObjects(array $aEmails) : array
|
||||||
|
{
|
||||||
|
$aEmailsObjects = \array_map(function ($mItem) {
|
||||||
|
$oResult = null;
|
||||||
|
try {
|
||||||
|
$oResult = \MailSo\Mime\Email::Parse(\trim($mItem));
|
||||||
|
} catch (\Throwable $oException) {
|
||||||
|
unset($oException);
|
||||||
|
}
|
||||||
|
return $oResult;
|
||||||
|
}, $aEmails);
|
||||||
|
|
||||||
|
$aEmailsObjects = \array_filter($aEmailsObjects, function ($oItem) {
|
||||||
|
return !!$oItem;
|
||||||
|
});
|
||||||
|
return $aEmailsObjects;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add/increment email address usage
|
||||||
|
* Handy for "most used" sorting suggestions in PdoAddressBook
|
||||||
|
*/
|
||||||
|
public function IncFrec(array $aEmails, bool $bCreateAuto = true) : bool
|
||||||
|
{
|
||||||
|
if ($bCreateAuto) {
|
||||||
|
$aEmailsObjects = $this->GetEmailObjects($aEmails);
|
||||||
|
|
||||||
|
if (!count($aEmailsObjects)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($aEmailsObjects as $oEmail) {
|
||||||
|
$this->createOrUpdateContact($oEmail);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function createOrUpdateContact($oEmail)
|
||||||
|
{
|
||||||
|
if ('' === \trim($oEmail->GetEmail())) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$sEmail = \trim($oEmail->GetEmail(true));
|
||||||
|
$existingResults = $this->getContactsManager()->search($sEmail, ['EMAIL'], ['strict_search' => true]);
|
||||||
|
|
||||||
|
if (!empty($existingResults)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$properties = [
|
||||||
|
'EMAIL' => $sEmail,
|
||||||
|
'FN' => $sEmail
|
||||||
|
];
|
||||||
|
|
||||||
|
if ('' !== \trim($oEmail->GetDisplayName())) {
|
||||||
|
$properties['FN'] = $oEmail->GetDisplayName();
|
||||||
|
}
|
||||||
|
$this->getContactsManager()->createOrUpdate($properties, $this->GetSavedAddressBookKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function Test() : 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());
|
||||||
|
}
|
||||||
|
|
||||||
|
private function GetSavedUri() : string
|
||||||
|
{
|
||||||
|
return $this->Settings()->GetConf(self::SETTINGS_KEY, $this->defaultUri);
|
||||||
|
}
|
||||||
|
}
|
||||||
14
plugins/nextcloud/README.md
Normal file
14
plugins/nextcloud/README.md
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
# SnappyMail plugin for nextcloud
|
||||||
|
|
||||||
|
## Nextcloud Addressbook to save recipients' contacts
|
||||||
|
|
||||||
|
This plugin can let user to choose which nextcloud addressbook to use save recipients (requires enableing snappyMail contacts) . This is opt-in feature (enabled by admin). After admin enable this, user will find a dropdown in his/her SnappyMail's `Contacts` section, containing all his/her addressbook. It works better with [Nextcloud Contacts App](https://github.com/nextcloud/contacts/)
|
||||||
|
|
||||||
|
### Admin settings
|
||||||
|
|
||||||
|
- `enableNcAddressbook` : Enable: save recipient contacts into nextcloud addressbook feature. User will see a new section into her/his `Contacts` setting, so s/he can choose Nextcloud addressbook to save recipients' contacts. Default value: `false`
|
||||||
|
- `disableSnappymailContactsUI` : Hide SnappyMail internal addressbook accesspoint. This is recomended if nextcloud addressbook to save recipients contacts is being used. So, users won't be confused to having multiple addressbook options. Default value: `false`
|
||||||
|
- `defaultNCAddressbookUri` : Default nextcloud addressbook URI to save recipients' contacts. Ignored if `enableNcAddressbook` is set to false. User can change this value for her/his account. Default value: `webmail`
|
||||||
|
- `defaultNCAddressbookName` : Default nextcloud addressbook Name to save recipients' contacts. Ignored if `enableNcAddressbook` is set to false. User can change this value for her/his account. Default value: `WebMail`
|
||||||
|
- `defaultNCAddressbookDescription` : Default nextcloud addressbook description to save recipients' contacts. Ignored if `enableNcAddressbook` is set to false. User can change this value for her/his account. Default value: `Recipients from snappymail`
|
||||||
|
|
||||||
|
|
@ -10,6 +10,26 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
DESCRIPTION = 'Integrate with Nextcloud v20+',
|
DESCRIPTION = 'Integrate with Nextcloud v20+',
|
||||||
REQUIRED = '2.38.0';
|
REQUIRED = '2.38.0';
|
||||||
|
|
||||||
|
private const IGNORE_SYSTEM_ADDRESSBOOK_KEY = 'ignoreSystemAddressbook';
|
||||||
|
private const IGNORE_SYSTEM_ADDRESSBOOK_DEFAULT_VALUE = true;
|
||||||
|
|
||||||
|
private const ENABLE_NC_ADDRESSBOOK_KEY = 'enableNcAddressbook';
|
||||||
|
private const ENABLE_NC_ADDRESSBOOK_DEFAULT_VALUE = false;
|
||||||
|
|
||||||
|
private const DISABLE_INHOUSE_ADDRESSBOOK_KEY = 'disableSnappymailContactsUI';
|
||||||
|
private const DISABLE_INHOUSE_ADDRESSBOOK_DEFAULT_VALUE = false;
|
||||||
|
|
||||||
|
private const DEFAULT_ADDRESSBOOK_URI_KEY = 'defaultNCAddressbookUri';
|
||||||
|
private const DEFAULT_ADDRESSBOOK_URI = 'webmail';
|
||||||
|
|
||||||
|
private const DEFAULT_ADDRESSBOOK_NAME_KEY = 'defaultNCAddressbookName';
|
||||||
|
private const DEFAULT_ADDRESSBOOK_NAME = 'WebMail';
|
||||||
|
|
||||||
|
private const DEFAULT_ADDRESSBOOK_DESCRIPTION_KEY = 'defaultNCAddressbookDescription';
|
||||||
|
private const DEFAULT_ADDRESSBOOK_DESCRIPTION = 'Recipients from snappymail';
|
||||||
|
|
||||||
|
private const ADDRESSBOOK_SETTINGS_KEY = 'nextcloudAddressBookUri';
|
||||||
|
|
||||||
public function Init() : void
|
public function Init() : void
|
||||||
{
|
{
|
||||||
if (static::IsIntegrated()) {
|
if (static::IsIntegrated()) {
|
||||||
|
|
@ -41,6 +61,16 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
$this->addHook('imap.before-login', 'beforeLogin');
|
$this->addHook('imap.before-login', 'beforeLogin');
|
||||||
$this->addHook('smtp.before-login', 'beforeLogin');
|
$this->addHook('smtp.before-login', 'beforeLogin');
|
||||||
$this->addHook('sieve.before-login', 'beforeLogin');
|
$this->addHook('sieve.before-login', 'beforeLogin');
|
||||||
|
|
||||||
|
if ($this->Config()->Get('plugin', self::ENABLE_NC_ADDRESSBOOK_KEY, self::ENABLE_NC_ADDRESSBOOK_DEFAULT_VALUE)) {
|
||||||
|
$this->addJs('js/nextcloudAddressbook.js');
|
||||||
|
$this->addJsonHook('NextcloudGetAddressBooks', 'GetAddressBooks');
|
||||||
|
$this->addJsonHook('NextcloudUpdateAddressBook', 'UpdateAddressBook');
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->Config()->Get('plugin', self::DISABLE_INHOUSE_ADDRESSBOOK_KEY, self::DISABLE_INHOUSE_ADDRESSBOOK_DEFAULT_VALUE)) {
|
||||||
|
$this->addJs('js/hideInhouseAddressbook.js');
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
\SnappyMail\Log::debug('Nextcloud', 'NOT integrated');
|
\SnappyMail\Log::debug('Nextcloud', 'NOT integrated');
|
||||||
// \OC::$server->getConfig()->getAppValue('snappymail', 'snappymail-no-embed');
|
// \OC::$server->getConfig()->getAppValue('snappymail', 'snappymail-no-embed');
|
||||||
|
|
@ -48,6 +78,50 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function GetAddressBooks()
|
||||||
|
{
|
||||||
|
$addressBooks = [];
|
||||||
|
|
||||||
|
$contactsManager = \OC::$server->getContactsManager();
|
||||||
|
|
||||||
|
$defaultUri = $this->Config()->Get('plugin', self::DEFAULT_ADDRESSBOOK_URI_KEY, self::DEFAULT_ADDRESSBOOK_URI);
|
||||||
|
$selectedUri = $this->UserSettings()->GetConf(self::ADDRESSBOOK_SETTINGS_KEY, $defaultUri);
|
||||||
|
$ignoreSystemAddressbook = $this->Config()->Get('plugin', self::IGNORE_SYSTEM_ADDRESSBOOK_KEY, self::IGNORE_SYSTEM_ADDRESSBOOK_DEFAULT_VALUE);
|
||||||
|
|
||||||
|
foreach ($contactsManager->getUserAddressBooks() as $addressBook) {
|
||||||
|
if ($ignoreSystemAddressbook && $addressBook->isSystemAddressBook()) {
|
||||||
|
$contactsManager->unregisterAddressBook($addressBook);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$book = new AddressBook();
|
||||||
|
$book->uri = $addressBook->getUri();
|
||||||
|
$book->name = $addressBook->getDisplayName();
|
||||||
|
if (strcmp($selectedUri, $book->uri) === 0) {
|
||||||
|
$book->selected = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$addressBooks[] = $book;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return $this->jsonResponse(__FUNCTION__, array(
|
||||||
|
'addressbooks' => json_encode($addressBooks)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function UpdateAddressBook() : array
|
||||||
|
{
|
||||||
|
$uri = $this->jsonParam('uri');
|
||||||
|
$oSettings = $this->UserSettings();
|
||||||
|
if (\is_string($uri)) {
|
||||||
|
$oSettings->SetConf(self::ADDRESSBOOK_SETTINGS_KEY, $uri);
|
||||||
|
$this->SettingsProvider()->Save($this->Account(), $oSettings);
|
||||||
|
}
|
||||||
|
return $this->jsonResponse(__FUNCTION__, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function ContentSecurityPolicy(\SnappyMail\HTTP\CSP $CSP)
|
public function ContentSecurityPolicy(\SnappyMail\HTTP\CSP $CSP)
|
||||||
{
|
{
|
||||||
if (\method_exists($CSP, 'add')) {
|
if (\method_exists($CSP, 'add')) {
|
||||||
|
|
@ -353,7 +427,26 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
}
|
}
|
||||||
include_once __DIR__ . '/NextcloudContactsSuggestions.php';
|
include_once __DIR__ . '/NextcloudContactsSuggestions.php';
|
||||||
$mResult[] = new NextcloudContactsSuggestions(
|
$mResult[] = new NextcloudContactsSuggestions(
|
||||||
$this->Config()->Get('plugin', 'ignoreSystemAddressbook', true)
|
$this->Config()->Get('plugin', self::IGNORE_SYSTEM_ADDRESSBOOK_KEY, self::IGNORE_SYSTEM_ADDRESSBOOK_DEFAULT_VALUE)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('address-book' === $sName && $this->Config()->Get('plugin', self::ENABLE_NC_ADDRESSBOOK_KEY, self::ENABLE_NC_ADDRESSBOOK_DEFAULT_VALUE)) {
|
||||||
|
if (!\is_array($mResult)) {
|
||||||
|
$mResult = array();
|
||||||
|
}
|
||||||
|
include_once __DIR__ . '/NextcloudAddressBook.php';
|
||||||
|
|
||||||
|
$ignoreSystemAddressbook = $this->Config()->Get('plugin', self::IGNORE_SYSTEM_ADDRESSBOOK_KEY, self::IGNORE_SYSTEM_ADDRESSBOOK_DEFAULT_VALUE);
|
||||||
|
$defaultName = $this->Config()->Get('plugin', self::DEFAULT_ADDRESSBOOK_NAME_KEY, self::DEFAULT_ADDRESSBOOK_NAME);
|
||||||
|
$defaultDescription = $this->Config()->Get('plugin', self::DEFAULT_ADDRESSBOOK_DESCRIPTION_KEY, self::DEFAULT_ADDRESSBOOK_DESCRIPTION);
|
||||||
|
$defaultUri = $this->Config()->Get('plugin', self::DEFAULT_ADDRESSBOOK_URI_KEY, self::DEFAULT_ADDRESSBOOK_URI);
|
||||||
|
|
||||||
|
$mResult = new NextcloudAddressBook(
|
||||||
|
$defaultUri,
|
||||||
|
$defaultName,
|
||||||
|
$defaultDescription,
|
||||||
|
$ignoreSystemAddressbook
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
|
|
@ -371,9 +464,9 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
\RainLoop\Plugins\Property::NewInstance('suggestions')->SetLabel('Suggestions')
|
\RainLoop\Plugins\Property::NewInstance('suggestions')->SetLabel('Suggestions')
|
||||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
|
||||||
->SetDefaultValue(true),
|
->SetDefaultValue(true),
|
||||||
\RainLoop\Plugins\Property::NewInstance('ignoreSystemAddressbook')->SetLabel('Ignore system addressbook')
|
\RainLoop\Plugins\Property::NewInstance(self::IGNORE_SYSTEM_ADDRESSBOOK_KEY)->SetLabel('Ignore system addressbook')
|
||||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
|
||||||
->SetDefaultValue(true),
|
->SetDefaultValue(self::IGNORE_SYSTEM_ADDRESSBOOK_DEFAULT_VALUE),
|
||||||
/*
|
/*
|
||||||
\RainLoop\Plugins\Property::NewInstance('storage')->SetLabel('Use Nextcloud user ID in config storage path')
|
\RainLoop\Plugins\Property::NewInstance('storage')->SetLabel('Use Nextcloud user ID in config storage path')
|
||||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
|
||||||
|
|
@ -381,7 +474,27 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
*/
|
*/
|
||||||
\RainLoop\Plugins\Property::NewInstance('calendar')->SetLabel('Enable "Put ICS in calendar"')
|
\RainLoop\Plugins\Property::NewInstance('calendar')->SetLabel('Enable "Put ICS in calendar"')
|
||||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
|
||||||
->SetDefaultValue(false)
|
->SetDefaultValue(false),
|
||||||
|
|
||||||
|
\RainLoop\Plugins\Property::NewInstance(self::ENABLE_NC_ADDRESSBOOK_KEY)->SetLabel('Enable User to choose Nextcloud addressbook for recipients')
|
||||||
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
|
||||||
|
->SetDefaultValue(self::ENABLE_NC_ADDRESSBOOK_DEFAULT_VALUE),
|
||||||
|
|
||||||
|
\RainLoop\Plugins\Property::NewInstance(self::DEFAULT_ADDRESSBOOK_URI_KEY)->SetLabel('Default nextcloud addressbook URI for recipients')
|
||||||
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING)
|
||||||
|
->SetDefaultValue(self::DEFAULT_ADDRESSBOOK_URI),
|
||||||
|
|
||||||
|
\RainLoop\Plugins\Property::NewInstance(self::DEFAULT_ADDRESSBOOK_NAME_KEY)->SetLabel('Default nextcloud addressbook Name for recipients')
|
||||||
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING)
|
||||||
|
->SetDefaultValue(self::DEFAULT_ADDRESSBOOK_NAME),
|
||||||
|
|
||||||
|
\RainLoop\Plugins\Property::NewInstance(self::DEFAULT_ADDRESSBOOK_DESCRIPTION_KEY)->SetLabel('Default nextcloud addressbook description for recipients')
|
||||||
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::STRING)
|
||||||
|
->SetDefaultValue(self::DEFAULT_ADDRESSBOOK_DESCRIPTION),
|
||||||
|
|
||||||
|
\RainLoop\Plugins\Property::NewInstance(self::DISABLE_INHOUSE_ADDRESSBOOK_KEY)->SetLabel('Disable SnappyMail internal addressbook. This is recomended if nextcloud addressbook is being used.')
|
||||||
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
|
||||||
|
->SetDefaultValue(self::DISABLE_INHOUSE_ADDRESSBOOK_DEFAULT_VALUE)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -413,4 +526,26 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
}
|
}
|
||||||
return $sFilePath;
|
return $sFilePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 UserSettings() : \RainLoop\Settings
|
||||||
|
{
|
||||||
|
return $this->SettingsProvider()->Load($this->Account());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AddressBook
|
||||||
|
{
|
||||||
|
public string $uri;
|
||||||
|
public string $name;
|
||||||
|
public bool $selected = false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
49
plugins/nextcloud/js/hideInhouseAddressbook.js
Normal file
49
plugins/nextcloud/js/hideInhouseAddressbook.js
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
(rl => {
|
||||||
|
if (rl) {
|
||||||
|
addEventListener('rl-view-model', e => {
|
||||||
|
if ('MailFolderList' === e.detail.viewModelTemplateID) {
|
||||||
|
const container = e.detail.viewModelDom.querySelector('.buttonContacts');
|
||||||
|
if (container) {
|
||||||
|
container.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
addEventListener('rl-view-model', e => {
|
||||||
|
if ('SystemDropDown' === e.detail.viewModelTemplateID) {
|
||||||
|
const container = e.detail.viewModelDom.querySelector('.dropdown-menu');
|
||||||
|
if (!container) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < container.children.length; i++) {
|
||||||
|
const element = container.children[i];
|
||||||
|
const attr = element.getAttribute("data-bind");
|
||||||
|
if (attr && attr.includes("visible: allowContacts")) {
|
||||||
|
element.remove();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
addEventListener('rl-view-model', e => {
|
||||||
|
if ('PopupsCompose' === e.detail.viewModelTemplateID) {
|
||||||
|
const container = e.detail.viewModelDom.querySelector('.pull-right');
|
||||||
|
if(!container) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < container.children.length; i++) {
|
||||||
|
const element = container.children[i];
|
||||||
|
const attr = element.getAttribute("data-bind");
|
||||||
|
if (attr && attr.includes("visible: allowContacts")) {
|
||||||
|
element.remove();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})(window.rl);
|
||||||
42
plugins/nextcloud/js/nextcloudAddressbook.js
Normal file
42
plugins/nextcloud/js/nextcloudAddressbook.js
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
(rl => {
|
||||||
|
if (rl) {
|
||||||
|
addEventListener('rl-view-model', e => {
|
||||||
|
if ('SettingsContacts' === e.detail.viewModelTemplateID) {
|
||||||
|
const container = e.detail.viewModelDom.querySelector('.form-horizontal');
|
||||||
|
if (!container) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
rl.pluginRemoteRequest((iError, oData) => {
|
||||||
|
if (iError) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const mainDivElement = Element.fromHTML('<div class="control-group">'
|
||||||
|
+ '<label>' + rl.i18n("NEXTCLOUD/ADDRESS_BOOK") + '</label>'
|
||||||
|
+ '</div>');
|
||||||
|
|
||||||
|
const selectElement = Element.fromHTML('<select></select>');
|
||||||
|
|
||||||
|
const addressbooks = JSON.parse(oData.Result.addressbooks);
|
||||||
|
addressbooks.forEach(addressbook => {
|
||||||
|
if (addressbook.selected) {
|
||||||
|
selectElement.append(Element.fromHTML('<option value="' + addressbook.uri + '" selected="selected">' + addressbook.name + '</option>'));
|
||||||
|
} else {
|
||||||
|
selectElement.append(Element.fromHTML('<option value="' + addressbook.uri + '">' + addressbook.name + '</option>'));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
selectElement.onchange = function() {
|
||||||
|
rl.pluginRemoteRequest(() => { }, 'NextcloudUpdateAddressBook', {
|
||||||
|
uri: selectElement.value
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
mainDivElement.append(selectElement);
|
||||||
|
container.append(mainDivElement);
|
||||||
|
}, "NextcloudGetAddressBooks");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})(window.rl);
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
"SELECT_CALENDAR": "Kalender auswählen",
|
"SELECT_CALENDAR": "Kalender auswählen",
|
||||||
"FILE_ATTACH": "anfügen",
|
"FILE_ATTACH": "anfügen",
|
||||||
"FILE_INTERNAL": "intern",
|
"FILE_INTERNAL": "intern",
|
||||||
"FILE_PUBLIC": "öffentlich"
|
"FILE_PUBLIC": "öffentlich",
|
||||||
|
"ADDRESS_BOOK": "Adressbuch"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
"SELECT_CALENDAR": "Select calendar",
|
"SELECT_CALENDAR": "Select calendar",
|
||||||
"FILE_ATTACH": "attach",
|
"FILE_ATTACH": "attach",
|
||||||
"FILE_INTERNAL": "internal",
|
"FILE_INTERNAL": "internal",
|
||||||
|
"ADDRESS_BOOK": "Address Book",
|
||||||
"FILE_PUBLIC": "public"
|
"FILE_PUBLIC": "public"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
5
plugins/nextcloud/langs/es.json
Normal file
5
plugins/nextcloud/langs/es.json
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"NEXTCLOUD": {
|
||||||
|
"ADDRESS_BOOK": "Libreta de direcciones"
|
||||||
|
}
|
||||||
|
}
|
||||||
5
plugins/nextcloud/langs/fr.json
Normal file
5
plugins/nextcloud/langs/fr.json
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"NEXTCLOUD": {
|
||||||
|
"ADDRESS_BOOK": "Carnet d'adresses"
|
||||||
|
}
|
||||||
|
}
|
||||||
5
plugins/nextcloud/langs/it.json
Normal file
5
plugins/nextcloud/langs/it.json
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"NEXTCLOUD": {
|
||||||
|
"ADDRESS_BOOK": "Rubrica"
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue