16 Commits

Author SHA1 Message Date
Sebastian 689d196176 chore(deps): update dependency phpunit/phpunit to v12.5.35
Build Test / test (pull_request) Successful in 50s
JS Unit Tests / test (pull_request) Successful in 1m13s
PHP Integration Tests / Integration Tests (pull_request) Failing after 1m18s
PHP Unit Tests / test (pull_request) Successful in 2m4s
2026-09-10 03:05:04 +00:00
Sebastian c8a632d20f refactor(module): register integrations through runtime contexts
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-08-31 22:55:11 -04:00
Sebastian 320db9f82b fix: move draft to sent and clear draft flag on submission
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-08-25 22:42:16 -04:00
Sebastian 72d72b29c5 feat: implement entityCreate and entityModify
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-08-19 21:49:56 -04:00
Sebastian a7a83f5737 chore: adjust logging folder name
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-08-19 21:24:55 -04:00
Sebastian f901f13953 feat: listen to user life cycle events
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-08-09 22:36:41 -04:00
Sebastian f39dd75ae5 fix: folder deletion while in trash
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-08-07 20:45:29 -04:00
Sebastian b60341f62d fix: message sending
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-07-30 21:03:59 -04:00
Sebastian 4cd249d019 fix: attachment upload on send
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-07-29 21:24:05 -04:00
Sebastian 152a8141d0 fix: logging
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-07-29 21:20:05 -04:00
Sebastian 5aa95fa329 feat: sync sending identities
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-07-28 21:50:37 -04:00
Sebastian f0b0f87ce2 fix: primary address saving
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-07-28 21:02:51 -04:00
Sebastian 75a462ad18 fix: disable auto complete
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-07-28 20:52:53 -04:00
Sebastian 8af08d8936 refactor: migrate to scoped execution contexts
Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
2026-07-27 00:52:29 -04:00
Sebastian edc1aece13 Merge pull request 'fix(deps): update dependency pinia to v4' (#57) from renovate/pinia-4.x into main
Reviewed-on: #57
2026-07-24 14:02:16 +00:00
Sebastian b81070338d fix(deps): update dependency pinia to v4
Build Test / test (pull_request) Successful in 35s
JS Unit Tests / test (pull_request) Successful in 37s
PHP Integration Tests / Integration Tests (pull_request) Successful in 56s
PHP Unit Tests / test (pull_request) Successful in 1m9s
2026-07-24 13:58:43 +00:00
14 changed files with 548 additions and 291 deletions
+1 -1
View File
@@ -31,7 +31,7 @@
"sebastiankrupinski/jmap-client-php": "dev-main" "sebastiankrupinski/jmap-client-php": "dev-main"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^13.0" "phpunit/phpunit": "^12.0"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
Generated
+46 -34
View File
@@ -862,20 +862,20 @@
"packages-dev": [ "packages-dev": [
{ {
"name": "myclabs/deep-copy", "name": "myclabs/deep-copy",
"version": "1.13.4", "version": "1.14.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/myclabs/DeepCopy.git", "url": "https://github.com/myclabs/DeepCopy.git",
"reference": "07d290f0c47959fd5eed98c95ee5602db07e0b6a" "reference": "8680aa248f8e07bc8fb43f56f0f5fc77a0c96aae"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/07d290f0c47959fd5eed98c95ee5602db07e0b6a", "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/8680aa248f8e07bc8fb43f56f0f5fc77a0c96aae",
"reference": "07d290f0c47959fd5eed98c95ee5602db07e0b6a", "reference": "8680aa248f8e07bc8fb43f56f0f5fc77a0c96aae",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": "^7.1 || ^8.0" "php": "^8.0"
}, },
"conflict": { "conflict": {
"doctrine/collections": "<1.6.8", "doctrine/collections": "<1.6.8",
@@ -910,15 +910,15 @@
], ],
"support": { "support": {
"issues": "https://github.com/myclabs/DeepCopy/issues", "issues": "https://github.com/myclabs/DeepCopy/issues",
"source": "https://github.com/myclabs/DeepCopy/tree/1.13.4" "source": "https://github.com/myclabs/DeepCopy/tree/1.14.0"
}, },
"funding": [ "funding": [
{ {
"url": "https://tidelift.com/funding/github/packagist/myclabs/deep-copy", "url": "https://github.com/mnapoli",
"type": "tidelift" "type": "github"
} }
], ],
"time": "2025-08-01T08:46:24+00:00" "time": "2026-08-11T10:17:44+00:00"
}, },
{ {
"name": "nikic/php-parser", "name": "nikic/php-parser",
@@ -1185,23 +1185,23 @@
}, },
{ {
"name": "phpunit/php-file-iterator", "name": "phpunit/php-file-iterator",
"version": "6.0.1", "version": "6.0.2",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sebastianbergmann/php-file-iterator.git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git",
"reference": "3d1cd096ef6bea4bf2762ba586e35dbd317cbfd5" "reference": "a248d1640ab059b075f53a2ef0f9856e864e06b5"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/3d1cd096ef6bea4bf2762ba586e35dbd317cbfd5", "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/a248d1640ab059b075f53a2ef0f9856e864e06b5",
"reference": "3d1cd096ef6bea4bf2762ba586e35dbd317cbfd5", "reference": "a248d1640ab059b075f53a2ef0f9856e864e06b5",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": ">=8.3" "php": ">=8.3"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^12.0" "phpunit/phpunit": "^12.5.33"
}, },
"type": "library", "type": "library",
"extra": { "extra": {
@@ -1234,7 +1234,7 @@
"support": { "support": {
"issues": "https://github.com/sebastianbergmann/php-file-iterator/issues", "issues": "https://github.com/sebastianbergmann/php-file-iterator/issues",
"security": "https://github.com/sebastianbergmann/php-file-iterator/security/policy", "security": "https://github.com/sebastianbergmann/php-file-iterator/security/policy",
"source": "https://github.com/sebastianbergmann/php-file-iterator/tree/6.0.1" "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/6.0.2"
}, },
"funding": [ "funding": [
{ {
@@ -1254,7 +1254,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2026-02-02T14:04:18+00:00" "time": "2026-08-25T14:40:53+00:00"
}, },
{ {
"name": "phpunit/php-invoker", "name": "phpunit/php-invoker",
@@ -1442,16 +1442,16 @@
}, },
{ {
"name": "phpunit/phpunit", "name": "phpunit/phpunit",
"version": "12.5.31", "version": "12.5.35",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sebastianbergmann/phpunit.git", "url": "https://github.com/sebastianbergmann/phpunit.git",
"reference": "0608d157a284f15cc73b99a3327eff06b66a176d" "reference": "345ac22e42cb14cdc7aa8428655d8bb8c82a4aab"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/0608d157a284f15cc73b99a3327eff06b66a176d", "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/345ac22e42cb14cdc7aa8428655d8bb8c82a4aab",
"reference": "0608d157a284f15cc73b99a3327eff06b66a176d", "reference": "345ac22e42cb14cdc7aa8428655d8bb8c82a4aab",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@@ -1461,18 +1461,18 @@
"ext-libxml": "*", "ext-libxml": "*",
"ext-mbstring": "*", "ext-mbstring": "*",
"ext-xmlwriter": "*", "ext-xmlwriter": "*",
"myclabs/deep-copy": "^1.13.4", "myclabs/deep-copy": "^1.14.0",
"phar-io/manifest": "^2.0.4", "phar-io/manifest": "^2.0.4",
"phar-io/version": "^3.2.1", "phar-io/version": "^3.2.1",
"php": ">=8.3", "php": ">=8.3",
"phpunit/php-code-coverage": "^12.5.7", "phpunit/php-code-coverage": "^12.5.7",
"phpunit/php-file-iterator": "^6.0.1", "phpunit/php-file-iterator": "^6.0.2",
"phpunit/php-invoker": "^6.0.0", "phpunit/php-invoker": "^6.0.0",
"phpunit/php-text-template": "^5.0.0", "phpunit/php-text-template": "^5.0.0",
"phpunit/php-timer": "^8.0.0", "phpunit/php-timer": "^8.0.0",
"sebastian/cli-parser": "^4.2.1", "sebastian/cli-parser": "^4.2.1",
"sebastian/comparator": "^7.1.8", "sebastian/comparator": "^7.1.8",
"sebastian/diff": "^7.0.0", "sebastian/diff": "^7.0.1",
"sebastian/environment": "^8.1.2", "sebastian/environment": "^8.1.2",
"sebastian/exporter": "^7.0.3", "sebastian/exporter": "^7.0.3",
"sebastian/global-state": "^8.0.3", "sebastian/global-state": "^8.0.3",
@@ -1520,7 +1520,7 @@
"support": { "support": {
"issues": "https://github.com/sebastianbergmann/phpunit/issues", "issues": "https://github.com/sebastianbergmann/phpunit/issues",
"security": "https://github.com/sebastianbergmann/phpunit/security/policy", "security": "https://github.com/sebastianbergmann/phpunit/security/policy",
"source": "https://github.com/sebastianbergmann/phpunit/tree/12.5.31" "source": "https://github.com/sebastianbergmann/phpunit/tree/12.5.35"
}, },
"funding": [ "funding": [
{ {
@@ -1528,7 +1528,7 @@
"type": "other" "type": "other"
} }
], ],
"time": "2026-07-06T14:54:16+00:00" "time": "2026-09-09T04:48:50+00:00"
}, },
{ {
"name": "sebastian/cli-parser", "name": "sebastian/cli-parser",
@@ -1751,24 +1751,24 @@
}, },
{ {
"name": "sebastian/diff", "name": "sebastian/diff",
"version": "7.0.0", "version": "7.0.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/sebastianbergmann/diff.git", "url": "https://github.com/sebastianbergmann/diff.git",
"reference": "7ab1ea946c012266ca32390913653d844ecd085f" "reference": "cd4cabe39f8a4e8ee6818ba99f10a05561ea4ad6"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/7ab1ea946c012266ca32390913653d844ecd085f", "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/cd4cabe39f8a4e8ee6818ba99f10a05561ea4ad6",
"reference": "7ab1ea946c012266ca32390913653d844ecd085f", "reference": "cd4cabe39f8a4e8ee6818ba99f10a05561ea4ad6",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": ">=8.3" "php": ">=8.3"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^12.0", "phpunit/phpunit": "^12.5.33",
"symfony/process": "^7.2" "symfony/process": "^7.4.17"
}, },
"type": "library", "type": "library",
"extra": { "extra": {
@@ -1806,15 +1806,27 @@
"support": { "support": {
"issues": "https://github.com/sebastianbergmann/diff/issues", "issues": "https://github.com/sebastianbergmann/diff/issues",
"security": "https://github.com/sebastianbergmann/diff/security/policy", "security": "https://github.com/sebastianbergmann/diff/security/policy",
"source": "https://github.com/sebastianbergmann/diff/tree/7.0.0" "source": "https://github.com/sebastianbergmann/diff/tree/7.0.1"
}, },
"funding": [ "funding": [
{ {
"url": "https://github.com/sebastianbergmann", "url": "https://github.com/sebastianbergmann",
"type": "github" "type": "github"
},
{
"url": "https://liberapay.com/sebastianbergmann",
"type": "liberapay"
},
{
"url": "https://thanks.dev/u/gh/sebastianbergmann",
"type": "thanks_dev"
},
{
"url": "https://tidelift.com/funding/github/packagist/sebastian/diff",
"type": "tidelift"
} }
], ],
"time": "2025-02-07T04:55:46+00:00" "time": "2026-08-25T15:35:54+00:00"
}, },
{ {
"name": "sebastian/environment", "name": "sebastian/environment",
@@ -2556,5 +2568,5 @@
"platform-overrides": { "platform-overrides": {
"php": "8.3" "php": "8.3"
}, },
"plugin-api-version": "2.6.0" "plugin-api-version": "2.9.0"
} }
+27
View File
@@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
namespace KTXM\ProviderJmapc\Listeners;
use KTXC\User\Event\UserCreatedEvent;
use KTXC\User\Event\UserDeletingEvent;
use KTXM\ProviderJmapc\Stores\ServiceStore;
final class UserEventListener
{
public function __construct(
private readonly ServiceStore $serviceStore,
) {
}
public function onUserCreated(UserCreatedEvent $event): void
{
// TODO: implement provisioning configuration
}
public function onUserDeleting(UserDeletingEvent $event): void
{
$this->serviceStore->deleteByUser($event->tenantIdentifier(), $event->userIdentifier());
}
}
+17 -12
View File
@@ -10,9 +10,15 @@ declare(strict_types=1);
namespace KTXM\ProviderJmapc; namespace KTXM\ProviderJmapc;
use KTXC\Resource\ProviderManager; use KTXC\Resource\ProviderManager;
use KTXF\Module\ModuleBrowserInterface; use KTXC\User\Event\UserCreatedEvent;
use KTXC\User\Event\UserDeletingEvent;
use KTXF\Event\DeliveryMode;
use KTXF\Event\EventListenerRegistrarInterface;
use KTXF\Module\Configuration\BrowserModuleContextInterface;
use KTXF\Module\Configuration\ModuleContextInterface;
use KTXF\Module\ModuleInstanceAbstract; use KTXF\Module\ModuleInstanceAbstract;
use KTXF\Resource\Provider\ProviderInterface; use KTXF\Resource\Provider\ProviderInterface;
use KTXM\ProviderJmapc\Listeners\UserEventListener;
use KTXM\ProviderJmapc\Providers\Mail\Provider as MailProvider; use KTXM\ProviderJmapc\Providers\Mail\Provider as MailProvider;
use KTXM\ProviderJmapc\Providers\Chrono\Provider as ChronoProvider; use KTXM\ProviderJmapc\Providers\Chrono\Provider as ChronoProvider;
use KTXM\ProviderJmapc\Providers\People\Provider as PeopleProvider; use KTXM\ProviderJmapc\Providers\People\Provider as PeopleProvider;
@@ -23,10 +29,11 @@ use KTXM\ProviderJmapc\Providers\Document\Provider as DocumentProvider;
* *
* Provides mail, calendar, and contacts services via JMAP protocol. * Provides mail, calendar, and contacts services via JMAP protocol.
*/ */
class Module extends ModuleInstanceAbstract implements ModuleBrowserInterface class Module extends ModuleInstanceAbstract
{ {
public function __construct( public function __construct(
private readonly ProviderManager $providerManager, private readonly ProviderManager $providerManager,
private readonly EventListenerRegistrarInterface $events,
) {} ) {}
public function handle(): string public function handle(): string
@@ -67,6 +74,9 @@ class Module extends ModuleInstanceAbstract implements ModuleBrowserInterface
public function boot(): void public function boot(): void
{ {
// Register listeners
$this->events->listen($this->handle(), UserCreatedEvent::class, UserEventListener::class, 'onUserCreated', DeliveryMode::Deferred);
$this->events->listen($this->handle(), UserDeletingEvent::class, UserEventListener::class, 'onUserDeleting', DeliveryMode::Deferred);
// Register JMAP providers - all three share the same service store // Register JMAP providers - all three share the same service store
$this->providerManager->register(ProviderInterface::TYPE_MAIL, 'jmap', MailProvider::class); $this->providerManager->register(ProviderInterface::TYPE_MAIL, 'jmap', MailProvider::class);
//$this->providerManager->register(ProviderInterface::TYPE_CHRONO, 'jmap', ChronoProvider::class); //$this->providerManager->register(ProviderInterface::TYPE_CHRONO, 'jmap', ChronoProvider::class);
@@ -74,15 +84,10 @@ class Module extends ModuleInstanceAbstract implements ModuleBrowserInterface
$this->providerManager->register(ProviderInterface::TYPE_DOCUMENT, 'jmap', DocumentProvider::class); $this->providerManager->register(ProviderInterface::TYPE_DOCUMENT, 'jmap', DocumentProvider::class);
} }
public function registerBI(): array { public function configure(ModuleContextInterface $context): void
return [ {
'handle' => $this->handle(), if ($context instanceof BrowserModuleContextInterface) {
'namespace' => 'ProviderJmapc', $context->registerModule($this, 'ProviderJmapc', 'static/module.mjs');
'version' => $this->version(), }
'label' => $this->label(),
'author' => $this->author(),
'description' => $this->description(),
'boot' => 'static/module.mjs',
];
} }
} }
+59
View File
@@ -9,6 +9,7 @@ declare(strict_types=1);
namespace KTXM\ProviderJmapc\Providers\Mail; namespace KTXM\ProviderJmapc\Providers\Mail;
use KTXF\Mail\Object\Address;
use KTXF\Mail\Provider\ProviderBaseInterface; use KTXF\Mail\Provider\ProviderBaseInterface;
use KTXF\Mail\Provider\ProviderServiceDiscoverInterface; use KTXF\Mail\Provider\ProviderServiceDiscoverInterface;
use KTXF\Mail\Provider\ProviderServiceMutateInterface; use KTXF\Mail\Provider\ProviderServiceMutateInterface;
@@ -142,9 +143,66 @@ class Provider implements ProviderBaseInterface, ProviderServiceMutateInterface,
} }
$created = $this->serviceStore->create($tenantId, $userId, $service); $created = $this->serviceStore->create($tenantId, $userId, $service);
$this->serviceIdentitiesSync($tenantId, $userId, (new Service())->fromStore($created));
return (string) $created['sid']; return (string) $created['sid'];
} }
/**
* Fetches sending identities from the JMAP server and overwrites
* primaryAddress/secondaryAddresses on the service with them.
*/
private function serviceIdentitiesSync(string $tenantId, string $userId, Service $service): void
{
try {
$client = RemoteService::freshClient($service);
$identities = RemoteService::mailService($client)->identityFetch();
// A JMAP server may expose multiple identities sharing the same
// address (e.g. distinct signatures/display names for one
// mailbox) — collapse those down to one entry per address,
// keeping the first label seen.
$addresses = [];
foreach ($identities as $identity) {
if ($identity->address() === null) {
continue;
}
$key = strtolower($identity->address());
if (!isset($addresses[$key])) {
$addresses[$key] = Address::fromArray(['address' => $identity->address(), 'label' => $identity->name()]);
}
}
$addresses = array_values($addresses);
if (empty($addresses)) {
return;
}
$currentAddress = strtolower($service->getPrimaryAddress()->getAddress());
$primaryIndex = 0;
foreach ($addresses as $index => $address) {
if (strtolower($address->getAddress()) === $currentAddress) {
$primaryIndex = $index;
break;
}
}
$secondary = [];
foreach ($addresses as $index => $address) {
if ($index !== $primaryIndex) {
$secondary[] = $address;
}
}
$service->setPrimaryAddress($addresses[$primaryIndex]);
$service->setSecondaryAddresses($secondary);
$this->serviceStore->modify($tenantId, $userId, $service);
} catch (\Throwable) {
// Server may not support urn:ietf:params:jmap:submission, or have
// no identities configured — fall back to what the user entered.
}
}
public function serviceModify(string $tenantId, string $userId, ResourceServiceMutateInterface $service): string public function serviceModify(string $tenantId, string $userId, ResourceServiceMutateInterface $service): string
{ {
if (!($service instanceof Service)) { if (!($service instanceof Service)) {
@@ -152,6 +210,7 @@ class Provider implements ProviderBaseInterface, ProviderServiceMutateInterface,
} }
$this->serviceStore->modify($tenantId, $userId, $service); $this->serviceStore->modify($tenantId, $userId, $service);
$this->serviceIdentitiesSync($tenantId, $userId, $service);
return (string) $service->identifier(); return (string) $service->identifier();
} }
+142 -30
View File
@@ -102,8 +102,8 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
], ],
self::CAPABILITY_ENTITY_FETCH => true, self::CAPABILITY_ENTITY_FETCH => true,
self::CAPABILITY_ENTITY_EXTANT => true, self::CAPABILITY_ENTITY_EXTANT => true,
self::CAPABILITY_ENTITY_CREATE => false, self::CAPABILITY_ENTITY_CREATE => true,
self::CAPABILITY_ENTITY_MODIFY => false, self::CAPABILITY_ENTITY_MODIFY => true,
self::CAPABILITY_ENTITY_PATCH => true, 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,
@@ -206,8 +206,9 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
if (isset($data[self::PROPERTY_IDENTITY])) { if (isset($data[self::PROPERTY_IDENTITY])) {
$this->setIdentity($this->freshIdentity(null, $data[self::PROPERTY_IDENTITY])); $this->setIdentity($this->freshIdentity(null, $data[self::PROPERTY_IDENTITY]));
} }
if (isset($data[self::PROPERTY_PRIMARY_ADDRESS]) && is_string($data[self::PROPERTY_PRIMARY_ADDRESS])) { if (isset($data[self::PROPERTY_PRIMARY_ADDRESS])) {
$this->setPrimaryAddress(new Address($data[self::PROPERTY_PRIMARY_ADDRESS])); $value = $data[self::PROPERTY_PRIMARY_ADDRESS];
$this->setPrimaryAddress(is_array($value) ? Address::fromArray($value) : new Address((string)$value));
} }
if (isset($data[self::PROPERTY_SECONDARY_ADDRESSES]) && is_array($data[self::PROPERTY_SECONDARY_ADDRESSES])) { if (isset($data[self::PROPERTY_SECONDARY_ADDRESSES]) && is_array($data[self::PROPERTY_SECONDARY_ADDRESSES])) {
$this->setSecondaryAddresses(array_map( $this->setSecondaryAddresses(array_map(
@@ -483,17 +484,34 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
} }
} }
// we need to determine if the folder being deleted is already in the trash if ($deleteMode === 'soft') {
if (str_starts_with((string) $target->collection(), (string) $deleteTargetIdentifier?->collection())) { $targetMailbox = $this->mailService->collectionFetch((string) $target->collection());
// if so, we should hard delete instead of moving to avoid duplicates in the trash if ($targetMailbox === null) {
$deleteMode = 'hard'; throw new \RuntimeException('Collection not found for delete operation');
}
$targetIdentifier = (string) $target->collection();
$trashIdentifier = (string) $deleteTargetIdentifier->collection();
$parentIdentifier = isset($targetMailbox['parentId'])
? (string) $targetMailbox['parentId']
: null;
// JMAP mailbox IDs are opaque, so containment must be determined
// from parentId rather than by comparing ID prefixes.
if ($targetIdentifier === $trashIdentifier || $parentIdentifier === $trashIdentifier) {
$deleteMode = 'hard';
}
} }
$result = match ($deleteMode) { if ($deleteMode === 'soft') {
'soft' => $this->collectionMove($deleteTargetIdentifier, $target), return $this->collectionMove($deleteTargetIdentifier, $target);
'hard' => $this->mailService->collectionDestroy($target->collection(), $force), }
};
return $result; if ($this->mailService->collectionDestroy((string) $target->collection(), $force) === null) {
throw new \RuntimeException("Failed to delete collection: {$target->collection()}");
}
return true;
} }
public function collectionMove(CollectionIdentifier $target, CollectionIdentifier $source): CollectionBaseInterface public function collectionMove(CollectionIdentifier $target, CollectionIdentifier $source): CollectionBaseInterface
@@ -620,14 +638,42 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
public function entityCreate(CollectionIdentifier $target, MessagePropertiesMutableInterface $properties, array $options = []): EntityResource public function entityCreate(CollectionIdentifier $target, MessagePropertiesMutableInterface $properties, array $options = []): EntityResource
{ {
// TODO: Implement entity create if ($target->provider() !== $this->provider() || (string)$target->service() !== (string)$this->identifier()) {
return $this->entityFresh(); throw new \InvalidArgumentException('Target collection does not belong to this service: ' . (string)$target);
}
$this->initialize();
[$nativeMessage, $nativeAttachments] = $this->messagePayload($properties);
$created = $this->mailService->entityCreate((string)$target->collection(), $nativeMessage, $nativeAttachments);
if ($created === null || !isset($created['id'])) {
throw new \RuntimeException('JMAP entity creation did not return an identifier');
}
$created['mailboxIds'] ??= [(string)$target->collection() => true];
return $this->entityFresh()->fromJmap($created);
} }
public function entityModify(EntityIdentifier $identifier, MessagePropertiesMutableInterface $properties): EntityResource public function entityModify(EntityIdentifier $target, MessagePropertiesMutableInterface $properties): EntityResource
{ {
// TODO: Implement entity modify if ($target->provider() !== $this->provider() || (string)$target->service() !== (string)$this->identifier()) {
return $this->entityFresh(); throw new \InvalidArgumentException('Target collection does not belong to this service: ' . (string)$target);
}
$this->initialize();
[$nativeMessage, $nativeAttachments] = $this->messagePayload($properties);
$nativeMessage['id'] = (string)$target->entity();
$nativeMessage['mailboxIds'] = [(string)$target->collection() => true];
// JMAP replaces immutable Email content and returns the new authoritative ID.
$modified = $this->mailService->entityReplace($nativeMessage, $nativeAttachments);
if ($modified === null) {
throw new \RuntimeException('JMAP entity modification failed');
}
return $this->entityFresh()->fromJmap($modified);
} }
public function entityPatch(MessagePropertiesMutableInterface $properties, EntityIdentifier ...$targets): array public function entityPatch(MessagePropertiesMutableInterface $properties, EntityIdentifier ...$targets): array
@@ -879,8 +925,14 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
); );
} }
$nativeMessage = $this->normalizeMessageProperties($message)->toJmap(); [$nativeMessage, $nativeAttachments] = $this->messagePayload($message);
$transportId = $this->mailService->entitySubmitFresh($identityId, $nativeMessage, $preSendTarget->collection(), $postSentTarget->collection()); $transportId = $this->mailService->entitySubmitFresh(
$identityId,
$nativeMessage,
$preSendTarget->collection(),
$postSentTarget->collection(),
$nativeAttachments,
);
return new EntitySubmitResult( return new EntitySubmitResult(
EntitySubmitResult::DISPOSITION_SENT, EntitySubmitResult::DISPOSITION_SENT,
@@ -898,12 +950,38 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
); );
} }
$patch = null; // determine the sent folder
if ($message !== null) { // if no explicit sent folder is configured, we will attempt to find a folder with the "sent" role.
$patch = $this->normalizeMessageProperties($message)->toJmap(); $postSentTarget = $this->auxiliary['sentTarget'] ?? null;
$postSentTarget = $postSentTarget !== null && (string) $postSentTarget !== ''
? new CollectionIdentifier($this->provider(), (string) $this->identifier(), (string) $postSentTarget)
: $this->resolveCollectionByRole(CollectionRoles::Sent->value);
if ($postSentTarget === null
|| $postSentTarget->provider() !== $this->provider()
|| $postSentTarget->service() !== (string)$this->identifier()) {
return new EntitySubmitResult(
EntitySubmitResult::DISPOSITION_ERROR,
errorCode: 'sent_collection_not_found',
errorMessage: 'No Sent target collection is configured or could be resolved for this service',
);
} }
$transportId = $this->mailService->entitySubmitDraft($identityId, (string)$source->entity(), $patch); if ($message !== null) {
[$nativeMessage, $nativeAttachments] = $this->messagePayload($message);
} else {
$nativeMessage = null;
$nativeAttachments = [];
}
$transportId = $this->mailService->entitySubmitDraft(
$identityId,
(string)$source->entity(),
(string)$source->collection(),
$postSentTarget->collection(),
$nativeMessage,
$nativeAttachments,
);
return new EntitySubmitResult( return new EntitySubmitResult(
EntitySubmitResult::DISPOSITION_SENT, EntitySubmitResult::DISPOSITION_SENT,
@@ -912,16 +990,50 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
); );
} }
private function normalizeMessageProperties(MessagePropertiesMutableInterface $message): MessageProperties /**
* Convert message properties and describe attachment blobs for the remote
* service. Uploading and request batching remain remote-layer concerns.
*
* @return array{0: array, 1: array<string, array{type: string, content: string}>}
*/
private function messagePayload(MessagePropertiesMutableInterface $message): array
{ {
if ($message instanceof MessageProperties) { if ($message instanceof MessageProperties === false) {
return $message; $native = new MessageProperties([]);
$native->jsonDeserialize($message->jsonSerialize());
} else {
$native = $message;
} }
$native = new MessageProperties([]); $attachments = $native->getAttachments();
$native->jsonDeserialize($message->jsonSerialize()); $uploads = [];
return $native; foreach ($attachments as $attachment) {
if ($attachment->getBlobId() !== null) {
continue;
}
$content = $attachment->getContent();
if ($content === null) {
throw new \InvalidArgumentException(sprintf(
'Attachment "%s" has neither content nor a JMAP blob identifier',
$attachment->getName() ?? 'unnamed',
));
}
$creationId = 'attachment_' . count($uploads);
$attachment->setBlobId('#' . $creationId);
$uploads[$creationId] = [
'type' => $attachment->getType() ?? 'application/octet-stream',
'content' => $content,
];
}
if ($attachments !== []) {
$native->setAttachments(...$attachments);
}
return [$native->toJmap(), $uploads];
} }
private function resolveCollectionByRole(string $role): ?CollectionIdentifier private function resolveCollectionByRole(string $role): ?CollectionIdentifier
+1 -1
View File
@@ -97,7 +97,7 @@ class Provider implements IProviderBase, IProviderServiceMutate
} }
// Note: This simplified interface doesn't pass tenantId // Note: This simplified interface doesn't pass tenantId
// Will need to get it from SessionTenant in actual implementation // Will need to get it from TenantContextInterface in actual implementation
throw new \RuntimeException('Use Mail Provider interface for service creation'); throw new \RuntimeException('Use Mail Provider interface for service creation');
} }
+207 -54
View File
@@ -11,6 +11,7 @@ namespace KTXM\ProviderJmapc\Service\Remote;
use Exception; use Exception;
use JmapClient\Client; use JmapClient\Client;
use JmapClient\Requests\Blob\BlobSet;
use JmapClient\Requests\Mail\MailboxGet; use JmapClient\Requests\Mail\MailboxGet;
use JmapClient\Requests\Mail\MailboxParameters as MailboxParametersRequest; use JmapClient\Requests\Mail\MailboxParameters as MailboxParametersRequest;
use JmapClient\Requests\Mail\MailboxQuery; use JmapClient\Requests\Mail\MailboxQuery;
@@ -727,7 +728,8 @@ class RemoteMailService {
* *
* @since Release 1.0.0 * @since Release 1.0.0
*/ */
public function entityCreate(string $location, array $so): ?array { public function entityCreate(string $location, array $so, array $attachments = []): ?array {
$blobRequest = $this->prepareAttachmentRequest($so, $attachments);
// convert entity // convert entity
$to = new MailParametersRequest(); $to = new MailParametersRequest();
$to->parametersRaw($so); $to->parametersRaw($so);
@@ -737,9 +739,11 @@ class RemoteMailService {
$r0 = new MailSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel); $r0 = new MailSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
$r0->create($id, $to); $r0->create($id, $to);
// transceive // transceive
$bundle = $this->dataStore->perform([$r0]); $requests = $blobRequest !== null ? [$blobRequest, $r0] : [$r0];
$bundle = $this->dataStore->perform($requests);
$this->assertAttachmentUploads($bundle, $blobRequest, $attachments, $so);
// extract response // extract response
$response = $bundle->response(0); $response = $bundle->response($blobRequest !== null ? 1 : 0);
// check for command error // check for command error
if ($response instanceof ResponseException) { if ($response instanceof ResponseException) {
if ($response->type() === 'unknownMethod') { if ($response->type() === 'unknownMethod') {
@@ -769,27 +773,64 @@ class RemoteMailService {
* *
* @since Release 1.0.0 * @since Release 1.0.0
*/ */
public function entityModify(array $so): ?array { public function entityReplace(array $so, array $attachments = []): ?array {
// extract entity id // JMAP Email content is immutable after creation. Replacing a draft must
$id = $so['id']; // therefore create a new Email and remove the superseded Email together.
// convert entity $id = (string)($so['id'] ?? '');
$to = new MailParametersRequest(); unset($so['id']);
$to->parametersRaw($so); if ($id === '') {
// construct request throw new Exception('Draft identifier is required for replacement', 1);
$r0 = new MailSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
$r0->update($id, $to);
// transceive
$bundle = $this->dataStore->perform([$r0]);
// extract response
$response = $bundle->response(0);
// determine if command succeeded
if (array_key_exists($id, $response->updated())) {
// update entity
$ro = $response->updated()[$id];
$so = array_merge($so, $ro);
return $so;
} }
return null;
$location = null;
foreach (($so['mailboxIds'] ?? []) as $mailboxId => $included) {
if ($included === true) {
$location = (string)$mailboxId;
break;
}
}
if ($location === null || $location === '') {
throw new Exception('Draft mailbox is required for replacement', 1);
}
$blobRequest = $this->prepareAttachmentRequest($so, $attachments);
$replacement = new MailParametersRequest();
$replacement->parametersRaw($so);
$replacement->in($location);
$creationId = uniqid();
// Email/set supports create and destroy in one method call. When attachment
// content is present, Blob/upload is included in the same HTTP request.
$request = new MailSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
$request->create($creationId, $replacement);
$request->delete($id);
$requests = $blobRequest !== null ? [$blobRequest, $request] : [$request];
$bundle = $this->dataStore->perform($requests);
$this->assertAttachmentUploads($bundle, $blobRequest, $attachments, $so);
$response = $bundle->response($blobRequest !== null ? 1 : 0);
if ($response instanceof ResponseException) {
if ($response->type() === 'unknownMethod') {
throw new JmapUnknownMethod($response->description(), 1);
}
throw new Exception($response->type() . ': ' . $response->description(), 1);
}
$created = $response->createSuccess($creationId);
if ($created === null) {
$failure = $response->createFailure($creationId);
$type = $failure['type'] ?? 'unknownError';
$description = $failure['description'] ?? 'JMAP draft replacement failed.';
throw new Exception("$type: $description", 1);
}
if ($response->deleteSuccess($id) === null) {
$failure = $response->deleteFailure($id);
$type = $failure['type'] ?? 'unknownError';
$description = $failure['description'] ?? 'The superseded JMAP draft could not be deleted.';
throw new Exception("$type: $description", 1);
}
return array_merge($so, $created);
} }
public function entityPatch(MailParametersRequest $properties, string ...$identifiers): ?array { public function entityPatch(MailParametersRequest $properties, string ...$identifiers): ?array {
@@ -912,24 +953,49 @@ class RemoteMailService {
* *
* @since Release 2.0.0 * @since Release 2.0.0
*/ */
public function entitySubmitFresh(string $identityId, array $message, string $preSendTarget, string $postSentTarget): string { public function entitySubmitFresh(string $identityId, array $data, string $preSendTarget, string $postSentTarget, array $attachments = []): string {
$blobRequest = $this->prepareAttachmentRequest($data, $attachments);
$mail = new MailParametersRequest(); $message = new MailParametersRequest();
$mail->parametersRaw($message); $message->parametersRaw($data);
$messageCreateId = 'm_' . uniqid(); $messageId = 'm_' . uniqid();
$submissionCreateId = 's_' . uniqid(); $submissionId = 's_' . uniqid();
$r0 = new MailSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel); $r0 = new MailSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
$createdMessage = $r0->create($messageCreateId, $mail); $m0 = $r0->create($messageId, $message);
$createdMessage->in($preSendTarget); $m0->in($preSendTarget);
$r1 = new MailSubmissionSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel); $m0->draft(true);
$submission = $r1->create($submissionCreateId); $m0->seen(true);
$submission->identity($identityId);
$submission->message('#' . $messageCreateId);
$bundle = $this->dataStore->perform([$r0, $r1]); $r1 = new MailSubmissionSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
$response = $bundle->response(1); $r1->completionUpdate('#' . $messageId, [
'mailboxIds/' . $postSentTarget => true,
'mailboxIds/' . $preSendTarget => null,
'keywords/$draft' => null,
]);
$s0 = $r1->create($submissionId);
$s0->identity($identityId);
$s0->message('#' . $messageId);
$requests = $blobRequest !== null ? [$blobRequest, $r0, $r1] : [$r0, $r1];
$bundle = $this->dataStore->perform($requests);
$this->assertAttachmentUploads($bundle, $blobRequest, $attachments, $data);
$responseOffset = $blobRequest !== null ? 1 : 0;
$messageResponse = $bundle->response($responseOffset);
if ($messageResponse instanceof ResponseException) {
throw new Exception($messageResponse->type() . ': ' . $messageResponse->description(), 1);
}
if (method_exists($messageResponse, 'createFailure')) {
$failure = $messageResponse->createFailure($messageId);
if (is_array($failure)) {
$type = $failure['type'] ?? 'unknownError';
$description = $failure['description'] ?? 'Email creation failed';
throw new Exception($type . ': ' . $description, 1);
}
}
$response = $bundle->response($responseOffset + 1);
if ($response instanceof ResponseException) { if ($response instanceof ResponseException) {
if ($response->type() === 'unknownMethod') { if ($response->type() === 'unknownMethod') {
throw new JmapUnknownMethod($response->description(), 1); throw new JmapUnknownMethod($response->description(), 1);
@@ -937,37 +1003,49 @@ class RemoteMailService {
throw new Exception($response->type() . ': ' . $response->description(), 1); throw new Exception($response->type() . ': ' . $response->description(), 1);
} }
return $this->extractSubmissionIdentifier($response, $submissionCreateId); return $this->extractSubmissionIdentifier($response, $submissionId);
} }
/** /**
* Submit an existing draft message. * Submit an existing draft message. On success, the draft Email is moved
* from the drafts mailbox to the sent mailbox and its \Draft keyword is
* cleared in the same request, so the submitted draft becomes the sent
* copy rather than lingering as an unsent draft.
* *
* @since Release 2.0.0 * @since Release 2.0.0
*/ */
public function entitySubmitDraft(string $identityId, string $draftId, ?array $patch = null): string { public function entitySubmitDraft(string $identityId, string $draftId, string $preSendTarget, string $postSentTarget, ?array $patch = null, array $attachments = []): string {
if ($draftId === '') { if ($draftId === '') {
throw new Exception('Draft identifier is required for draft submission', 1); throw new Exception('Draft identifier is required for draft submission', 1);
} }
$requests = []; $blobRequest = $patch !== null ? $this->prepareAttachmentRequest($patch, $attachments) : null;
$requests = $blobRequest !== null ? [$blobRequest] : [];
if ($patch !== null && $patch !== []) { if ($patch !== null && $patch !== []) {
$draftMutation = new MailParametersRequest(); $m0 = new MailParametersRequest();
$draftMutation->parametersRaw($patch); $m0->parametersRaw($patch);
$r0 = new MailSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel); $r0 = new MailSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
$r0->update($draftId, $draftMutation); $r0->update($draftId, $m0);
$requests[] = $r0; $requests[] = $r0;
} }
$submissionCreateId = 's_' . uniqid(); $submissionId = 's_' . uniqid();
$r1 = new MailSubmissionSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel); $r1 = new MailSubmissionSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
$submission = $r1->create($submissionCreateId); $r1->completionUpdate($draftId, [
$submission->identity($identityId); 'mailboxIds/' . $postSentTarget => true,
$submission->message($draftId); 'mailboxIds/' . $preSendTarget => null,
'keywords/$draft' => null,
]);
$s0 = $r1->create($submissionId);
$s0->identity($identityId);
$s0->message($draftId);
$requests[] = $r1; $requests[] = $r1;
$bundle = $this->dataStore->perform($requests); $bundle = $this->dataStore->perform($requests);
if ($patch !== null) {
$this->assertAttachmentUploads($bundle, $blobRequest, $attachments, $patch);
}
$responseIndex = count($requests) - 1; $responseIndex = count($requests) - 1;
$response = $bundle->response($responseIndex); $response = $bundle->response($responseIndex);
if ($response instanceof ResponseException) { if ($response instanceof ResponseException) {
@@ -977,19 +1055,94 @@ class RemoteMailService {
throw new Exception($response->type() . ': ' . $response->description(), 1); throw new Exception($response->type() . ': ' . $response->description(), 1);
} }
return $this->extractSubmissionIdentifier($response, $submissionCreateId); return $this->extractSubmissionIdentifier($response, $submissionId);
} }
private function collectionByRole(string $role): ?string { /**
$filter = $this->collectionListFilter(); * Upload attachment content and return its JMAP blob identifier.
$filter->condition('role', $role); */
public function blobDeposit(string $type, string $data): string {
$response = json_decode($this->dataStore->upload($this->dataAccount, $type, $data), true);
if (!is_array($response) || !isset($response['blobId']) || !is_string($response['blobId']) || $response['blobId'] === '') {
throw new Exception('JMAP attachment upload did not return a blob identifier', 1);
}
$collections = $this->collectionList(null, $filter, null); return $response['blobId'];
if ($collections === []) { }
/**
* Build one Blob/upload method call for all new attachment content. Servers
* without the Blob capability fall back to the standard upload endpoint.
*
* @param array<string, array{type: string, content: string}> $attachments
*/
private function prepareAttachmentRequest(array &$data, array $attachments): ?BlobSet {
if ($attachments === []) {
return null; return null;
} }
return (string)array_key_first($collections); if (!$this->dataStore->sessionCapable('blob')) {
foreach ($attachments as $creationId => $attachment) {
$blobId = $this->blobDeposit($attachment['type'], $attachment['content']);
$this->replaceBlobReference($data, '#' . $creationId, $blobId);
}
return null;
}
$request = new BlobSet($this->dataAccount);
foreach ($attachments as $creationId => $attachment) {
$request->create($creationId)
->type($attachment['type'])
->dataEncoded(base64_encode($attachment['content']));
}
return $request;
}
/**
* Validate a batched Blob/upload response and replace creation references
* in the returned local representation with actual server blob IDs.
*
* @param array<string, array{type: string, content: string}> $attachments
*/
private function assertAttachmentUploads(object $bundle, ?BlobSet $request, array $attachments, array &$data): void {
if ($request === null) {
return;
}
$response = $bundle->response(0);
if ($response instanceof ResponseException) {
throw new Exception('Attachment upload failed: ' . $response->type() . ': ' . $response->description(), 1);
}
foreach (array_keys($attachments) as $creationId) {
$failure = $response->createFailure($creationId);
if ($failure !== null) {
$type = $failure['type'] ?? 'unknownError';
$description = $failure['description'] ?? 'Attachment upload failed.';
throw new Exception("$type: $description", 1);
}
$success = $response->createSuccess($creationId);
$blobId = is_array($success) ? ($success['id'] ?? null) : null;
if (!is_string($blobId) || $blobId === '') {
throw new Exception('Attachment upload did not return a blob identifier', 1);
}
$this->replaceBlobReference($data, '#' . $creationId, $blobId);
}
}
private function replaceBlobReference(array &$data, string $reference, string $blobId): void {
foreach ($data as &$value) {
if (is_array($value)) {
$this->replaceBlobReference($value, $reference, $blobId);
continue;
}
if ($value === $reference) {
$value = $blobId;
}
}
unset($value);
} }
private function extractSubmissionIdentifier(object $response, string $createId): string { private function extractSubmissionIdentifier(object $response, string $createId): string {
+9 -8
View File
@@ -13,7 +13,7 @@ use GuzzleHttp\Client as HttpClient;
use GuzzleHttp\Psr7\HttpFactory; use GuzzleHttp\Psr7\HttpFactory;
use JmapClient\Authentication\Basic; use JmapClient\Authentication\Basic;
use JmapClient\Client as JmapClient; use JmapClient\Client as JmapClient;
use KTXC\Server; use KTXF\Security\Crypto;
use KTXF\Resource\Provider\ResourceServiceIdentityBasic; use KTXF\Resource\Provider\ResourceServiceIdentityBasic;
use KTXF\Resource\Provider\ResourceServiceLocationUri; use KTXF\Resource\Provider\ResourceServiceLocationUri;
use KTXM\ProviderJmapc\Providers\Mail\Service as MailService; use KTXM\ProviderJmapc\Providers\Mail\Service as MailService;
@@ -73,10 +73,13 @@ class RemoteService {
} }
// debugging // debugging
if ($service->getDebug()) { if ($service->getDebug()) {
$logDir = Server::getInstance()?->logDir(); $logDirectory = dirname(__DIR__, 5) . '/var/logs/provider_jmap';
$logDir .= '/jmap/' . $service->identifier() . '.json'; if (!is_dir($logDirectory) && !mkdir($logDirectory, 0775, true) && !is_dir($logDirectory)) {
throw new \RuntimeException(sprintf('Unable to create JMAP log directory: %s', $logDirectory));
}
$logFile = $logDirectory . '/' . $service->identifier() . '.json';
$client->configureTransportLogState(true); $client->configureTransportLogState(true);
$client->configureTransportLogLocation($logDir); $client->configureTransportLogLocation($logFile);
} }
// return // return
return $client; return $client;
@@ -200,7 +203,7 @@ class RemoteService {
return $service; return $service;
} }
public static function cookieStoreRetrieve(mixed $id): ?array { public static function cookieStoreRetrieve(mixed $id, Crypto $crypto): ?array {
$file = sys_get_temp_dir() . DIRECTORY_SEPARATOR . (string)$id . '.jmapc'; $file = sys_get_temp_dir() . DIRECTORY_SEPARATOR . (string)$id . '.jmapc';
@@ -209,7 +212,6 @@ class RemoteService {
} }
$data = file_get_contents($file); $data = file_get_contents($file);
$crypto = Server::getInstance()->container()->get(\KTXF\Security\Crypto::class);
$data = $crypto->decrypt($data); $data = $crypto->decrypt($data);
if (!empty($data)) { if (!empty($data)) {
@@ -220,13 +222,12 @@ class RemoteService {
} }
public static function cookieStoreDeposit(mixed $id, array $value): void { public static function cookieStoreDeposit(mixed $id, array $value, Crypto $crypto): void {
if (empty($value)) { if (empty($value)) {
return; return;
} }
$crypto = Server::getInstance()->container()->get(\KTXF\Security\Crypto::class);
$data = $crypto->encrypt(json_encode($value)); $data = $crypto->encrypt(json_encode($value));
$file = sys_get_temp_dir() . DIRECTORY_SEPARATOR . (string)$id . '.jmapc'; $file = sys_get_temp_dir() . DIRECTORY_SEPARATOR . (string)$id . '.jmapc';
+11
View File
@@ -176,4 +176,15 @@ class ServiceStore
return $result->getDeletedCount() > 0; return $result->getDeletedCount() > 0;
} }
/**
* Delete every service owned by a user.
*/
public function deleteByUser(string $tenantId, string $userId): void
{
$this->dataStore->selectCollection(self::COLLECTION_NAME)->deleteMany([
'tid' => $tenantId,
'uid' => $userId,
]);
}
} }
+10 -83
View File
@@ -9,7 +9,7 @@
"version": "1.0.0", "version": "1.0.0",
"license": "AGPL-3.0-or-later", "license": "AGPL-3.0-or-later",
"dependencies": { "dependencies": {
"pinia": "^3.0.0", "pinia": "^4.0.0",
"vue": "^3.5.18", "vue": "^3.5.18",
"vue-router": "^5.0.0", "vue-router": "^5.0.0",
"vuetify": "^4.0.0" "vuetify": "^4.0.0"
@@ -1040,26 +1040,6 @@
"integrity": "sha512-LjgdTytVFXeUgtHZr9WYViYSM/g8MkcTPYDlPa3cDqMirHjKiSZPYd6DoL7pK8AJQr+uWkQvCjHNdiMqsrJs+g==", "integrity": "sha512-LjgdTytVFXeUgtHZr9WYViYSM/g8MkcTPYDlPa3cDqMirHjKiSZPYd6DoL7pK8AJQr+uWkQvCjHNdiMqsrJs+g==",
"license": "MIT" "license": "MIT"
}, },
"node_modules/@vue/devtools-kit": {
"version": "7.7.9",
"license": "MIT",
"dependencies": {
"@vue/devtools-shared": "^7.7.9",
"birpc": "^2.3.0",
"hookable": "^5.5.3",
"mitt": "^3.0.1",
"perfect-debounce": "^1.0.0",
"speakingurl": "^14.0.1",
"superjson": "^2.2.2"
}
},
"node_modules/@vue/devtools-shared": {
"version": "7.7.9",
"license": "MIT",
"dependencies": {
"rfdc": "^1.4.1"
}
},
"node_modules/@vue/language-core": { "node_modules/@vue/language-core": {
"version": "3.3.8", "version": "3.3.8",
"resolved": "https://registry.npmjs.org/@vue/language-core/-/language-core-3.3.8.tgz", "resolved": "https://registry.npmjs.org/@vue/language-core/-/language-core-3.3.8.tgz",
@@ -1343,19 +1323,6 @@
"dev": true, "dev": true,
"license": "MIT" "license": "MIT"
}, },
"node_modules/copy-anything": {
"version": "4.0.5",
"license": "MIT",
"dependencies": {
"is-what": "^5.2.0"
},
"engines": {
"node": ">=18"
},
"funding": {
"url": "https://github.com/sponsors/mesqueeb"
}
},
"node_modules/cross-spawn": { "node_modules/cross-spawn": {
"version": "7.0.6", "version": "7.0.6",
"dev": true, "dev": true,
@@ -1587,16 +1554,6 @@
"dev": true, "dev": true,
"license": "MIT" "license": "MIT"
}, },
"node_modules/is-what": {
"version": "5.5.0",
"license": "MIT",
"engines": {
"node": ">=18"
},
"funding": {
"url": "https://github.com/sponsors/mesqueeb"
}
},
"node_modules/isexe": { "node_modules/isexe": {
"version": "2.0.0", "version": "2.0.0",
"dev": true, "dev": true,
@@ -2078,10 +2035,6 @@
"node": ">=16 || 14 >=14.17" "node": ">=16 || 14 >=14.17"
} }
}, },
"node_modules/mitt": {
"version": "3.0.1",
"license": "MIT"
},
"node_modules/mlly": { "node_modules/mlly": {
"version": "1.8.2", "version": "1.8.2",
"license": "MIT", "license": "MIT",
@@ -2226,10 +2179,6 @@
"version": "2.0.3", "version": "2.0.3",
"license": "MIT" "license": "MIT"
}, },
"node_modules/perfect-debounce": {
"version": "1.0.0",
"license": "MIT"
},
"node_modules/picocolors": { "node_modules/picocolors": {
"version": "1.1.1", "version": "1.1.1",
"license": "ISC" "license": "ISC"
@@ -2245,31 +2194,30 @@
} }
}, },
"node_modules/pinia": { "node_modules/pinia": {
"version": "3.0.4", "version": "4.0.2",
"resolved": "https://registry.npmjs.org/pinia/-/pinia-4.0.2.tgz",
"integrity": "sha512-yKVVA7bSj5oRZFp/Ab9wLlmyb5gPUYEiIm4ryiWTe/xe7PtkRdMVOp1X1ggvq0c6Uj7Q0Du1HnV2mtAwM0Ks1g==",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@vue/devtools-api": "^7.7.7" "nostics": "^1.1.4"
}, },
"funding": { "funding": {
"url": "https://github.com/sponsors/posva" "url": "https://github.com/sponsors/posva"
}, },
"peerDependencies": { "peerDependencies": {
"typescript": ">=4.5.0", "@vue/devtools-api": "^8.1.5",
"typescript": ">=5.6.0",
"vue": "^3.5.11" "vue": "^3.5.11"
}, },
"peerDependenciesMeta": { "peerDependenciesMeta": {
"@vue/devtools-api": {
"optional": false
},
"typescript": { "typescript": {
"optional": true "optional": true
} }
} }
}, },
"node_modules/pinia/node_modules/@vue/devtools-api": {
"version": "7.7.9",
"license": "MIT",
"dependencies": {
"@vue/devtools-kit": "^7.7.9"
}
},
"node_modules/pkg-types": { "node_modules/pkg-types": {
"version": "2.3.1", "version": "2.3.1",
"license": "MIT", "license": "MIT",
@@ -2351,10 +2299,6 @@
"node": ">=0.10.0" "node": ">=0.10.0"
} }
}, },
"node_modules/rfdc": {
"version": "1.4.1",
"license": "MIT"
},
"node_modules/rolldown": { "node_modules/rolldown": {
"version": "1.1.5", "version": "1.1.5",
"devOptional": true, "devOptional": true,
@@ -2468,13 +2412,6 @@
"node": ">=0.10.0" "node": ">=0.10.0"
} }
}, },
"node_modules/speakingurl": {
"version": "14.0.1",
"license": "BSD-3-Clause",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/stackback": { "node_modules/stackback": {
"version": "0.0.2", "version": "0.0.2",
"dev": true, "dev": true,
@@ -2573,16 +2510,6 @@
"node": ">=8" "node": ">=8"
} }
}, },
"node_modules/superjson": {
"version": "2.2.6",
"license": "MIT",
"dependencies": {
"copy-anything": "^4"
},
"engines": {
"node": ">=16"
}
},
"node_modules/supports-color": { "node_modules/supports-color": {
"version": "7.2.0", "version": "7.2.0",
"dev": true, "dev": true,
+1 -1
View File
@@ -18,7 +18,7 @@
"test:coverage": "vitest run --coverage --config tests/js/vitest.config.ts" "test:coverage": "vitest run --coverage --config tests/js/vitest.config.ts"
}, },
"dependencies": { "dependencies": {
"pinia": "^3.0.0", "pinia": "^4.0.0",
"vue": "^3.5.18", "vue": "^3.5.18",
"vue-router": "^5.0.0", "vue-router": "^5.0.0",
"vuetify": "^4.0.0" "vuetify": "^4.0.0"
+2 -2
View File
@@ -274,7 +274,7 @@ async function initiateOAuth() {
variant="outlined" variant="outlined"
prepend-inner-icon="mdi-account" prepend-inner-icon="mdi-account"
class="mb-4" class="mb-4"
autocomplete="username" autocomplete="off"
autocorrect="off" autocorrect="off"
autocapitalize="none" autocapitalize="none"
:rules="[rules.required]" :rules="[rules.required]"
@@ -289,7 +289,7 @@ async function initiateOAuth() {
variant="outlined" variant="outlined"
prepend-inner-icon="mdi-lock" prepend-inner-icon="mdi-lock"
class="mb-4" class="mb-4"
autocomplete="current-password" autocomplete="new-password"
:rules="[rules.required]" :rules="[rules.required]"
/> />
</template> </template>
+15 -65
View File
@@ -25,7 +25,7 @@ const settingGroups = [
title: 'Addresses', title: 'Addresses',
value: 'addresses' as const, value: 'addresses' as const,
icon: 'mdi-at', icon: 'mdi-at',
description: 'Configure the primary mailbox identity and any sender aliases exposed by this service.' description: 'View the primary mailbox identity and sender aliases synced from the JMAP server.'
}, },
{ {
title: 'Messages', title: 'Messages',
@@ -71,7 +71,7 @@ watch(
) )
watch( watch(
[deleteMode, deleteDestination, primaryAddress, secondaryAddresses], [deleteMode, deleteDestination],
() => { () => {
const nextService = props.service ?? new ServiceObject() const nextService = props.service ?? new ServiceObject()
const nextAuxiliary = { const nextAuxiliary = {
@@ -83,13 +83,9 @@ watch(
} }
if (sameAuxiliary(nextService.auxiliary ?? {}, nextAuxiliary)) { if (sameAuxiliary(nextService.auxiliary ?? {}, nextAuxiliary)) {
if (sameAddresses(nextService)) { return
return
}
} }
nextService.primaryAddress = primaryAddress.value.empty ? null : primaryAddress.value
nextService.secondaryAddresses = dedupeAddresses(secondaryAddresses.value)
nextService.auxiliary = nextAuxiliary nextService.auxiliary = nextAuxiliary
emit('update:service', nextService) emit('update:service', nextService)
}, },
@@ -111,44 +107,10 @@ function normalizeDeleteDestination(value: string): string {
return trimmedValue.length > 0 ? trimmedValue : 'Trash' return trimmedValue.length > 0 ? trimmedValue : 'Trash'
} }
function dedupeAddresses(entries: ServiceAddressObject[]): ServiceAddressObject[] {
const populated = entries.filter(entry => !entry.empty)
return populated.filter((entry, index) =>
populated.findIndex(candidate => candidate.matches(entry.address)) === index)
}
function addSecondaryAddress() {
secondaryAddresses.value.push(new ServiceAddressObject())
}
function removeSecondaryAddress(index: number) {
secondaryAddresses.value.splice(index, 1)
}
function validAddress(value: string): boolean | string {
const trimmedValue = value.trim()
return trimmedValue.length === 0 || /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(trimmedValue) || 'Invalid email address'
}
function sameAuxiliary(current: Record<string, any>, next: Record<string, any>): boolean { function sameAuxiliary(current: Record<string, any>, next: Record<string, any>): boolean {
return (current.deleteMode === 'hard' ? 'hard' : 'soft') === next.deleteMode return (current.deleteMode === 'hard' ? 'hard' : 'soft') === next.deleteMode
&& (current.deleteDestination ?? undefined) === (next.deleteDestination ?? undefined) && (current.deleteDestination ?? undefined) === (next.deleteDestination ?? undefined)
} }
function sameAddresses(service: ServiceObject): boolean {
const nextPrimary = primaryAddress.value.empty ? null : primaryAddress.value
const nextSecondary = dedupeAddresses(secondaryAddresses.value)
return sameAddress(service.primaryAddress, nextPrimary)
&& service.secondaryAddresses.length === nextSecondary.length
&& service.secondaryAddresses.every((entry, index) => sameAddress(entry, nextSecondary[index]))
}
function sameAddress(current: ServiceAddressObject | null, next: ServiceAddressObject | null): boolean {
if (current === null || next === null) {
return current === next
}
return current.equals(next)
}
</script> </script>
<template> <template>
@@ -176,69 +138,57 @@ function sameAddress(current: ServiceAddressObject | null, next: ServiceAddressO
<div class="jmap-settings-card"> <div class="jmap-settings-card">
<h3 class="text-h6 mb-2">Addresses</h3> <h3 class="text-h6 mb-2">Addresses</h3>
<p class="text-body-2 text-medium-emphasis mb-6"> <p class="text-body-2 text-medium-emphasis mb-6">
Configure the primary mailbox identity and any additional sender aliases exposed by this service. The primary mailbox identity and sender aliases are managed by the JMAP server and synced automatically.
</p> </p>
<div class="text-subtitle-2 mb-2">Primary Address</div> <div class="text-subtitle-2 mb-2">Primary Address</div>
<div class="d-flex ga-2 mb-6"> <div class="d-flex ga-2 mb-6">
<v-text-field <v-text-field
v-model="primaryAddress.label" :model-value="primaryAddress.label"
label="Display Name" label="Display Name"
variant="outlined" variant="outlined"
density="compact" density="compact"
hide-details="auto" hide-details="auto"
readonly
/> />
<v-text-field <v-text-field
v-model="primaryAddress.address" :model-value="primaryAddress.address"
label="Email Address" label="Email Address"
variant="outlined" variant="outlined"
density="compact" density="compact"
prepend-inner-icon="mdi-email-outline" prepend-inner-icon="mdi-email-outline"
:rules="[validAddress]"
hide-details="auto" hide-details="auto"
readonly
/> />
</div> </div>
<div class="text-subtitle-2 mb-2">Secondary Addresses</div> <div class="text-subtitle-2 mb-2">Secondary Addresses</div>
<p v-if="secondaryAddresses.length === 0" class="text-body-2 text-medium-emphasis">
No aliases reported by the server.
</p>
<div <div
v-for="(entry, index) in secondaryAddresses" v-for="(entry, index) in secondaryAddresses"
:key="index" :key="index"
class="d-flex ga-2 mb-2" class="d-flex ga-2 mb-2"
> >
<v-text-field <v-text-field
v-model="entry.label" :model-value="entry.label"
label="Display Name" label="Display Name"
variant="outlined" variant="outlined"
density="compact" density="compact"
hide-details="auto" hide-details="auto"
readonly
/> />
<v-text-field <v-text-field
v-model="entry.address" :model-value="entry.address"
label="Email Address" label="Email Address"
variant="outlined" variant="outlined"
density="compact" density="compact"
prepend-inner-icon="mdi-email-multiple-outline" prepend-inner-icon="mdi-email-multiple-outline"
:rules="[validAddress]"
hide-details="auto" hide-details="auto"
readonly
/> />
<v-btn
icon
size="small"
variant="text"
@click="removeSecondaryAddress(index)"
>
<v-icon>mdi-delete-outline</v-icon>
<v-tooltip activator="parent" location="bottom">Remove Alias</v-tooltip>
</v-btn>
</div> </div>
<v-btn
variant="tonal"
prepend-icon="mdi-plus"
@click="addSecondaryAddress"
>
Add Alias
</v-btn>
</div> </div>
</v-window-item> </v-window-item>