1 Commits

Author SHA1 Message Date
c6935c47e3 refactor: use new mail interface desing
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-05-14 22:44:28 -04:00
2 changed files with 9 additions and 91 deletions

View File

@@ -17,7 +17,6 @@ use KTXF\Mail\Object\Address;
use KTXF\Mail\Object\AddressInterface;
use KTXF\Mail\Service\ServiceBaseInterface;
use KTXF\Mail\Service\ServiceCollectionMutableInterface;
use KTXF\Mail\Service\ServiceEntityMutableInterface;
use KTXF\Mail\Service\ServiceConfigurableInterface;
use KTXF\Mail\Service\ServiceMutableInterface;
use KTXF\Resource\Provider\ResourceServiceIdentityInterface;
@@ -565,7 +564,7 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
};
}
public function entityFetch(string|int $collection, string|int ...$identifiers): array
public function entityFetch(string|int $collection, string|int ...$identifiers): array
{
$this->initialize();
@@ -606,10 +605,10 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
throw new \RuntimeException('Entity modification is not supported in this service');
}
public function entityDelete(EntityIdentifier ...$targets): array
public function entityDelete(EntityIdentifier ...$identifiers): array
{
// validate identifiers and group by collection
$targets = $this->groupEntitiesByCollection(...$targets);
$identifiers = $this->groupEntitiesByCollection(...$identifiers);
// determine delete mode and target collection (e.g. Trash) if applicable
$deleteMode = $this->auxiliary['deleteMode'] ?? 'soft';
@@ -646,7 +645,7 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
// entities need to be moved or deleted by collection
$list = [];
foreach ($targets as $sourceCollection => $sourceEntities) {
foreach ($identifiers as $sourceCollection => $sourceEntities) {
if ($deleteMode === 'soft' && $sourceCollection === $deleteTargetNative) {
continue;
}
@@ -676,30 +675,7 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
throw new \RuntimeException('Entity patching is not supported in this service');
}
public function entityPatch(MessagePropertiesMutableInterface $properties, EntityIdentifier ...$targets): array
{
// validate identifiers and group by collection
$targets = $this->groupEntitiesByCollection(...$targets);
// move entities on remote store and construct result map
$this->initialize();
$list = [];
foreach ($targets as $targetCollection => $targetIdentifiers) {
$uids = array_keys($targetIdentifiers);
$mutations = $this->mailService->entityPatch($targetCollection, $properties, ...$uids);
foreach ($uids as $uid) {
$list[(string)$targetIdentifiers[$uid]] = ['disposition' => 'patched'];
}
}
return $list;
}
public function entityCopy(CollectionIdentifier $target, EntityIdentifier ...$sources): array
public function entityMove(CollectionIdentifier $target, EntityIdentifier ...$identifiers): array
{
// validate target belongs to this service
if ($target->provider() !== $this->provider() || $target->service() !== $this->identifier()) {
@@ -707,47 +683,12 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
}
// validate identifiers and group by collection
$sources = $this->groupEntitiesByCollection(...$sources);
// copy entities on remote store and construct result map
$this->initialize();
$list = [];
foreach ($sources as $sourceCollection => $sourceEntities) {
$uids = array_keys($sourceEntities);
$mutations = $this->mailService->entityCopy($target->collection(), $sourceCollection, ...$uids);
foreach ($uids as $uid) {
$mutatedUid = $mutations[$uid] ?? null;
$list[(string)$sourceEntities[$uid]] = [
'disposition' => $mutatedUid !== null ? 'copied' : 'error',
'destination' => $target,
'mutation' => $mutatedUid !== null ? new EntityIdentifier($this->provider(), $this->identifier(), $target->collection(), $mutatedUid) : null,
];
}
}
return $list;
}
public function entityMove(CollectionIdentifier $target, EntityIdentifier ...$sources): array
{
// validate target belongs to this service
if ($target->provider() !== $this->provider() || $target->service() !== $this->identifier()) {
throw new \InvalidArgumentException('Target collection does not belong to this service: ' . $target);
}
// validate identifiers and group by collection
$sources = $this->groupEntitiesByCollection(...$sources);
$identifiers = $this->groupEntitiesByCollection(...$identifiers);
// move entities on remote store and construct result map
$this->initialize();
$list = [];
foreach ($sources as $sourceCollection => $sourceEntities) {
foreach ($identifiers as $sourceCollection => $sourceEntities) {
$uids = array_keys($sourceEntities);
$mutations = $this->mailService->entityMove($target->collection(), $sourceCollection, ...$uids);

View File

@@ -59,6 +59,8 @@ class RemoteMailService
public function __construct(
private readonly Client $client,
private readonly string $provider,
private readonly string|int $service,
) {}
/**
@@ -345,31 +347,6 @@ class RemoteMailService
return array_fill_keys($uids, true);
}
public function entityPatch(string $collection, array $flagsToAdd = [], array $flagsToRemove = [], int ...$uids): void
{
if (empty($uids)) {
return;
}
$this->client->perform(new SelectCommand($collection, false));
if (!empty($flagsToAdd)) {
$this->client->perform(new StoreCommand(
FetchTarget::uid(SequenceSet::items(...array_values($uids))),
$flagsToAdd,
'+',
));
}
if (!empty($flagsToRemove)) {
$this->client->perform(new StoreCommand(
FetchTarget::uid(SequenceSet::items(...array_values($uids))),
$flagsToRemove,
'-',
));
}
}
public function entityMove(string $targetCollection, string $sourceCollection, int ...$uids): array
{
if (empty($uids)) {