fix(imap client): harden IMAP client message processing and modernize test tooling
This commit is contained in:
@@ -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.'
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user