feat: entity patch #30

Merged
Sebastian merged 1 commits from feat/entity-patch into main 2026-05-21 03:52:19 +00:00
2 changed files with 34 additions and 1 deletions

View File

@@ -91,6 +91,7 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
self::CAPABILITY_ENTITY_FETCH => true, self::CAPABILITY_ENTITY_FETCH => true,
self::CAPABILITY_ENTITY_CREATE => false, self::CAPABILITY_ENTITY_CREATE => false,
self::CAPABILITY_ENTITY_MODIFY => false, self::CAPABILITY_ENTITY_MODIFY => false,
self::CAPABILITY_ENTITY_PATCH => true,
self::CAPABILITY_ENTITY_DELETE => true, self::CAPABILITY_ENTITY_DELETE => true,
self::CAPABILITY_ENTITY_MOVE => true, self::CAPABILITY_ENTITY_MOVE => true,
self::CAPABILITY_ENTITY_COPY => false, self::CAPABILITY_ENTITY_COPY => false,
@@ -631,8 +632,18 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
foreach ($targets as $targetCollection => $targetIdentifiers) { foreach ($targets as $targetCollection => $targetIdentifiers) {
$uids = array_keys($targetIdentifiers); $uids = array_keys($targetIdentifiers);
$flagsAdd = [];
$flagsRemove = [];
$mutations = $this->mailService->entityPatch($targetCollection, $properties, ...$uids); foreach ($properties->getFlags() as $flag => $value) {
if ($value === true) {
$flagsAdd[] = $flag;
} elseif ($value === false) {
$flagsRemove[] = $flag;
}
}
$mutations = $this->mailService->entityPatch($targetCollection, $flagsAdd, $flagsRemove, ...$uids);
foreach ($uids as $uid) { foreach ($uids as $uid) {
$list[(string)$targetIdentifiers[$uid]] = ['disposition' => 'patched']; $list[(string)$targetIdentifiers[$uid]] = ['disposition' => 'patched'];

View File

@@ -353,6 +353,9 @@ class RemoteMailService
$this->client->perform(new SelectCommand($collection, false)); $this->client->perform(new SelectCommand($collection, false));
$flagsToAdd = $this->normalizeFlags($flagsToAdd);
$flagsToRemove = $this->normalizeFlags($flagsToRemove);
if (!empty($flagsToAdd)) { if (!empty($flagsToAdd)) {
$this->client->perform(new StoreCommand( $this->client->perform(new StoreCommand(
FetchTarget::uid(SequenceSet::items(...array_values($uids))), FetchTarget::uid(SequenceSet::items(...array_values($uids))),
@@ -869,4 +872,23 @@ class RemoteMailService
return CollectionRoles::None->value; return CollectionRoles::None->value;
} }
private function normalizeFlags(array $flags): array
{
$map = [
'read' => '\\Seen',
'answered' => '\\Answered',
'flagged' => '\\Flagged',
'deleted' => '\\Deleted',
'draft' => '\\Draft',
];
$normalized = [];
foreach ($flags as $flag) {
$flag = strtolower(trim($flag));
if (isset($map[$flag])) {
$normalized[] = $map[$flag];
}
}
return $normalized;
}
} }