Skip to content

Commit

Permalink
fixup! fix no sent mailbox configured
Browse files Browse the repository at this point in the history
Signed-off-by: hamza221 <[email protected]>
  • Loading branch information
hamza221 committed Mar 7, 2025
1 parent 48edd0e commit 3913ba7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/components/AccountDefaultsSettings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export default {
await this.mainStore.patchAccount({
account: this.account,
data: {
sentMailboxId,
sentMailboxId: null,
},
})
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/Composer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1276,7 +1276,7 @@ export default {
this.saveDraftDebounced()
},
async onSend(_, force = false) {
const selectedAccount = this.$store.getters.getAccount(this.selectedAlias.id)
const selectedAccount = this.mainStore.getAccount(this.selectedAlias.id)
if (!selectedAccount?.sentMailboxId) {
this.$emit('new-mailbox-then-send', {
...this.getMessageData(),
Expand Down
63 changes: 30 additions & 33 deletions src/components/NewMessageModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@
@discard-draft="discardDraft"
@upload-attachment="onAttachmentUploading"
@send="onSend"
@show-toolbar="handleShow"
@new-mailbox-then-send="onNewSentMailbox"/>
@show-toolbar="handleShow"
@new-mailbox-then-send="onNewSentMailbox" />
</div>

<div v-if="showRecipientPane" class="right-pane">
Expand All @@ -133,7 +133,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'
Expand Down Expand Up @@ -299,28 +298,26 @@ export default {
toHtml,
plain,
async onNewSentMailbox(data) {
const account = this.$store.getters.getAccount(data.accountId)
const account = this.mainStore.getAccount(data.accountId)
showWarning(t('mail', 'Setting Sent default folder'))
this.creatingSentMailbox = true
const mailboxes = this.$store.getters.getMailboxes(data.accountId)
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`)
this.newSentMailboxId = newSentMailbox.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')
}

if (this.newSentMailboxId) {
await this.setSentMailboxAndResend(account, this.newSentMailboxId, data)
Expand All @@ -333,24 +330,24 @@ export default {

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')
} finally {
this.creatingSentMailbox = false
}

},
/**
* @param data Message data
Expand Down

0 comments on commit 3913ba7

Please sign in to comment.