diff --git a/src/components/NewMessageModal.vue b/src/components/NewMessageModal.vue
index d43eef0149..092763f9b2 100644
--- a/src/components/NewMessageModal.vue
+++ b/src/components/NewMessageModal.vue
@@ -30,20 +30,27 @@
-
- {{ warning }}
-
- {{ t('mail', 'Go back') }}
-
-
- {{ t('mail', 'Send anyway') }}
-
+
+
+ {{ warning }}
+
+
+
+ {{ t('mail', 'Go back') }}
+
+
+ {{ t('mail', 'Send anyway') }}
+
+
@@ -114,6 +121,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'
@@ -290,7 +298,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
@@ -313,6 +321,20 @@ 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)
@@ -325,7 +347,6 @@ export default {
// This is an outbox message
dataForServer.id = this.composerData.id
await this.$store.dispatch('outbox/updateMessage', {
- message: dataForServer,
id: this.composerData.id,
})
} else {
@@ -357,10 +378,18 @@ export default {
[ManyRecipientsError.getName()]() {
return t('mail', 'You are trying to send to many recipients in To and/or Cc. Consider using Bcc to hide recipient addresses.')
},
+ // eslint-disable-next-line node/handle-callback-err
default(error) {
- if (error && error.toString) {
- return error.toString()
- }
+ return undefined
+ },
+ })
+ this.warning = await matchError(error, {
+ [AttachmentMissingError.getName()]() {
+ return t('mail', 'You mentioned an attachment. Did you forget to add it?')
+ },
+ // eslint-disable-next-line node/handle-callback-err
+ default(error) {
+ return undefined
},
})
} finally {
@@ -380,7 +409,7 @@ export default {
}
},
async onForceSend() {
- await this.onSend(null, true)
+ await this.onSend(this.cookedComposerData, true)
},
recipientToRfc822(recipient) {
if (recipient.email === recipient.label) {
diff --git a/src/errors/AttachmentMissingError.js b/src/errors/AttachmentMissingError.js
new file mode 100644
index 0000000000..c00c3b0136
--- /dev/null
+++ b/src/errors/AttachmentMissingError.js
@@ -0,0 +1,32 @@
+/**
+ * @author 2023 Maximilian Martin
+ *
+ * @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 .
+ */
+
+export default class AttachmentMissingError extends Error {
+
+ constructor(message) {
+ super(message)
+ this.name = AttachmentMissingError.getName()
+ this.message = message
+ }
+
+ static getName() {
+ return 'AttachmentMissingError'
+ }
+
+}