Skip to content

Commit d186f2b

Browse files
author
Derek Zen
committed
fix: resolve null body content issue
- Ensure bodyStructure is always fetched when enhanced fields are enabled - Add comprehensive debug logging for content extraction troubleshooting - Fix issue where email body content was returning null - Version bump to 2.11.9
1 parent cedc183 commit d186f2b

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
## [2.11.9](https://github.com/callzhang/n8n-nodes-imap/compare/v2.11.8...v2.11.9) (2025-01-XX)
2+
3+
### Bug Fixes
4+
5+
* **Body Content Extraction**: Fixed issue where email body content was returning null when "Include Body" is enabled
6+
* **Body Structure Fetching**: Ensure bodyStructure is always fetched when enhanced fields are enabled
7+
* **Debug Logging**: Added comprehensive debug logging to help troubleshoot content extraction issues
8+
19
## [2.11.8](https://github.com/callzhang/n8n-nodes-imap/compare/v2.11.7...v2.11.8) (2025-01-XX)
210

311
### Improvements

nodes/Imap/operations/email/functions/EmailGetList.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "n8n-nodes-imap-enhanced",
3-
"version": "2.11.8",
3+
"version": "2.11.9",
44
"description": "Enhanced IMAP node with custom labels support, limit parameters, and structured email fields for n8n workflows.",
55
"keywords": [
66
"n8n-community-node-package"

0 commit comments

Comments
 (0)