Merge pull request 'feat: entity move' (#7) from feat/entity-move into main
Some checks failed
Renovate / renovate (push) Failing after 1m20s

Reviewed-on: #7
This commit was merged in pull request #7.
This commit is contained in:
2026-03-28 16:37:34 +00:00
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\ServiceBaseInterface;
use KTXF\Mail\Service\ServiceCollectionMutableInterface; use KTXF\Mail\Service\ServiceCollectionMutableInterface;
use KTXF\Mail\Service\ServiceConfigurableInterface; use KTXF\Mail\Service\ServiceConfigurableInterface;
use KTXF\Mail\Service\ServiceEntityMutableInterface;
use KTXF\Mail\Service\ServiceMutableInterface; use KTXF\Mail\Service\ServiceMutableInterface;
use KTXF\Resource\Provider\ResourceServiceIdentityInterface; use KTXF\Resource\Provider\ResourceServiceIdentityInterface;
use KTXF\Resource\Provider\ResourceServiceLocationInterface; use KTXF\Resource\Provider\ResourceServiceLocationInterface;
@@ -534,4 +535,12 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
return $entities; 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\MailQueryChanges;
use JmapClient\Requests\Mail\MailSet; use JmapClient\Requests\Mail\MailSet;
use JmapClient\Requests\Mail\MailSubmissionSet; use JmapClient\Requests\Mail\MailSubmissionSet;
use JmapClient\Requests\RequestBundle;
use JmapClient\Responses\Mail\MailboxParameters as MailboxParametersResponse; use JmapClient\Responses\Mail\MailboxParameters as MailboxParametersResponse;
use JmapClient\Responses\Mail\MailParameters as MailParametersResponse; use JmapClient\Responses\Mail\MailParameters as MailParametersResponse;
use JmapClient\Responses\ResponseException; use JmapClient\Responses\ResponseException;
@@ -635,7 +636,7 @@ class RemoteMailService {
// select properties to return // select properties to return
$r0->property(...$this->defaultMailProperties); $r0->property(...$this->defaultMailProperties);
$r0->bodyAll(true); $r0->bodyAll(true);
// transmit request and receive response // transceive
$bundle = $this->dataStore->perform([$r0]); $bundle = $this->dataStore->perform([$r0]);
// extract response // extract response
$response = $bundle->response(0); $response = $bundle->response(0);
@@ -709,7 +710,7 @@ class RemoteMailService {
// construct request // construct request
$r0 = new MailSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel); $r0 = new MailSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
$r0->update($id, $to); $r0->update($id, $to);
// transmit request and receive response // transceive
$bundle = $this->dataStore->perform([$r0]); $bundle = $this->dataStore->perform([$r0]);
// extract response // extract response
$response = $bundle->response(0); $response = $bundle->response(0);
@@ -733,7 +734,7 @@ class RemoteMailService {
$r0 = new MailSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel); $r0 = new MailSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
// construct object // construct object
$r0->delete($id); $r0->delete($id);
// transmit request and receive response // transceive
$bundle = $this->dataStore->perform([$r0]); $bundle = $this->dataStore->perform([$r0]);
// extract response // extract response
$response = $bundle->response(0); $response = $bundle->response(0);
@@ -750,8 +751,8 @@ class RemoteMailService {
* @since Release 1.0.0 * @since Release 1.0.0
* *
*/ */
public function entityCopy(string $location, MailMessageObject $so): ?MailMessageObject { public function entityCopy(string $target, array $sources): array {
return null; return [];
} }
/** /**
@@ -760,22 +761,42 @@ class RemoteMailService {
* @since Release 1.0.0 * @since Release 1.0.0
* *
*/ */
public function entityMove(string $location, array $so): ?array { public function entityMove(string $target, array $sources): array {
// extract entity id
$id = $so['id']; // extract identifiers from sources
$identifiers = [];
foreach ($sources as $source) {
$identifiers = array_merge($identifiers, $source);
}
// construct request // construct request
$r0 = new MailSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel); $r0 = new MailSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
$r0->update($id)->in($location); foreach ($identifiers as $id) {
// transmit request and receive response $r0->update($id)->in($target);
}
// transceive
$bundle = $this->dataStore->perform([$r0]); $bundle = $this->dataStore->perform([$r0]);
// extract response // extract response
$response = $bundle->response(0); $response = $bundle->first();
// determine if command succeeded // check for command error
if (array_key_exists($id, $response->updated())) { if ($response instanceof ResponseException) {
$so = array_merge($so, ['mailboxIds' => [$location => true]]); if ($response->type() === 'unknownMethod') {
return $so; 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->message('#1');
$e1->from($from); $e1->from($from);
$e1->to($to); $e1->to($to);
// transmit request and receive response // transceive
$bundle = $this->dataStore->perform([$r0, $r1]); $bundle = $this->dataStore->perform([$r0, $r1]);
// extract response // extract response
$response = $bundle->response(1); $response = $bundle->response(1);