Skip to content

Commit

Permalink
warn about missing attachments
Browse files Browse the repository at this point in the history
Signed-off-by: Maximilian Martin <[email protected]>
  • Loading branch information
max65482 authored and GretaD committed Sep 29, 2023
1 parent 2b9be83 commit e2f9310
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 42 deletions.
96 changes: 54 additions & 42 deletions src/components/NewMessageModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,27 @@
<Loading v-else-if="sending"
:hint="t('mail', 'Sending …')"
role="alert" />
<EmptyContent v-else-if="warning" :title="t('mail', 'Warning sending your message')" role="alert">
<p>{{ warning }}</p>
<ButtonVue
type="tertiary"
:aria-label="t('mail', 'Go back')"
@click="warning = undefined">
{{ t('mail', 'Go back') }}
</ButtonVue>
<ButtonVue
type="tertiary"
:aria-label="t('mail', 'Send anyway')"
@click="onForceSend">
{{ t('mail', 'Send anyway') }}
</ButtonVue>
<EmptyContent v-else-if="warning"
:title="t('mail', 'Warning sending your message')"
class="centered-content"
role="alert">
<template #description>
{{ warning }}
</template>
<template #action>
<ButtonVue
type="tertiary"
:aria-label="t('mail', 'Go back')"
@click="warning = undefined">
{{ t('mail', 'Go back') }}
</ButtonVue>
<ButtonVue
type="tertiary"
:aria-label="t('mail', 'Send anyway')"
@click="onForceSend">
{{ t('mail', 'Send anyway') }}
</ButtonVue>
</template>
</EmptyContent>
<template v-else>
<NcActions class="minimize-button">
Expand Down Expand Up @@ -75,7 +82,6 @@
:smime-encrypt="composerData.smimeEncrypt"
:is-first-open="modalFirstOpen"
:request-mdn="composerData.requestMdn"
:accounts="accounts"
@update:from-account="patchComposerData({ accountId: $event })"
@update:from-alias="patchComposerData({ aliasId: $event })"
@update:to="patchComposerData({ to: $event })"
Expand Down Expand Up @@ -114,6 +120,7 @@ import { UNDO_DELAY } from '../store/constants'
import { matchError } from '../errors/match'
import NoSentMailboxConfiguredError from '../errors/NoSentMailboxConfiguredError'
import ManyRecipientsError from '../errors/ManyRecipientsError'
import AttachmentMissingError from '../errors/AttachmentMissingError.js'
import Loading from './Loading'
import { mapGetters } from 'vuex'
import MinimizeIcon from 'vue-material-design-icons/Minus.vue'
Expand All @@ -131,12 +138,6 @@ export default {
NcActionButton,
MinimizeIcon,
},
props: {
accounts: {
type: Array,
required: true,
},
},
data() {
return {
toolbarElements: undefined,
Expand Down Expand Up @@ -219,7 +220,7 @@ export default {
let idToReturn
const dataForServer = this.getDataForServer(data, true)
if (!id) {
const { id } = await saveDraft(dataForServer)
const { id } = await saveDraft(data.account, dataForServer)
dataForServer.id = id
await this.$store.dispatch('patchComposerData', { id, draftId: dataForServer.draftId })
this.canSaveDraft = true
Expand Down Expand Up @@ -290,7 +291,7 @@ export default {
.then(() => logger.debug('attachments uploaded'))
.catch((error) => logger.error('could not upload attachments', { error }))
},
async onSend(data) {
async onSend(data, force = false) {
logger.debug('sending message', { data })
await this.attachmentsPromise
Expand All @@ -313,27 +314,30 @@ export default {
dataForServer.sendAt = Math.floor((now + UNDO_DELAY) / 1000)
}
if (!force && data.attachments.length === 0) {
const lines = toPlain(data.body).value.toLowerCase().split('\n')
const wordAttachment = t('mail', 'attachment').toLowerCase()
const wordAttached = t('mail', 'attached').toLowerCase()
for (const line of lines) {
if (line.startsWith('>') || line.startsWith('--')) {
break
}
if (line.includes(wordAttachment) || line.includes(wordAttached)) {
throw new AttachmentMissingError()
}
}
}
if (!this.composerData.id) {
// This is a new message
const { id } = await saveDraft(dataForServer)
const { id } = await saveDraft(data.account, dataForServer)
dataForServer.id = id
await this.$store.dispatch('outbox/enqueueFromDraft', {
draftMessage: dataForServer,
id,
})
} else if (this.composerData.type === 0) {
// This is an outbox message
dataForServer.id = this.composerData.id
await this.$store.dispatch('outbox/updateMessage', {
await this.$store.dispatch('outbox/enqueueMessage', {
message: dataForServer,
id: this.composerData.id,
})
} else {
// This is a draft
await updateDraft(dataForServer)
dataForServer.id = this.composerData.id
await this.$store.dispatch('outbox/enqueueFromDraft', {
draftMessage: dataForServer,
await this.$store.dispatch('outbox/updateMessage', {
message: dataForServer,
id: this.composerData.id,
})
}
Expand All @@ -358,9 +362,17 @@ export default {
return t('mail', 'You are trying to send to many recipients in To and/or Cc. Consider using Bcc to hide recipient addresses.')
},
default(error) {
if (error && error.toString) {
return error.toString()
}
logger.error('You are trying to send to many recipients in To and/or Cc. Consider using Bcc to hide recipient addresses.', error)
return t('mail', 'You are trying to send to many recipients in To and/or Cc. Consider using Bcc to hide recipient addresses.')
},
})
this.warning = await matchError(error, {
[AttachmentMissingError.getName()]() {
return t('mail', 'You mentioned an attachment. Did you forget to add it?')
},
default(error) {
logger.error('You mentioned an attachment. Did you forget to add it?', error)
return t('mail', 'You mentioned an attachment. Did you forget to add it?')
},
})
} finally {
Expand All @@ -380,7 +392,7 @@ export default {
}
},
async onForceSend() {
await this.onSend(null, true)
await this.onSend(this.cookedComposerData, true)
},
recipientToRfc822(recipient) {
if (recipient.email === recipient.label) {
Expand Down
32 changes: 32 additions & 0 deletions src/errors/AttachmentMissingError.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* @author 2023 Maximilian Martin <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

export default class AttachmentMissingError extends Error {

constructor(message) {
super(message)
this.name = AttachmentMissingError.getName()
this.message = message
}

static getName() {
return 'AttachmentMissingError'
}

}

0 comments on commit e2f9310

Please sign in to comment.