Compare commits
1 Commits
renovate/v
...
b83b0952e6
| Author | SHA1 | Date | |
|---|---|---|---|
| b83b0952e6 |
16
composer.lock
generated
16
composer.lock
generated
@@ -1260,16 +1260,16 @@
|
||||
},
|
||||
{
|
||||
"name": "phpunit/phpunit",
|
||||
"version": "11.5.55",
|
||||
"version": "11.5.53",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/sebastianbergmann/phpunit.git",
|
||||
"reference": "adc7262fccc12de2b30f12a8aa0b33775d814f00"
|
||||
"reference": "a997a653a82845f1240d73ee73a8a4e97e4b0607"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/adc7262fccc12de2b30f12a8aa0b33775d814f00",
|
||||
"reference": "adc7262fccc12de2b30f12a8aa0b33775d814f00",
|
||||
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/a997a653a82845f1240d73ee73a8a4e97e4b0607",
|
||||
"reference": "a997a653a82845f1240d73ee73a8a4e97e4b0607",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -1342,7 +1342,7 @@
|
||||
"support": {
|
||||
"issues": "https://github.com/sebastianbergmann/phpunit/issues",
|
||||
"security": "https://github.com/sebastianbergmann/phpunit/security/policy",
|
||||
"source": "https://github.com/sebastianbergmann/phpunit/tree/11.5.55"
|
||||
"source": "https://github.com/sebastianbergmann/phpunit/tree/11.5.53"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
@@ -1366,7 +1366,7 @@
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2026-02-18T12:37:06+00:00"
|
||||
"time": "2026-02-10T12:28:25+00:00"
|
||||
},
|
||||
{
|
||||
"name": "sebastian/cli-parser",
|
||||
@@ -2467,9 +2467,9 @@
|
||||
"platform": {
|
||||
"php": ">=8.2 <=8.5"
|
||||
},
|
||||
"platform-dev": {},
|
||||
"platform-dev": [],
|
||||
"platform-overrides": {
|
||||
"php": "8.2"
|
||||
},
|
||||
"plugin-api-version": "2.9.0"
|
||||
"plugin-api-version": "2.3.0"
|
||||
}
|
||||
|
||||
@@ -23,91 +23,91 @@ class MessageProperties extends MessagePropertiesMutableAbstract {
|
||||
*/
|
||||
public function fromJmap(array $parameters): static {
|
||||
|
||||
if (isset($parameters['size'])) {
|
||||
$this->data[static::PROPERTY_SIZE] = $parameters['size'];
|
||||
}
|
||||
|
||||
if (isset($parameters['headers']) && is_array($parameters['headers'])) {
|
||||
$this->data[static::PROPERTY_HEADERS] = $parameters['headers'];
|
||||
}
|
||||
|
||||
if (isset($parameters['messageId'])) {
|
||||
$this->data[static::PROPERTY_URID] = $parameters['messageId'][0];
|
||||
$this->data['urid'] = $parameters['messageId'][0];
|
||||
}
|
||||
if (isset($parameters['size'])) {
|
||||
$this->data['size'] = $parameters['size'];
|
||||
}
|
||||
|
||||
if (isset($parameters['receivedAt'])) {
|
||||
$this->data[static::PROPERTY_RECEIVED] = $parameters['receivedAt'];
|
||||
$this->data['received'] = $parameters['receivedAt'];
|
||||
}
|
||||
|
||||
if (isset($parameters['sentAt'])) {
|
||||
$this->data[static::PROPERTY_SENT] = $parameters['sentAt'];
|
||||
$this->data['date'] = $parameters['sentAt'];
|
||||
}
|
||||
|
||||
if (isset($parameters['inReplyTo'])) {
|
||||
$this->data[static::PROPERTY_IN_REPLY_TO] = $parameters['inReplyTo'];
|
||||
$this->data['inReplyTo'] = $parameters['inReplyTo'];
|
||||
}
|
||||
|
||||
if (isset($parameters['references'])) {
|
||||
$this->data[static::PROPERTY_REFERENCES] = is_array($parameters['references']) ? $parameters['references'] : [];
|
||||
$this->data['references'] = is_array($parameters['references']) ? $parameters['references'] : [];
|
||||
}
|
||||
if (isset($parameters['subject'])) {
|
||||
$this->data['subject'] = $parameters['subject'];
|
||||
}
|
||||
if (isset($parameters['preview'])) {
|
||||
$this->data['snippet'] = $parameters['preview'];
|
||||
}
|
||||
|
||||
if (isset($parameters['sender'])) {
|
||||
$this->data[static::PROPERTY_SENDER] = $parameters['sender'];
|
||||
$this->data['sender'] = $parameters['sender'];
|
||||
}
|
||||
|
||||
if (isset($parameters['from']) && is_array($parameters['from']) && !empty($parameters['from'])) {
|
||||
$this->data[static::PROPERTY_FROM] = [
|
||||
$this->data['from'] = [
|
||||
'address' => $parameters['from'][0]['email'] ?? '',
|
||||
'label' => $parameters['from'][0]['name'] ?? null
|
||||
];
|
||||
}
|
||||
|
||||
if (isset($parameters['replyTo']) && is_array($parameters['replyTo'])) {
|
||||
$this->data[static::PROPERTY_REPLY_TO] = [];
|
||||
foreach ($parameters['replyTo'] as $addr) {
|
||||
$this->data[static::PROPERTY_REPLY_TO][] = [
|
||||
'address' => $addr['email'] ?? '',
|
||||
'label' => $addr['name'] ?? null
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($parameters['to']) && is_array($parameters['to'])) {
|
||||
$this->data[static::PROPERTY_TO] = [];
|
||||
$this->data['to'] = [];
|
||||
foreach ($parameters['to'] as $addr) {
|
||||
$this->data[static::PROPERTY_TO][] = [
|
||||
$this->data['to'][] = [
|
||||
'address' => $addr['email'] ?? '',
|
||||
'label' => $addr['name'] ?? null
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($parameters['cc']) && is_array($parameters['cc'])) {
|
||||
$this->data[static::PROPERTY_CC] = [];
|
||||
$this->data['cc'] = [];
|
||||
foreach ($parameters['cc'] as $addr) {
|
||||
$this->data[static::PROPERTY_CC][] = [
|
||||
$this->data['cc'][] = [
|
||||
'address' => $addr['email'] ?? '',
|
||||
'label' => $addr['name'] ?? null
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($parameters['bcc']) && is_array($parameters['bcc'])) {
|
||||
$this->data[static::PROPERTY_BCC] = [];
|
||||
$this->data['bcc'] = [];
|
||||
foreach ($parameters['bcc'] as $addr) {
|
||||
$this->data[static::PROPERTY_BCC][] = [
|
||||
$this->data['bcc'][] = [
|
||||
'address' => $addr['email'] ?? '',
|
||||
'label' => $addr['name'] ?? null
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($parameters['subject'])) {
|
||||
$this->data[static::PROPERTY_SUBJECT] = $parameters['subject'];
|
||||
if (isset($parameters['replyTo']) && is_array($parameters['replyTo'])) {
|
||||
$this->data['replyTo'] = [];
|
||||
foreach ($parameters['replyTo'] as $addr) {
|
||||
$this->data['replyTo'][] = [
|
||||
'address' => $addr['email'] ?? '',
|
||||
'label' => $addr['name'] ?? null
|
||||
];
|
||||
}
|
||||
}
|
||||
if (isset($parameters['keywords']) && is_array($parameters['keywords'])) {
|
||||
$this->data['flags'] = [];
|
||||
foreach ($parameters['keywords'] as $keyword => $value) {
|
||||
$flag = match($keyword) {
|
||||
'$seen' => 'read',
|
||||
'$flagged' => 'flagged',
|
||||
'$answered' => 'answered',
|
||||
'$draft' => 'draft',
|
||||
'$deleted' => 'deleted',
|
||||
default => $keyword
|
||||
};
|
||||
$this->data['flags'][$flag] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($parameters['bodyStructure'])) {
|
||||
$this->data[static::PROPERTY_BODY] = $parameters['bodyStructure'];
|
||||
$this->data['body'] = $parameters['bodyStructure'];
|
||||
// Recursively add content from bodyValues to matching parts
|
||||
if (isset($parameters['bodyValues']) && is_array($parameters['bodyValues'])) {
|
||||
$addContentToParts = function(&$structure, $bodyValues) use (&$addContentToParts) {
|
||||
@@ -123,27 +123,14 @@ class MessageProperties extends MessagePropertiesMutableAbstract {
|
||||
}
|
||||
};
|
||||
|
||||
$addContentToParts($this->data[static::PROPERTY_BODY], $parameters['bodyValues']);
|
||||
$addContentToParts($this->data['body'], $parameters['bodyValues']);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($parameters['headers']) && is_array($parameters['headers'])) {
|
||||
$this->data['headers'] = $parameters['headers'];
|
||||
}
|
||||
if (isset($parameters['attachments'])) {
|
||||
$this->data[static::PROPERTY_ATTACHMENTS] = $parameters['attachments'];
|
||||
}
|
||||
|
||||
if (isset($parameters['keywords']) && is_array($parameters['keywords'])) {
|
||||
$this->data[static::PROPERTY_FLAGS] = [];
|
||||
foreach ($parameters['keywords'] as $keyword => $value) {
|
||||
$flag = match($keyword) {
|
||||
'$seen' => 'read',
|
||||
'$flagged' => 'flagged',
|
||||
'$answered' => 'answered',
|
||||
'$draft' => 'draft',
|
||||
'$deleted' => 'deleted',
|
||||
default => $keyword
|
||||
};
|
||||
$this->data[static::PROPERTY_FLAGS][$flag] = $value;
|
||||
}
|
||||
$this->data['attachments'] = $parameters['attachments'];
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
||||
@@ -14,7 +14,6 @@ use KTXF\Mail\Provider\ProviderServiceDiscoverInterface;
|
||||
use KTXF\Mail\Provider\ProviderServiceMutateInterface;
|
||||
use KTXF\Mail\Provider\ProviderServiceTestInterface;
|
||||
use KTXF\Mail\Service\ServiceBaseInterface;
|
||||
use KTXF\Mail\Service\ServiceMutableInterface;
|
||||
use KTXF\Resource\Provider\ResourceServiceLocationInterface;
|
||||
use KTXF\Resource\Provider\ResourceServiceMutateInterface;
|
||||
use KTXM\ProviderJmapc\Service\Discovery;
|
||||
@@ -24,9 +23,10 @@ use KTXM\ProviderJmapc\Stores\ServiceStore;
|
||||
/**
|
||||
* JMAP Mail Provider
|
||||
*/
|
||||
class Provider implements ProviderBaseInterface, ProviderServiceMutateInterface, ProviderServiceDiscoverInterface, ProviderServiceTestInterface
|
||||
class Provider implements ProviderServiceMutateInterface, ProviderServiceDiscoverInterface, ProviderServiceTestInterface
|
||||
{
|
||||
|
||||
public const JSON_TYPE = ProviderBaseInterface::JSON_TYPE;
|
||||
protected const PROVIDER_IDENTIFIER = 'jmap';
|
||||
protected const PROVIDER_LABEL = 'JMAP Mail Provider';
|
||||
protected const PROVIDER_DESCRIPTION = 'Provides mail services via JMAP protocol (RFC 8620)';
|
||||
@@ -155,7 +155,7 @@ class Provider implements ProviderBaseInterface, ProviderServiceMutateInterface,
|
||||
}
|
||||
|
||||
$updated = $this->serviceStore->modify($tenantId, $userId, $service);
|
||||
return (string) $updated['sid'];
|
||||
return (string) $updated['id'];
|
||||
}
|
||||
|
||||
public function serviceDestroy(string $tenantId, string $userId, ResourceServiceMutateInterface $service): bool
|
||||
@@ -180,8 +180,7 @@ class Provider implements ProviderBaseInterface, ProviderServiceMutateInterface,
|
||||
return $discovery->discover($identity, $location, $secret, $verifySSL);
|
||||
}
|
||||
|
||||
public function serviceTest(ServiceBaseInterface|ServiceMutableInterface $service, array $options = []): array
|
||||
{
|
||||
public function serviceTest(ServiceBaseInterface $service, array $options = []): array {
|
||||
$startTime = microtime(true);
|
||||
|
||||
try {
|
||||
@@ -200,7 +199,8 @@ class Provider implements ProviderBaseInterface, ProviderServiceMutateInterface,
|
||||
. ' (Account ID: ' . ($session->username() ?? 'N/A') . ')'
|
||||
. ' (Latency: ' . $latency . ' ms)',
|
||||
];
|
||||
} catch (\Throwable $e) {
|
||||
} catch (\Exception $e) {
|
||||
$latency = round((microtime(true) - $startTime) * 1000);
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => 'Test failed: ' . $e->getMessage(),
|
||||
|
||||
@@ -13,16 +13,13 @@ use Generator;
|
||||
use KTXF\Mail\Collection\CollectionBaseInterface;
|
||||
use KTXF\Mail\Collection\CollectionRoles;
|
||||
use KTXF\Mail\Collection\CollectionMutableInterface;
|
||||
use KTXF\Mail\Collection\CollectionPropertiesBaseInterface;
|
||||
use KTXF\Mail\Object\Address;
|
||||
use KTXF\Mail\Object\AddressInterface;
|
||||
use KTXF\Mail\Object\MessagePropertiesMutableInterface;
|
||||
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\BinaryResource;
|
||||
use KTXF\Resource\Provider\ResourceServiceIdentityInterface;
|
||||
use KTXF\Resource\Provider\ResourceServiceLocationInterface;
|
||||
use KTXF\Resource\Delta\Delta;
|
||||
@@ -30,7 +27,6 @@ use KTXF\Resource\Filter\Filter;
|
||||
use KTXF\Resource\Filter\IFilter;
|
||||
use KTXF\Resource\Identifier\CollectionIdentifier;
|
||||
use KTXF\Resource\Identifier\EntityIdentifier;
|
||||
use KTXF\Resource\Identifier\EntityIdentifierInterface;
|
||||
use KTXF\Resource\Range\IRange;
|
||||
use KTXF\Resource\Range\Range;
|
||||
use KTXF\Resource\Range\RangeType;
|
||||
@@ -41,8 +37,9 @@ use KTXM\ProviderJmapc\Providers\ServiceLocation;
|
||||
use KTXM\ProviderJmapc\Service\Remote\RemoteMailService;
|
||||
use KTXM\ProviderJmapc\Service\Remote\RemoteService;
|
||||
|
||||
class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceConfigurableInterface, ServiceCollectionMutableInterface, ServiceEntityMutableInterface
|
||||
class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceConfigurableInterface, ServiceCollectionMutableInterface
|
||||
{
|
||||
public const JSON_TYPE = ServiceBaseInterface::JSON_TYPE;
|
||||
|
||||
private const PROVIDER_IDENTIFIER = 'jmap';
|
||||
|
||||
@@ -51,6 +48,7 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
||||
private ?string $serviceIdentifier = null;
|
||||
private ?string $serviceLabel = null;
|
||||
private bool $serviceEnabled = false;
|
||||
private bool $serviceDebug = false;
|
||||
private string $primaryAddress = '';
|
||||
private array $secondaryAddresses = [];
|
||||
private ?ServiceLocation $location = null;
|
||||
@@ -60,20 +58,18 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
||||
private array $serviceAbilities = [
|
||||
self::CAPABILITY_COLLECTION_LIST => true,
|
||||
self::CAPABILITY_COLLECTION_LIST_FILTER => [
|
||||
self::CAPABILITY_COLLECTION_FILTER_LABEL => 's:128:256:256',
|
||||
self::CAPABILITY_COLLECTION_FILTER_ROLE => 's:32:1:1',
|
||||
self::CAPABILITY_COLLECTION_FILTER_SUBSCRIBED => 'b:0:1:1',
|
||||
self::CAPABILITY_COLLECTION_FILTER_LABEL => 's:100:256:256',
|
||||
self::CAPABILITY_COLLECTION_FILTER_ROLE => 's:100:256:256',
|
||||
],
|
||||
self::CAPABILITY_COLLECTION_LIST_SORT => [
|
||||
self::CAPABILITY_COLLECTION_SORT_LABEL,
|
||||
self::CAPABILITY_COLLECTION_SORT_RANK,
|
||||
],
|
||||
self::CAPABILITY_COLLECTION_FETCH => true,
|
||||
self::CAPABILITY_COLLECTION_EXTANT => true,
|
||||
self::CAPABILITY_COLLECTION_FETCH => true,
|
||||
self::CAPABILITY_COLLECTION_CREATE => true,
|
||||
self::CAPABILITY_COLLECTION_UPDATE => true,
|
||||
self::CAPABILITY_COLLECTION_DELETE => true,
|
||||
self::CAPABILITY_COLLECTION_MOVE => true,
|
||||
self::CAPABILITY_ENTITY_LIST => true,
|
||||
self::CAPABILITY_ENTITY_LIST_FILTER => [
|
||||
self::CAPABILITY_ENTITY_FILTER_ALL => 's:200:256:256',
|
||||
@@ -99,14 +95,11 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
||||
self::CAPABILITY_ENTITY_LIST_RANGE => [
|
||||
'tally' => ['absolute', 'relative']
|
||||
],
|
||||
self::CAPABILITY_ENTITY_FETCH => true,
|
||||
self::CAPABILITY_ENTITY_DELTA => true,
|
||||
self::CAPABILITY_ENTITY_EXTANT => true,
|
||||
self::CAPABILITY_ENTITY_CREATE => false,
|
||||
self::CAPABILITY_ENTITY_MODIFY => false,
|
||||
self::CAPABILITY_ENTITY_PATCH => true,
|
||||
self::CAPABILITY_ENTITY_DELETE => true,
|
||||
self::CAPABILITY_ENTITY_MOVE => true,
|
||||
self::CAPABILITY_ENTITY_COPY => false,
|
||||
self::CAPABILITY_ENTITY_FETCH => true,
|
||||
//self::CAPABILITY_ENTITY_DELETE => true,
|
||||
//self::CAPABILITY_ENTITY_MOVE => true,
|
||||
];
|
||||
|
||||
private readonly RemoteMailService $mailService;
|
||||
@@ -114,22 +107,21 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
||||
public function __construct(
|
||||
) {}
|
||||
|
||||
private function initialize(): void
|
||||
{
|
||||
private function initialize(): void {
|
||||
if (!isset($this->mailService)) {
|
||||
$client = RemoteService::freshClient($this);
|
||||
$this->mailService = RemoteService::mailService($client);
|
||||
}
|
||||
}
|
||||
|
||||
public function toStore(): array
|
||||
{
|
||||
public function toStore(): array {
|
||||
return array_filter([
|
||||
'tid' => $this->serviceTenantId,
|
||||
'uid' => $this->serviceUserId,
|
||||
'sid' => $this->serviceIdentifier,
|
||||
'enabled' => $this->serviceEnabled,
|
||||
'label' => $this->serviceLabel,
|
||||
'enabled' => $this->serviceEnabled,
|
||||
'debug' => $this->serviceDebug,
|
||||
'primaryAddress' => $this->primaryAddress,
|
||||
'secondaryAddresses' => $this->secondaryAddresses,
|
||||
'location' => $this->location?->toStore(),
|
||||
@@ -138,13 +130,13 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
||||
], fn($v) => $v !== null);
|
||||
}
|
||||
|
||||
public function fromStore(array $data): static
|
||||
{
|
||||
public function fromStore(array $data): static {
|
||||
$this->serviceTenantId = $data['tid'] ?? null;
|
||||
$this->serviceUserId = $data['uid'] ?? null;
|
||||
$this->serviceIdentifier = $data['sid'];
|
||||
$this->serviceLabel = $data['label'] ?? '';
|
||||
$this->serviceEnabled = $data['enabled'] ?? false;
|
||||
$this->serviceDebug = $data['debug'] ?? false;
|
||||
|
||||
if (isset($data['primaryAddress'])) {
|
||||
$this->primaryAddress = $data['primaryAddress'];
|
||||
@@ -167,8 +159,7 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function jsonSerialize(): array
|
||||
{
|
||||
public function jsonSerialize(): array {
|
||||
return array_filter([
|
||||
self::JSON_PROPERTY_TYPE => self::JSON_TYPE,
|
||||
self::JSON_PROPERTY_PROVIDER => self::PROVIDER_IDENTIFIER,
|
||||
@@ -184,18 +175,17 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
||||
], fn($v) => $v !== null);
|
||||
}
|
||||
|
||||
public function jsonDeserialize(array|string $data, bool $delta = false): static
|
||||
{
|
||||
public function jsonDeserialize(array|string $data, bool $delta = false): static {
|
||||
if (is_string($data)) {
|
||||
$data = json_decode($data, true, 512, JSON_THROW_ON_ERROR);
|
||||
}
|
||||
|
||||
if (isset($data[self::JSON_PROPERTY_ENABLED])) {
|
||||
$this->setEnabled($data[self::JSON_PROPERTY_ENABLED]);
|
||||
}
|
||||
if (isset($data[self::JSON_PROPERTY_LABEL])) {
|
||||
$this->setLabel($data[self::JSON_PROPERTY_LABEL]);
|
||||
}
|
||||
if (isset($data[self::JSON_PROPERTY_ENABLED])) {
|
||||
$this->setEnabled($data[self::JSON_PROPERTY_ENABLED]);
|
||||
}
|
||||
if (isset($data[self::JSON_PROPERTY_LOCATION])) {
|
||||
$this->setLocation($this->freshLocation(null, $data[self::JSON_PROPERTY_LOCATION]));
|
||||
}
|
||||
@@ -223,8 +213,7 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
||||
return isset($this->serviceAbilities[$value]);
|
||||
}
|
||||
|
||||
public function capabilities(): array
|
||||
{
|
||||
public function capabilities(): array {
|
||||
return $this->serviceAbilities;
|
||||
}
|
||||
|
||||
@@ -337,12 +326,12 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
||||
|
||||
public function getDebug(): bool
|
||||
{
|
||||
return ($this->auxiliary['debug'] ?? false) === true;
|
||||
return $this->serviceDebug;
|
||||
}
|
||||
|
||||
public function setDebug(bool $debug): static
|
||||
{
|
||||
$this->auxiliary['debug'] = $debug;
|
||||
$this->serviceDebug = $debug;
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -357,6 +346,8 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
||||
return $this;
|
||||
}
|
||||
|
||||
// Collection operations
|
||||
|
||||
public function collectionList(string|int|null $location, ?IFilter $filter = null, ?ISort $sort = null): array
|
||||
{
|
||||
$this->initialize();
|
||||
@@ -391,132 +382,82 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
||||
return $this->mailService->collectionExtant(...$identifiers);
|
||||
}
|
||||
|
||||
public function collectionFetch(string|int $identifier): ?CollectionResource
|
||||
public function collectionFetch(string|int $identifier): ?CollectionBaseInterface
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
$mailbox = $this->mailService->collectionFetch($identifier);
|
||||
$collection = $this->mailService->collectionFetch($identifier);
|
||||
|
||||
if (!is_array($mailbox) || !isset($mailbox['id'])) {
|
||||
return null;
|
||||
if (is_array($collection) && isset($collection['id'])) {
|
||||
$object = new CollectionResource(provider: $this->provider(), service: $this->identifier());
|
||||
$object->fromJmap($collection);
|
||||
$collection = $object;
|
||||
}
|
||||
|
||||
$collection = $this->collectionFresh();
|
||||
$collection->fromJmap($mailbox);
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
public function collectionFresh(): CollectionResource
|
||||
public function collectionFresh(): CollectionMutableInterface
|
||||
{
|
||||
return new CollectionResource($this->provider(), $this->identifier());
|
||||
return new CollectionResource(provider: $this->provider(), service: $this->identifier());
|
||||
}
|
||||
|
||||
public function collectionCreate(CollectionIdentifier|null $target, CollectionPropertiesBaseInterface $properties, array $options = []): CollectionBaseInterface
|
||||
public function collectionCreate(string|int|null $location, CollectionMutableInterface $collection, array $options = []): CollectionBaseInterface
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
if ($properties instanceof CollectionProperties === false) {
|
||||
$native = new CollectionProperties([]);
|
||||
$native->jsonDeserialize($properties->jsonSerialize());
|
||||
} else {
|
||||
$native = $properties;
|
||||
if ($collection instanceof CollectionResource === false) {
|
||||
$object = new CollectionResource(provider: $this->provider(), service: $this->identifier());
|
||||
$object->jsonDeserialize($collection->jsonSerialize());
|
||||
$collection = $object;
|
||||
}
|
||||
|
||||
$collection = $native->toJmap();
|
||||
$collection = $this->mailService->collectionCreate($target?->collection(), $collection, $options);
|
||||
$collection = $collection->toJmap();
|
||||
$collection = $this->mailService->collectionCreate($location, $collection, $options);
|
||||
|
||||
$object = $this->collectionFresh();
|
||||
$object = new CollectionResource(provider: $this->provider(), service: $this->identifier());
|
||||
$object->fromJmap($collection);
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
public function collectionUpdate(CollectionIdentifier $target, CollectionPropertiesBaseInterface $properties): CollectionBaseInterface
|
||||
public function collectionUpdate(string|int $identifier, CollectionMutableInterface $collection): CollectionBaseInterface
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
if ($properties instanceof CollectionProperties === false) {
|
||||
$native = new CollectionProperties([]);
|
||||
$native->jsonDeserialize($properties->jsonSerialize());
|
||||
} else {
|
||||
$native = $properties;
|
||||
if ($collection instanceof CollectionResource === false) {
|
||||
$object = new CollectionResource(provider: $this->provider(), service: $this->identifier());
|
||||
$object->jsonDeserialize($collection->jsonSerialize());
|
||||
$collection = $object;
|
||||
}
|
||||
|
||||
$collection = $native->toJmap();
|
||||
$collection = $this->mailService->collectionModify($target->collection(), $collection);
|
||||
$collection = $collection->toJmap();
|
||||
$collection = $this->mailService->collectionModify($identifier, $collection);
|
||||
|
||||
$object = $this->collectionFresh();
|
||||
$object = new CollectionResource(provider: $this->provider(), service: $this->identifier());
|
||||
$object->fromJmap($collection);
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
public function collectionDelete(CollectionIdentifier $target, bool $force = false): CollectionBaseInterface | true
|
||||
public function collectionDelete(string|int $identifier, bool $force = false, bool $recursive = false): bool
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
$deleteMode = $this->auxiliary['deleteMode'] ?? 'soft';
|
||||
$deleteTarget = $this->auxiliary['deleteTarget'] ?? null;
|
||||
|
||||
if ($deleteMode !== 'soft' && $deleteMode !== 'hard') {
|
||||
throw new \InvalidArgumentException("Invalid delete mode: $deleteMode");
|
||||
return $this->mailService->collectionDestroy($identifier, $force, $recursive) !== null;
|
||||
}
|
||||
|
||||
// Move to target collection (e.g. Trash) instead of deleting
|
||||
if ($deleteMode === 'soft' && $deleteTarget !== null) {
|
||||
return $this->collectionMove(new CollectionIdentifier($target->provider(), $target->service(), $deleteTarget), $target);
|
||||
}
|
||||
|
||||
if ($deleteMode === 'soft' && $deleteTarget === null) {
|
||||
$filter = $this->collectionListFilter();
|
||||
$filter->condition('role', CollectionRoles::Trash->value);
|
||||
|
||||
$mailboxes = iterator_to_array($this->mailService->collectionList(null, $filter, null));
|
||||
if (empty($mailboxes)) {
|
||||
throw new \RuntimeException('No Trash collection configured or found for deletion');
|
||||
}
|
||||
|
||||
$deleteTarget = key($mailboxes);
|
||||
}
|
||||
|
||||
// we need to determine if the folder being deleted is already in the trash
|
||||
if (str_starts_with((string) $target->collection(), (string) $deleteTarget)) {
|
||||
// if so, we should hard delete instead of moving to avoid duplicates in the trash
|
||||
$deleteMode = 'hard';
|
||||
}
|
||||
|
||||
$result = match ($deleteMode) {
|
||||
'soft' => $this->collectionMove(new CollectionIdentifier($target->provider(), $target->service(), $deleteTarget), $target),
|
||||
'hard' => $this->mailService->collectionDestroy($target->collection(), $force),
|
||||
};
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function collectionMove(CollectionIdentifier $target, CollectionIdentifier $source): CollectionBaseInterface
|
||||
public function collectionMove(string|int $identifier, string|int|null $targetLocation): CollectionBaseInterface
|
||||
{
|
||||
// TODO: Implement collection move
|
||||
$this->initialize();
|
||||
|
||||
$sourceMailbox = $this->mailService->collectionFetch((string) $source->collection());
|
||||
$targetMailbox = $this->mailService->collectionFetch((string) $target->collection());
|
||||
if ($sourceMailbox === null) {
|
||||
throw new \RuntimeException('Source collection not found for move operation');
|
||||
}
|
||||
if ($targetMailbox === null) {
|
||||
throw new \RuntimeException('Target collection not found for move operation');
|
||||
}
|
||||
|
||||
$mutation['parentId'] = $targetMailbox['id'];
|
||||
$mutation = $this->mailService->collectionModify($sourceMailbox['id'], $mutation);
|
||||
$mutation = array_merge($sourceMailbox, $mutation);
|
||||
|
||||
$collection = $this->collectionFresh();
|
||||
$collection->fromJmap($mutation);
|
||||
|
||||
$collection = new CollectionResource(provider: $this->provider(), service: $this->identifier());
|
||||
return $collection;
|
||||
}
|
||||
|
||||
public function entityListBulk(string|int $collection, ?IFilter $filter = null, ?ISort $sort = null, ?IRange $range = null, ?array $properties = null): array
|
||||
// Entity operations
|
||||
|
||||
public function entityList(string|int $collection, ?IFilter $filter = null, ?ISort $sort = null, ?IRange $range = null, ?array $properties = null): array
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
@@ -525,9 +466,9 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
||||
$list = [];
|
||||
foreach ($result['list'] as $index => $entry) {
|
||||
if (is_array($entry) && isset($entry['id'])) {
|
||||
$object = $this->entityFresh();
|
||||
$object = new EntityResource(provider: $this->provider(), service: $this->identifier());
|
||||
$object->fromJmap($entry);
|
||||
$list[$object->urn()] = $object;
|
||||
$list[$object->identifier()] = $object;
|
||||
}
|
||||
unset($result['list'][$index]);
|
||||
}
|
||||
@@ -537,8 +478,17 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
||||
|
||||
public function entityListStream(string|int $collection, ?IFilter $filter = null, ?ISort $sort = null, ?IRange $range = null, ?array $properties = null): Generator
|
||||
{
|
||||
foreach ($this->entityListBulk($collection, $filter, $sort, $range, $properties) as $urn => $entity) {
|
||||
yield $urn => $entity;
|
||||
$this->initialize();
|
||||
|
||||
$result = $this->mailService->entityList($collection, $filter, $sort, $range, $properties);
|
||||
|
||||
foreach ($result['list'] as $index => $entry) {
|
||||
if (is_array($entry) && isset($entry['id'])) {
|
||||
$object = new EntityResource(provider: $this->provider(), service: $this->identifier());
|
||||
$object->fromJmap($entry);
|
||||
yield $object;
|
||||
}
|
||||
unset($result['list'][$index]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -557,45 +507,6 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
||||
return new Range();
|
||||
}
|
||||
|
||||
public function entityFetchBulk(EntityIdentifierInterface ...$identifiers): array
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
$ids = [];
|
||||
foreach ($identifiers as $identifier) {
|
||||
$ids[] = $identifier->entity();
|
||||
}
|
||||
|
||||
$entities = $this->mailService->entityFetch(...$ids);
|
||||
|
||||
$list = [];
|
||||
foreach ($entities as $entity) {
|
||||
if (is_array($entity) && isset($entity['id'])) {
|
||||
$object = $this->entityFresh();
|
||||
$object->fromJmap($entity);
|
||||
$list[$object->urn()] = $object;
|
||||
}
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function entityFetchStream(EntityIdentifierInterface ...$identifiers): Generator
|
||||
{
|
||||
foreach ($this->entityFetchBulk(...$identifiers) as $urn => $entity) {
|
||||
yield $urn => $entity;
|
||||
}
|
||||
}
|
||||
|
||||
public function entityDownload(EntityIdentifierInterface $target, array|null $part): BinaryResource
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
$blobId = isset($part['blobId']) ? (string) $part['blobId'] : null;
|
||||
|
||||
return $this->mailService->entityDownload($target->entity(), $blobId);
|
||||
}
|
||||
|
||||
public function entityDelta(string|int $collection, string $signature, string $detail = 'ids'): Delta
|
||||
{
|
||||
$this->initialize();
|
||||
@@ -610,159 +521,53 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
||||
return $this->mailService->entityExtant(...$identifiers);
|
||||
}
|
||||
|
||||
public function entityFresh(): EntityResource
|
||||
public function entityFetch(string|int $collection, string|int ...$identifiers): array
|
||||
{
|
||||
return new EntityResource($this->provider(), $this->identifier());
|
||||
}
|
||||
|
||||
public function entityCreate(CollectionIdentifier $target, MessagePropertiesMutableInterface $properties, array $options = []): EntityResource
|
||||
{
|
||||
// TODO: Implement entity create
|
||||
return $this->entityFresh();
|
||||
}
|
||||
|
||||
public function entityModify(EntityIdentifier $identifier, MessagePropertiesMutableInterface $properties): EntityResource
|
||||
{
|
||||
// TODO: Implement entity modify
|
||||
return $this->entityFresh();
|
||||
}
|
||||
|
||||
public function entityPatch(MessagePropertiesMutableInterface $properties, EntityIdentifier ...$targets): array
|
||||
{
|
||||
// validate identifiers and construct ID list
|
||||
$targets = $this->mapEntities(...$targets);
|
||||
|
||||
// move entities on remote store and construct result map
|
||||
$this->initialize();
|
||||
|
||||
$patch = $this->mailService->entityFresh();
|
||||
$flags = $properties->getFlags();
|
||||
foreach ($flags as $flag => $value) {
|
||||
$patch->keyword($flag, $value);
|
||||
$entities = $this->mailService->entityFetch(...$identifiers);
|
||||
|
||||
foreach ($entities as &$entity) {
|
||||
if (is_array($entity) && isset($entity['id'])) {
|
||||
$object = new EntityResource(provider: $this->provider(), service: $this->identifier());
|
||||
$object->fromJmap($entity);
|
||||
$entity = $object;
|
||||
}
|
||||
}
|
||||
|
||||
$dispositions = $this->mailService->entityPatch($patch, ...array_keys($targets));
|
||||
|
||||
$list = [];
|
||||
foreach ($targets as $target) {
|
||||
$entityId = $target->entity();
|
||||
// if the source entity ID is not in the dispositions, it means an unknown error occurred during the move operation for that entity
|
||||
if (!isset($dispositions[$entityId])) {
|
||||
$list[(string)$target] = [
|
||||
'disposition' => 'error',
|
||||
'error' => 'Unknown error occurred during move operation',
|
||||
];
|
||||
continue;
|
||||
}
|
||||
// if the disposition for the entity ID is not true, it means the move operation failed for that entity with a known error
|
||||
if ($dispositions[$entityId] !== true) {
|
||||
$list[(string)$target] = [
|
||||
'disposition' => 'error',
|
||||
'error' => $dispositions[$entityId] ?? 'Unknown error occurred during move operation',
|
||||
];
|
||||
continue;
|
||||
return $entities;
|
||||
}
|
||||
|
||||
$list[(string)$target] = [
|
||||
'disposition' => 'patched'
|
||||
];
|
||||
unset($targets[$entityId]);
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function entityDelete(EntityIdentifier ...$targets): array
|
||||
public function entityDelete(EntityIdentifier ...$identifiers): array
|
||||
{
|
||||
// validate identifiers and construct ID list
|
||||
$targets = $this->mapEntities(...$targets);
|
||||
|
||||
// determine delete mode and target collection (e.g. Trash) if applicable
|
||||
$deleteMode = $this->auxiliary['deleteMode'] ?? 'soft';
|
||||
$deleteTarget = $this->auxiliary['deleteTarget'] ?? null;
|
||||
|
||||
if ($deleteMode !== 'soft' && $deleteMode !== 'hard') {
|
||||
throw new \InvalidArgumentException("Invalid delete mode: $deleteMode");
|
||||
$ids = [];
|
||||
foreach ($identifiers as $identifier) {
|
||||
if ($identifier->provider() !== $this->provider() || $identifier->service() !== (string)$this->identifier()) {
|
||||
throw new \InvalidArgumentException('Entity identifier does not belong to this service: ' . (string)$identifier);
|
||||
}
|
||||
$ids[] = $identifier->entity();
|
||||
}
|
||||
|
||||
// connect to remote store
|
||||
$this->initialize();
|
||||
|
||||
// attempt to find a target collection for soft deletion if none was specified
|
||||
if ($deleteMode === 'soft' && $deleteTarget === null) {
|
||||
$filter = $this->collectionListFilter();
|
||||
$filter->condition('role', CollectionRoles::Trash->value);
|
||||
|
||||
$mailboxes = iterator_to_array($this->mailService->collectionList(null, $filter, null));
|
||||
if (empty($mailboxes)) {
|
||||
throw new \RuntimeException('No Trash collection configured or found for deletion');
|
||||
}
|
||||
|
||||
$targetMailbox = reset($mailboxes);
|
||||
if ($targetMailbox === false) {
|
||||
throw new \RuntimeException('No Trash collection configured or found for deletion');
|
||||
}
|
||||
|
||||
$deleteTargetNative = $targetMailbox->id();
|
||||
$deleteTargetIdentifier = new CollectionIdentifier($this->provider(), (string) $this->identifier(), $deleteTargetNative);
|
||||
} else {
|
||||
$deleteTargetNative = $deleteTarget;
|
||||
$deleteTargetIdentifier = new CollectionIdentifier($this->provider(), (string) $this->identifier(), $deleteTargetNative);
|
||||
}
|
||||
|
||||
// if all targets are already in the delete target collection, we should hard delete instead of moving to avoid duplicates in the trash
|
||||
$targetCollections = [];
|
||||
foreach ($targets as $target) {
|
||||
$targetCollections[$target->collection()] = true;
|
||||
}
|
||||
if (array_keys($targetCollections) === [$deleteTargetNative]) {
|
||||
$deleteMode = 'hard';
|
||||
}
|
||||
|
||||
// move or delete target entities on remote store and construct result map
|
||||
$dispositions = match ($deleteMode) {
|
||||
'soft' => $this->mailService->entityMove($deleteTargetNative, ...array_keys($targets)),
|
||||
'hard' => $this->mailService->entityDelete(...array_keys($targets)),
|
||||
};
|
||||
|
||||
$list = [];
|
||||
foreach ($targets as $target) {
|
||||
$entityId = $target->entity();
|
||||
// if the source entity ID is not in the dispositions, it means an unknown error occurred during the move operation for that entity
|
||||
if (!isset($dispositions[$entityId])) {
|
||||
$list[(string)$target] = [
|
||||
'disposition' => 'error',
|
||||
'error' => 'Unknown error occurred during move operation',
|
||||
];
|
||||
continue;
|
||||
}
|
||||
// if the disposition for the entity ID is not true, it means the move operation failed for that entity with a known error
|
||||
if ($dispositions[$entityId] !== true) {
|
||||
$list[(string)$target] = [
|
||||
'disposition' => 'error',
|
||||
'error' => $dispositions[$entityId] ?? 'Unknown error occurred during move operation',
|
||||
];
|
||||
continue;
|
||||
}
|
||||
|
||||
$deleteMode = strtolower(trim((string) ($this->getAuxiliary()['deleteMode'] ?? 'soft')));
|
||||
if ($deleteMode === 'soft') {
|
||||
$list[(string)$target] = [
|
||||
'disposition' => 'moved',
|
||||
'destination' => $deleteTargetIdentifier,
|
||||
'mutation' => new EntityIdentifier($this->provider(), $this->identifier(), $target->collection(), $entityId),
|
||||
];
|
||||
} else {
|
||||
$list[(string)$target] = [
|
||||
'disposition' => 'deleted',
|
||||
];
|
||||
}
|
||||
unset($targets[$entityId]);
|
||||
$filter = $this->collectionListFilter();
|
||||
$filter->condition('role', 'trash');
|
||||
$targets = $this->collectionList(null, $filter);
|
||||
|
||||
if (empty($targets)) {
|
||||
throw new \RuntimeException('No trash collection found for soft delete');
|
||||
}
|
||||
|
||||
return $list;
|
||||
return $this->mailService->entityMove(reset($targets)->identifier(), ...$ids);
|
||||
}
|
||||
|
||||
public function entityMove(CollectionIdentifier $target, EntityIdentifier ...$sources): array
|
||||
return $this->mailService->entityDelete(...$ids);
|
||||
}
|
||||
|
||||
public function entityMove(CollectionIdentifier $target, EntityIdentifier ...$identifiers): array
|
||||
{
|
||||
// validate target belongs to this service
|
||||
if ($target->provider() !== $this->provider() || $target->service() !== (string)$this->identifier()) {
|
||||
@@ -770,59 +575,16 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
||||
}
|
||||
|
||||
// validate identifiers and construct ID list
|
||||
$sources = $this->mapEntities(...$sources);
|
||||
|
||||
// move entities on remote store and construct result map
|
||||
$this->initialize();
|
||||
|
||||
$dispositions = $this->mailService->entityMove($target->collection(), ...array_keys($sources));
|
||||
|
||||
$list = [];
|
||||
foreach ($sources as $source) {
|
||||
$entityId = $source->entity();
|
||||
// if the source entity ID is not in the dispositions, it means an unknown error occurred during the move operation for that entity
|
||||
if (!isset($dispositions[$entityId])) {
|
||||
$list[(string)$source] = [
|
||||
'disposition' => 'error',
|
||||
'error' => 'Unknown error occurred during move operation',
|
||||
];
|
||||
continue;
|
||||
}
|
||||
// if the disposition for the entity ID is not true, it means the move operation failed for that entity with a known error
|
||||
if ($dispositions[$entityId] !== true) {
|
||||
$list[(string)$source] = [
|
||||
'disposition' => 'error',
|
||||
'error' => $dispositions[$entityId] ?? 'Unknown error occurred during move operation',
|
||||
];
|
||||
continue;
|
||||
}
|
||||
|
||||
$list[(string)$source] = [
|
||||
'disposition' => 'moved',
|
||||
'destination' => $target,
|
||||
'mutation' => new EntityIdentifier($this->provider(), $this->identifier(), $target->collection(), $entityId),
|
||||
];
|
||||
unset($sources[$entityId]);
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function entityCopy(CollectionIdentifier $target, EntityIdentifier ...$sources): array
|
||||
{
|
||||
// TODO: Implement entity copy
|
||||
return [];
|
||||
}
|
||||
|
||||
private function mapEntities(EntityIdentifier ...$identifiers): array
|
||||
{
|
||||
$list = [];
|
||||
$ids = [];
|
||||
foreach ($identifiers as $identifier) {
|
||||
if ($identifier->provider() !== $this->provider() || $identifier->service() !== (string)$this->identifier()) {
|
||||
throw new \InvalidArgumentException('Entity identifier does not belong to this service: ' . (string)$identifier);
|
||||
}
|
||||
$list[$identifier->entity()] = $identifier;
|
||||
$ids[] = $identifier->entity();
|
||||
}
|
||||
return $list;
|
||||
|
||||
$this->initialize();
|
||||
|
||||
return $this->mailService->entityMove($target->collection(), ...$ids);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ namespace KTXM\ProviderJmapc\Service\Remote;
|
||||
|
||||
use Exception;
|
||||
use JmapClient\Client;
|
||||
use JmapClient\Requests\Blob\BlobGet;
|
||||
use JmapClient\Requests\Blob\BlobSet;
|
||||
use JmapClient\Requests\Mail\MailboxGet;
|
||||
use JmapClient\Requests\Mail\MailboxParameters as MailboxParametersRequest;
|
||||
use JmapClient\Requests\Mail\MailboxQuery;
|
||||
@@ -23,16 +25,17 @@ 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\MailPart;
|
||||
use JmapClient\Responses\Mail\MailParameters as MailParametersResponse;
|
||||
use JmapClient\Responses\ResponseException;
|
||||
use KTXF\Resource\BinaryResource;
|
||||
use KTXF\Resource\Delta\Delta;
|
||||
use KTXF\Resource\Delta\DeltaCollection;
|
||||
use KTXF\Resource\Filter\Filter;
|
||||
use KTXF\Resource\Filter\IFilter;
|
||||
use KTXF\Resource\Range\IRange;
|
||||
use KTXF\Resource\Range\IRangeTally;
|
||||
use KTXF\Resource\Range\Range;
|
||||
use KTXF\Resource\Range\RangeAnchorType;
|
||||
use KTXF\Resource\Range\RangeTally;
|
||||
use KTXF\Resource\Sort\ISort;
|
||||
@@ -493,103 +496,6 @@ class RemoteMailService {
|
||||
return new RangeTally();
|
||||
}
|
||||
|
||||
/**
|
||||
* retrieve entity from remote storage
|
||||
*
|
||||
* @since Release 1.0.0
|
||||
*/
|
||||
public function entityFetch(string ...$identifiers): ?array {
|
||||
// construct request
|
||||
$r0 = new MailGet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
|
||||
$r0->target(...$identifiers);
|
||||
// select properties to return
|
||||
$r0->property(...$this->defaultMailProperties);
|
||||
$r0->bodyAll(true);
|
||||
// transceive
|
||||
$bundle = $this->dataStore->perform([$r0]);
|
||||
// extract response
|
||||
$response = $bundle->response(0);
|
||||
// convert json objects to message objects
|
||||
$list = [];
|
||||
foreach ($response->objects() as $so) {
|
||||
if (!$so instanceof MailParametersResponse) {
|
||||
continue;
|
||||
}
|
||||
$id = $so->id();
|
||||
$list[$id] = $so->parametersRaw();
|
||||
$list[$id]['signature'] = $response->state();
|
||||
}
|
||||
// return message collection
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function entityDownload(string $identifier, string|null $blobId = null): BinaryResource {
|
||||
|
||||
// construct request
|
||||
$r0 = new MailGet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
|
||||
$r0->target($identifier);
|
||||
// select properties to return
|
||||
$r0->property(...['id', 'blobId', 'bodyStructure']);
|
||||
// transceive
|
||||
$bundle = $this->dataStore->perform([$r0]);
|
||||
// extract response
|
||||
$response = $bundle->response(0);
|
||||
|
||||
$parameters = $response->object(0);
|
||||
if (!$parameters instanceof MailParametersResponse) {
|
||||
throw new Exception('Unexpected response type received from server.', 1);
|
||||
}
|
||||
|
||||
if ($blobId === null) {
|
||||
$blobId = $parameters->blob();
|
||||
$filename = 'message.eml';
|
||||
$mimeType = 'text/plain';
|
||||
} else {
|
||||
$walk = function (?MailPart $part) use (&$walk, $blobId): ?MailPart {
|
||||
if ($part === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($part->blob() === $blobId) {
|
||||
return $part;
|
||||
}
|
||||
|
||||
foreach ($part->parts() ?? [] as $subPart) {
|
||||
$subPartResult = $walk($subPart);
|
||||
if ($subPartResult !== null) {
|
||||
return $subPartResult;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
$part = $walk($parameters->bodyPartStructure());
|
||||
$filename = $part->name() ?? 'file.bin';
|
||||
$mimeType = $part->type() ?? 'application/octet-stream';
|
||||
}
|
||||
|
||||
$streamResource = $this->dataStore->downloadStream($this->dataAccount, $blobId, $mimeType, $filename);
|
||||
|
||||
$stream = (function () use ($streamResource): \Generator {
|
||||
try {
|
||||
while (!$streamResource->eof()) {
|
||||
$chunk = $streamResource->read(8192);
|
||||
if ($chunk === '' && !$streamResource->eof()) {
|
||||
throw new Exception('Unable to read from download stream.', 1);
|
||||
}
|
||||
if ($chunk !== '') {
|
||||
yield $chunk;
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
$streamResource->close();
|
||||
}
|
||||
})();
|
||||
|
||||
return new BinaryResource($filename, $mimeType, $stream);
|
||||
}
|
||||
|
||||
/**
|
||||
* check existence of entities in remote storage
|
||||
*
|
||||
@@ -718,8 +624,34 @@ class RemoteMailService {
|
||||
return $delta;
|
||||
}
|
||||
|
||||
public function entityFresh(): MailParametersRequest {
|
||||
return new MailParametersRequest();
|
||||
/**
|
||||
* retrieve entity from remote storage
|
||||
*
|
||||
* @since Release 1.0.0
|
||||
*/
|
||||
public function entityFetch(string ...$identifiers): ?array {
|
||||
// construct request
|
||||
$r0 = new MailGet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
|
||||
$r0->target(...$identifiers);
|
||||
// select properties to return
|
||||
$r0->property(...$this->defaultMailProperties);
|
||||
$r0->bodyAll(true);
|
||||
// transceive
|
||||
$bundle = $this->dataStore->perform([$r0]);
|
||||
// extract response
|
||||
$response = $bundle->response(0);
|
||||
// convert json objects to message objects
|
||||
$list = [];
|
||||
foreach ($response->objects() as $so) {
|
||||
if (!$so instanceof MailParametersResponse) {
|
||||
continue;
|
||||
}
|
||||
$id = $so->id();
|
||||
$list[$id] = $so->parametersRaw();
|
||||
$list[$id]['signature'] = $response->state();
|
||||
}
|
||||
// return message collection
|
||||
return $list;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -792,37 +724,6 @@ class RemoteMailService {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function entityPatch(MailParametersRequest $properties, string ...$identifiers): ?array {
|
||||
// construct request
|
||||
$r0 = new MailSet($this->dataAccount);
|
||||
foreach ($identifiers as $id) {
|
||||
$r0->patch($id, $properties);
|
||||
}
|
||||
// transceive
|
||||
$bundle = $this->dataStore->perform([$r0]);
|
||||
// extract response
|
||||
$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);
|
||||
}
|
||||
}
|
||||
$results = [];
|
||||
// check for success
|
||||
foreach ($response->updateSuccesses() as $id => $data) {
|
||||
$results[$id] = true;
|
||||
}
|
||||
// check for failure
|
||||
foreach ($response->updateFailures() as $id => $data) {
|
||||
$results[$id] = $data['type'] ?? 'unknownError';
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* delete entities from remote storage
|
||||
*
|
||||
@@ -860,6 +761,16 @@ class RemoteMailService {
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* copy entity in remote storage
|
||||
*
|
||||
* @since Release 1.0.0
|
||||
*
|
||||
*/
|
||||
public function entityCopy(string $target, string ...$identifiers): array {
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* move entity in remote storage
|
||||
*
|
||||
@@ -897,16 +808,6 @@ class RemoteMailService {
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* copy entity in remote storage
|
||||
*
|
||||
* @since Release 1.0.0
|
||||
*
|
||||
*/
|
||||
public function entityCopy(string $target, string ...$identifiers): array {
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* send entity
|
||||
*
|
||||
|
||||
1589
package-lock.json
generated
1589
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -28,8 +28,8 @@
|
||||
"@vitest/coverage-v8": "^4.0.18",
|
||||
"@vitest/ui": "^4.0.18",
|
||||
"@vue/tsconfig": "^0.9.0",
|
||||
"typescript": "~6.0.0",
|
||||
"vite": "^8.0.0",
|
||||
"typescript": "~5.8.3",
|
||||
"vite": "^7.1.2",
|
||||
"vue-tsc": "^3.0.5"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user