diff --git a/src/ReplyBuilder.js b/src/ReplyBuilder.js index 8833a80fe92acc737223a8bf4b718aca0405b5bd..fe57b6335e3370a207ca489978f77ee6cfde6df7 100644 --- a/src/ReplyBuilder.js +++ b/src/ReplyBuilder.js @@ -75,27 +75,32 @@ export const buildRecipients = (envelope, ownAddress) => { let to = [] let cc = [] if (recipientType === RecipientType.To) { - // Send to everyone except yourself plus the original sender + // Send to everyone except yourself, plus the original sender if not ourself to = envelope.to.filter(isNotOwnAddress) - to = to.concat(envelope.from) + to = to.concat(envelope.from.filter(isNotOwnAddress)) // CC remains the same cc = envelope.cc } else if (recipientType === RecipientType.Cc) { - // Send to the same people plus the sender - to = envelope.to.concat(envelope.from) + // Send to the same people, plus the sender if not ourself + to = envelope.to.concat(envelope.from.filter(isNotOwnAddress)) // All CC values are being kept except the replying address cc = envelope.cc.filter(isNotOwnAddress) } else { - // Send to the same recipient and the sender -> answer all + // Send to the same recipient and the sender (if not ourself) -> answer all to = envelope.to - to = to.concat(envelope.from) + to = to.concat(envelope.from.filter(isNotOwnAddress)) // Keep CC values cc = envelope.cc } + // edge case: pure self-sent email + if (to.length == 0) { + to = envelope.from + } + return { to, from: replyingAddress ? [replyingAddress] : [], diff --git a/src/components/NewMessageDetail.vue b/src/components/NewMessageDetail.vue index db355730315e1e9cd5a9d8546f07d9bf853c9d43..0a5b405982316cca7f6d0118e6557972a4ae1b9b 100644 --- a/src/components/NewMessageDetail.vue +++ b/src/components/NewMessageDetail.vue @@ -28,7 +28,13 @@ import AppContentDetails from '@nextcloud/vue/dist/Components/AppContentDetails' import Axios from '@nextcloud/axios' import {generateUrl} from '@nextcloud/router' -import {buildForwardSubject, buildHtmlReplyBody, buildReplyBody, buildReplySubject} from '../ReplyBuilder' +import { + buildForwardSubject, + buildHtmlReplyBody, + buildReplyBody, + buildReplySubject, + buildRecipients as buildReplyRecipients, +} from '../ReplyBuilder' import Composer from './Composer' import {getRandomMessageErrorMessage} from '../util/ErrorMessageFactory' import Error from './Error' @@ -71,22 +77,30 @@ export default { const message = this.original Logger.debug('forwarding or replying to message', {message}) - // message headers set for 'reply' actions by default - let subject = buildReplySubject(message.subject) - let msgTo = message.from - let msgCc = [] - if (this.$route.params.messageUid === 'replyAll') { - msgCc = message.to.concat(message.cc) - } else if (this.$route.params.messageUid !== 'reply') { + let subject = '' + let replyRecipients = {} + if (this.$route.params.messageUid === 'reply') { + Logger.debug('simple reply') + subject = buildReplySubject(message.subject) + replyRecipients.to = message.from + } else if (this.$route.params.messageUid === 'replyAll') { + Logger.debug('replying to all') + Logger.debug('replying to all: original', {original: this.original}) + subject = buildReplySubject(message.subject) + const account = this.$store.getters.getAccount(message.accountId) + replyRecipients = buildReplyRecipients(message, { + email: account.emailAddress, + label: account.name, + }) + } else { // forward subject = buildForwardSubject(message.subject) - msgTo = [] } return { accountId: message.accountId, - to: msgTo, - cc: msgCc, + to: replyRecipients.to, + cc: replyRecipients.cc, subject: subject, body: this.getForwardReplyBody(), } diff --git a/src/tests/unit/ReplyBuilder.spec.js b/src/tests/unit/ReplyBuilder.spec.js index df1419bcbc6dbe99635d583acb96b4eb3f1ad29d..6905e53e26a57d42e777d16fb4b507dd874fb002 100644 --- a/src/tests/unit/ReplyBuilder.spec.js +++ b/src/tests/unit/ReplyBuilder.spec.js @@ -181,6 +181,50 @@ describe('ReplyBuilder', () => { assertSameAddressList(reply.cc, []) }) + it('removes original sender for recipients list when same as replier (self-sent email)', () => { + const a = createAddress('a@domain.tld') + const b = createAddress('b@domain.tld') + envelope.from = [a] + envelope.to = [a, b] + envelope.cc = [] + + var reply = buildRecipients(envelope, a) + + assertSameAddressList(reply.from, [a]) + assertSameAddressList(reply.to, [b]) + assertSameAddressList(reply.cc, []) + }) + + it('removes original sender for recipients list when same as replier (self-sent email) with many CC', () => { + const a = createAddress('a@domain.tld') + const b = createAddress('b@domain.tld') + const c = createAddress('c@domain.tld') + const d = createAddress('d@domain.tld') + const e = createAddress('e@domain.tld') + envelope.from = [a] + envelope.to = [b, c] + envelope.cc = [a, d, e] + + const reply = buildRecipients(envelope, a) + + assertSameAddressList(reply.from, [a]) + assertSameAddressList(reply.to, [b, c]) + assertSameAddressList(reply.cc, [d, e]) + }) + + it('pure self-sent email', () => { + const a = createAddress('a@domain.tld') + envelope.from = [a] + envelope.to = [a] + envelope.cc = [] + + var reply = buildRecipients(envelope, a) + + assertSameAddressList(reply.from, [a]) + assertSameAddressList(reply.to, [a]) + assertSameAddressList(reply.cc, []) + }) + it('adds re: to a reply subject', () => { const orig = 'Hello'