diff --git a/lib/Providers/IServiceIdentity.php b/lib/Providers/IServiceIdentity.php new file mode 100644 index 0000000..d8b55b5 --- /dev/null +++ b/lib/Providers/IServiceIdentity.php @@ -0,0 +1,37 @@ + +* +* @author Sebastian Krupinski +* +* @license AGPL-3.0-or-later +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Affero General Public License as +* published by the Free Software Foundation, either version 3 of the +* License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Affero General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with this program. If not, see . +* +*/ +namespace OCA\JMAPC\Providers; + +/** + * This is the interface that is implemented by apps that + * implement a mail provider + * + * @since 30.0.0 + */ +interface IServiceIdentity { + + + +} diff --git a/lib/Providers/IServiceIdentityBAuth.php b/lib/Providers/IServiceIdentityBAuth.php new file mode 100644 index 0000000..0437c08 --- /dev/null +++ b/lib/Providers/IServiceIdentityBAuth.php @@ -0,0 +1,59 @@ + +* +* @author Sebastian Krupinski +* +* @license AGPL-3.0-or-later +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Affero General Public License as +* published by the Free Software Foundation, either version 3 of the +* License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Affero General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with this program. If not, see . +* +*/ +namespace OCA\JMAPC\Providers; + +/** + * This is the interface that is implemented by apps that + * implement a mail provider + * + * @since 30.0.0 + */ +interface IServiceIdentityBAuth extends IServiceIdentity { + + /** + * + * @since 30.0.0 + */ + public function getIdentity(): string; + + /** + * + * @since 30.0.0 + */ + public function setIdentity(string $value); + + /** + * + * @since 30.0.0 + */ + public function getSecret(): string; + + /** + * + * @since 30.0.0 + */ + public function setSecret(string $value); + +} diff --git a/lib/Providers/IServiceIdentityOAuth.php b/lib/Providers/IServiceIdentityOAuth.php new file mode 100644 index 0000000..0f6767f --- /dev/null +++ b/lib/Providers/IServiceIdentityOAuth.php @@ -0,0 +1,95 @@ + +* +* @author Sebastian Krupinski +* +* @license AGPL-3.0-or-later +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Affero General Public License as +* published by the Free Software Foundation, either version 3 of the +* License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Affero General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with this program. If not, see . +* +*/ +namespace OCA\JMAPC\Providers; + +/** + * This is the interface that is implemented by apps that + * implement a mail provider + * + * @since 30.0.0 + */ +interface IServiceIdentityOAuth extends IServiceIdentity { + + /** + * + * @since 30.0.0 + */ + public function getAccessToken(): string; + + /** + * + * @since 30.0.0 + */ + public function setAccessToken(string $value); + + /** + * + * @since 30.0.0 + */ + public function getAccessScope(): array; + + /** + * + * @since 30.0.0 + */ + public function setAccessScope(array $value); + + /** + * + * @since 30.0.0 + */ + public function getAccessExpiry(): int; + + /** + * + * @since 30.0.0 + */ + public function setAccessExpiry(int $value); + + /** + * + * @since 30.0.0 + */ + public function getRefreshToken(): string; + + /** + * + * @since 30.0.0 + */ + public function setRefreshToken(string $value); + + /** + * + * @since 30.0.0 + */ + public function getRefreshLocation(): string; + + /** + * + * @since 30.0.0 + */ + public function setRefreshLocation(string $value); + +} diff --git a/lib/Providers/IServiceLocation.php b/lib/Providers/IServiceLocation.php new file mode 100644 index 0000000..21b51bb --- /dev/null +++ b/lib/Providers/IServiceLocation.php @@ -0,0 +1,41 @@ + +* +* @author Sebastian Krupinski +* +* @license AGPL-3.0-or-later +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Affero General Public License as +* published by the Free Software Foundation, either version 3 of the +* License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Affero General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with this program. If not, see . +* +*/ +namespace OCA\JMAPC\Providers; + +/** + * This is the interface that is implemented by apps that + * implement a mail provider + * + * @since 30.0.0 + */ +interface IServiceLocation { + + /** + * + * @since 30.0.0 + */ + public function type(): string; + +} diff --git a/lib/Providers/IServiceLocationUri.php b/lib/Providers/IServiceLocationUri.php new file mode 100644 index 0000000..c8e043e --- /dev/null +++ b/lib/Providers/IServiceLocationUri.php @@ -0,0 +1,89 @@ + +* +* @author Sebastian Krupinski +* +* @license AGPL-3.0-or-later +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Affero General Public License as +* published by the Free Software Foundation, either version 3 of the +* License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU Affero General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with this program. If not, see . +* +*/ +namespace OCA\JMAPC\Providers; + +/** + * This is the interface that is implemented by apps that + * implement a mail provider + * + * @since 30.0.0 + */ +interface IServiceLocationUri extends IServiceLocation { + + /** + * + * @since 30.0.0 + */ + public function location(): string; + + /** + * + * @since 30.0.0 + */ + public function getScheme(): string; + + /** + * + * @since 30.0.0 + */ + public function setScheme(string $value); + + /** + * + * @since 30.0.0 + */ + public function getHost(): string; + + /** + * + * @since 30.0.0 + */ + public function setHost(string $value); + + /** + * + * @since 30.0.0 + */ + public function getPort(): int; + + /** + * + * @since 30.0.0 + */ + public function setPort(int $value); + + /** + * + * @since 30.0.0 + */ + public function getPath(): string; + + /** + * + * @since 30.0.0 + */ + public function setPath(string $value); + +} diff --git a/lib/Providers/Mail/Provider.php b/lib/Providers/Mail/Provider.php index 0ac6257..0f10494 100644 --- a/lib/Providers/Mail/Provider.php +++ b/lib/Providers/Mail/Provider.php @@ -206,7 +206,7 @@ protected function instanceService(string $uid, array $entry): Service { */ public function initiateService(): IService { - return (new Service($this->container)); + return new Service($this->container); } diff --git a/lib/Providers/Mail/Service.php b/lib/Providers/Mail/Service.php index 5589b60..5440c86 100644 --- a/lib/Providers/Mail/Service.php +++ b/lib/Providers/Mail/Service.php @@ -35,14 +35,15 @@ use OCP\Mail\Provider\IMessage; use OCP\Mail\Provider\IMessageSend; use OCP\Mail\Provider\IService; -use OCP\Mail\Provider\IServiceIdentity; -use OCP\Mail\Provider\IServiceLocation; +use OCA\JMAPC\Providers\IServiceIdentity; +use OCA\JMAPC\Providers\IServiceLocation; use OCP\Mail\Provider\Address; use Psr\Container\ContainerInterface; class Service implements IService, IMessageSend { protected array $serviceSecondaryAddress = []; + protected array $serviceAbilities = []; public function __construct( protected ContainerInterface $container, @@ -53,6 +54,26 @@ public function __construct( protected ?IServiceIdentity $serviceIdentity = null, protected ?IServiceLocation $serviceLocation = null, ) { + $this->serviceAbilities = [ + 'Collections' => true, + 'CollectionFetch' => true, + 'CollectionCreate' => true, + 'CollectionUpdate' => true, + 'CollectionDelete' => true, + 'CollectionMove' => true, + 'CollectionSearch' => true, + 'MessageFetch' => true, + 'MessageCreate' => true, + 'MessageUpdate' => true, + 'MessageDelete' => true, + 'MessageCopy' => true, + 'MessageMove' => true, + 'MessageForward' => true, + 'MessageRelay' => true, + 'MessageSend' => true, + 'MessageList' => true, + 'MessageSearch' => true, + ]; } /** @@ -69,26 +90,35 @@ public function id(): string { } /** - * checks or retrieves what capabilites the service has + * checks if a service is able of performing an specific action * - * @since 2024.05.25 + * @since 4.0.0 * - * @param string $ability required ability e.g. 'MessageSend' + * @param string $value required ability e.g. 'MessageSend' * - * @return bool|array true/false if ability is supplied, collection of abilities otherwise + * @return bool true/false if ability is supplied and found in collection */ - public function capable(?string $ability = null): bool | array { + public function capable(string $value): bool { - // define all abilities - $abilities = [ - 'MessageSend' => true, - ]; - // evaluate if required ability was specified - if (isset($ability)) { - return (isset($abilities[$ability]) ? (bool) $abilities[$ability] : false); - } else { - return $abilities; + // evaluate if required ability exists + if (isset($this->serviceAbilities[$value])) { + return (bool) $this->serviceAbilities[$value]; } + + return false; + + } + + /** + * retrieves a collection of what actions a service can perfrom + * + * @since 4.0.0 + * + * @return array collection of abilities otherwise empty collection + */ + public function capabilities(): array { + + return $this->serviceAbilities; } @@ -121,6 +151,24 @@ public function setLabel(string $value): self { } + /** + * construct a new empty identity object + * + * @since 30.0.0 + * + * @param string $type identity type e.g. BA = Basic, OA = Bearer + * + * @return IServiceIdentity blank identity object + */ + public function initiateIdentity(string $type): IServiceIdentity { + + return match ($type) { + 'BAUTH' => new ServiceIdentityBAuth(), + 'OAUTH' => new ServiceIdentityOAuth(), + }; + + } + /** * gets service itentity * @@ -149,6 +197,19 @@ public function setIdentity(IServiceIdentity $value): self { return $this; } + /** + * construct a new empty identity object + * + * @since 30.0.0 + * + * @return IServiceLocation blank identity object + */ + public function initiateLocation(): IServiceLocation { + + return new ServiceLocation(); + + } + /** * gets service location * diff --git a/lib/Providers/ServiceIdentityBAuth.php b/lib/Providers/ServiceIdentityBAuth.php index f83a724..60b05d2 100644 --- a/lib/Providers/ServiceIdentityBAuth.php +++ b/lib/Providers/ServiceIdentityBAuth.php @@ -24,11 +24,10 @@ */ namespace OCA\JMAPC\Providers; -use OCP\Mail\Provider\IServiceIdentity; +//use OCP\Mail\Provider\IServiceIdentity; //use OCP\Mail\Provider\IServiceIdentityBAuth; -class ServiceIdentityBAuth implements IServiceIdentity { -//class ServiceIdentityBAuth implements IServiceIdentityBAuth { +class ServiceIdentityBAuth implements IServiceIdentityBAuth { private string $_identity = ''; private string $_secret = ''; diff --git a/lib/Providers/ServiceIdentityOAuth.php b/lib/Providers/ServiceIdentityOAuth.php index 4c764e9..473b658 100644 --- a/lib/Providers/ServiceIdentityOAuth.php +++ b/lib/Providers/ServiceIdentityOAuth.php @@ -24,11 +24,10 @@ */ namespace OCA\JMAPC\Providers; -use OCP\Mail\Provider\IServiceIdentity; +//use OCP\Mail\Provider\IServiceIdentity; //use OCP\Mail\Provider\IServiceIdentityOAuth; -class ServiceIdentityOAuth implements IServiceIdentity { -//class ServiceIdentityOAuth implements IServiceIdentityOAuth { +class ServiceIdentityOAuth implements IServiceIdentityOAuth { private string $_AccessToken = ''; private array $_AccessScope = []; diff --git a/lib/Providers/ServiceLocation.php b/lib/Providers/ServiceLocation.php index 917e394..b119ff5 100644 --- a/lib/Providers/ServiceLocation.php +++ b/lib/Providers/ServiceLocation.php @@ -25,10 +25,9 @@ namespace OCA\JMAPC\Providers; //use OCP\Mail\Provider\IServiceLocationUri; -use OCP\Mail\Provider\IServiceLocation; +//use OCP\Mail\Provider\IServiceLocation; -//class ServiceLocation implements IServiceLocationUri { -class ServiceLocation implements IServiceLocation { +class ServiceLocation implements IServiceLocationUri { private string $_scheme = 'https://'; private string $_host = ''; private string $_path = '/'; diff --git a/lib/Service/Remote/RemoteClientService.php b/lib/Service/Remote/RemoteClientService.php index d19cc98..6a9cd8c 100644 --- a/lib/Service/Remote/RemoteClientService.php +++ b/lib/Service/Remote/RemoteClientService.php @@ -28,8 +28,8 @@ use JmapClient\Client; use JmapClient\Authentication\Basic; use JmapClient\Authentication\Bearer; -use OCP\Mail\Provider\IServiceIdentity; -use OCP\Mail\Provider\IServiceLocation; +use OCA\JMAPC\Providers\IServiceIdentity; +use OCA\JMAPC\Providers\IServiceLocation; class RemoteClientService { diff --git a/lib/Tasks/Test.php b/lib/Tasks/Test.php index 0019c2d..6f87c66 100644 --- a/lib/Tasks/Test.php +++ b/lib/Tasks/Test.php @@ -82,6 +82,15 @@ // $RemoteCommonService = \OC::$server->get(\OCA\JMAPC\Service\Remote\RemoteCommonService::class); // $RemoteEventsService = \OC::$server->get(\OCA\JMAPC\Service\Remote\RemoteEventsService::class); + /////////////// CalDAV Test ////////////////// + /* + $CalDavBackend = \OC::$server->get(\OCA\DAV\CalDAV\CalDavBackend::class); + + $results = $CalDavBackend->getChangesForCalendar('4512', '0', 1); + + exit; + */ + // execute initial harmonization //$HarmonizationService->performHarmonization($uid, 'S');