Skip to content

Commit 3187571

Browse files
committed
fix: handle non-iterable messageInfo.attachments in mailbox sync
Add defensive || [] fallback when iterating over messageInfo.attachments to prevent TypeError when attachments is undefined or null. This fixes crashes during processNew, publishSyncedEvents, and other sync operations when processing messages without attachments. Affected locations: - ARF complaint attachment download (line 780) - Inline attachment fetching (line 1088) - CID-referenced attachment collection (lines 1380, 2317)
1 parent 533f026 commit 3187571

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

lib/email-client/imap/mailbox.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ class Mailbox {
777777
if (this.mightBeAComplaint(messageInfo)) {
778778
try {
779779
// Download relevant attachments for ARF parsing
780-
for (let attachment of messageInfo.attachments) {
780+
for (let attachment of messageInfo.attachments || []) {
781781
if (!['message/feedback-report', 'message/rfc822-headers', 'message/rfc822'].includes(attachment.contentType)) {
782782
continue;
783783
}
@@ -1085,7 +1085,7 @@ class Mailbox {
10851085
// Fetch inline attachments referenced in HTML
10861086
if (messageInfo.attachments?.length && messageInfo.text?.html) {
10871087
// fetch inline attachments
1088-
for (let attachment of messageInfo.attachments) {
1088+
for (let attachment of messageInfo.attachments || []) {
10891089
if (attachment.encodedSize && attachment.encodedSize > MAX_INLINE_ATTACHMENT_SIZE) {
10901090
// skip large attachments
10911091
continue;
@@ -1377,7 +1377,7 @@ class Mailbox {
13771377
let partList = [];
13781378

13791379
// Collect CID-referenced attachments
1380-
for (let attachment of messageInfo.attachments) {
1380+
for (let attachment of messageInfo.attachments || []) {
13811381
let contentId = attachment.contentId && attachment.contentId.replace(/^<|>$/g, '');
13821382
if (contentId && messageInfo.text.html.indexOf(contentId) >= 0) {
13831383
attachmentList.set(contentId, {
@@ -2314,7 +2314,7 @@ class Mailbox {
23142314
let partList = [];
23152315

23162316
// Find images referenced by CID
2317-
for (let attachment of messageInfo.attachments) {
2317+
for (let attachment of messageInfo.attachments || []) {
23182318
let contentId = attachment.contentId && attachment.contentId.replace(/^<|>$/g, '');
23192319
if (contentId && messageInfo.text.html.indexOf(contentId) >= 0) {
23202320
attachmentList.set(contentId, { attachment, content: null });

0 commit comments

Comments
 (0)