@@ -392,6 +392,28 @@ module.exports = (db, server, messageHandler, userHandler, storageHandler, setti
392392 idate : Joi . date ( ) . description ( 'Date string of receive time' ) ,
393393 intro : Joi . string ( ) . required ( ) . description ( 'First 128 bytes of the message' ) ,
394394 attachments : booleanSchema . required ( ) . description ( 'Does the message have attachments' ) ,
395+ attachmentsList : Joi . array ( )
396+ . items (
397+ Joi . object ( {
398+ id : Joi . string ( ) . required ( ) . description ( 'Attachment ID' ) ,
399+ hash : Joi . string ( ) . description ( 'SHA-256 hash of the contents of the attachment' ) ,
400+ filename : Joi . string ( ) . required ( ) . description ( 'Filename of the attachment' ) ,
401+ contentType : Joi . string ( ) . required ( ) . description ( 'MIME type' ) ,
402+ disposition : Joi . string ( ) . required ( ) . description ( 'Attachment disposition' ) ,
403+ transferEncoding : Joi . string ( )
404+ . required ( )
405+ . description (
406+ 'Which transfer encoding was used (actual content when fetching attachments is not encoded)'
407+ ) ,
408+ related : booleanSchema
409+ . required ( )
410+ . description (
411+ 'Was this attachment found from a multipart/related node. This usually means that this is an embedded image'
412+ ) ,
413+ sizeKb : Joi . number ( ) . required ( ) . description ( 'Approximate size of the attachment in kilobytes' )
414+ } )
415+ )
416+ . description ( 'Attachments for the message' ) ,
395417 size : Joi . number ( ) . required ( ) . description ( 'Message size in bytes' ) ,
396418 seen : booleanSchema . required ( ) . description ( 'Is this message already seen or not' ) ,
397419 deleted : booleanSchema
@@ -525,10 +547,12 @@ module.exports = (db, server, messageHandler, userHandler, storageHandler, setti
525547 msgid : true ,
526548 mailbox : true ,
527549 [ result . value . metaData ? 'meta' : 'meta.from' ] : true ,
550+ 'mimeTree.attachmentMap' : true ,
528551 hdate : true ,
529552 idate : true ,
530553 subject : true ,
531554 ha : true ,
555+ attachments : true ,
532556 size : true ,
533557 intro : true ,
534558 unseen : true ,
@@ -4037,6 +4061,13 @@ function formatMessageListing(messageData, includeHeaders) {
40374061 idate : messageData . idate ? messageData . idate . toISOString ( ) : null ,
40384062 intro : messageData . intro ,
40394063 attachments : ! ! messageData . ha ,
4064+ attachmentsList : ( messageData . attachments || [ ] ) . map ( attachmentData => {
4065+ let hash = messageData . mimeTree && messageData . mimeTree . attachmentMap && messageData . mimeTree . attachmentMap [ attachmentData . id ] ;
4066+ if ( ! hash ) {
4067+ return attachmentData ;
4068+ }
4069+ return Object . assign ( { hash : hash . toString ( 'hex' ) } , attachmentData ) ;
4070+ } ) ,
40404071 size : messageData . size ,
40414072 seen : ! messageData . unseen ,
40424073 deleted : ! messageData . undeleted ,
0 commit comments