generated from Nodarx/template
refactor: rename remote mail service
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
@@ -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());
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
+29
-29
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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'];
|
||||
Reference in New Issue
Block a user