feat(core): Introduce ImapClient and ImapServer classes for enhanced IMAP support

This commit is contained in:
2024-11-26 22:58:26 +01:00
parent d3cc3ef9a5
commit 9c42210acd
9 changed files with 3706 additions and 506 deletions

View File

@ -2,10 +2,10 @@ import { expect, expectAsync, tap } from '@push.rocks/tapbundle';
import { tapNodeTools } from '@push.rocks/tapbundle/node';
import * as smartimap from '../ts/index.js';
let testSmartImap: smartimap.SmartImap;
let testSmartImap: smartimap.ImapClient;
tap.test('smartimap', async () => {
testSmartImap = new smartimap.SmartImap({
testSmartImap = new smartimap.ImapClient({
host: await tapNodeTools.getEnvVarOnDemand('IMAP_URL'),
port: 993,
secure: true,
@ -13,14 +13,14 @@ tap.test('smartimap', async () => {
user: await tapNodeTools.getEnvVarOnDemand('IMAP_USER'),
pass: await tapNodeTools.getEnvVarOnDemand('IMAP_PASSWORD'),
},
mailbox: 'buchhaltung',
mailbox: 'INBOX',
filter: { seen: true, to: await tapNodeTools.getEnvVarOnDemand('IMAP_USER'), },
});
await testSmartImap.connect();
testSmartImap.on('message', (message) => {
console.log(message);
testSmartImap.on('message', (message: smartimap.SmartImapMessage) => {
console.log(message.subject);
});
testSmartImap.on('error', (error) => {

29
test/test.imapserver.ts Normal file
View File

@ -0,0 +1,29 @@
import { tap, expect, expectAsync } from '@push.rocks/tapbundle';
import { jestExpect } from '@push.rocks/tapbundle/node';
import { ImapServer } from '../ts/classes.imapserver.js';
tap.test('imapserver', async () => {
// Example usage
const imapServer = new ImapServer();
imapServer.addUser('testuser', 'password');
imapServer.createInbox('testuser', 'INBOX');
imapServer.createInbox('testuser', 'Sent');
// Add a sample message
const testUser = imapServer.users.get('testuser')!;
const inbox = testUser.inboxes.get('INBOX')!;
inbox.messages.push({
id: '1',
subject: 'Welcome',
sender: 'no-reply@example.com',
recipient: 'testuser@example.com',
date: new Date(),
body: 'Welcome to your new IMAP inbox!',
});
// Start the server on port 143 (commonly used for IMAP)
// imapServer.start(143);
});
tap.start();