diff --git a/src/js/controller/write.js b/src/js/controller/write.js index d476ce2..75631c0 100644 --- a/src/js/controller/write.js +++ b/src/js/controller/write.js @@ -98,6 +98,13 @@ define(function(require) { $scope.cc.forEach($scope.verify); } + // fill attachments on forward + if (forward) { + // 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); + } + // fill subject if (forward) { $scope.subject = 'Fwd: ' + re.subject; diff --git a/test/new-unit/write-ctrl-test.js b/test/new-unit/write-ctrl-test.js index 79d5d5a..70f606a 100644 --- a/test/new-unit/write-ctrl-test.js +++ b/test/new-unit/write-ctrl-test.js @@ -124,6 +124,40 @@ define(function(require) { scope.verify.restore(); }); + it('should prefill write view for forward', function() { + var verifyMock = sinon.stub(scope, 'verify'), + address = 'pity@dafool', + subject = 'Ermahgerd!', + body = 'so much body!', + re = { + from: [{ + address: address + }], + to: [{ + address: address + }], + subject: subject, + sentDate: new Date(), + body: body, + attachments: [{}] + }; + + scope.state.writer.write(re, null, true); + + expect(scope.writerTitle).to.equal('Forward'); + expect(scope.to).to.deep.equal([{ + address: '' + }]); + expect(scope.subject).to.equal('Fwd: ' + subject); + expect(scope.body).to.contain(body); + expect(scope.ciphertextPreview).to.not.be.empty; + expect(verifyMock.called).to.be.true; + expect(scope.attachments).to.not.equal(re.attachments); // not the same reference + expect(scope.attachments).to.deep.equal(re.attachments); // but the same content + + scope.verify.restore(); + }); + }); describe('onAddressUpdate', function() {