Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix no sent mailbox configured #8311

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 51 additions & 2 deletions src/components/NewMessageModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,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'
Expand Down Expand Up @@ -294,6 +294,51 @@ export default {
},
toHtml,
plain,
async onNewSentMailbox(data, account) {
showWarning(t('mail', 'Setting Sent default folder'))
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit. first look for the localized, then search for Sent. this ensures that the localized takes priority.

if (sentMailboxId) {
await this.setSentMailboxAndResend(account, sentMailboxId, data)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm missing a return or anything else that leaves this method after setting the existing mailbox

}
logger.info(`creating ${t('mail', 'Sent')} mailbox`)
try {
const newSentMailbox = await this.mainStore.createMailbox({ account, name: account.personalNamespace + t('mail', 'Sent') })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the IMAP server supports it (likely) we should also set the specialuse attribute to \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 (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.$emit('close')
}
},

async setSentMailboxAndResend(account, id, data) {
logger.debug('setting sent mailbox to ' + id)
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')
}
},
/**
* @param data Message data
* @param {object=} opts Options
Expand Down Expand Up @@ -392,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
Expand Down Expand Up @@ -495,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({
Expand Down
Loading