Compare commits
7 Commits
791825b318
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
| f39dd75ae5 | |||
| b60341f62d | |||
| 4cd249d019 | |||
| 152a8141d0 | |||
| 5aa95fa329 | |||
| f0b0f87ce2 | |||
| 75a462ad18 |
Generated
+7
-7
@@ -1442,16 +1442,16 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "phpunit/phpunit",
|
"name": "phpunit/phpunit",
|
||||||
"version": "12.5.32",
|
"version": "12.5.31",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/sebastianbergmann/phpunit.git",
|
"url": "https://github.com/sebastianbergmann/phpunit.git",
|
||||||
"reference": "c02591dd7840ed124a98d7770753329ad28e9f8f"
|
"reference": "0608d157a284f15cc73b99a3327eff06b66a176d"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/c02591dd7840ed124a98d7770753329ad28e9f8f",
|
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/0608d157a284f15cc73b99a3327eff06b66a176d",
|
||||||
"reference": "c02591dd7840ed124a98d7770753329ad28e9f8f",
|
"reference": "0608d157a284f15cc73b99a3327eff06b66a176d",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
@@ -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.32"
|
"source": "https://github.com/sebastianbergmann/phpunit/tree/12.5.31"
|
||||||
},
|
},
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
@@ -1528,7 +1528,7 @@
|
|||||||
"type": "other"
|
"type": "other"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"time": "2026-07-25T06:54:13+00:00"
|
"time": "2026-07-06T14:54:16+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "sebastian/cli-parser",
|
"name": "sebastian/cli-parser",
|
||||||
@@ -2556,5 +2556,5 @@
|
|||||||
"platform-overrides": {
|
"platform-overrides": {
|
||||||
"php": "8.3"
|
"php": "8.3"
|
||||||
},
|
},
|
||||||
"plugin-api-version": "2.9.0"
|
"plugin-api-version": "2.6.0"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -879,7 +897,31 @@ class Service implements ServiceBaseInterface, ServiceMutableInterface, ServiceC
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$nativeMessage = $this->normalizeMessageProperties($message)->toJmap();
|
$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();
|
||||||
$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(
|
||||||
|
|||||||
@@ -912,23 +912,44 @@ 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): string {
|
||||||
|
|
||||||
$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);
|
||||||
|
$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);
|
||||||
$submission = $r1->create($submissionCreateId);
|
$r1->completionUpdate('#' . $messageId, [
|
||||||
$submission->identity($identityId);
|
'mailboxIds/' . $postSentTarget => true,
|
||||||
$submission->message('#' . $messageCreateId);
|
'mailboxIds/' . $preSendTarget => null,
|
||||||
|
'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') {
|
||||||
@@ -937,7 +958,19 @@ 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -953,18 +986,18 @@ class RemoteMailService {
|
|||||||
$requests = [];
|
$requests = [];
|
||||||
|
|
||||||
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);
|
$s0 = $r1->create($submissionId);
|
||||||
$submission->identity($identityId);
|
$s0->identity($identityId);
|
||||||
$submission->message($draftId);
|
$s0->message($draftId);
|
||||||
$requests[] = $r1;
|
$requests[] = $r1;
|
||||||
|
|
||||||
$bundle = $this->dataStore->perform($requests);
|
$bundle = $this->dataStore->perform($requests);
|
||||||
@@ -977,19 +1010,7 @@ 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();
|
|
||||||
$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 {
|
||||||
|
|||||||
@@ -73,9 +73,13 @@ class RemoteService {
|
|||||||
}
|
}
|
||||||
// debugging
|
// debugging
|
||||||
if ($service->getDebug()) {
|
if ($service->getDebug()) {
|
||||||
$logDir = dirname(__DIR__, 5) . '/var/log/jmap/' . $service->identifier() . '.json';
|
$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';
|
||||||
$client->configureTransportLogState(true);
|
$client->configureTransportLogState(true);
|
||||||
$client->configureTransportLogLocation($logDir);
|
$client->configureTransportLogLocation($logFile);
|
||||||
}
|
}
|
||||||
// return
|
// return
|
||||||
return $client;
|
return $client;
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user