feat: entity move
All checks were successful
Build Test / test (pull_request) Successful in 24s
JS Unit Tests / test (pull_request) Successful in 27s
PHP Unit Tests / test (pull_request) Successful in 52s

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-03-28 12:37:01 -04:00
parent afa6325e05
commit 6486799e2c
2 changed files with 47 additions and 17 deletions

View File

@@ -17,6 +17,7 @@ use KTXF\Mail\Object\AddressInterface;
use KTXF\Mail\Service\ServiceBaseInterface;
use KTXF\Mail\Service\ServiceCollectionMutableInterface;
use KTXF\Mail\Service\ServiceConfigurableInterface;
use KTXF\Mail\Service\ServiceEntityMutableInterface;
use KTXF\Mail\Service\ServiceMutableInterface;
use KTXF\Resource\Provider\ResourceServiceIdentityInterface;
use KTXF\Resource\Provider\ResourceServiceLocationInterface;
@@ -534,4 +535,12 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
return $entities;
}
public function entityMove(string|int $target, array $sources): array
{
$this->initialize();
$result = $this->mailService->entityMove($target, $sources);
return $result;
}
}

View File

@@ -25,6 +25,7 @@ use JmapClient\Requests\Mail\MailQuery;
use JmapClient\Requests\Mail\MailQueryChanges;
use JmapClient\Requests\Mail\MailSet;
use JmapClient\Requests\Mail\MailSubmissionSet;
use JmapClient\Requests\RequestBundle;
use JmapClient\Responses\Mail\MailboxParameters as MailboxParametersResponse;
use JmapClient\Responses\Mail\MailParameters as MailParametersResponse;
use JmapClient\Responses\ResponseException;
@@ -635,7 +636,7 @@ class RemoteMailService {
// select properties to return
$r0->property(...$this->defaultMailProperties);
$r0->bodyAll(true);
// transmit request and receive response
// transceive
$bundle = $this->dataStore->perform([$r0]);
// extract response
$response = $bundle->response(0);
@@ -709,7 +710,7 @@ class RemoteMailService {
// construct request
$r0 = new MailSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
$r0->update($id, $to);
// transmit request and receive response
// transceive
$bundle = $this->dataStore->perform([$r0]);
// extract response
$response = $bundle->response(0);
@@ -733,7 +734,7 @@ class RemoteMailService {
$r0 = new MailSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
// construct object
$r0->delete($id);
// transmit request and receive response
// transceive
$bundle = $this->dataStore->perform([$r0]);
// extract response
$response = $bundle->response(0);
@@ -750,8 +751,8 @@ class RemoteMailService {
* @since Release 1.0.0
*
*/
public function entityCopy(string $location, MailMessageObject $so): ?MailMessageObject {
return null;
public function entityCopy(string $target, array $sources): array {
return [];
}
/**
@@ -760,22 +761,42 @@ class RemoteMailService {
* @since Release 1.0.0
*
*/
public function entityMove(string $location, array $so): ?array {
// extract entity id
$id = $so['id'];
public function entityMove(string $target, array $sources): array {
// extract identifiers from sources
$identifiers = [];
foreach ($sources as $source) {
$identifiers = array_merge($identifiers, $source);
}
// construct request
$r0 = new MailSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
$r0->update($id)->in($location);
// transmit request and receive response
foreach ($identifiers as $id) {
$r0->update($id)->in($target);
}
// transceive
$bundle = $this->dataStore->perform([$r0]);
// extract response
$response = $bundle->response(0);
// determine if command succeeded
if (array_key_exists($id, $response->updated())) {
$so = array_merge($so, ['mailboxIds' => [$location => true]]);
return $so;
$response = $bundle->first();
// check for command error
if ($response instanceof ResponseException) {
if ($response->type() === 'unknownMethod') {
throw new JmapUnknownMethod($response->description(), 1);
} else {
throw new Exception($response->type() . ': ' . $response->description(), 1);
}
}
return null;
$results = [];
// check for success
foreach ($response->updateSuccesses() as $identifier => $data) {
$results[$identifier] = true;
}
// check for failure
foreach ($response->updateFailures() as $identifier => $data) {
$results[$identifier] = $data['type'] ?? 'unknownError';
}
return $results;
}
/**
@@ -824,7 +845,7 @@ class RemoteMailService {
$e1->message('#1');
$e1->from($from);
$e1->to($to);
// transmit request and receive response
// transceive
$bundle = $this->dataStore->perform([$r0, $r1]);
// extract response
$response = $bundle->response(1);