From b9fc1c8244c2f940723703e536686e03104b53ed Mon Sep 17 00:00:00 2001 From: Andris Reinman Date: Wed, 21 May 2014 15:19:18 +0300 Subject: [PATCH] [WO-399] Handle reply-to, in-reply-to and references headers --- src/js/controller/write.js | 39 ++++++++++++++++++++++++-------- test/new-unit/write-ctrl-test.js | 5 +++- 2 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/js/controller/write.js b/src/js/controller/write.js index e78f469..1a906bf 100644 --- a/src/js/controller/write.js +++ b/src/js/controller/write.js @@ -63,7 +63,7 @@ define(function(require) { } function fillFields(re, replyAll, forward) { - var from, sentDate, body; + var replyTo, from, sentDate, body; if (!re) { return; @@ -71,17 +71,26 @@ define(function(require) { $scope.writerTitle = (forward) ? 'Forward' : 'Reply'; - // fill recipient field + replyTo = re.replyTo && re.replyTo[0] && re.replyTo[0].address || re.from[0].address; + + // fill recipient field and references if (!forward) { $scope.to.unshift({ - address: re.from[0].address + address: replyTo }); $scope.to.forEach($scope.verify); + if ((re.references || []).indexOf(re.id) < 0) { + // references might not exist yet, so use the double concat + $scope.references = [].concat(re.references || []).concat(re.id); + } else { + $scope.references = re.references; + } + $scope.inReplyTo = re.id; } if (replyAll) { re.to.concat(re.cc).forEach(function(recipient) { var me = emailDao._account.emailAddress; - if (recipient.address === me && re.from[0].address !== me) { + if (recipient.address === me && replyTo !== me) { // don't reply to yourself return; } @@ -98,11 +107,12 @@ define(function(require) { $scope.cc.forEach($scope.verify); } - // fill attachments on forward + // fill attachments and references on forward if (forward) { - // create a new array, otherwise removing an attachment will also + // create a new array, otherwise removing an attachment will also // remove it from the original in the mail list as a side effect $scope.attachments = [].concat(re.attachments); + $scope.references = [re.id]; } // fill subject @@ -113,7 +123,7 @@ define(function(require) { } // fill text body - from = re.from[0].name || re.from[0].address; + from = re.from[0].name || replyTo; sentDate = $filter('date')(re.sentDate, 'EEEE, MMM d, yyyy h:mm a'); function createString(array) { @@ -292,9 +302,20 @@ define(function(require) { subject: $scope.subject.trim() ? $scope.subject.trim() : str.fallbackSubject, // Subject line, or the fallback subject, if nothing valid was entered body: $scope.body.trim() + (!$scope.sendBtnSecure ? str.signature : ''), // use parsed plaintext body attachments: $scope.attachments, - sentDate: new Date() + sentDate: new Date(), + headers: {} }; + if ($scope.inReplyTo) { + email.headers['in-reply-to'] = '<' + $scope.inReplyTo + '>'; + } + + if ($scope.references && $scope.references.length) { + email.headers.references = $scope.references.map(function(reference) { + return '<' + reference + '>'; + }).join(' '); + } + // close the writer $scope.state.writer.close(); @@ -339,7 +360,7 @@ define(function(require) { }; }; - + // // Helpers // diff --git a/test/new-unit/write-ctrl-test.js b/test/new-unit/write-ctrl-test.js index 70f606a..3b56bc6 100644 --- a/test/new-unit/write-ctrl-test.js +++ b/test/new-unit/write-ctrl-test.js @@ -100,12 +100,14 @@ define(function(require) { subject = 'Ermahgerd!', body = 'so much body!', re = { + id: 'abc', from: [{ address: address }], subject: subject, sentDate: new Date(), - body: body + body: body, + references: ['ghi', 'def'] }; scope.state.writer.write(re); @@ -118,6 +120,7 @@ define(function(require) { }]); expect(scope.subject).to.equal('Re: ' + subject); expect(scope.body).to.contain(body); + expect(scope.references).to.deep.equal(['ghi', 'def', 'abc']); expect(scope.ciphertextPreview).to.not.be.empty; expect(verifyMock.called).to.be.true;