Compare commits
1 Commits
main
..
0891a5b600
| Author | SHA1 | Date | |
|---|---|---|---|
| 0891a5b600 |
@@ -1,59 +0,0 @@
|
|||||||
name: PHP Integration Tests
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request:
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
name: Integration Tests
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
services:
|
|
||||||
mongo:
|
|
||||||
image: mongo:8
|
|
||||||
options: >-
|
|
||||||
--health-cmd "mongosh --quiet --eval \"db.adminCommand('ping')\""
|
|
||||||
--health-interval 5s
|
|
||||||
--health-timeout 5s
|
|
||||||
--health-retries 12
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Retrieve Server Install Action
|
|
||||||
uses: actions/checkout@v6.0.2
|
|
||||||
with:
|
|
||||||
repository: Nodarx/action-server-install
|
|
||||||
ref: main
|
|
||||||
path: action-server-install
|
|
||||||
github-server-url: https://git.ktrix.dev
|
|
||||||
|
|
||||||
- name: Install server
|
|
||||||
uses: ./action-server-install
|
|
||||||
with:
|
|
||||||
install-php: 'true'
|
|
||||||
php-version: '8.5'
|
|
||||||
server-path: './server'
|
|
||||||
database-uri: 'mongodb://mongo:27017/?tls=false'
|
|
||||||
database-name: 'ktrix_ci'
|
|
||||||
app-environment: 'test'
|
|
||||||
|
|
||||||
- name: Checkout module under test
|
|
||||||
uses: actions/checkout@v6.0.2
|
|
||||||
with:
|
|
||||||
repository: ${{ github.repository }}
|
|
||||||
ref: ${{ github.event.pull_request.head.sha || github.sha }}
|
|
||||||
path: server/modules/provider_jmapc
|
|
||||||
github-server-url: https://git.ktrix.dev
|
|
||||||
|
|
||||||
- name: Install module dependencies
|
|
||||||
run: composer install --prefer-dist --no-progress
|
|
||||||
working-directory: server/modules/provider_jmapc
|
|
||||||
|
|
||||||
- name: Install and enable module
|
|
||||||
working-directory: server
|
|
||||||
run: |
|
|
||||||
php bin/console module:install provider_jmapc
|
|
||||||
php bin/console module:enable provider_jmapc
|
|
||||||
|
|
||||||
- name: Run integration tests
|
|
||||||
working-directory: server/modules/provider_jmapc
|
|
||||||
run: composer test:integration
|
|
||||||
+5
-1
@@ -14,7 +14,11 @@ node_modules/
|
|||||||
# Backend development
|
# Backend development
|
||||||
/lib/vendor/
|
/lib/vendor/
|
||||||
coverage/
|
coverage/
|
||||||
*.cache
|
phpunit.xml.cache
|
||||||
|
.phpunit.cache
|
||||||
|
.phpunit.result.cache
|
||||||
|
.php-cs-fixer.cache
|
||||||
|
.phpstan.cache
|
||||||
.phpactor/
|
.phpactor/
|
||||||
|
|
||||||
# Editors
|
# Editors
|
||||||
|
|||||||
+5
-6
@@ -10,7 +10,7 @@
|
|||||||
"config": {
|
"config": {
|
||||||
"optimize-autoloader": true,
|
"optimize-autoloader": true,
|
||||||
"platform": {
|
"platform": {
|
||||||
"php": "8.3"
|
"php": "8.2"
|
||||||
},
|
},
|
||||||
"autoloader-suffix": "ProviderJmapc",
|
"autoloader-suffix": "ProviderJmapc",
|
||||||
"vendor-dir": "lib/vendor",
|
"vendor-dir": "lib/vendor",
|
||||||
@@ -27,11 +27,11 @@
|
|||||||
"require": {
|
"require": {
|
||||||
"guzzlehttp/guzzle": "^7.0",
|
"guzzlehttp/guzzle": "^7.0",
|
||||||
"guzzlehttp/psr7": "^2.0",
|
"guzzlehttp/psr7": "^2.0",
|
||||||
"php": ">=8.3 <=8.5",
|
"php": ">=8.2 <=8.5",
|
||||||
"sebastiankrupinski/jmap-client-php": "dev-main"
|
"sebastiankrupinski/jmap-client-php": "dev-main"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "^12.0"
|
"phpunit/phpunit": "^11.0"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
@@ -48,8 +48,7 @@
|
|||||||
],
|
],
|
||||||
"post-update-cmd": [
|
"post-update-cmd": [
|
||||||
],
|
],
|
||||||
"test:unit": "phpunit --configuration tests/php/phpunit.xml --testsuite \"Unit Tests\" --colors=always --testdox",
|
"test:unit": "phpunit --configuration tests/php/phpunit.unit.xml --colors=always --testdox",
|
||||||
"test:integration": "phpunit --configuration tests/php/phpunit.xml --testsuite \"Integration Tests\" --colors=always --testdox",
|
"test:coverage": "XDEBUG_MODE=coverage phpunit --configuration tests/php/phpunit.unit.xml --coverage-html .phpunit.coverage --coverage-text"
|
||||||
"test:coverage": "XDEBUG_MODE=coverage phpunit --configuration tests/php/phpunit.xml --testsuite \"Unit Tests\" --coverage-html .phpunit.coverage --coverage-text"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+360
-276
File diff suppressed because it is too large
Load Diff
@@ -9,7 +9,6 @@ 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;
|
||||||
@@ -143,64 +142,7 @@ 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['id'];
|
||||||
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
|
||||||
@@ -209,9 +151,8 @@ class Provider implements ProviderBaseInterface, ProviderServiceMutateInterface,
|
|||||||
throw new \InvalidArgumentException('Service must be instance of JMAP Service');
|
throw new \InvalidArgumentException('Service must be instance of JMAP Service');
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->serviceStore->modify($tenantId, $userId, $service);
|
$updated = $this->serviceStore->modify($tenantId, $userId, $service);
|
||||||
$this->serviceIdentitiesSync($tenantId, $userId, $service);
|
return (string) $updated['sid'];
|
||||||
return (string) $service->identifier();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function serviceDestroy(string $tenantId, string $userId, ResourceServiceMutateInterface $service): bool
|
public function serviceDestroy(string $tenantId, string $userId, ResourceServiceMutateInterface $service): bool
|
||||||
|
|||||||
@@ -206,9 +206,8 @@ 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])) {
|
if (isset($data[self::PROPERTY_PRIMARY_ADDRESS]) && is_string($data[self::PROPERTY_PRIMARY_ADDRESS])) {
|
||||||
$value = $data[self::PROPERTY_PRIMARY_ADDRESS];
|
$this->setPrimaryAddress(new Address($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(
|
||||||
@@ -484,34 +483,17 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($deleteMode === 'soft') {
|
// we need to determine if the folder being deleted is already in the trash
|
||||||
$targetMailbox = $this->mailService->collectionFetch((string) $target->collection());
|
if (str_starts_with((string) $target->collection(), (string) $deleteTargetIdentifier?->collection())) {
|
||||||
if ($targetMailbox === null) {
|
// if so, we should hard delete instead of moving to avoid duplicates in the trash
|
||||||
throw new \RuntimeException('Collection not found for delete operation');
|
$deleteMode = 'hard';
|
||||||
}
|
|
||||||
|
|
||||||
$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';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($deleteMode === 'soft') {
|
$result = match ($deleteMode) {
|
||||||
return $this->collectionMove($deleteTargetIdentifier, $target);
|
'soft' => $this->collectionMove($deleteTargetIdentifier, $target),
|
||||||
}
|
'hard' => $this->mailService->collectionDestroy($target->collection(), $force),
|
||||||
|
};
|
||||||
if ($this->mailService->collectionDestroy((string) $target->collection(), $force) === null) {
|
return $result;
|
||||||
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
|
||||||
@@ -897,31 +879,7 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$nativeProperties = $this->normalizeMessageProperties($message);
|
$nativeMessage = $this->normalizeMessageProperties($message)->toJmap();
|
||||||
$attachments = $nativeProperties->getAttachments();
|
|
||||||
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',
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
$attachment->setBlobId($this->mailService->blobDeposit(
|
|
||||||
$attachment->getType() ?? 'application/octet-stream',
|
|
||||||
$content,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
if ($attachments !== []) {
|
|
||||||
$nativeProperties->setAttachments(...$attachments);
|
|
||||||
}
|
|
||||||
|
|
||||||
$nativeMessage = $nativeProperties->toJmap();
|
|
||||||
$transportId = $this->mailService->entitySubmitFresh($identityId, $nativeMessage, $preSendTarget->collection(), $postSentTarget->collection());
|
$transportId = $this->mailService->entitySubmitFresh($identityId, $nativeMessage, $preSendTarget->collection(), $postSentTarget->collection());
|
||||||
|
|
||||||
return new EntitySubmitResult(
|
return new EntitySubmitResult(
|
||||||
|
|||||||
@@ -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 TenantContextInterface in actual implementation
|
// Will need to get it from SessionTenant in actual implementation
|
||||||
throw new \RuntimeException('Use Mail Provider interface for service creation');
|
throw new \RuntimeException('Use Mail Provider interface for service creation');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -912,44 +912,23 @@ class RemoteMailService {
|
|||||||
*
|
*
|
||||||
* @since Release 2.0.0
|
* @since Release 2.0.0
|
||||||
*/
|
*/
|
||||||
public function entitySubmitFresh(string $identityId, array $data, string $preSendTarget, string $postSentTarget): string {
|
public function entitySubmitFresh(string $identityId, array $message, string $preSendTarget, string $postSentTarget): string {
|
||||||
|
|
||||||
$message = new MailParametersRequest();
|
$mail = new MailParametersRequest();
|
||||||
$message->parametersRaw($data);
|
$mail->parametersRaw($message);
|
||||||
|
|
||||||
$messageId = 'm_' . uniqid();
|
$messageCreateId = 'm_' . uniqid();
|
||||||
$submissionId = 's_' . uniqid();
|
$submissionCreateId = 's_' . uniqid();
|
||||||
|
|
||||||
$r0 = new MailSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
|
$r0 = new MailSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
|
||||||
$m0 = $r0->create($messageId, $message);
|
$createdMessage = $r0->create($messageCreateId, $mail);
|
||||||
$m0->in($preSendTarget);
|
$createdMessage->in($preSendTarget);
|
||||||
$m0->draft(true);
|
|
||||||
$m0->seen(true);
|
|
||||||
|
|
||||||
$r1 = new MailSubmissionSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
|
$r1 = new MailSubmissionSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
|
||||||
$r1->completionUpdate('#' . $messageId, [
|
$submission = $r1->create($submissionCreateId);
|
||||||
'mailboxIds/' . $postSentTarget => true,
|
$submission->identity($identityId);
|
||||||
'mailboxIds/' . $preSendTarget => null,
|
$submission->message('#' . $messageCreateId);
|
||||||
'keywords/$draft' => null,
|
|
||||||
]);
|
|
||||||
$s0 = $r1->create($submissionId);
|
|
||||||
$s0->identity($identityId);
|
|
||||||
$s0->message('#' . $messageId);
|
|
||||||
|
|
||||||
$bundle = $this->dataStore->perform([$r0, $r1]);
|
$bundle = $this->dataStore->perform([$r0, $r1]);
|
||||||
$messageResponse = $bundle->response(0);
|
|
||||||
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(1);
|
$response = $bundle->response(1);
|
||||||
if ($response instanceof ResponseException) {
|
if ($response instanceof ResponseException) {
|
||||||
if ($response->type() === 'unknownMethod') {
|
if ($response->type() === 'unknownMethod') {
|
||||||
@@ -958,19 +937,7 @@ class RemoteMailService {
|
|||||||
throw new Exception($response->type() . ': ' . $response->description(), 1);
|
throw new Exception($response->type() . ': ' . $response->description(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->extractSubmissionIdentifier($response, $submissionId);
|
return $this->extractSubmissionIdentifier($response, $submissionCreateId);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Upload attachment content and return its JMAP blob identifier.
|
|
||||||
*/
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $response['blobId'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -986,18 +953,18 @@ class RemoteMailService {
|
|||||||
$requests = [];
|
$requests = [];
|
||||||
|
|
||||||
if ($patch !== null && $patch !== []) {
|
if ($patch !== null && $patch !== []) {
|
||||||
$m0 = new MailParametersRequest();
|
$draftMutation = new MailParametersRequest();
|
||||||
$m0->parametersRaw($patch);
|
$draftMutation->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, $m0);
|
$r0->update($draftId, $draftMutation);
|
||||||
$requests[] = $r0;
|
$requests[] = $r0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$submissionId = 's_' . uniqid();
|
$submissionCreateId = 's_' . uniqid();
|
||||||
$r1 = new MailSubmissionSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
|
$r1 = new MailSubmissionSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
|
||||||
$s0 = $r1->create($submissionId);
|
$submission = $r1->create($submissionCreateId);
|
||||||
$s0->identity($identityId);
|
$submission->identity($identityId);
|
||||||
$s0->message($draftId);
|
$submission->message($draftId);
|
||||||
$requests[] = $r1;
|
$requests[] = $r1;
|
||||||
|
|
||||||
$bundle = $this->dataStore->perform($requests);
|
$bundle = $this->dataStore->perform($requests);
|
||||||
@@ -1010,7 +977,19 @@ class RemoteMailService {
|
|||||||
throw new Exception($response->type() . ': ' . $response->description(), 1);
|
throw new Exception($response->type() . ': ' . $response->description(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->extractSubmissionIdentifier($response, $submissionId);
|
return $this->extractSubmissionIdentifier($response, $submissionCreateId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function collectionByRole(string $role): ?string {
|
||||||
|
$filter = $this->collectionListFilter();
|
||||||
|
$filter->condition('role', $role);
|
||||||
|
|
||||||
|
$collections = $this->collectionList(null, $filter, null);
|
||||||
|
if ($collections === []) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (string)array_key_first($collections);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function extractSubmissionIdentifier(object $response, string $createId): string {
|
private function extractSubmissionIdentifier(object $response, string $createId): string {
|
||||||
|
|||||||
@@ -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 KTXF\Security\Crypto;
|
use KTXC\Server;
|
||||||
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,13 +73,10 @@ class RemoteService {
|
|||||||
}
|
}
|
||||||
// debugging
|
// debugging
|
||||||
if ($service->getDebug()) {
|
if ($service->getDebug()) {
|
||||||
$logDirectory = dirname(__DIR__, 5) . '/var/logs/jmap';
|
$logDir = Server::getInstance()?->logDir();
|
||||||
if (!is_dir($logDirectory) && !mkdir($logDirectory, 0775, true) && !is_dir($logDirectory)) {
|
$logDir .= '/jmap/' . $service->identifier() . '.json';
|
||||||
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($logFile);
|
$client->configureTransportLogLocation($logDir);
|
||||||
}
|
}
|
||||||
// return
|
// return
|
||||||
return $client;
|
return $client;
|
||||||
@@ -203,7 +200,7 @@ class RemoteService {
|
|||||||
return $service;
|
return $service;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function cookieStoreRetrieve(mixed $id, Crypto $crypto): ?array {
|
public static function cookieStoreRetrieve(mixed $id): ?array {
|
||||||
|
|
||||||
$file = sys_get_temp_dir() . DIRECTORY_SEPARATOR . (string)$id . '.jmapc';
|
$file = sys_get_temp_dir() . DIRECTORY_SEPARATOR . (string)$id . '.jmapc';
|
||||||
|
|
||||||
@@ -212,6 +209,7 @@ 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)) {
|
||||||
@@ -222,12 +220,13 @@ class RemoteService {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function cookieStoreDeposit(mixed $id, array $value, Crypto $crypto): void {
|
public static function cookieStoreDeposit(mixed $id, array $value): 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';
|
||||||
|
|||||||
Generated
+767
-1131
File diff suppressed because it is too large
Load Diff
+2
-5
@@ -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": "^4.0.0",
|
"pinia": "^3.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"
|
||||||
@@ -27,12 +27,9 @@
|
|||||||
"@vitejs/plugin-vue": "^6.0.1",
|
"@vitejs/plugin-vue": "^6.0.1",
|
||||||
"@vitest/coverage-v8": "^4.0.18",
|
"@vitest/coverage-v8": "^4.0.18",
|
||||||
"@vitest/ui": "^4.0.18",
|
"@vitest/ui": "^4.0.18",
|
||||||
"@vue/test-utils": "^2.4.10",
|
|
||||||
"@vue/tsconfig": "^0.9.0",
|
"@vue/tsconfig": "^0.9.0",
|
||||||
"jsdom": "^29.1.1",
|
"typescript": "~7.0.0",
|
||||||
"typescript": "~6.0.0",
|
|
||||||
"vite": "^8.0.0",
|
"vite": "^8.0.0",
|
||||||
"vitest": "^4.0.18",
|
|
||||||
"vue-tsc": "^3.0.5"
|
"vue-tsc": "^3.0.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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="off"
|
autocomplete="username"
|
||||||
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="new-password"
|
autocomplete="current-password"
|
||||||
:rules="[rules.required]"
|
:rules="[rules.required]"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
|
|||||||
@@ -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: 'View the primary mailbox identity and sender aliases synced from the JMAP server.'
|
description: 'Configure the primary mailbox identity and any sender aliases exposed by this service.'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'Messages',
|
title: 'Messages',
|
||||||
@@ -71,7 +71,7 @@ watch(
|
|||||||
)
|
)
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
[deleteMode, deleteDestination],
|
[deleteMode, deleteDestination, primaryAddress, secondaryAddresses],
|
||||||
() => {
|
() => {
|
||||||
const nextService = props.service ?? new ServiceObject()
|
const nextService = props.service ?? new ServiceObject()
|
||||||
const nextAuxiliary = {
|
const nextAuxiliary = {
|
||||||
@@ -83,9 +83,13 @@ watch(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sameAuxiliary(nextService.auxiliary ?? {}, nextAuxiliary)) {
|
if (sameAuxiliary(nextService.auxiliary ?? {}, nextAuxiliary)) {
|
||||||
return
|
if (sameAddresses(nextService)) {
|
||||||
|
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)
|
||||||
},
|
},
|
||||||
@@ -107,10 +111,44 @@ 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>
|
||||||
@@ -138,57 +176,69 @@ function sameAuxiliary(current: Record<string, any>, next: Record<string, any>):
|
|||||||
<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">
|
||||||
The primary mailbox identity and sender aliases are managed by the JMAP server and synced automatically.
|
Configure the primary mailbox identity and any additional sender aliases exposed by this service.
|
||||||
</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
|
||||||
:model-value="primaryAddress.label"
|
v-model="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
|
||||||
:model-value="primaryAddress.address"
|
v-model="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
|
||||||
:model-value="entry.label"
|
v-model="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
|
||||||
:model-value="entry.address"
|
v-model="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>
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
import { fileURLToPath } from 'node:url'
|
import { fileURLToPath } from 'node:url'
|
||||||
import { defineConfig, configDefaults } from 'vitest/config'
|
import { defineConfig, configDefaults } from 'vitest/config'
|
||||||
import vue from '@vitejs/plugin-vue'
|
import vue from '@vitejs/plugin-vue'
|
||||||
|
import vuetify from 'vite-plugin-vuetify'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
|
|
||||||
const __filename = fileURLToPath(import.meta.url)
|
const __filename = fileURLToPath(import.meta.url)
|
||||||
const __dirname = path.dirname(__filename)
|
const __dirname = path.dirname(__filename)
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [vue()],
|
plugins: [vue(), vuetify()],
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
'@': path.resolve(__dirname, '../../src'),
|
'@KTXC': path.resolve(__dirname, '../../../core/src'),
|
||||||
'@KTXC': path.resolve(__dirname, '../../../../core/src'),
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
test: {
|
test: {
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace KTXT\ProviderJmapc\Integration;
|
|
||||||
|
|
||||||
use PHPUnit\Framework\TestCase;
|
|
||||||
|
|
||||||
class BaseTest extends TestCase
|
|
||||||
{
|
|
||||||
public function testBasicAssertion(): void
|
|
||||||
{
|
|
||||||
$this->assertTrue(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testArrayOperations(): void
|
|
||||||
{
|
|
||||||
$array = ['foo' => 'bar'];
|
|
||||||
|
|
||||||
$this->assertArrayHasKey('foo', $array);
|
|
||||||
$this->assertEquals('bar', $array['foo']);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testStringOperations(): void
|
|
||||||
{
|
|
||||||
$string = 'Hello, World!';
|
|
||||||
|
|
||||||
$this->assertStringContainsString('World', $string);
|
|
||||||
$this->assertEquals(13, strlen($string));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -2,16 +2,6 @@
|
|||||||
|
|
||||||
require dirname(__DIR__, 2).'/lib/vendor/autoload.php';
|
require dirname(__DIR__, 2).'/lib/vendor/autoload.php';
|
||||||
|
|
||||||
// When this module is checked out inside a full server (server/modules/<handle>,
|
|
||||||
// as it is in CI and in this monorepo checkout), also load the server's own
|
|
||||||
// core/shared autoloader so tests can reference framework (KTXC/KTXF) types.
|
|
||||||
// Standalone module checkouts without a server alongside them skip this.
|
|
||||||
define('SERVER_ROOT', dirname(__DIR__, 4));
|
|
||||||
$serverAutoload = SERVER_ROOT . '/vendor/autoload.php';
|
|
||||||
if (is_file($serverAutoload)) {
|
|
||||||
require $serverAutoload;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($_SERVER['APP_DEBUG']) && $_SERVER['APP_DEBUG']) {
|
if (isset($_SERVER['APP_DEBUG']) && $_SERVER['APP_DEBUG']) {
|
||||||
umask(0000);
|
umask(0000);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,9 +21,6 @@
|
|||||||
<testsuite name="Unit Tests">
|
<testsuite name="Unit Tests">
|
||||||
<directory>unit</directory>
|
<directory>unit</directory>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
<testsuite name="Integration Tests">
|
|
||||||
<directory>Integration</directory>
|
|
||||||
</testsuite>
|
|
||||||
</testsuites>
|
</testsuites>
|
||||||
|
|
||||||
<source ignoreSuppressionOfDeprecations="true"
|
<source ignoreSuppressionOfDeprecations="true"
|
||||||
@@ -32,7 +29,8 @@
|
|||||||
restrictWarnings="true"
|
restrictWarnings="true"
|
||||||
>
|
>
|
||||||
<include>
|
<include>
|
||||||
<directory>../../lib</directory>
|
<directory>../../core/lib</directory>
|
||||||
|
<directory>../../shared/lib</directory>
|
||||||
</include>
|
</include>
|
||||||
|
|
||||||
<deprecationTrigger>
|
<deprecationTrigger>
|
||||||
Reference in New Issue
Block a user