dcrouter/test/suite/smtpclient_rfc-compliance/test.crfc-02.esmtp-compliance.ts

77 lines
2.4 KiB
TypeScript
Raw Permalink Normal View History

2025-05-24 17:00:59 +00:00
import { expect, tap } from '@git.zone/tstest/tapbundle';
2025-05-26 14:50:55 +00:00
import { createTestServer } from '../../helpers/server.loader.js';
import { createTestSmtpClient } from '../../helpers/smtp.client.js';
import { Email } from '../../../ts/mail/core/classes.email.js';
2025-05-24 17:00:59 +00:00
2025-05-26 14:50:55 +00:00
tap.test('CRFC-02: Basic ESMTP Compliance', async () => {
console.log('\n📧 Testing SMTP Client ESMTP Compliance');
console.log('=' .repeat(60));
2025-05-24 17:00:59 +00:00
2025-05-26 14:50:55 +00:00
const testServer = await createTestServer({});
2025-05-24 17:00:59 +00:00
2025-05-26 14:50:55 +00:00
try {
const smtpClient = createTestSmtpClient({
2025-05-24 17:00:59 +00:00
host: testServer.hostname,
2025-05-26 14:50:55 +00:00
port: testServer.port
2025-05-24 17:00:59 +00:00
});
2025-05-26 14:50:55 +00:00
console.log('\nTest 1: Basic EHLO negotiation');
const email1 = new Email({
2025-05-24 17:00:59 +00:00
from: 'sender@example.com',
to: ['recipient@example.com'],
subject: 'ESMTP test',
2025-05-26 14:50:55 +00:00
text: 'Testing ESMTP'
2025-05-24 17:00:59 +00:00
});
2025-05-26 14:50:55 +00:00
const result1 = await smtpClient.sendMail(email1);
console.log(' ✓ EHLO negotiation successful');
expect(result1).toBeDefined();
2025-05-24 17:00:59 +00:00
2025-05-26 14:50:55 +00:00
console.log('\nTest 2: Multiple recipients');
const email2 = new Email({
2025-05-24 17:00:59 +00:00
from: 'sender@example.com',
2025-05-26 14:50:55 +00:00
to: ['recipient1@example.com', 'recipient2@example.com'],
cc: ['cc@example.com'],
bcc: ['bcc@example.com'],
subject: 'Multiple recipients',
text: 'Testing multiple recipients'
2025-05-24 17:00:59 +00:00
});
2025-05-26 14:50:55 +00:00
const result2 = await smtpClient.sendMail(email2);
console.log(' ✓ Multiple recipients handled');
expect(result2).toBeDefined();
2025-05-24 17:00:59 +00:00
2025-05-26 14:50:55 +00:00
console.log('\nTest 3: UTF-8 content');
const email3 = new Email({
2025-05-24 17:00:59 +00:00
from: 'sender@example.com',
to: ['recipient@example.com'],
2025-05-26 14:50:55 +00:00
subject: 'UTF-8: café ☕ 测试',
text: 'International text: émojis 🎉, 日本語',
html: '<p>HTML: <strong>Zürich</strong></p>'
2025-05-24 17:00:59 +00:00
});
2025-05-26 14:50:55 +00:00
const result3 = await smtpClient.sendMail(email3);
console.log(' ✓ UTF-8 content accepted');
expect(result3).toBeDefined();
2025-05-24 17:00:59 +00:00
2025-05-26 14:50:55 +00:00
console.log('\nTest 4: Long headers');
const longSubject = 'This is a very long subject line that exceeds 78 characters and should be properly folded according to RFC 2822';
const email4 = new Email({
2025-05-24 17:00:59 +00:00
from: 'sender@example.com',
to: ['recipient@example.com'],
2025-05-26 14:50:55 +00:00
subject: longSubject,
text: 'Testing header folding'
2025-05-24 17:00:59 +00:00
});
2025-05-26 14:50:55 +00:00
const result4 = await smtpClient.sendMail(email4);
console.log(' ✓ Long headers handled');
expect(result4).toBeDefined();
2025-05-24 17:00:59 +00:00
2025-05-26 14:50:55 +00:00
console.log('\n✅ CRFC-02: ESMTP compliance tests completed');
2025-05-24 17:00:59 +00:00
2025-05-26 14:50:55 +00:00
} finally {
testServer.server.close();
}
});
2025-05-24 17:00:59 +00:00
2025-05-26 14:50:55 +00:00
tap.start();