diff --git a/lib/Provider/Command/MessageSend.php b/lib/Provider/Command/MessageSend.php index 14c098bba9..ad6cfca519 100644 --- a/lib/Provider/Command/MessageSend.php +++ b/lib/Provider/Command/MessageSend.php @@ -4,7 +4,7 @@ /** * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors - * SPDX-License-Identifier: AGPL-3.0-only + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\Mail\Provider\Command; diff --git a/lib/Provider/MailProvider.php b/lib/Provider/MailProvider.php index 89a5ecd143..b7d9c145ef 100644 --- a/lib/Provider/MailProvider.php +++ b/lib/Provider/MailProvider.php @@ -4,7 +4,7 @@ /** * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors - * SPDX-License-Identifier: AGPL-3.0-only + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\Mail\Provider; @@ -19,22 +19,16 @@ class MailProvider implements IProvider { - private ContainerInterface $container; - private AccountService $AccountService; private ?array $ServiceCollection = []; public function __construct( - ContainerInterface $container, - AccountService $AccountService + protected ContainerInterface $container, + protected AccountService $AccountService ) { - - $this->container = $container; - $this->AccountService = $AccountService; - } /** - * An arbitrary unique text string identifying this provider + * arbitrary unique text string identifying this provider * * @since 2024.05.25 * @@ -47,7 +41,7 @@ public function id(): string { } /** - * The localized human frendly name of this provider + * localized human frendly name of this provider * * @since 2024.05.25 * @@ -60,15 +54,17 @@ public function label(): string { } /** - * Determain if any services are configured for a specific user + * determain if any services are configured for a specific user * * @since 2024.05.25 * + * @param string $userId user id + * * @return bool true if any services are configure for the user */ - public function hasServices(string $uid): bool { + public function hasServices(string $userId): bool { - return (count($this->listServices($uid)) > 0); + return (count($this->listServices($userId)) > 0); } @@ -77,13 +73,15 @@ public function hasServices(string $uid): bool { * * @since 2024.05.25 * - * @return array collection of service objects + * @param string $userId user id + * + * @return array collection of service id and object ['1' => IServiceObject] */ - public function listServices(string $uid): array { + public function listServices(string $userId): array { try { // retrieve service(s) details from data store - $accounts = $this->AccountService->findByUserId($uid); + $accounts = $this->AccountService->findByUserId($userId); } catch (\Throwable $th) { return []; } @@ -92,13 +90,13 @@ public function listServices(string $uid): array { // add services to collection foreach ($accounts as $entry) { // extract values - $id = (string) $entry->getId(); + $serviceId = (string) $entry->getId(); $label = $entry->getName(); $address = new MailAddress($entry->getEmail(), $entry->getName()); $identity = new MailServiceIdentity(); $location = new MailServiceLocation(); // add service to collection - $services[$id] = new MailService($this->container, $uid, $id, $label, $address, $identity, $location); + $services[$serviceId] = new MailService($this->container, $userId, $serviceId, $label, $address, $identity, $location); } // return list of services for user return $services; @@ -106,22 +104,22 @@ public function listServices(string $uid): array { } /** - * Retrieve a service with a specific id + * retrieve a service with a specific id * * @since 2024.05.25 * - * @param string $uid user id - * @param string $id service id + * @param string $userId user id + * @param string $serviceId service id * - * @return IService|null returns service object or null if non found + * @return IService|null returns service object or null if none found */ - public function findServiceById(string $uid, string $id): IService | null { + public function findServiceById(string $userId, string $serviceId): IService | null { // evaluate if id is a number - if (is_numeric($id)) { + if (is_numeric($serviceId)) { try { // retrieve service details from data store - $account = $this->AccountService->find($uid, (int) $id); + $account = $this->AccountService->find($userId, (int) $serviceId); } catch(\Throwable $th) { return null; } @@ -129,13 +127,13 @@ public function findServiceById(string $uid, string $id): IService | null { // evaliate if service details where found if ($account instanceof Account) { // extract values - $id = (string) $account->getId(); + $serviceId = (string) $account->getId(); $label = $account->getName(); $address = new MailAddress($account->getEmail(), $account->getName()); $identity = new MailServiceIdentity(); $location = new MailServiceLocation(); - // return mail service instance - return (new MailService($this->container, $uid, $id, $label, $address, $identity, $location)); + // return mail service object + return (new MailService($this->container, $userId, $serviceId, $label, $address, $identity, $location)); } return null; @@ -143,50 +141,63 @@ public function findServiceById(string $uid, string $id): IService | null { } /** - * Retrieve a service for a specific mail address + * retrieve a service for a specific mail address * * @since 2024.05.25 * - * @param string $uid user id + * @param string $userId user id * @param string $address mail address (e.g. test@example.com) * - * @return IService returns service object or null if non found + * @return IService returns service object or null if none found */ - public function findServiceByAddress(string $uid, string $address): IService | null { + public function findServiceByAddress(string $userId, string $address): IService | null { try { // retrieve service details from data store - $accounts = $this->AccountService->findByUserIdAndAddress($uid, $address); + $accounts = $this->AccountService->findByUserIdAndAddress($userId, $address); } catch(\Throwable $th) { return null; } // evaliate if service details where found if (is_array($accounts) && count($accounts) > 0 && $accounts[0] instanceof Account) { // extract values - $id = (string) $accounts[0]->getId(); + $serviceId = (string) $accounts[0]->getId(); $label = $accounts[0]->getName(); $address = new MailAddress($accounts[0]->getEmail(), $accounts[0]->getName()); $identity = new MailServiceIdentity(); $location = new MailServiceLocation(); - // return mail service instance - return (new MailService($this->container, $uid, $id, $label, $address, $identity, $location)); + // return mail service object + return (new MailService($this->container, $userId, $serviceId, $label, $address, $identity, $location)); } return null; } + /** + * construct a new empty service object + * + * @since 30.0.0 + * + * @return IService blank service object + */ + public function initiateService(): IService { + + return (new MailService($this->container, $userId, '', '', '')); + + } + /** * create a service configuration for a specific user * * @since 2024.05.25 * - * @param string $uid user id of user to configure service for - * @param IService $service service configuration object + * @param string $userId user id + * @param IService $service service object * - * @return string id of created service + * @return string id of created service */ - public function createService(string $uid, IService $service): string { + public function createService(string $userId, IService $service): string { return ''; @@ -197,12 +208,12 @@ public function createService(string $uid, IService $service): string { * * @since 2024.05.25 * - * @param string $uid user id of user to configure service for - * @param IService $service service configuration object + * @param string $userId user id + * @param IService $service service object * - * @return string id of modifided service + * @return string id of modifided service */ - public function modifyService(string $uid, IService $service): string { + public function modifyService(string $userId, IService $service): string { return ''; @@ -213,12 +224,12 @@ public function modifyService(string $uid, IService $service): string { * * @since 2024.05.25 * - * @param string $uid user id of user to delete service for - * @param IService $service service configuration object + * @param string $userId user id + * @param IService $service service object * - * @return bool status of delete action + * @return bool status of delete action */ - public function deleteService(string $uid, IService $service): bool { + public function deleteService(string $userId, IService $service): bool { return false; diff --git a/lib/Provider/MailService.php b/lib/Provider/MailService.php index 66b263f022..ea9571a6ed 100644 --- a/lib/Provider/MailService.php +++ b/lib/Provider/MailService.php @@ -4,7 +4,7 @@ /** * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors - * SPDX-License-Identifier: AGPL-3.0-only + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\Mail\Provider; @@ -14,41 +14,27 @@ use OCP\Mail\Provider\IService; use OCP\Mail\Provider\IServiceIdentity; use OCP\Mail\Provider\IServiceLocation; +use OCP\Mail\Provider\Message; use Psr\Container\ContainerInterface; class MailService implements IService, IMessageSend { - private string $userId; - private string $serviceId; - private string $serviceLabel; - private IAddress $servicePrimaryAddress; - private ?array $serviceSecondaryAddress; - private ?MailServiceIdentity $serviceIdentity; - private ?MailServiceLocation $serviceLocation; + protected array $serviceSecondaryAddresses = []; public function __construct( - ContainerInterface $container, - string $uid, - string $sid, - string $label, - IAddress $primaryAddress, - ?MailServiceIdentity $identity = null, - ?MailServiceLocation $location = null + protected ContainerInterface $container, + protected string $userId, + protected string $serviceId, + protected string $serviceLabel, + protected IAddress $servicePrimaryAddress, + protected ?MailServiceIdentity $serviceIdentity = null, + protected ?MailServiceLocation $serviceLocation = null ) { - - $this->container = $container; - $this->userId = $uid; - $this->serviceId = $sid; - $this->serviceLabel = $label; - $this->servicePrimaryAddress = $primaryAddress; - $this->serviceIdentity = $identity; - $this->serviceLocation = $location; - } /** - * An arbitrary unique text string identifying this service + * arbitrary unique text string identifying this service * * @since 2024.05.25 * @@ -205,12 +191,12 @@ public function setPrimaryAddress(IAddress $value): self { * * @since 2024.05.25 * - * @return array collection of mail address objects + * @return array collection of mail address object [IAddress, IAddress] */ - public function getSecondaryAddress(): array | null { + public function getSecondaryAddresses(): array { // retrieve and return secondary service addressess (aliases) collection - return $this->serviceSecondaryAddress; + return $this->serviceSecondaryAddresses; } @@ -219,19 +205,32 @@ public function getSecondaryAddress(): array | null { * * @since 2024.05.25 * - * @param IAddress ...$value collection of or one or more mail address objects + * @param IAddress ...$value collection of one or more mail address object * * @return self return this object for command chaining */ - public function setSecondaryAddress(IAddress ...$value): self { + public function setSecondaryAddresses(IAddress ...$value): self { - $this->serviceSecondaryAddress = $value; + $this->serviceSecondaryAddresses = $value; return $this; } /** - * Sends an outbound message + * construct a new empty message object + * + * @since 30.0.0 + * + * @return IMessage blank message object + */ + public function initiateMessage(): IMessage { + + return (new Message()); + + } + + /** + * sends an outbound message * * @since 2024.05.25 * diff --git a/lib/Provider/MailServiceIdentity.php b/lib/Provider/MailServiceIdentity.php index d433d5382b..8f4816cd05 100644 --- a/lib/Provider/MailServiceIdentity.php +++ b/lib/Provider/MailServiceIdentity.php @@ -4,7 +4,7 @@ /** * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors - * SPDX-License-Identifier: AGPL-3.0-only + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\Mail\Provider; @@ -13,7 +13,7 @@ class MailServiceIdentity implements IServiceIdentity { /** - * An arbitrary unique text string identifying this credential type + * arbitrary unique text string identifying this credential type * * @since 2024.05.25 * diff --git a/lib/Provider/MailServiceLocation.php b/lib/Provider/MailServiceLocation.php index eef8769c0d..4d1f4a45b1 100644 --- a/lib/Provider/MailServiceLocation.php +++ b/lib/Provider/MailServiceLocation.php @@ -4,7 +4,7 @@ /** * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors - * SPDX-License-Identifier: AGPL-3.0-only + * SPDX-License-Identifier: AGPL-3.0-or-later */ namespace OCA\Mail\Provider; @@ -13,7 +13,7 @@ class MailServiceLocation implements IServiceLocation { /** - * A string identifiing this location type + * arbitrary unique text string identifying this location type * * @since 2024.05.25 * diff --git a/tests/Unit/Provider/MailProviderTest.php b/tests/Unit/Provider/MailProviderTest.php index 1010b20595..4b245aa32a 100644 --- a/tests/Unit/Provider/MailProviderTest.php +++ b/tests/Unit/Provider/MailProviderTest.php @@ -3,27 +3,9 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2024 Sebastian Krupinski - * - * @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 . - * + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ - namespace OCA\Mail\Tests\Unit\Provider; use ChristophWurst\Nextcloud\Testing\TestCase; @@ -94,7 +76,7 @@ public function testHasServices(): void { $this->returnValueMap( [ ['user0', []], - ['user1', [$mailAccount]] + ['user1', [100 => $mailAccount]] ] ) ); @@ -150,7 +132,7 @@ public function testListServices(): void { // test result with no services found $this->assertEquals([], $mailProvider->listServices('user0')); // test result with services found - $this->assertEquals([$mailService], $mailProvider->listServices('user1')); + $this->assertEquals([100 => $mailService], $mailProvider->listServices('user1')); } diff --git a/tests/Unit/Provider/MailServiceTest.php b/tests/Unit/Provider/MailServiceTest.php index 9e468e9509..ed249165d1 100644 --- a/tests/Unit/Provider/MailServiceTest.php +++ b/tests/Unit/Provider/MailServiceTest.php @@ -3,27 +3,9 @@ declare(strict_types=1); /** - * @copyright Copyright (c) 2024 Sebastian Krupinski - * - * @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 . - * + * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors + * SPDX-License-Identifier: AGPL-3.0-or-later */ - namespace OCA\Mail\Tests\Unit\Provider; use ChristophWurst\Nextcloud\Testing\TestCase; @@ -117,13 +99,13 @@ public function testPrimaryAddress(): void { } - public function testSecondaryAddress(): void { + public function testSecondaryAddresses(): void { // test set by setter $address1 = new Address('test1@testing.com'); $address2 = new Address('test2@testing.com'); - $this->mailService->setSecondaryAddress($address1, $address2); - $this->assertEquals([$address1, $address2], $this->mailService->getSecondaryAddress()); + $this->mailService->setSecondaryAddresses($address1, $address2); + $this->assertEquals([$address1, $address2], $this->mailService->getSecondaryAddresses()); }