diff --git a/lib/api/messages.js b/lib/api/messages.js index fbda7631..af86db7b 100644 --- a/lib/api/messages.js +++ b/lib/api/messages.js @@ -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,