Skip to content

Commit bf57cf5

Browse files
Warren Choisyandris9
authored andcommitted
Fixes resolveContent with streams overriding data
1 parent 91108d7 commit bf57cf5

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

lib/shared/index.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,11 @@ module.exports.resolveContent = (data, key, callback) => {
327327
}
328328
// we can't stream twice the same content, so we need
329329
// to replace the stream object with the streaming result
330-
data[key] = value;
330+
if (data[key].content) {
331+
data[key].content = value;
332+
} else {
333+
data[key] = value;
334+
}
331335
callback(null, value);
332336
});
333337
} else if (/^https?:\/\//i.test(content.path || content.href)) {

test/shared/shared-test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,30 @@ describe('Shared Funcs Tests', function () {
200200
});
201201
});
202202

203+
it('should set content from a stream and preserve other properties', function (done) {
204+
let mail = {
205+
data: {
206+
attachment: {
207+
filename: 'message.html',
208+
content: fs.createReadStream(__dirname + '/fixtures/message.html')
209+
}
210+
}
211+
};
212+
shared.resolveContent(mail.data, 'attachment', function (err, value) {
213+
expect(err).to.not.exist;
214+
expect(mail).to.deep.equal({
215+
data: {
216+
attachment: {
217+
filename: 'message.html',
218+
content: Buffer.from('<p>Tere, tere</p><p>vana kere!</p>\n')
219+
}
220+
}
221+
});
222+
expect(value).to.deep.equal(Buffer.from('<p>Tere, tere</p><p>vana kere!</p>\n'));
223+
done();
224+
});
225+
});
226+
203227
it('should return an error', function (done) {
204228
let mail = {
205229
data: {

0 commit comments

Comments
 (0)