diff options
author | Cyrille Bollu <cyrpub@bollu.be> | 2020-01-23 15:57:48 +0300 |
---|---|---|
committer | Cyrille Bollu <cyrpub@bollu.be> | 2020-01-23 15:57:48 +0300 |
commit | a91f14ef631458f9633ea58ea870ab833035adca (patch) | |
tree | ba96f642f5877e0144a967d52dc70751179e4b2e /src | |
parent | 63dde264eedf2fa4d08207ce2db73abaa33a971e (diff) |
- Adds a unit test for ReplyBuilder.js for when original sender is the same as replier (self-sent emails)
- Fixes an edge-case for ReplyBuilder.js
Signed-off-by: Cyrille Bollu <cyrpub@bollu.be>
Diffstat (limited to 'src')
-rw-r--r-- | src/ReplyBuilder.js | 5 | ||||
-rw-r--r-- | src/tests/unit/ReplyBuilder.spec.js | 44 |
2 files changed, 49 insertions, 0 deletions
diff --git a/src/ReplyBuilder.js b/src/ReplyBuilder.js index d29c4d70c..fe57b6335 100644 --- a/src/ReplyBuilder.js +++ b/src/ReplyBuilder.js @@ -96,6 +96,11 @@ export const buildRecipients = (envelope, ownAddress) => { 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/tests/unit/ReplyBuilder.spec.js b/src/tests/unit/ReplyBuilder.spec.js index df1419bcb..6905e53e2 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' |