fix(imap client): harden IMAP client message processing and modernize test tooling

This commit is contained in:
2026-05-01 16:59:04 +00:00
parent 98263058bf
commit 13ca27db86
12 changed files with 4285 additions and 6059 deletions
+1 -1
View File
@@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@push.rocks/smartimap',
version: '1.2.0',
version: '1.2.1',
description: 'A Node.js library for event-driven streaming and parsing of IMAP email messages.'
}
+7 -1
View File
@@ -68,6 +68,9 @@ export class ImapClient extends plugins.events.EventEmitter {
try {
const searchResult = await this.client.search(this.filter);
if (!searchResult) {
return;
}
// Convert searchResult to a regular array
const searchResultArray = Array.from(searchResult);
@@ -80,6 +83,9 @@ export class ImapClient extends plugins.events.EventEmitter {
// Fetch messages
for await (const message of this.client.fetch(newUids, { envelope: true, source: true })) {
if (!message.source) {
continue;
}
const parsed = await plugins.mailparser.simpleParser(message.source);
this.emit('message', parsed);
this.seenUids.add(message.uid);
@@ -102,4 +108,4 @@ export class ImapClient extends plugins.events.EventEmitter {
this.emit('disconnected');
}
}
}
}
+2 -1
View File
@@ -145,7 +145,8 @@ export class ImapServer {
}
}
} catch (error) {
response = `${tag} BAD Error: ${error.message}`;
const errorMessage = error instanceof Error ? error.message : String(error);
response = `${tag} BAD Error: ${errorMessage}`;
}
socket.write(response + "\r\n");