Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
getMessages list, add attachmentsList to response for easier attachme…
Browse files Browse the repository at this point in the history
…nt handling
NickOvt committed Jan 13, 2025

Verified

This commit was signed with the committer’s verified signature.
1 parent 8feae38 commit 35456d7
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
@@ -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
@@ -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,
@@ -4036,6 +4060,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,

0 comments on commit 35456d7

Please sign in to comment.