From 40f8232c6558c586c9f8fb14ce1ddef7bf5b01f7 Mon Sep 17 00:00:00 2001 From: hamza221 Date: Tue, 9 May 2023 00:45:48 +0200 Subject: [PATCH] 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({