From 8abd2c2c8c2e685a540d191c77394d26bf0212c0 Mon Sep 17 00:00:00 2001 From: Sebastian Krupinski Date: Sat, 26 Sep 2026 22:00:16 -0400 Subject: [PATCH] refactor: rename remote mail service Signed-off-by: Sebastian Krupinski --- lib/Console/TestCommand.php | 6 +- lib/Providers/Provider.php | 6 +- lib/Providers/Service.php | 58 +++++++++---------- .../LiveMailService.php} | 6 +- tests/php/Unit/CommandCompletionTest.php | 6 +- ...erviceTest.php => LiveMailServiceTest.php} | 10 ++-- tests/php/Unit/ServiceTest.php | 12 ++-- 7 files changed, 52 insertions(+), 52 deletions(-) rename lib/Service/{Remote/RemoteMailService.php => Live/LiveMailService.php} (99%) rename tests/php/Unit/{RemoteMailServiceTest.php => LiveMailServiceTest.php} (85%) diff --git a/lib/Console/TestCommand.php b/lib/Console/TestCommand.php index 1c95526..465fb6c 100644 --- a/lib/Console/TestCommand.php +++ b/lib/Console/TestCommand.php @@ -17,7 +17,7 @@ use KTXM\ProviderImap\Client\Message; use KTXM\ProviderImap\Client\Protocol\SequenceSet; use KTXM\ProviderImap\Providers\Provider; use KTXM\ProviderImap\Providers\Service; -use KTXM\ProviderImap\Service\Remote\RemoteMailService; +use KTXM\ProviderImap\Service\Live\LiveMailService; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; @@ -119,7 +119,7 @@ class TestCommand extends Command $startedAt = microtime(true); try { - $mailService = new RemoteMailService($service); + $mailService = new LiveMailService($service); $mailboxes = $mailService->collectionList(); } catch (\Throwable $e) { $io->error('IMAP diagnostic failed: ' . $e->getMessage()); @@ -183,7 +183,7 @@ class TestCommand extends Command $io->section(sprintf('Recent Messages: %s', $mailboxName)); try { - $mailboxService = new RemoteMailService($service); + $mailboxService = new LiveMailService($service); $selectedMailbox = $mailboxService->imapClient()->perform(new SelectCommand($mailboxName, true)); } catch (\Throwable $e) { $io->error('Mailbox inspection failed: ' . $e->getMessage()); diff --git a/lib/Providers/Provider.php b/lib/Providers/Provider.php index 5ed0044..28079bb 100644 --- a/lib/Providers/Provider.php +++ b/lib/Providers/Provider.php @@ -18,7 +18,7 @@ use KTXF\Mail\Service\ServiceMutableInterface; use KTXF\Resource\Provider\ResourceServiceLocationInterface; use KTXF\Resource\Provider\ResourceServiceMutateInterface; use KTXM\ProviderImap\Service\Discovery; -use KTXM\ProviderImap\Service\Remote\RemoteMailService; +use KTXM\ProviderImap\Service\Live\LiveMailService; use KTXM\ProviderImap\Stores\ServiceStore; /** @@ -192,8 +192,8 @@ class Provider implements ProviderBaseInterface, ProviderServiceMutateInterface, $service->fromStore(['sid' => 'test']); // Attempt to authenticate and list mailboxes as a connectivity check - $remote = new RemoteMailService($service); - $mailboxes = iterator_to_array($remote->collectionList()); + $live = new LiveMailService($service); + $mailboxes = iterator_to_array($live->collectionList()); $latency = (int) round((microtime(true) - $startTime) * 1000); diff --git a/lib/Providers/Service.php b/lib/Providers/Service.php index 80104e1..bac6753 100644 --- a/lib/Providers/Service.php +++ b/lib/Providers/Service.php @@ -38,7 +38,7 @@ use KTXF\Resource\Sort\Sort; use KTXM\ProviderImap\Providers\ServiceIdentityBasic; use KTXM\ProviderImap\Providers\ServiceLocation; use KTXM\ProviderImap\Mime\MessageBuilder; -use KTXM\ProviderImap\Service\Remote\RemoteMailService; +use KTXM\ProviderImap\Service\Live\LiveMailService; use KTXM\ProviderImap\Providers\CollectionResource; use KTXF\Mail\Collection\CollectionRoles; use KTXF\Mail\Object\MessagePropertiesMutableInterface; @@ -111,14 +111,14 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC 'EntityTransmit' => true, ]; - private RemoteMailService $remoteService; + private LiveMailService $liveService; public function __construct() {} private function initialize(): void { - if (!isset($this->remoteService)) { - $this->remoteService = new RemoteMailService($this); + if (!isset($this->liveService)) { + $this->liveService = new LiveMailService($this); } } @@ -368,7 +368,7 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC $list = []; - foreach ($this->remoteService->collectionList($location, $filter, $sort) as $mailbox) { + foreach ($this->liveService->collectionList($location, $filter, $sort) as $mailbox) { $resource = $this->collectionFresh(); $resource->fromImap($mailbox); $list[$mailbox->name()] = $resource; @@ -395,7 +395,7 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC foreach ($identifiers as $identifier) { $key = (string) $identifier; - $result = $this->remoteService->collectionFetch($key); + $result = $this->liveService->collectionFetch($key); $list[$key] = $result !== false; } @@ -407,7 +407,7 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC { $this->initialize(); - $mailbox = $this->remoteService->collectionFetch((string) $identifier); + $mailbox = $this->liveService->collectionFetch((string) $identifier); if ($mailbox === null) { return null; } @@ -436,13 +436,13 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC if ($target !== null) { $path = $target->collection(); // Determine the hierarchy delimiter from an existing mailbox, default to '/' - $mailboxes = iterator_to_array($this->remoteService->collectionList(null, null, null, '')); + $mailboxes = iterator_to_array($this->liveService->collectionList(null, null, null, '')); $rootMailbox = $mailboxes === [] ? null : reset($mailboxes); $delimiter = $rootMailbox === false ? '/' : ($rootMailbox?->delimiter() ?? '/'); $label = rtrim((string) $path, $delimiter) . $delimiter . ltrim($label, $delimiter); } - $mailbox = $this->remoteService->collectionCreate($label); + $mailbox = $this->liveService->collectionCreate($label); $collection = $this->collectionFresh(); $collection->fromImap($mailbox, ['delimiter' => $delimiter ?? null]); @@ -462,7 +462,7 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC // In IMAP, "update" = rename to the new label $oldPath = (string) $target->collection(); $newName = $properties->getLabel(); - $mailbox = $this->remoteService->collectionRename($oldPath, $newName); + $mailbox = $this->liveService->collectionRename($oldPath, $newName); $collection = $this->collectionFresh(); $collection->fromImap($mailbox); @@ -489,7 +489,7 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC $result = match ($deleteMode) { 'soft' => $this->collectionMove(new CollectionIdentifier($target->provider(), $target->service(), $deleteTarget), $target), - 'hard' => $this->remoteService->collectionDestroy((string) $target->collection()), + 'hard' => $this->liveService->collectionDestroy((string) $target->collection()), }; return $result; } @@ -498,8 +498,8 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC { $this->initialize(); - $sourceMailbox = $this->remoteService->collectionFetch((string) $source->collection()); - $targetMailbox = $this->remoteService->collectionFetch((string) $target->collection()); + $sourceMailbox = $this->liveService->collectionFetch((string) $source->collection()); + $targetMailbox = $this->liveService->collectionFetch((string) $target->collection()); if ($sourceMailbox === null) { throw new \RuntimeException('Source collection not found for move operation'); } @@ -515,7 +515,7 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC $freshPath = rtrim($targetMailbox->name(), $targetDelimiter) . $targetDelimiter . end($extantPathLeafs); - $mutatedMailbox = $this->remoteService->collectionRename($extantPath, $freshPath); + $mutatedMailbox = $this->liveService->collectionRename($extantPath, $freshPath); $collection = $this->collectionFresh(); $collection->fromImap($mutatedMailbox, ['delimiter' => $targetDelimiter]); @@ -531,7 +531,7 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC { $this->initialize(); - foreach ($this->remoteService->entityList((string) $collection, $filter, $sort, $range) as $identifier => $message) { + foreach ($this->liveService->entityList((string) $collection, $filter, $sort, $range) as $identifier => $message) { $resource = $this->entityFresh(); $resource->fromImap($message, $collection); yield $resource->urn() => $resource; @@ -569,7 +569,7 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC foreach ($identifiers as $collection => $entities) { $uids = array_keys($entities); - foreach ($this->remoteService->entityFetch((string) $collection, null, ...$uids) as $uid => $message) { + foreach ($this->liveService->entityFetch((string) $collection, null, ...$uids) as $uid => $message) { $resource = $this->entityFresh(); $resource->fromImap($message, $collection); yield $resource->urn() => $resource; @@ -584,7 +584,7 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC $uid = (int) $target->entity(); $partId = isset($part['partId']) ? (string) $part['partId'] : null; - return $this->remoteService->entityDownload($collection, $uid, $partId); + return $this->liveService->entityDownload($collection, $uid, $partId); } public function entityDelta(string|int $collection, string $signature, string $detail = 'ids'): Delta @@ -602,7 +602,7 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC static fn (int $uid): bool => $uid > 0, )); - $existing = array_flip($this->remoteService->entityExtant((string) $collection, ...$uids)); + $existing = array_flip($this->liveService->entityExtant((string) $collection, ...$uids)); $extant = []; foreach ($identifiers as $id) { @@ -635,7 +635,7 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC } $this->initialize(); - $smtp = $this->remoteService->smtpClient(); + $smtp = $this->liveService->smtpClient(); try { $queueId = $smtp->send(trim($sender->getAddress()), $recipients, $raw); } finally { @@ -656,7 +656,7 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC $this->initialize(); $sentCollection = $this->resolveSentCollection(); if ($sentCollection !== null) { - $uid = $this->remoteService->entityCreate($sentCollection, $raw, ['\\Seen']); + $uid = $this->liveService->entityCreate($sentCollection, $raw, ['\\Seen']); if ($uid !== null && $uid > 0) { $sentEntity = new EntityIdentifier($this->provider(), $this->identifier(), $sentCollection, (string) $uid); } @@ -675,7 +675,7 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC && $source->service() === $this->identifier()) { try { $this->initialize(); - $this->remoteService->entityDestroy($source->collection(), (int) $source->entity()); + $this->liveService->entityDestroy($source->collection(), (int) $source->entity()); } catch (\Throwable) { // ignore — the message was already delivered } @@ -698,7 +698,7 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC $this->initialize(); [$nativeMessage, $nativeFlags] = $this->messagePayload($properties, $options); - $created = $this->remoteService->entityCreate( + $created = $this->liveService->entityCreate( (string)$target->collection(), $nativeMessage, $nativeFlags, @@ -719,7 +719,7 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC $this->initialize(); [$nativeMessage, $nativeFlags] = $this->messagePayload($properties); - $modified = $this->remoteService->entityReplace( + $modified = $this->liveService->entityReplace( (string)$target->collection(), (int)$target->entity(), $nativeMessage, @@ -755,7 +755,7 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC } } - $mutations = $this->remoteService->entityPatch($targetCollection, $flagsAdd, $flagsRemove, ...$uids); + $mutations = $this->liveService->entityPatch($targetCollection, $flagsAdd, $flagsRemove, ...$uids); foreach ($uids as $uid) { $list[(string)$targetIdentifiers[$uid]] = ['disposition' => 'patched']; @@ -802,8 +802,8 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC $uids = array_keys($sourceEntities); $mutations = match ($deleteMode) { - 'soft' => $this->remoteService->entityMove($deleteTargetNative, $sourceCollection, ...$uids), - 'hard' => $this->remoteService->entityDestroy($sourceCollection, ...$uids), + 'soft' => $this->liveService->entityMove($deleteTargetNative, $sourceCollection, ...$uids), + 'hard' => $this->liveService->entityDestroy($sourceCollection, ...$uids), }; foreach ($uids as $uid) { @@ -837,7 +837,7 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC foreach ($sources as $sourceCollection => $sourceEntities) { $uids = array_keys($sourceEntities); - $mutations = $this->remoteService->entityMove($target->collection(), $sourceCollection, ...$uids); + $mutations = $this->liveService->entityMove($target->collection(), $sourceCollection, ...$uids); foreach ($uids as $uid) { $mutatedUid = $mutations[$uid] ?? null; @@ -871,7 +871,7 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC foreach ($sources as $sourceCollection => $sourceEntities) { $uids = array_keys($sourceEntities); - $mutations = $this->remoteService->entityCopy($target->collection(), $sourceCollection, ...$uids); + $mutations = $this->liveService->entityCopy($target->collection(), $sourceCollection, ...$uids); foreach ($uids as $uid) { $mutatedUid = $mutations[$uid] ?? null; @@ -895,7 +895,7 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC $filter->condition('role', $role->value); /** @var Mailbox[] $mailboxes */ - $mailboxes = iterator_to_array($this->remoteService->collectionList(null, $filter, null)); + $mailboxes = iterator_to_array($this->liveService->collectionList(null, $filter, null)); if ($mailboxes === []) { return null; } diff --git a/lib/Service/Remote/RemoteMailService.php b/lib/Service/Live/LiveMailService.php similarity index 99% rename from lib/Service/Remote/RemoteMailService.php rename to lib/Service/Live/LiveMailService.php index a1a4001..294ec77 100644 --- a/lib/Service/Remote/RemoteMailService.php +++ b/lib/Service/Live/LiveMailService.php @@ -7,7 +7,7 @@ declare(strict_types=1); * SPDX-License-Identifier: AGPL-3.0-or-later */ -namespace KTXM\ProviderImap\Service\Remote; +namespace KTXM\ProviderImap\Service\Live; use DateTimeImmutable; use Generator; @@ -54,9 +54,9 @@ use KTXM\ProviderImap\Smtp\Client as SmtpClient; use RuntimeException; /** - * IMAP Remote Mail Service + * IMAP Live Mail Service */ -class RemoteMailService +class LiveMailService { private const COLLECTION_FILTER_OPTIONS = ['name', 'role', 'subscription']; diff --git a/tests/php/Unit/CommandCompletionTest.php b/tests/php/Unit/CommandCompletionTest.php index d493dbc..a1991c1 100644 --- a/tests/php/Unit/CommandCompletionTest.php +++ b/tests/php/Unit/CommandCompletionTest.php @@ -9,7 +9,7 @@ use KTXM\ProviderImap\Client\Protocol\Command\CreateCommand; use KTXM\ProviderImap\Client\Result\CommandCompletion; use KTXM\ProviderImap\Client\Transport\{ConnectionInterface, ConnectionFactoryInterface}; use KTXM\ProviderImap\Providers\Service; -use KTXM\ProviderImap\Service\Remote\RemoteMailService; +use KTXM\ProviderImap\Service\Live\LiveMailService; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; @@ -46,9 +46,9 @@ final class CommandCompletionTest extends TestCase return $client; } - private function service(Client $client): RemoteMailService + private function service(Client $client): LiveMailService { - return new class($this->createStub(Service::class), $client) extends RemoteMailService { + return new class($this->createStub(Service::class), $client) extends LiveMailService { public function __construct(Service $service, private readonly Client $client) { parent::__construct($service); diff --git a/tests/php/Unit/RemoteMailServiceTest.php b/tests/php/Unit/LiveMailServiceTest.php similarity index 85% rename from tests/php/Unit/RemoteMailServiceTest.php rename to tests/php/Unit/LiveMailServiceTest.php index 4f66b68..a78ecfb 100644 --- a/tests/php/Unit/RemoteMailServiceTest.php +++ b/tests/php/Unit/LiveMailServiceTest.php @@ -5,14 +5,14 @@ declare(strict_types=1); namespace KTXT\ProviderImap\Tests\Unit; use KTXM\ProviderImap\Providers\Service; -use KTXM\ProviderImap\Service\Remote\RemoteMailService; +use KTXM\ProviderImap\Service\Live\LiveMailService; use PHPUnit\Framework\TestCase; use RuntimeException; -final class RemoteMailServiceTest extends TestCase { +final class LiveMailServiceTest extends TestCase { public function testEntityReplaceReturnsAuthoritativeReplacementUid(): void { - $service = new RemoteMailServiceStub($this->createStub(Service::class)); + $service = new LiveMailServiceStub($this->createStub(Service::class)); $service->appendUid = 202; $service->destroyResults = [[101 => true]]; @@ -28,7 +28,7 @@ final class RemoteMailServiceTest extends TestCase { } public function testEntityReplaceRemovesReplacementWhenOldUidCannotBeDeleted(): void { - $service = new RemoteMailServiceStub($this->createStub(Service::class)); + $service = new LiveMailServiceStub($this->createStub(Service::class)); $service->appendUid = 202; $service->destroyResults = [ [101 => false], @@ -49,7 +49,7 @@ final class RemoteMailServiceTest extends TestCase { } } -final class RemoteMailServiceStub extends RemoteMailService { +final class LiveMailServiceStub extends LiveMailService { public ?int $appendUid = null; public array $createCalls = []; diff --git a/tests/php/Unit/ServiceTest.php b/tests/php/Unit/ServiceTest.php index 471702a..f040ac5 100644 --- a/tests/php/Unit/ServiceTest.php +++ b/tests/php/Unit/ServiceTest.php @@ -5,7 +5,7 @@ declare(strict_types=1); namespace KTXT\ProviderImap\Tests\Unit; use KTXM\ProviderImap\Providers\Service; -use KTXM\ProviderImap\Service\Remote\RemoteMailService; +use KTXM\ProviderImap\Service\Live\LiveMailService; use PHPUnit\Framework\TestCase; use ReflectionProperty; @@ -14,18 +14,18 @@ final class ServiceTest extends TestCase public function testEntityExtantReportsExistenceOfEachIdentifier(): void { $service = new Service(); - $remote = new ServiceTestRemoteStub($this->createStub(Service::class)); - $remote->existing = [5]; - (new ReflectionProperty(Service::class, 'remoteService'))->setValue($service, $remote); + $live = new ServiceTestLiveStub($this->createStub(Service::class)); + $live->existing = [5]; + (new ReflectionProperty(Service::class, 'liveService'))->setValue($service, $live); $result = $service->entityExtant('INBOX', 5, '6', 'abc', 0); $this->assertSame([5 => true, 6 => false, 'abc' => false, 0 => false], $result); - $this->assertSame([['INBOX', [5, 6]]], $remote->extantCalls); + $this->assertSame([['INBOX', [5, 6]]], $live->extantCalls); } } -final class ServiceTestRemoteStub extends RemoteMailService +final class ServiceTestLiveStub extends LiveMailService { /** @var int[] */ public array $existing = [];