Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 36aaa8b9c7 |
@@ -9,7 +9,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace KTXM\ProviderJmapc\Providers\Mail;
|
||||
|
||||
use KTXF\Mail\Object\Address;
|
||||
use KTXF\Mail\Provider\ProviderBaseInterface;
|
||||
use KTXF\Mail\Provider\ProviderServiceDiscoverInterface;
|
||||
use KTXF\Mail\Provider\ProviderServiceMutateInterface;
|
||||
@@ -143,66 +142,9 @@ class Provider implements ProviderBaseInterface, ProviderServiceMutateInterface,
|
||||
}
|
||||
|
||||
$created = $this->serviceStore->create($tenantId, $userId, $service);
|
||||
$this->serviceIdentitiesSync($tenantId, $userId, (new Service())->fromStore($created));
|
||||
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
|
||||
{
|
||||
if (!($service instanceof Service)) {
|
||||
@@ -210,7 +152,6 @@ class Provider implements ProviderBaseInterface, ProviderServiceMutateInterface,
|
||||
}
|
||||
|
||||
$this->serviceStore->modify($tenantId, $userId, $service);
|
||||
$this->serviceIdentitiesSync($tenantId, $userId, $service);
|
||||
return (string) $service->identifier();
|
||||
}
|
||||
|
||||
|
||||
@@ -206,9 +206,8 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
||||
if (isset($data[self::PROPERTY_IDENTITY])) {
|
||||
$this->setIdentity($this->freshIdentity(null, $data[self::PROPERTY_IDENTITY]));
|
||||
}
|
||||
if (isset($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_PRIMARY_ADDRESS]) && is_string($data[self::PROPERTY_PRIMARY_ADDRESS])) {
|
||||
$this->setPrimaryAddress(new Address($data[self::PROPERTY_PRIMARY_ADDRESS]));
|
||||
}
|
||||
if (isset($data[self::PROPERTY_SECONDARY_ADDRESSES]) && is_array($data[self::PROPERTY_SECONDARY_ADDRESSES])) {
|
||||
$this->setSecondaryAddresses(array_map(
|
||||
@@ -484,34 +483,17 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
||||
}
|
||||
}
|
||||
|
||||
if ($deleteMode === 'soft') {
|
||||
$targetMailbox = $this->mailService->collectionFetch((string) $target->collection());
|
||||
if ($targetMailbox === null) {
|
||||
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';
|
||||
}
|
||||
// we need to determine if the folder being deleted is already in the trash
|
||||
if (str_starts_with((string) $target->collection(), (string) $deleteTargetIdentifier?->collection())) {
|
||||
// if so, we should hard delete instead of moving to avoid duplicates in the trash
|
||||
$deleteMode = 'hard';
|
||||
}
|
||||
|
||||
if ($deleteMode === 'soft') {
|
||||
return $this->collectionMove($deleteTargetIdentifier, $target);
|
||||
}
|
||||
|
||||
if ($this->mailService->collectionDestroy((string) $target->collection(), $force) === null) {
|
||||
throw new \RuntimeException("Failed to delete collection: {$target->collection()}");
|
||||
}
|
||||
|
||||
return true;
|
||||
$result = match ($deleteMode) {
|
||||
'soft' => $this->collectionMove($deleteTargetIdentifier, $target),
|
||||
'hard' => $this->mailService->collectionDestroy($target->collection(), $force),
|
||||
};
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function collectionMove(CollectionIdentifier $target, CollectionIdentifier $source): CollectionBaseInterface
|
||||
@@ -897,31 +879,7 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
||||
);
|
||||
}
|
||||
|
||||
$nativeProperties = $this->normalizeMessageProperties($message);
|
||||
$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();
|
||||
$nativeMessage = $this->normalizeMessageProperties($message)->toJmap();
|
||||
$transportId = $this->mailService->entitySubmitFresh($identityId, $nativeMessage, $preSendTarget->collection(), $postSentTarget->collection());
|
||||
|
||||
return new EntitySubmitResult(
|
||||
|
||||
@@ -912,44 +912,23 @@ class RemoteMailService {
|
||||
*
|
||||
* @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();
|
||||
$message->parametersRaw($data);
|
||||
$mail = new MailParametersRequest();
|
||||
$mail->parametersRaw($message);
|
||||
|
||||
$messageId = 'm_' . uniqid();
|
||||
$submissionId = 's_' . uniqid();
|
||||
$messageCreateId = 'm_' . uniqid();
|
||||
$submissionCreateId = 's_' . uniqid();
|
||||
|
||||
$r0 = new MailSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
|
||||
$m0 = $r0->create($messageId, $message);
|
||||
$m0->in($preSendTarget);
|
||||
$m0->draft(true);
|
||||
$m0->seen(true);
|
||||
|
||||
$createdMessage = $r0->create($messageCreateId, $mail);
|
||||
$createdMessage->in($preSendTarget);
|
||||
$r1 = new MailSubmissionSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
|
||||
$r1->completionUpdate('#' . $messageId, [
|
||||
'mailboxIds/' . $postSentTarget => true,
|
||||
'mailboxIds/' . $preSendTarget => null,
|
||||
'keywords/$draft' => null,
|
||||
]);
|
||||
$s0 = $r1->create($submissionId);
|
||||
$s0->identity($identityId);
|
||||
$s0->message('#' . $messageId);
|
||||
$submission = $r1->create($submissionCreateId);
|
||||
$submission->identity($identityId);
|
||||
$submission->message('#' . $messageCreateId);
|
||||
|
||||
$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);
|
||||
if ($response instanceof ResponseException) {
|
||||
if ($response->type() === 'unknownMethod') {
|
||||
@@ -958,19 +937,7 @@ class RemoteMailService {
|
||||
throw new Exception($response->type() . ': ' . $response->description(), 1);
|
||||
}
|
||||
|
||||
return $this->extractSubmissionIdentifier($response, $submissionId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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'];
|
||||
return $this->extractSubmissionIdentifier($response, $submissionCreateId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -986,18 +953,18 @@ class RemoteMailService {
|
||||
$requests = [];
|
||||
|
||||
if ($patch !== null && $patch !== []) {
|
||||
$m0 = new MailParametersRequest();
|
||||
$m0->parametersRaw($patch);
|
||||
$draftMutation = new MailParametersRequest();
|
||||
$draftMutation->parametersRaw($patch);
|
||||
$r0 = new MailSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
|
||||
$r0->update($draftId, $m0);
|
||||
$r0->update($draftId, $draftMutation);
|
||||
$requests[] = $r0;
|
||||
}
|
||||
|
||||
$submissionId = 's_' . uniqid();
|
||||
$submissionCreateId = 's_' . uniqid();
|
||||
$r1 = new MailSubmissionSet($this->dataAccount, null, $this->resourceNamespace, $this->resourceEntityLabel);
|
||||
$s0 = $r1->create($submissionId);
|
||||
$s0->identity($identityId);
|
||||
$s0->message($draftId);
|
||||
$submission = $r1->create($submissionCreateId);
|
||||
$submission->identity($identityId);
|
||||
$submission->message($draftId);
|
||||
$requests[] = $r1;
|
||||
|
||||
$bundle = $this->dataStore->perform($requests);
|
||||
@@ -1010,7 +977,19 @@ class RemoteMailService {
|
||||
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 {
|
||||
|
||||
@@ -73,13 +73,9 @@ class RemoteService {
|
||||
}
|
||||
// debugging
|
||||
if ($service->getDebug()) {
|
||||
$logDirectory = dirname(__DIR__, 5) . '/var/logs/jmap';
|
||||
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';
|
||||
$logDir = dirname(__DIR__, 5) . '/var/log/jmap/' . $service->identifier() . '.json';
|
||||
$client->configureTransportLogState(true);
|
||||
$client->configureTransportLogLocation($logFile);
|
||||
$client->configureTransportLogLocation($logDir);
|
||||
}
|
||||
// return
|
||||
return $client;
|
||||
|
||||
Generated
+47
-38
@@ -20,7 +20,7 @@
|
||||
"@vitest/ui": "^4.0.18",
|
||||
"@vue/test-utils": "^2.4.10",
|
||||
"@vue/tsconfig": "^0.9.0",
|
||||
"jsdom": "^29.1.1",
|
||||
"jsdom": "^30.0.0",
|
||||
"typescript": "~6.0.0",
|
||||
"vite": "^8.0.0",
|
||||
"vitest": "^4.0.18",
|
||||
@@ -28,48 +28,38 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@asamuzakjp/css-color": {
|
||||
"version": "5.1.11",
|
||||
"version": "6.0.5",
|
||||
"resolved": "https://registry.npmjs.org/@asamuzakjp/css-color/-/css-color-6.0.5.tgz",
|
||||
"integrity": "sha512-mbhpPMmnw/kwW19aRNmSUl1QzLbdGo1SCuE49BT98MNwqF6zaHb3o2owssFc/PEO/4t2UjqtCNwocuDtJornzA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@asamuzakjp/generational-cache": "^1.0.1",
|
||||
"@csstools/css-calc": "^3.2.0",
|
||||
"@csstools/css-color-parser": "^4.1.0",
|
||||
"@csstools/css-calc": "^3.2.1",
|
||||
"@csstools/css-color-parser": "^4.1.9",
|
||||
"@csstools/css-parser-algorithms": "^4.0.0",
|
||||
"@csstools/css-tokenizer": "^4.0.0"
|
||||
"@csstools/css-tokenizer": "^4.0.0",
|
||||
"lru-cache": "^11.5.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^20.19.0 || ^22.12.0 || >=24.0.0"
|
||||
"node": "^22.13.0 || >=24.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@asamuzakjp/dom-selector": {
|
||||
"version": "7.1.1",
|
||||
"version": "8.3.0",
|
||||
"resolved": "https://registry.npmjs.org/@asamuzakjp/dom-selector/-/dom-selector-8.3.0.tgz",
|
||||
"integrity": "sha512-UJLfKXBhrc8i1vH2eJXuYQMwlsLKWFw3O+CPqXSuVEiikeAim3UgrfWX0k4tA/X8cRFM8iZ7OaqBokFGbYusdg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@asamuzakjp/generational-cache": "^1.0.1",
|
||||
"@asamuzakjp/nwsapi": "^2.3.9",
|
||||
"bidi-js": "^1.0.3",
|
||||
"css-tree": "^3.2.1",
|
||||
"is-potential-custom-element-name": "^1.0.1"
|
||||
"is-potential-custom-element-name": "^1.0.1",
|
||||
"lru-cache": "^11.5.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^20.19.0 || ^22.12.0 || >=24.0.0"
|
||||
"node": "^22.13.0 || >=24.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@asamuzakjp/generational-cache": {
|
||||
"version": "1.0.1",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": "^20.19.0 || ^22.12.0 || >=24.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@asamuzakjp/nwsapi": {
|
||||
"version": "2.3.9",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@babel/generator": {
|
||||
"version": "8.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@babel/generator/-/generator-8.0.0.tgz",
|
||||
@@ -1637,37 +1627,39 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/jsdom": {
|
||||
"version": "29.1.1",
|
||||
"version": "30.0.0",
|
||||
"resolved": "https://registry.npmjs.org/jsdom/-/jsdom-30.0.0.tgz",
|
||||
"integrity": "sha512-JQHfRGmmKmaZoUAvIgff5jjG/0SzTQlGz8c7t72KzBzo8ZULEjAjnYE0sNwBOUA4QtWwYE2xoYitg8NFsmiYxA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@asamuzakjp/css-color": "^5.1.11",
|
||||
"@asamuzakjp/dom-selector": "^7.1.1",
|
||||
"@asamuzakjp/css-color": "^6.0.5",
|
||||
"@asamuzakjp/dom-selector": "^8.2.5",
|
||||
"@bramus/specificity": "^2.4.2",
|
||||
"@csstools/css-syntax-patches-for-csstree": "^1.1.3",
|
||||
"@exodus/bytes": "^1.15.0",
|
||||
"@csstools/css-syntax-patches-for-csstree": "^1.1.6",
|
||||
"@exodus/bytes": "^1.15.1",
|
||||
"css-tree": "^3.2.1",
|
||||
"data-urls": "^7.0.0",
|
||||
"decimal.js": "^10.6.0",
|
||||
"html-encoding-sniffer": "^6.0.0",
|
||||
"is-potential-custom-element-name": "^1.0.1",
|
||||
"lru-cache": "^11.3.5",
|
||||
"lru-cache": "^11.5.2",
|
||||
"parse5": "^8.0.1",
|
||||
"saxes": "^6.0.0",
|
||||
"symbol-tree": "^3.2.4",
|
||||
"tough-cookie": "^6.0.1",
|
||||
"undici": "^7.25.0",
|
||||
"tough-cookie": "^6.0.2",
|
||||
"undici": "^8.7.0",
|
||||
"w3c-xmlserializer": "^5.0.0",
|
||||
"webidl-conversions": "^8.0.1",
|
||||
"whatwg-mimetype": "^5.0.0",
|
||||
"whatwg-url": "^16.0.1",
|
||||
"whatwg-url": "^17.1.0",
|
||||
"xml-name-validator": "^5.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^20.19.0 || ^22.13.0 || >=24.0.0"
|
||||
"node": "^22.22.2 || ^24.15.0 || >=26.0.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"canvas": "^3.0.0"
|
||||
"canvas": "^3.2.3"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"canvas": {
|
||||
@@ -1675,6 +1667,21 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/jsdom/node_modules/whatwg-url": {
|
||||
"version": "17.1.0",
|
||||
"resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-17.1.0.tgz",
|
||||
"integrity": "sha512-3GeworPmc2ZfEEHP7lEbUfBX/L75wdEsi0rLNhXcXxnoN5jyq0SL5gCy06SGW2cyTIZdTvWIDQNQoza++vKeaw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@exodus/bytes": "^1.15.1",
|
||||
"tr46": "^6.0.0",
|
||||
"webidl-conversions": "^8.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^22.14.0 || >=24.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/jsesc": {
|
||||
"version": "3.1.0",
|
||||
"license": "MIT",
|
||||
@@ -2631,11 +2638,13 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/undici": {
|
||||
"version": "7.28.0",
|
||||
"version": "8.9.0",
|
||||
"resolved": "https://registry.npmjs.org/undici/-/undici-8.9.0.tgz",
|
||||
"integrity": "sha512-aWZpUj7XoGonMClx4gdDRfgBjqeA+F473aDmROQQbM9n6PRfK/u1q/a0X4wMTgcHfT8H6fpbt98PFuDUwFg2YA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=20.18.1"
|
||||
"node": ">=22.19.0"
|
||||
}
|
||||
},
|
||||
"node_modules/unplugin": {
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@
|
||||
"@vitest/ui": "^4.0.18",
|
||||
"@vue/test-utils": "^2.4.10",
|
||||
"@vue/tsconfig": "^0.9.0",
|
||||
"jsdom": "^29.1.1",
|
||||
"jsdom": "^30.0.0",
|
||||
"typescript": "~6.0.0",
|
||||
"vite": "^8.0.0",
|
||||
"vitest": "^4.0.18",
|
||||
|
||||
@@ -274,7 +274,7 @@ async function initiateOAuth() {
|
||||
variant="outlined"
|
||||
prepend-inner-icon="mdi-account"
|
||||
class="mb-4"
|
||||
autocomplete="off"
|
||||
autocomplete="username"
|
||||
autocorrect="off"
|
||||
autocapitalize="none"
|
||||
:rules="[rules.required]"
|
||||
@@ -289,7 +289,7 @@ async function initiateOAuth() {
|
||||
variant="outlined"
|
||||
prepend-inner-icon="mdi-lock"
|
||||
class="mb-4"
|
||||
autocomplete="new-password"
|
||||
autocomplete="current-password"
|
||||
:rules="[rules.required]"
|
||||
/>
|
||||
</template>
|
||||
|
||||
@@ -25,7 +25,7 @@ const settingGroups = [
|
||||
title: 'Addresses',
|
||||
value: 'addresses' as const,
|
||||
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',
|
||||
@@ -71,7 +71,7 @@ watch(
|
||||
)
|
||||
|
||||
watch(
|
||||
[deleteMode, deleteDestination],
|
||||
[deleteMode, deleteDestination, primaryAddress, secondaryAddresses],
|
||||
() => {
|
||||
const nextService = props.service ?? new ServiceObject()
|
||||
const nextAuxiliary = {
|
||||
@@ -83,9 +83,13 @@ watch(
|
||||
}
|
||||
|
||||
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
|
||||
emit('update:service', nextService)
|
||||
},
|
||||
@@ -107,10 +111,44 @@ function normalizeDeleteDestination(value: string): string {
|
||||
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 {
|
||||
return (current.deleteMode === 'hard' ? 'hard' : 'soft') === next.deleteMode
|
||||
&& (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>
|
||||
|
||||
<template>
|
||||
@@ -138,57 +176,69 @@ function sameAuxiliary(current: Record<string, any>, next: Record<string, any>):
|
||||
<div class="jmap-settings-card">
|
||||
<h3 class="text-h6 mb-2">Addresses</h3>
|
||||
<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>
|
||||
|
||||
<div class="text-subtitle-2 mb-2">Primary Address</div>
|
||||
<div class="d-flex ga-2 mb-6">
|
||||
<v-text-field
|
||||
:model-value="primaryAddress.label"
|
||||
v-model="primaryAddress.label"
|
||||
label="Display Name"
|
||||
variant="outlined"
|
||||
density="compact"
|
||||
hide-details="auto"
|
||||
readonly
|
||||
/>
|
||||
<v-text-field
|
||||
:model-value="primaryAddress.address"
|
||||
v-model="primaryAddress.address"
|
||||
label="Email Address"
|
||||
variant="outlined"
|
||||
density="compact"
|
||||
prepend-inner-icon="mdi-email-outline"
|
||||
:rules="[validAddress]"
|
||||
hide-details="auto"
|
||||
readonly
|
||||
/>
|
||||
</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
|
||||
v-for="(entry, index) in secondaryAddresses"
|
||||
:key="index"
|
||||
class="d-flex ga-2 mb-2"
|
||||
>
|
||||
<v-text-field
|
||||
:model-value="entry.label"
|
||||
v-model="entry.label"
|
||||
label="Display Name"
|
||||
variant="outlined"
|
||||
density="compact"
|
||||
hide-details="auto"
|
||||
readonly
|
||||
/>
|
||||
<v-text-field
|
||||
:model-value="entry.address"
|
||||
v-model="entry.address"
|
||||
label="Email Address"
|
||||
variant="outlined"
|
||||
density="compact"
|
||||
prepend-inner-icon="mdi-email-multiple-outline"
|
||||
:rules="[validAddress]"
|
||||
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>
|
||||
|
||||
<v-btn
|
||||
variant="tonal"
|
||||
prepend-icon="mdi-plus"
|
||||
@click="addSecondaryAddress"
|
||||
>
|
||||
Add Alias
|
||||
</v-btn>
|
||||
</div>
|
||||
</v-window-item>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user