Skip to content

Commit

Permalink
fix(api-getMessagesList): getMessages list, add attachmentsList to re…
Browse files Browse the repository at this point in the history
…sponse for easier attachment handling ZMS-195 (#773)
  • Loading branch information
NickOvt authored Jan 27, 2025
1 parent d3e2f14 commit 959c707
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions lib/api/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,28 @@ module.exports = (db, server, messageHandler, userHandler, storageHandler, setti
idate: Joi.date().description('Date string of receive time'),
intro: Joi.string().required().description('First 128 bytes of the message'),
attachments: booleanSchema.required().description('Does the message have attachments'),
attachmentsList: Joi.array()
.items(
Joi.object({
id: Joi.string().required().description('Attachment ID'),
hash: Joi.string().description('SHA-256 hash of the contents of the attachment'),
filename: Joi.string().required().description('Filename of the attachment'),
contentType: Joi.string().required().description('MIME type'),
disposition: Joi.string().required().description('Attachment disposition'),
transferEncoding: Joi.string()
.required()
.description(
'Which transfer encoding was used (actual content when fetching attachments is not encoded)'
),
related: booleanSchema
.required()
.description(
'Was this attachment found from a multipart/related node. This usually means that this is an embedded image'
),
sizeKb: Joi.number().required().description('Approximate size of the attachment in kilobytes')
})
)
.description('Attachments for the message'),
size: Joi.number().required().description('Message size in bytes'),
seen: booleanSchema.required().description('Is this message already seen or not'),
deleted: booleanSchema
Expand Down Expand Up @@ -525,10 +547,12 @@ module.exports = (db, server, messageHandler, userHandler, storageHandler, setti
msgid: true,
mailbox: true,
[result.value.metaData ? 'meta' : 'meta.from']: true,
'mimeTree.attachmentMap': true,
hdate: true,
idate: true,
subject: true,
ha: true,
attachments: true,
size: true,
intro: true,
unseen: true,
Expand Down Expand Up @@ -4037,6 +4061,13 @@ function formatMessageListing(messageData, includeHeaders) {
idate: messageData.idate ? messageData.idate.toISOString() : null,
intro: messageData.intro,
attachments: !!messageData.ha,
attachmentsList: (messageData.attachments || []).map(attachmentData => {
let hash = messageData.mimeTree && messageData.mimeTree.attachmentMap && messageData.mimeTree.attachmentMap[attachmentData.id];
if (!hash) {
return attachmentData;
}
return Object.assign({ hash: hash.toString('hex') }, attachmentData);
}),
size: messageData.size,
seen: !messageData.unseen,
deleted: !messageData.undeleted,
Expand Down

0 comments on commit 959c707

Please sign in to comment.