mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-08-25 18:19:22 +03:00
feat: add addressBook user settings section for nextcloud plugin
This commit is contained in:
parent
957654c746
commit
500b997f91
10 changed files with 232 additions and 73 deletions
|
|
@ -1,38 +1,44 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
use RainLoop\Providers\AddressBook\Classes\Contact;
|
use RainLoop\Providers\AddressBook\Classes\Contact;
|
||||||
|
|
||||||
class NextcloudAddressBook implements \RainLoop\Providers\AddressBook\AddressBookInterface
|
class NextcloudAddressBook implements \RainLoop\Providers\AddressBook\AddressBookInterface
|
||||||
{
|
{
|
||||||
use RainLoop\Providers\AddressBook\CardDAV;
|
use RainLoop\Providers\AddressBook\CardDAV;
|
||||||
private const URI = 'webmail';
|
|
||||||
private $contactsManager;
|
private $contactsManager;
|
||||||
private $key;
|
|
||||||
|
|
||||||
function __construct()
|
function __construct()
|
||||||
|
{
|
||||||
|
$this->GetSavedAddressBookKey();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function GetSavedAddressBookKey(): string
|
||||||
{
|
{
|
||||||
$this->contactsManager = \OC::$server->getContactsManager();
|
$this->contactsManager = \OC::$server->getContactsManager();
|
||||||
|
|
||||||
foreach($this->contactsManager->getUserAddressBooks() as $addressBook) {
|
foreach ($this->contactsManager->getUserAddressBooks() as $addressBook) {
|
||||||
if($addressBook->isSystemAddressBook()) {
|
if ($addressBook->isSystemAddressBook()) {
|
||||||
$this->contactsManager->unregisterAddressBook($addressBook);
|
$this->contactsManager->unregisterAddressBook($addressBook);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$uid = \OC::$server->getUserSession()->getUser()->getUID();
|
$uid = \OC::$server->getUserSession()->getUser()->getUID();
|
||||||
$cardDavBackend = \OC::$server->get(\OCA\DAV\CardDAV\CardDavBackend::class);
|
$cardDavBackend = \OC::$server->get(\OCA\DAV\CardDAV\CardDavBackend::class);
|
||||||
$principalUri = 'principals/users/'. $uid;
|
$principalUri = 'principals/users/' . $uid;
|
||||||
$addressBookId = $cardDavBackend->getAddressBooksByUri($principalUri, self::URI);
|
$uri = $this->GetSavedUri();
|
||||||
|
$addressBookId = $cardDavBackend->getAddressBooksByUri($principalUri, $uri);
|
||||||
if ($addressBookId === null) {
|
if ($addressBookId === null) {
|
||||||
$addressBookId = $cardDavBackend->createAddressBook($principalUri, self::URI, array_filter([
|
$addressBookId = $cardDavBackend->createAddressBook($principalUri, $uri, array_filter([
|
||||||
'{DAV:}displayname' => 'Webmail',
|
'{DAV:}displayname' => 'WebMail',
|
||||||
'{urn:ietf:params:xml:ns:carddav}addressbook-description' => 'Recipients from snappymail',
|
'{urn:ietf:params:xml:ns:carddav}addressbook-description' => 'Recipients from snappymail',
|
||||||
]));
|
]));
|
||||||
} else {
|
} else {
|
||||||
$addressBookId = $addressBookId['id'];
|
$addressBookId = $addressBookId['id'];
|
||||||
}
|
}
|
||||||
$this->key = $addressBookId;
|
return $addressBookId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function IsSupported() : bool {
|
public function IsSupported(): bool
|
||||||
|
{
|
||||||
// Maybe just return true, contacts app is just a frontend
|
// Maybe just return true, contacts app is just a frontend
|
||||||
//return \OC::$server->getAppManager()->isEnabledForUser('contacts');
|
//return \OC::$server->getAppManager()->isEnabledForUser('contacts');
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -43,53 +49,63 @@ class NextcloudAddressBook implements \RainLoop\Providers\AddressBook\AddressBoo
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function SetEmail(string $sEmail) : bool {
|
public function SetEmail(string $sEmail): bool
|
||||||
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function Sync() : bool {
|
public function Sync(): bool
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function Export(string $sType = 'vcf') : bool {
|
public function Export(string $sType = 'vcf'): bool
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function ContactSave(Contact $oContact) : bool {
|
public function ContactSave(Contact $oContact): bool
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function DeleteContacts(array $aContactIds) : bool {
|
public function DeleteContacts(array $aContactIds): bool
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function DeleteAllContacts(string $sEmail) : bool {
|
public function DeleteAllContacts(string $sEmail): bool
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetContacts(int $iOffset = 0, int $iLimit = 20, string $sSearch = '', int &$iResultCount = 0) : array {
|
public function GetContacts(int $iOffset = 0, int $iLimit = 20, string $sSearch = '', int &$iResultCount = 0): array
|
||||||
|
{
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetContactByEmail(string $sEmail) : ?Contact {
|
public function GetContactByEmail(string $sEmail): ?Contact
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetContactByID($mID, bool $bIsStrID = false) : ?Contact {
|
public function GetContactByID($mID, bool $bIsStrID = false): ?Contact
|
||||||
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetSuggestions(string $sSearch, int $iLimit = 20) : array {
|
public function GetSuggestions(string $sSearch, int $iLimit = 20): array
|
||||||
|
{
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function GetEmailObjects(array $aEmails) : array {
|
private function GetEmailObjects(array $aEmails): array
|
||||||
|
{
|
||||||
$aEmailsObjects = \array_map(function ($mItem) {
|
$aEmailsObjects = \array_map(function ($mItem) {
|
||||||
$oResult = null;
|
$oResult = null;
|
||||||
try {
|
try {
|
||||||
$oResult = \MailSo\Mime\Email::Parse(\trim($mItem));
|
$oResult = \MailSo\Mime\Email::Parse(\trim($mItem));
|
||||||
}
|
} catch (\Throwable $oException) {
|
||||||
catch (\Throwable $oException) {
|
|
||||||
unset($oException);
|
unset($oException);
|
||||||
}
|
}
|
||||||
return $oResult;
|
return $oResult;
|
||||||
|
|
@ -105,20 +121,21 @@ class NextcloudAddressBook implements \RainLoop\Providers\AddressBook\AddressBoo
|
||||||
* Add/increment email address usage
|
* Add/increment email address usage
|
||||||
* Handy for "most used" sorting suggestions in PdoAddressBook
|
* Handy for "most used" sorting suggestions in PdoAddressBook
|
||||||
*/
|
*/
|
||||||
public function IncFrec(array $aEmails, bool $bCreateAuto = true) : bool {
|
public function IncFrec(array $aEmails, bool $bCreateAuto = true): bool
|
||||||
|
{
|
||||||
if ($bCreateAuto) {
|
if ($bCreateAuto) {
|
||||||
$aEmailsObjects = $this->GetEmailObjects($aEmails);
|
$aEmailsObjects = $this->GetEmailObjects($aEmails);
|
||||||
|
|
||||||
if (!count($aEmailsObjects)) {
|
if (!count($aEmailsObjects)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
foreach ($aEmailsObjects as $oEmail) {
|
foreach ($aEmailsObjects as $oEmail) {
|
||||||
if ('' === \trim($oEmail->GetEmail())) {
|
if ('' === \trim($oEmail->GetEmail())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$sEmail = \trim($oEmail->GetEmail(true));
|
$sEmail = \trim($oEmail->GetEmail(true));
|
||||||
$existingResults = $this->contactsManager->search($sEmail, ['EMAIL'], ['strict_search' => true]);
|
$existingResults = $this->contactsManager->search($sEmail, ['EMAIL'], ['strict_search' => true]);
|
||||||
|
|
||||||
if (!empty($existingResults)) {
|
if (!empty($existingResults)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -127,20 +144,39 @@ class NextcloudAddressBook implements \RainLoop\Providers\AddressBook\AddressBoo
|
||||||
'EMAIL' => $sEmail,
|
'EMAIL' => $sEmail,
|
||||||
'FN' => $sEmail
|
'FN' => $sEmail
|
||||||
];
|
];
|
||||||
|
|
||||||
if ('' !== \trim($oEmail->GetDisplayName())) {
|
if ('' !== \trim($oEmail->GetDisplayName())) {
|
||||||
$properties['FN'] = $oEmail->GetDisplayName();
|
$properties['FN'] = $oEmail->GetDisplayName();
|
||||||
}
|
}
|
||||||
$this->contactsManager->createOrUpdate($properties, $this->key);
|
$this->contactsManager->createOrUpdate($properties, $this->GetSavedAddressBookKey());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function Test() : string {
|
public function Test(): string
|
||||||
|
{
|
||||||
return '';
|
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('NextCloudAddressBookUri', 'webmail');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
DESCRIPTION = 'Integrate with Nextcloud v20+',
|
DESCRIPTION = 'Integrate with Nextcloud v20+',
|
||||||
REQUIRED = '2.36.2';
|
REQUIRED = '2.36.2';
|
||||||
|
|
||||||
public function Init() : void
|
public function Init(): void
|
||||||
{
|
{
|
||||||
if (static::IsIntegrated()) {
|
if (static::IsIntegrated()) {
|
||||||
\SnappyMail\Log::debug('Nextcloud', 'integrated');
|
\SnappyMail\Log::debug('Nextcloud', 'integrated');
|
||||||
|
|
@ -36,11 +36,16 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
$this->addTemplate('templates/PopupsNextcloudFiles.html');
|
$this->addTemplate('templates/PopupsNextcloudFiles.html');
|
||||||
$this->addTemplate('templates/PopupsNextcloudCalendars.html');
|
$this->addTemplate('templates/PopupsNextcloudCalendars.html');
|
||||||
|
|
||||||
// $this->addHook('login.credentials.step-2', 'loginCredentials2');
|
// $this->addHook('login.credentials.step-2', 'loginCredentials2');
|
||||||
// $this->addHook('login.credentials', 'loginCredentials');
|
// $this->addHook('login.credentials', 'loginCredentials');
|
||||||
$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');
|
||||||
|
|
||||||
|
$this->addJs('js/addressbook.js'); // add js file
|
||||||
|
$this->addTemplate('templates/AddressBookSettings.html');
|
||||||
|
$this->addJsonHook('JsonGetAddressbooks', 'GetAddressBooks');
|
||||||
|
$this->addJsonHook('NextcloudUpdateAddressBook', 'UpdateAddressBook');
|
||||||
} 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 +53,48 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function GetAddressBooks()
|
||||||
|
{
|
||||||
|
$addressBooks = [];
|
||||||
|
|
||||||
|
$contactsManager = \OC::$server->getContactsManager();
|
||||||
|
|
||||||
|
$selectedUri = $this->Settings()->GetConf('NextCloudAddressBookUri', 'webmail');
|
||||||
|
|
||||||
|
foreach ($contactsManager->getUserAddressBooks() as $addressBook) {
|
||||||
|
if ($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->Settings();
|
||||||
|
if (\is_string($uri)) {
|
||||||
|
$oSettings->SetConf('NextCloudAddressBookUri', $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')) {
|
||||||
|
|
@ -55,7 +102,7 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function Supported() : string
|
public function Supported(): string
|
||||||
{
|
{
|
||||||
return static::IsIntegrated() ? '' : 'Nextcloud not found to use this plugin';
|
return static::IsIntegrated() ? '' : 'Nextcloud not found to use this plugin';
|
||||||
}
|
}
|
||||||
|
|
@ -70,24 +117,24 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
return static::IsIntegrated() && \OC::$server->getUserSession()->isLoggedIn();
|
return static::IsIntegrated() && \OC::$server->getUserSession()->isLoggedIn();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function loginCredentials(string &$sEmail, string &$sLogin, ?string &$sPassword = null) : void
|
public function loginCredentials(string &$sEmail, string &$sLogin, ?string &$sPassword = null): void
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* This has an issue.
|
* This has an issue.
|
||||||
* When user changes email address, all settings are gone as the new
|
* When user changes email address, all settings are gone as the new
|
||||||
* _data_/_default_/storage/{domain}/{local-part} is used
|
* _data_/_default_/storage/{domain}/{local-part} is used
|
||||||
*/
|
*/
|
||||||
// $ocUser = \OC::$server->getUserSession()->getUser();
|
// $ocUser = \OC::$server->getUserSession()->getUser();
|
||||||
// $sEmail = $ocUser->getEMailAddress() ?: $ocUser->getPrimaryEMailAddress() ?: $sEmail;
|
// $sEmail = $ocUser->getEMailAddress() ?: $ocUser->getPrimaryEMailAddress() ?: $sEmail;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function loginCredentials2(string &$sEmail, ?string &$sPassword = null) : void
|
public function loginCredentials2(string &$sEmail, ?string &$sPassword = null): void
|
||||||
{
|
{
|
||||||
$ocUser = \OC::$server->getUserSession()->getUser();
|
$ocUser = \OC::$server->getUserSession()->getUser();
|
||||||
$sEmail = $ocUser->getEMailAddress() ?: $ocUser->getPrimaryEMailAddress() ?: $sEmail;
|
$sEmail = $ocUser->getEMailAddress() ?: $ocUser->getPrimaryEMailAddress() ?: $sEmail;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function beforeLogin(\RainLoop\Model\Account $oAccount, \MailSo\Net\NetClient $oClient, \MailSo\Net\ConnectSettings $oSettings) : void
|
public function beforeLogin(\RainLoop\Model\Account $oAccount, \MailSo\Net\NetClient $oClient, \MailSo\Net\ConnectSettings $oSettings): void
|
||||||
{
|
{
|
||||||
// https://apps.nextcloud.com/apps/oidc_login
|
// https://apps.nextcloud.com/apps/oidc_login
|
||||||
$config = \OC::$server->getConfig();
|
$config = \OC::$server->getConfig();
|
||||||
|
|
@ -104,11 +151,12 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
// Only login with OIDC access token if
|
// Only login with OIDC access token if
|
||||||
// it is enabled in config, the user is currently logged in with OIDC,
|
// it is enabled in config, the user is currently logged in with OIDC,
|
||||||
// the current snappymail account is the OIDC account and no account defined explicitly
|
// the current snappymail account is the OIDC account and no account defined explicitly
|
||||||
if (\OC::$server->getConfig()->getAppValue('snappymail', 'snappymail-autologin-oidc', false)
|
if (
|
||||||
&& \OC::$server->getSession()->get('is_oidc')
|
\OC::$server->getConfig()->getAppValue('snappymail', 'snappymail-autologin-oidc', false)
|
||||||
&& $sNcEmail === $oSettings->username
|
&& \OC::$server->getSession()->get('is_oidc')
|
||||||
&& !$bAccountDefinedExplicitly
|
&& $sNcEmail === $oSettings->username
|
||||||
// && $oClient->supportsAuthType('OAUTHBEARER') // v2.28
|
&& !$bAccountDefinedExplicitly
|
||||||
|
// && $oClient->supportsAuthType('OAUTHBEARER') // v2.28
|
||||||
) {
|
) {
|
||||||
$sAccessToken = \OC::$server->getSession()->get('oidc_access_token');
|
$sAccessToken = \OC::$server->getSession()->get('oidc_access_token');
|
||||||
if ($sAccessToken) {
|
if ($sAccessToken) {
|
||||||
|
|
@ -123,7 +171,7 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
\OC::$server->getLDAPProvider();
|
\OC::$server->getLDAPProvider();
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function NextcloudAttachFile() : array
|
public function NextcloudAttachFile(): array
|
||||||
{
|
{
|
||||||
$aResult = [
|
$aResult = [
|
||||||
'success' => false,
|
'success' => false,
|
||||||
|
|
@ -147,10 +195,10 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
return $this->jsonResponse(__FUNCTION__, $aResult);
|
return $this->jsonResponse(__FUNCTION__, $aResult);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function NextcloudSaveMsg() : array
|
public function NextcloudSaveMsg(): array
|
||||||
{
|
{
|
||||||
$sSaveFolder = \ltrim($this->jsonParam('folder', ''), '/');
|
$sSaveFolder = \ltrim($this->jsonParam('folder', ''), '/');
|
||||||
// $aValues = \RainLoop\Api::Actions()->decodeRawKey($this->jsonParam('msgHash', ''));
|
// $aValues = \RainLoop\Api::Actions()->decodeRawKey($this->jsonParam('msgHash', ''));
|
||||||
$msgHash = $this->jsonParam('msgHash', '');
|
$msgHash = $this->jsonParam('msgHash', '');
|
||||||
$aValues = \json_decode(\MailSo\Base\Utils::UrlSafeBase64Decode($msgHash), true);
|
$aValues = \json_decode(\MailSo\Base\Utils::UrlSafeBase64Decode($msgHash), true);
|
||||||
$aResult = [
|
$aResult = [
|
||||||
|
|
@ -204,14 +252,14 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
foreach ($data->items as $aItem) {
|
foreach ($data->items as $aItem) {
|
||||||
$sSavedFileName = empty($aItem['fileName']) ? 'file.dat' : $aItem['fileName'];
|
$sSavedFileName = empty($aItem['fileName']) ? 'file.dat' : $aItem['fileName'];
|
||||||
if (!empty($aItem['data'])) {
|
if (!empty($aItem['data'])) {
|
||||||
$sSavedFileNameFull = static::SmartFileExists($sSaveFolder.'/'.$sSavedFileName, $oFiles);
|
$sSavedFileNameFull = static::SmartFileExists($sSaveFolder . '/' . $sSavedFileName, $oFiles);
|
||||||
if (!$oFiles->file_put_contents($sSavedFileNameFull, $aItem['data'])) {
|
if (!$oFiles->file_put_contents($sSavedFileNameFull, $aItem['data'])) {
|
||||||
$data->result = false;
|
$data->result = false;
|
||||||
}
|
}
|
||||||
} else if (!empty($aItem['fileHash'])) {
|
} else if (!empty($aItem['fileHash'])) {
|
||||||
$fFile = $data->filesProvider->GetFile($data->account, $aItem['fileHash'], 'rb');
|
$fFile = $data->filesProvider->GetFile($data->account, $aItem['fileHash'], 'rb');
|
||||||
if (\is_resource($fFile)) {
|
if (\is_resource($fFile)) {
|
||||||
$sSavedFileNameFull = static::SmartFileExists($sSaveFolder.'/'.$sSavedFileName, $oFiles);
|
$sSavedFileNameFull = static::SmartFileExists($sSaveFolder . '/' . $sSavedFileName, $oFiles);
|
||||||
if (!$oFiles->file_put_contents($sSavedFileNameFull, $fFile)) {
|
if (!$oFiles->file_put_contents($sSavedFileNameFull, $fFile)) {
|
||||||
$data->result = false;
|
$data->result = false;
|
||||||
}
|
}
|
||||||
|
|
@ -225,19 +273,19 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function FilterAppData($bAdmin, &$aResult) : void
|
public function FilterAppData($bAdmin, &$aResult): void
|
||||||
{
|
{
|
||||||
if (!$bAdmin && \is_array($aResult)) {
|
if (!$bAdmin && \is_array($aResult)) {
|
||||||
$ocUser = \OC::$server->getUserSession()->getUser();
|
$ocUser = \OC::$server->getUserSession()->getUser();
|
||||||
$sUID = $ocUser->getUID();
|
$sUID = $ocUser->getUID();
|
||||||
$oUrlGen = \OC::$server->getURLGenerator();
|
$oUrlGen = \OC::$server->getURLGenerator();
|
||||||
$sWebDAV = $oUrlGen->getAbsoluteURL($oUrlGen->linkTo('', 'remote.php') . '/dav');
|
$sWebDAV = $oUrlGen->getAbsoluteURL($oUrlGen->linkTo('', 'remote.php') . '/dav');
|
||||||
// $sWebDAV = \OCP\Util::linkToRemote('dav');
|
// $sWebDAV = \OCP\Util::linkToRemote('dav');
|
||||||
$aResult['Nextcloud'] = [
|
$aResult['Nextcloud'] = [
|
||||||
'UID' => $sUID,
|
'UID' => $sUID,
|
||||||
'WebDAV' => $sWebDAV,
|
'WebDAV' => $sWebDAV,
|
||||||
'CalDAV' => $this->Config()->Get('plugin', 'calendar', false)
|
'CalDAV' => $this->Config()->Get('plugin', 'calendar', false)
|
||||||
// 'WebDAV_files' => $sWebDAV . '/files/' . $sUID
|
// 'WebDAV_files' => $sWebDAV . '/files/' . $sUID
|
||||||
];
|
];
|
||||||
if (empty($aResult['Auth'])) {
|
if (empty($aResult['Auth'])) {
|
||||||
$config = \OC::$server->getConfig();
|
$config = \OC::$server->getConfig();
|
||||||
|
|
@ -259,9 +307,9 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
}
|
}
|
||||||
if (!$sEmail) {
|
if (!$sEmail) {
|
||||||
$sEmail = $ocUser->getEMailAddress();
|
$sEmail = $ocUser->getEMailAddress();
|
||||||
// ?: $ocUser->getPrimaryEMailAddress();
|
// ?: $ocUser->getPrimaryEMailAddress();
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
if ($config->getAppValue('snappymail', 'snappymail-autologin-oidc', false)) {
|
if ($config->getAppValue('snappymail', 'snappymail-autologin-oidc', false)) {
|
||||||
if (\OC::$server->getSession()->get('is_oidc')) {
|
if (\OC::$server->getSession()->get('is_oidc')) {
|
||||||
$sEmail = "{$sUID}@nextcloud";
|
$sEmail = "{$sUID}@nextcloud";
|
||||||
|
|
@ -308,7 +356,7 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function FilterLanguage(&$sLanguage, $bAdmin) : void
|
public function FilterLanguage(&$sLanguage, $bAdmin): void
|
||||||
{
|
{
|
||||||
if (!\RainLoop\Api::Config()->Get('webmail', 'allow_languages_on_settings', true)) {
|
if (!\RainLoop\Api::Config()->Get('webmail', 'allow_languages_on_settings', true)) {
|
||||||
$aResultLang = \SnappyMail\L10n::getLanguages($bAdmin);
|
$aResultLang = \SnappyMail\L10n::getLanguages($bAdmin);
|
||||||
|
|
@ -331,7 +379,7 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
*
|
*
|
||||||
* @return string return locale
|
* @return string return locale
|
||||||
*/
|
*/
|
||||||
private function determineLocale(string $langCode, array $languagesArray) : ?string
|
private function determineLocale(string $langCode, array $languagesArray): ?string
|
||||||
{
|
{
|
||||||
// Direct check for the language code
|
// Direct check for the language code
|
||||||
if (\in_array($langCode, $languagesArray)) {
|
if (\in_array($langCode, $languagesArray)) {
|
||||||
|
|
@ -378,7 +426,7 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
include_once __DIR__ . '/NextcloudAddressBook.php';
|
include_once __DIR__ . '/NextcloudAddressBook.php';
|
||||||
$mResult = new NextcloudAddressBook();
|
$mResult = new NextcloudAddressBook();
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
if ($this->Config()->Get('plugin', 'storage', false) && ('storage' === $sName || 'storage-local' === $sName)) {
|
if ($this->Config()->Get('plugin', 'storage', false) && ('storage' === $sName || 'storage-local' === $sName)) {
|
||||||
require_once __DIR__ . '/storage.php';
|
require_once __DIR__ . '/storage.php';
|
||||||
$oDriver = new \NextcloudStorage(APP_PRIVATE_DATA.'storage', $sName === 'storage-local');
|
$oDriver = new \NextcloudStorage(APP_PRIVATE_DATA.'storage', $sName === 'storage-local');
|
||||||
|
|
@ -387,7 +435,7 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function configMapping() : array
|
protected function configMapping(): array
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
\RainLoop\Plugins\Property::NewInstance('suggestions')->SetLabel('Suggestions')
|
\RainLoop\Plugins\Property::NewInstance('suggestions')->SetLabel('Suggestions')
|
||||||
|
|
@ -396,7 +444,7 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
\RainLoop\Plugins\Property::NewInstance('ignoreSystemAddressbook')->SetLabel('Ignore system addressbook')
|
\RainLoop\Plugins\Property::NewInstance('ignoreSystemAddressbook')->SetLabel('Ignore system addressbook')
|
||||||
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
|
->SetType(\RainLoop\Enumerations\PluginPropertyType::BOOL)
|
||||||
->SetDefaultValue(true),
|
->SetDefaultValue(true),
|
||||||
/*
|
/*
|
||||||
\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)
|
||||||
->SetDefaultValue(false)
|
->SetDefaultValue(false)
|
||||||
|
|
@ -407,7 +455,7 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function SmartFileExists(string $sFilePath, $oFiles) : string
|
private static function SmartFileExists(string $sFilePath, $oFiles): string
|
||||||
{
|
{
|
||||||
$sFilePath = \str_replace('\\', '/', \trim($sFilePath));
|
$sFilePath = \str_replace('\\', '/', \trim($sFilePath));
|
||||||
|
|
||||||
|
|
@ -421,11 +469,10 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
++$iIndex;
|
++$iIndex;
|
||||||
$sFilePathNew = $aFileInfo['dirname'].'/'.
|
$sFilePathNew = $aFileInfo['dirname'] . '/' .
|
||||||
\preg_replace('/\(\d{1,2}\)$/', '', $aFileInfo['filename']).
|
\preg_replace('/\(\d{1,2}\)$/', '', $aFileInfo['filename']) .
|
||||||
' ('.$iIndex.')'.
|
' (' . $iIndex . ')' .
|
||||||
(empty($aFileInfo['extension']) ? '' : '.'.$aFileInfo['extension'])
|
(empty($aFileInfo['extension']) ? '' : '.' . $aFileInfo['extension']);
|
||||||
;
|
|
||||||
if (!$oFiles->file_exists($sFilePathNew)) {
|
if (!$oFiles->file_exists($sFilePathNew)) {
|
||||||
return $sFilePathNew;
|
return $sFilePathNew;
|
||||||
}
|
}
|
||||||
|
|
@ -435,4 +482,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 Settings(): \RainLoop\Settings
|
||||||
|
{
|
||||||
|
return $this->SettingsProvider()->Load($this->Account());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AddressBook
|
||||||
|
{
|
||||||
|
public string $uri;
|
||||||
|
public string $name;
|
||||||
|
public bool $selected = false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
36
plugins/nextcloud/js/addressbook.js
Normal file
36
plugins/nextcloud/js/addressbook.js
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
(rl => {
|
||||||
|
if (rl) {
|
||||||
|
class AddressBookSettings /* extends AbstractViewSettings */ {
|
||||||
|
constructor() {
|
||||||
|
this.addressBookList = ko.observableArray();
|
||||||
|
this.selectedAddressBook = ko.observable();
|
||||||
|
|
||||||
|
rl.pluginRemoteRequest((iError, oData) => {
|
||||||
|
if (!iError) {
|
||||||
|
const books = JSON.parse(oData.Result.addressbooks);
|
||||||
|
books.forEach(book => {
|
||||||
|
this.addressBookList.push(book);
|
||||||
|
|
||||||
|
if (book.selected) {
|
||||||
|
this.selectedAddressBook(book.uri);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.selectedAddressBook.subscribe(value => {
|
||||||
|
rl.pluginRemoteRequest(() => { }, 'NextcloudUpdateAddressBook', {
|
||||||
|
uri: value
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, "JsonGetAddressbooks");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rl.addSettingsViewModel(
|
||||||
|
AddressBookSettings,
|
||||||
|
'AddressBookSettings',
|
||||||
|
'NEXTCLOUD/ADDRESS_BOOK',
|
||||||
|
'addressbook'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
})(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": "Address Book"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
"SELECT_CALENDAR": "Select calendar",
|
"SELECT_CALENDAR": "Select calendar",
|
||||||
"FILE_ATTACH": "attach",
|
"FILE_ATTACH": "attach",
|
||||||
"FILE_INTERNAL": "internal",
|
"FILE_INTERNAL": "internal",
|
||||||
"FILE_PUBLIC": "public"
|
"FILE_PUBLIC": "public",
|
||||||
|
"ADDRESS_BOOK": "Address Book"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
"SELECT_CALENDAR": "Wybierz kalendarz",
|
"SELECT_CALENDAR": "Wybierz kalendarz",
|
||||||
"FILE_ATTACH": "dołącz",
|
"FILE_ATTACH": "dołącz",
|
||||||
"FILE_INTERNAL": "link wewnętrzny",
|
"FILE_INTERNAL": "link wewnętrzny",
|
||||||
"FILE_PUBLIC": "link publiczny"
|
"FILE_PUBLIC": "link publiczny",
|
||||||
|
"ADDRESS_BOOK": "Address Book"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
"SELECT_CALENDAR": "Выбрать календарь",
|
"SELECT_CALENDAR": "Выбрать календарь",
|
||||||
"FILE_ATTACH": "Прикрепить с ПК",
|
"FILE_ATTACH": "Прикрепить с ПК",
|
||||||
"FILE_INTERNAL": "Внутреняя",
|
"FILE_INTERNAL": "Внутреняя",
|
||||||
"FILE_PUBLIC": "Публичная"
|
"FILE_PUBLIC": "Публичная",
|
||||||
|
"ADDRESS_BOOK": "Address Book"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
"SELECT_CALENDAR": "選擇日曆",
|
"SELECT_CALENDAR": "選擇日曆",
|
||||||
"FILE_ATTACH": "附加",
|
"FILE_ATTACH": "附加",
|
||||||
"FILE_INTERNAL": "內部",
|
"FILE_INTERNAL": "內部",
|
||||||
"FILE_PUBLIC": "公開"
|
"FILE_PUBLIC": "公開",
|
||||||
|
"ADDRESS_BOOK": "Address Book"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
"SELECT_CALENDAR": "选择日历",
|
"SELECT_CALENDAR": "选择日历",
|
||||||
"FILE_ATTACH": "附加",
|
"FILE_ATTACH": "附加",
|
||||||
"FILE_INTERNAL": "内部",
|
"FILE_INTERNAL": "内部",
|
||||||
"FILE_PUBLIC": "公开"
|
"FILE_PUBLIC": "公开",
|
||||||
|
"ADDRESS_BOOK": "Address Book"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
12
plugins/nextcloud/templates/AddressBookSettings.html
Normal file
12
plugins/nextcloud/templates/AddressBookSettings.html
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
<div class="b-settings-nextcloud-addressbook form-horizontal">
|
||||||
|
<div class="legend">AddressBook</div>
|
||||||
|
<div class="form-horizontal">
|
||||||
|
|
||||||
|
<div class="control-group">
|
||||||
|
<label data-i18n="NEXTCLOUD/ADDRESS_BOOK"></label>
|
||||||
|
<select data-bind="options: addressBookList, value: selectedAddressBook,
|
||||||
|
optionsText: 'name', optionsValue: 'uri'"></select>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue