From d05d43ec76650287c87cd902146e2fdc06f1434c Mon Sep 17 00:00:00 2001 From: hamza221 Date: Wed, 29 Mar 2023 00:59:21 +0200 Subject: [PATCH 1/5] fix no sent mailbox configured Signed-off-by: hamza221 --- src/components/Composer.vue | 7 ++++ src/components/NewMessageModal.vue | 56 ++++++++++++++++++++++++++++-- 2 files changed, 60 insertions(+), 3 deletions(-) diff --git a/src/components/Composer.vue b/src/components/Composer.vue index 94d9ac646f..a089a7986b 100644 --- a/src/components/Composer.vue +++ b/src/components/Composer.vue @@ -1276,6 +1276,13 @@ export default { this.saveDraftDebounced() }, async onSend(_, force = false) { + const selectedAccount = this.$store.getters.getAccount(this.selectedAlias.id) + if (!selectedAccount?.sentMailboxId) { + this.$emit('new-mailbox-then-send', { + ...this.getMessageData(), + }) + return + } if (this.encrypt) { logger.debug('get encrypted message from mailvelope') await this.$refs.mailvelopeEditor.pull() diff --git a/src/components/NewMessageModal.vue b/src/components/NewMessageModal.vue index 5e79f5c606..9a3bdb537b 100644 --- a/src/components/NewMessageModal.vue +++ b/src/components/NewMessageModal.vue @@ -26,7 +26,7 @@ - @@ -111,7 +111,8 @@ @discard-draft="discardDraft" @upload-attachment="onAttachmentUploading" @send="onSend" - @show-toolbar="handleShow" /> + @show-toolbar="handleShow" + @new-mailbox-then-send="onNewSentMailbox"/>
@@ -127,7 +128,7 @@ import { NcEmptyContent as EmptyContent, NcModal as Modal, } from '@nextcloud/vue' -import { showError, showSuccess } from '@nextcloud/dialogs' +import { showError, showSuccess, showWarning } from '@nextcloud/dialogs' import { translate as t } from '@nextcloud/l10n' import logger from '../logger.js' @@ -177,6 +178,7 @@ export default { savingDraft: false, draftSaved: false, uploadingAttachments: false, + creatingSentMailbox: false, sending: false, error: undefined, warning: undefined, @@ -190,6 +192,7 @@ export default { name: '', email: '', }, + newSentMailboxId: null, } }, computed: { @@ -294,6 +297,53 @@ export default { }, toHtml, plain, + async onNewSentMailbox(data) { + const account = this.$store.getters.getAccount(data.accountId) + showWarning(t('mail', 'Setting Sent default folder')) + this.creatingSentMailbox = true + + logger.info('creating automated_sent mailbox') + await this.$store + .dispatch('createMailbox', { account, name: 'automated_sent' }) + .then((e) => { + logger.info('mailbox Temporary automated_sent created') + this.newSentMailboxId = e.databaseId + }) + .catch((error) => { + this.creatingSentMailbox = false + showError(t('mail', 'Could not create new mailbox, please try setting a sent mailbox manually')) + logger.error('could not create mailbox', { error }) + this.$emit('close') + throw error + }) + + if (this.newSentMailboxId) { + logger.debug('setting sent mailbox to ' + this.newSentMailboxId) + await this.$store.dispatch('patchAccount', { + account, + data: { + sentMailboxId: this.newSentMailboxId, + }, + }) + .then(() => { + logger.debug('Resending message after new setting sent mailbox') + this.onSend(data) + showSuccess(t('mail', 'New sent folder set, resending message')) + }) + .catch((error) => { + showError(t('mail', 'Couldn\'t set sent default folder, please try manually before sending a new message')) + logger.error('could not set sent mailbox', { error }) + this.$emit('close') + }) + .finally(() => { + this.creatingSentMailbox = false + }) + } else { + showError(t('mail', 'Couldn\'t set sent default folder, please try manually before sending a new message')) + this.creatingSentMailbox = false + this.$emit('close') + } + }, /** * @param data Message data * @param {object=} opts Options From de9c8d92f8395358204861618338175a8be1b11a Mon Sep 17 00:00:00 2001 From: hamza221 Date: Mon, 8 May 2023 12:22:51 +0200 Subject: [PATCH 2/5] fixup! fix no sent mailbox configured Signed-off-by: hamza221 --- lib/Controller/MailboxesController.php | 19 ++++++++ lib/Service/MailManager.php | 16 +++++++ src/components/NewMessageModal.vue | 63 ++++++++++++++++---------- src/service/MailboxService.js | 9 ++++ 4 files changed, 84 insertions(+), 23 deletions(-) diff --git a/lib/Controller/MailboxesController.php b/lib/Controller/MailboxesController.php index b3485df6d6..aff593cb12 100644 --- a/lib/Controller/MailboxesController.php +++ b/lib/Controller/MailboxesController.php @@ -289,6 +289,25 @@ public function clearMailbox(int $id): JSONResponse { return new JSONResponse(); } + /** + * @NoAdminRequired + * + * @param int $accountId + * @param string $name + * + * @return JSONResponse + * @throws ClientException + * @throws ServiceException + * @throws \OCP\AppFramework\Db\DoesNotExistException + */ + public function checkMailbox(int $accountId, string $name): JSONResponse { + $account = $this->accountService->find($this->currentUserId, $accountId); + + $mailbox = $this->mailManager->getMailboxByName($account, $name); + + return new JSONResponse($mailbox); + } + /** * Delete all vanished mails that are still cached. */ diff --git a/lib/Service/MailManager.php b/lib/Service/MailManager.php index 0efc64545d..c563ea6eb0 100644 --- a/lib/Service/MailManager.php +++ b/lib/Service/MailManager.php @@ -139,6 +139,22 @@ public function getMailboxes(Account $account): array { return $this->mailboxMapper->findAll($account); } + /** + * @param Account $account + * @param string $name + * + * @return Mailbox + * @throws ServiceException + */ + public function getMailboxByName(Account $account, string $name): int { + try { + $mailbox = $this->mailboxMapper->find($account, $name); + return $mailbox->getId(); + } catch (DoesNotExistException $e) { + return -1; + } + } + /** * @param Account $account * @param string $name diff --git a/src/components/NewMessageModal.vue b/src/components/NewMessageModal.vue index 9a3bdb537b..fbb2ad99ec 100644 --- a/src/components/NewMessageModal.vue +++ b/src/components/NewMessageModal.vue @@ -133,6 +133,7 @@ import { translate as t } from '@nextcloud/l10n' import logger from '../logger.js' import { toPlain, toHtml, plain } from '../util/text.js' +import { getMailboxExists } from '../service/MailboxService' import Composer from './Composer.vue' import { UNDO_DELAY } from '../store/constants.js' import { matchError } from '../errors/match.js' @@ -302,11 +303,25 @@ export default { showWarning(t('mail', 'Setting Sent default folder')) this.creatingSentMailbox = true + // check if sent mailbox already exists + let sentMailboxId = await getMailboxExists(data.accountId, account.personalNamespace + 'Sent').catch((error) => { + this.creatingSentMailbox = false + showError(t('mail', 'Could not set Sent default folder, Please try manually')) + logger.error('could not find sent mailbox', { error }) + this.$emit('close') + }) + if (sentMailboxId < 0) { + sentMailboxId = await getMailboxExists(data.accountId, account.personalNamespace + t('mail', 'Sent')) + } + if (sentMailboxId > 0) { + await this.setSentMailboxAndResend(account, sentMailboxId, data) + return + } logger.info('creating automated_sent mailbox') await this.$store - .dispatch('createMailbox', { account, name: 'automated_sent' }) + .dispatch('createMailbox', { account, name: account.personalNamespace + t('mail', 'Sent') }) .then((e) => { - logger.info('mailbox Temporary automated_sent created') + logger.info(`mailbox ${account.personalNamespace + t('mail', 'Sent')} created`) this.newSentMailboxId = e.databaseId }) .catch((error) => { @@ -314,36 +329,38 @@ export default { showError(t('mail', 'Could not create new mailbox, please try setting a sent mailbox manually')) logger.error('could not create mailbox', { error }) this.$emit('close') - throw error }) if (this.newSentMailboxId) { - logger.debug('setting sent mailbox to ' + this.newSentMailboxId) - await this.$store.dispatch('patchAccount', { - account, - data: { - sentMailboxId: this.newSentMailboxId, - }, - }) - .then(() => { - logger.debug('Resending message after new setting sent mailbox') - this.onSend(data) - showSuccess(t('mail', 'New sent folder set, resending message')) - }) - .catch((error) => { - showError(t('mail', 'Couldn\'t set sent default folder, please try manually before sending a new message')) - logger.error('could not set sent mailbox', { error }) - this.$emit('close') - }) - .finally(() => { - this.creatingSentMailbox = false - }) + await this.setSentMailboxAndResend(account, this.newSentMailboxId, data) } else { showError(t('mail', 'Couldn\'t set sent default folder, please try manually before sending a new message')) this.creatingSentMailbox = false this.$emit('close') } }, + + async setSentMailboxAndResend(account, id, data) { + logger.debug('setting sent mailbox to ' + id) + await this.$store.dispatch('patchAccount', { + account, + data: { + sentMailboxId: id, + }, + }).then(() => { + logger.debug('Resending message after new setting sent mailbox') + this.onSend(data) + showSuccess(t('mail', 'New sent folder set, resending message')) + }) + .catch((error) => { + showError(t('mail', 'Couldn\'t set sent default folder, please try manually before sending a new message')) + logger.error('could not set sent mailbox', { error }) + this.$emit('close') + }) + .finally(() => { + this.creatingSentMailbox = false + }) + }, /** * @param data Message data * @param {object=} opts Options diff --git a/src/service/MailboxService.js b/src/service/MailboxService.js index ff5f42f030..863f8192af 100644 --- a/src/service/MailboxService.js +++ b/src/service/MailboxService.js @@ -35,6 +35,15 @@ export function getMailboxStatus(id) { return axios.get(url).then((resp) => resp.data) } +export function getMailboxExists(id, name) { + const url = generateUrl('/apps/mail/api/mailboxes/{id}/name/{name}', { + id, + name, + }) + + return axios.get(url).then((resp) => resp.data) +} + export function markMailboxRead(id) { const url = generateUrl('/apps/mail/api/mailboxes/{id}/read', { id, From 48edd0eb46948dd121a99c51dbd42ea6580c5152 Mon Sep 17 00:00:00 2001 From: hamza221 Date: Tue, 9 May 2023 00:42:19 +0200 Subject: [PATCH 3/5] fixup! fix no sent mailbox configured Signed-off-by: hamza221 --- lib/Service/MailManager.php | 16 ---------------- src/components/NewMessageModal.vue | 17 ++++------------- src/service/MailboxService.js | 9 --------- 3 files changed, 4 insertions(+), 38 deletions(-) diff --git a/lib/Service/MailManager.php b/lib/Service/MailManager.php index c563ea6eb0..0efc64545d 100644 --- a/lib/Service/MailManager.php +++ b/lib/Service/MailManager.php @@ -139,22 +139,6 @@ public function getMailboxes(Account $account): array { return $this->mailboxMapper->findAll($account); } - /** - * @param Account $account - * @param string $name - * - * @return Mailbox - * @throws ServiceException - */ - public function getMailboxByName(Account $account, string $name): int { - try { - $mailbox = $this->mailboxMapper->find($account, $name); - return $mailbox->getId(); - } catch (DoesNotExistException $e) { - return -1; - } - } - /** * @param Account $account * @param string $name diff --git a/src/components/NewMessageModal.vue b/src/components/NewMessageModal.vue index fbb2ad99ec..2dabdb2c79 100644 --- a/src/components/NewMessageModal.vue +++ b/src/components/NewMessageModal.vue @@ -302,18 +302,9 @@ export default { const account = this.$store.getters.getAccount(data.accountId) showWarning(t('mail', 'Setting Sent default folder')) this.creatingSentMailbox = true - - // check if sent mailbox already exists - let sentMailboxId = await getMailboxExists(data.accountId, account.personalNamespace + 'Sent').catch((error) => { - this.creatingSentMailbox = false - showError(t('mail', 'Could not set Sent default folder, Please try manually')) - logger.error('could not find sent mailbox', { error }) - this.$emit('close') - }) - if (sentMailboxId < 0) { - sentMailboxId = await getMailboxExists(data.accountId, account.personalNamespace + t('mail', 'Sent')) - } - if (sentMailboxId > 0) { + const mailboxes = this.$store.getters.getMailboxes(data.accountId) + const sentMailboxId = mailboxes.find((mailbox) => mailbox.name === account.personalNamespace + 'Sent' || mailbox.name === account.personalNamespace + t('mail', 'Sent'))?.databaseId + if (sentMailboxId) { await this.setSentMailboxAndResend(account, sentMailboxId, data) return } @@ -350,7 +341,7 @@ export default { }).then(() => { logger.debug('Resending message after new setting sent mailbox') this.onSend(data) - showSuccess(t('mail', 'New sent folder set, resending message')) + showSuccess(t('mail', 'Sent folder set, resending message')) }) .catch((error) => { showError(t('mail', 'Couldn\'t set sent default folder, please try manually before sending a new message')) diff --git a/src/service/MailboxService.js b/src/service/MailboxService.js index 863f8192af..ff5f42f030 100644 --- a/src/service/MailboxService.js +++ b/src/service/MailboxService.js @@ -35,15 +35,6 @@ export function getMailboxStatus(id) { return axios.get(url).then((resp) => resp.data) } -export function getMailboxExists(id, name) { - const url = generateUrl('/apps/mail/api/mailboxes/{id}/name/{name}', { - id, - name, - }) - - return axios.get(url).then((resp) => resp.data) -} - export function markMailboxRead(id) { const url = generateUrl('/apps/mail/api/mailboxes/{id}/read', { id, From 40f8232c6558c586c9f8fb14ce1ddef7bf5b01f7 Mon Sep 17 00:00:00 2001 From: hamza221 Date: Tue, 9 May 2023 00:45:48 +0200 Subject: [PATCH 4/5] fixup! fix no sent mailbox configured Signed-off-by: hamza221 Signed-off-by: Hamza Mahjoubi --- lib/Controller/MailboxesController.php | 19 ------ src/components/AccountDefaultsSettings.vue | 2 +- src/components/Composer.vue | 7 -- src/components/NewMessageModal.vue | 77 ++++++++++------------ 4 files changed, 35 insertions(+), 70 deletions(-) diff --git a/lib/Controller/MailboxesController.php b/lib/Controller/MailboxesController.php index aff593cb12..b3485df6d6 100644 --- a/lib/Controller/MailboxesController.php +++ b/lib/Controller/MailboxesController.php @@ -289,25 +289,6 @@ public function clearMailbox(int $id): JSONResponse { return new JSONResponse(); } - /** - * @NoAdminRequired - * - * @param int $accountId - * @param string $name - * - * @return JSONResponse - * @throws ClientException - * @throws ServiceException - * @throws \OCP\AppFramework\Db\DoesNotExistException - */ - public function checkMailbox(int $accountId, string $name): JSONResponse { - $account = $this->accountService->find($this->currentUserId, $accountId); - - $mailbox = $this->mailManager->getMailboxByName($account, $name); - - return new JSONResponse($mailbox); - } - /** * Delete all vanished mails that are still cached. */ diff --git a/src/components/AccountDefaultsSettings.vue b/src/components/AccountDefaultsSettings.vue index ff6254db51..fc2ad748ad 100644 --- a/src/components/AccountDefaultsSettings.vue +++ b/src/components/AccountDefaultsSettings.vue @@ -104,7 +104,7 @@ export default { await this.mainStore.patchAccount({ account: this.account, data: { - sentMailboxId, + sentMailboxId: null, }, }) } catch (error) { diff --git a/src/components/Composer.vue b/src/components/Composer.vue index a089a7986b..94d9ac646f 100644 --- a/src/components/Composer.vue +++ b/src/components/Composer.vue @@ -1276,13 +1276,6 @@ export default { this.saveDraftDebounced() }, async onSend(_, force = false) { - const selectedAccount = this.$store.getters.getAccount(this.selectedAlias.id) - if (!selectedAccount?.sentMailboxId) { - this.$emit('new-mailbox-then-send', { - ...this.getMessageData(), - }) - return - } if (this.encrypt) { logger.debug('get encrypted message from mailvelope') await this.$refs.mailvelopeEditor.pull() diff --git a/src/components/NewMessageModal.vue b/src/components/NewMessageModal.vue index 2dabdb2c79..80b5445eaf 100644 --- a/src/components/NewMessageModal.vue +++ b/src/components/NewMessageModal.vue @@ -26,7 +26,7 @@ - @@ -111,8 +111,7 @@ @discard-draft="discardDraft" @upload-attachment="onAttachmentUploading" @send="onSend" - @show-toolbar="handleShow" - @new-mailbox-then-send="onNewSentMailbox"/> + @show-toolbar="handleShow" />
@@ -133,7 +132,6 @@ import { translate as t } from '@nextcloud/l10n' import logger from '../logger.js' import { toPlain, toHtml, plain } from '../util/text.js' -import { getMailboxExists } from '../service/MailboxService' import Composer from './Composer.vue' import { UNDO_DELAY } from '../store/constants.js' import { matchError } from '../errors/match.js' @@ -179,7 +177,6 @@ export default { savingDraft: false, draftSaved: false, uploadingAttachments: false, - creatingSentMailbox: false, sending: false, error: undefined, warning: undefined, @@ -193,7 +190,6 @@ export default { name: '', email: '', }, - newSentMailboxId: null, } }, computed: { @@ -298,59 +294,50 @@ export default { }, toHtml, plain, - async onNewSentMailbox(data) { - const account = this.$store.getters.getAccount(data.accountId) + async onNewSentMailbox(data, account) { showWarning(t('mail', 'Setting Sent default folder')) - this.creatingSentMailbox = true - const mailboxes = this.$store.getters.getMailboxes(data.accountId) + let newSentMailboxId = null + const mailboxes = this.mainStore.getMailboxes(data.accountId) const sentMailboxId = mailboxes.find((mailbox) => mailbox.name === account.personalNamespace + 'Sent' || mailbox.name === account.personalNamespace + t('mail', 'Sent'))?.databaseId if (sentMailboxId) { await this.setSentMailboxAndResend(account, sentMailboxId, data) - return } - logger.info('creating automated_sent mailbox') - await this.$store - .dispatch('createMailbox', { account, name: account.personalNamespace + t('mail', 'Sent') }) - .then((e) => { - logger.info(`mailbox ${account.personalNamespace + t('mail', 'Sent')} created`) - this.newSentMailboxId = e.databaseId - }) - .catch((error) => { - this.creatingSentMailbox = false - showError(t('mail', 'Could not create new mailbox, please try setting a sent mailbox manually')) - logger.error('could not create mailbox', { error }) - this.$emit('close') - }) + logger.info(`creating ${t('mail', 'Sent')} mailbox`) + try { + const newSentMailbox = await this.mainStore.createMailbox({ account, name: account.personalNamespace + t('mail', 'Sent') }) + logger.info(`mailbox ${account.personalNamespace + t('mail', 'Sent')} created`) + newSentMailboxId = newSentMailbox.databaseId + } catch (error) { + showError(t('mail', 'Could not create new mailbox, please try setting a sent mailbox manually')) + logger.error('could not create mailbox', { error }) + this.$emit('close') + } - if (this.newSentMailboxId) { - await this.setSentMailboxAndResend(account, this.newSentMailboxId, data) + if (newSentMailboxId) { + await this.setSentMailboxAndResend(account, newSentMailboxId, data) } else { showError(t('mail', 'Couldn\'t set sent default folder, please try manually before sending a new message')) - this.creatingSentMailbox = false this.$emit('close') } }, async setSentMailboxAndResend(account, id, data) { logger.debug('setting sent mailbox to ' + id) - await this.$store.dispatch('patchAccount', { - account, - data: { - sentMailboxId: id, - }, - }).then(() => { + try { + await this.mainStore.patchAccount({ + account, + data: { + sentMailboxId: id, + }, + }) logger.debug('Resending message after new setting sent mailbox') this.onSend(data) showSuccess(t('mail', 'Sent folder set, resending message')) - }) - .catch((error) => { - showError(t('mail', 'Couldn\'t set sent default folder, please try manually before sending a new message')) - logger.error('could not set sent mailbox', { error }) - this.$emit('close') - }) - .finally(() => { - this.creatingSentMailbox = false - }) + } catch (error) { + showError(t('mail', 'Couldn\'t set sent default folder, please try manually before sending a new message')) + logger.error('could not set sent mailbox', { error }) + this.$emit('close') + } }, /** * @param data Message data @@ -450,6 +437,11 @@ export default { .catch((error) => logger.error('could not upload attachments', { error })) }, async onSend(data, force = false) { + const account = this.mainStore.getAccount(data.accountId) + if (!account?.sentMailboxId) { + this.onNewSentMailbox(data, account) + return + } logger.debug('sending message', { data }) await this.attachmentsPromise @@ -553,7 +545,6 @@ export default { } // Sync sent mailbox when it's currently open - const account = this.mainStore.getAccount(data.accountId) if (account && parseInt(this.$route.params.mailboxId, 10) === account.sentMailboxId) { setTimeout(() => { this.mainStore.syncEnvelopes({ From b5984359f79fff884db6227f5e749e073e9d5d91 Mon Sep 17 00:00:00 2001 From: Hamza Mahjoubi Date: Fri, 7 Mar 2025 17:51:58 +0100 Subject: [PATCH 5/5] fixup! fix no sent mailbox configured Signed-off-by: Hamza Mahjoubi --- src/components/AccountDefaultsSettings.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/AccountDefaultsSettings.vue b/src/components/AccountDefaultsSettings.vue index fc2ad748ad..ff6254db51 100644 --- a/src/components/AccountDefaultsSettings.vue +++ b/src/components/AccountDefaultsSettings.vue @@ -104,7 +104,7 @@ export default { await this.mainStore.patchAccount({ account: this.account, data: { - sentMailboxId: null, + sentMailboxId, }, }) } catch (error) {