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]>
Signed-off-by: Hamza Mahjoubi <[email protected]>
  • Loading branch information
hamza221 committed Mar 7, 2025
1 parent 48edd0e commit 40f8232
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 70 deletions.
19 changes: 0 additions & 19 deletions lib/Controller/MailboxesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
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
7 changes: 0 additions & 7 deletions src/components/Composer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
77 changes: 34 additions & 43 deletions src/components/NewMessageModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</NcButton>
</template>
</EmptyContent>
<Loading v-else-if="uploadingAttachments || creatingSentMailbox"
<Loading v-else-if="uploadingAttachments"
:hint="t('mail', 'Uploading attachments …')"
role="alert" />
<Loading v-else-if="sending" :hint="t('mail', 'Sending …')" role="alert" />
Expand Down Expand Up @@ -111,8 +111,7 @@
@discard-draft="discardDraft"
@upload-attachment="onAttachmentUploading"
@send="onSend"
@show-toolbar="handleShow"
@new-mailbox-then-send="onNewSentMailbox"/>
@show-toolbar="handleShow" />
</div>

<div v-if="showRecipientPane" class="right-pane">
Expand All @@ -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'
Expand Down Expand Up @@ -179,7 +177,6 @@ export default {
savingDraft: false,
draftSaved: false,
uploadingAttachments: false,
creatingSentMailbox: false,
sending: false,
error: undefined,
warning: undefined,
Expand All @@ -193,7 +190,6 @@ export default {
name: '',
email: '',
},
newSentMailboxId: null,
}
},
computed: {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit 40f8232

Please sign in to comment.