@@ -262,6 +262,14 @@ export const getEmailsListOperation: IResourceOperationDef = {
262262 context . logger ?. debug ( `Search object: ${ JSON . stringify ( searchObject ) } ` ) ;
263263 context . logger ?. debug ( `Fetch query: ${ JSON . stringify ( fetchQuery ) } ` ) ;
264264
265+ // get enhanced fields parameter
266+ const enhancedFields = context . getNodeParameter ( 'enhancedFields' , itemIndex ) as boolean ;
267+
268+ // if enhanced fields are enabled, we need bodyStructure to extract content
269+ if ( enhancedFields ) {
270+ fetchQuery . bodyStructure = true ;
271+ }
272+
265273 // get limit parameter
266274 const limit = context . getNodeParameter ( 'limit' , itemIndex ) as number ;
267275
@@ -281,9 +289,6 @@ export const getEmailsListOperation: IResourceOperationDef = {
281289 }
282290 context . logger ?. info ( `Found ${ emailsList . length } emails` ) ;
283291
284- // get enhanced fields parameter
285- const enhancedFields = context . getNodeParameter ( 'enhancedFields' , itemIndex ) as boolean ;
286-
287292 // process the emails
288293 for ( const email of emailsList ) {
289294 context . logger ?. info ( ` ${ email . uid } ` ) ;
@@ -334,15 +339,19 @@ export const getEmailsListOperation: IResourceOperationDef = {
334339 var textPartId = null ;
335340 var htmlPartId = null ;
336341 var attachmentsInfo = [ ] ;
342+
343+ context . logger ?. debug ( `Analyzing body structure for email ${ email . uid } : ${ analyzeBodyStructure } ` ) ;
337344
338345
339346 if ( analyzeBodyStructure ) {
340347 // workaround: dispositionParameters is an object, but it is not typed as such
341348 const bodyStructure = email . bodyStructure as unknown as any ;
342349
343350 if ( bodyStructure ) {
351+ context . logger ?. debug ( `Body structure found for email ${ email . uid } : ${ JSON . stringify ( bodyStructure ) } ` ) ;
344352
345353 const partsInfo = getEmailPartsInfoRecursive ( context , bodyStructure ) ;
354+ context . logger ?. debug ( `Parts info for email ${ email . uid } : ${ JSON . stringify ( partsInfo ) } ` ) ;
346355
347356 // filter attachments and text/html parts
348357 for ( const partInfo of partsInfo ) {
@@ -360,12 +369,16 @@ export const getEmailsListOperation: IResourceOperationDef = {
360369 // in that case, ImapFlow uses "TEXT" as partId to download the only part
361370 if ( partInfo . type === 'text/plain' ) {
362371 textPartId = partInfo . partId || "TEXT" ;
372+ context . logger ?. debug ( `Found text part for email ${ email . uid } : ${ textPartId } ` ) ;
363373 }
364374 if ( partInfo . type === 'text/html' ) {
365375 htmlPartId = partInfo . partId || "TEXT" ;
376+ context . logger ?. debug ( `Found HTML part for email ${ email . uid } : ${ htmlPartId } ` ) ;
366377 }
367378 }
368379 }
380+ } else {
381+ context . logger ?. warn ( `No body structure found for email ${ email . uid } ` ) ;
369382 }
370383 }
371384
0 commit comments