Skip to content

Commit

Permalink
fix(handler-filter): Filter handler response includes file content sh…
Browse files Browse the repository at this point in the history
…a256 hash ZMS-176 (#739)

* filter handler response includes file content sha256 hash

* fix tests
  • Loading branch information
NickOvt authored Oct 3, 2024
1 parent 6dac6ae commit 37374be
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
8 changes: 6 additions & 2 deletions imap-core/lib/indexer/indexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -619,17 +619,21 @@ class Indexer {
}

let node = nodes[pos++];
this.attachmentStorage.create(node, (err, id) => {
this.attachmentStorage.create(node, (err, id, fileContentHash) => {
if (err) {
return callback(err);
}
mimeTree.attachmentMap[node.attachmentId] = id;

let attachmentInfo = maildata.attachments && maildata.attachments.find(a => a.id === node.attachmentId);
let attachmentInfo = maildata.attachments && maildata.attachments.find(a => a.id === node.attachmentId); // get reference to attachment info
if (attachmentInfo && node.body) {
attachmentInfo.size = node.body.length;
}

if (fileContentHash) {
attachmentInfo.fileContentHash = fileContentHash;
}

return storeNode();
});
};
Expand Down
6 changes: 6 additions & 0 deletions lib/filter-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,12 @@ class FilterHandler {
if (binaryHash) {
resp.encodedSha256 = binaryHash.toString('base64');
}

let attachmentInfo = maildata.attachments.find(a => a.id === att.id);

if (attachmentInfo && attachmentInfo.fileContentHash) {
resp.fileContentHash = attachmentInfo.fileContentHash;
}
return resp;
})
},
Expand Down
1 change: 1 addition & 0 deletions test/api-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ describe('API tests', function () {
{
contentType: 'image/png',
disposition: 'inline',
fileContentHash: 'SnEfXNA8Cf15ri8Zuy9xFo5xwYt1YmJqGujZnrwyEv8=',
filename: 'attachment-1.png',
hash: '6bb932138c9062004611ca0170d773e78d79154923c5daaf6d8a2f27361c33a2',
id: 'ATT00001',
Expand Down

0 comments on commit 37374be

Please sign in to comment.