mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 20:45:00 -05:00
Email that comes back is handled in WeKan instead of landing in the administrator's own inbox. Admin Panel -> E-mail -> Bounces: hard bounces (a mistyped invited address), soft bounces, automatic replies and spam complaints, each with actions done after a count - list it, stop emailing the address, tell who invited it, delete the invitation, ignore - as listmonk and Discourse do it, and the list of addresses that bounced, which an admin clears to email them again. Amazon SES Bounce and Complaint notifications and mail SES receives arrive through SNS at /api/inbound-email/ses, signature-checked against Amazon's certificate and accepted only from the topics the Admin Panel lists. Delivery status notifications and out-of-office replies arriving by IMAP, a provider webhook or a Sandstorm grain are bounces too, never cards. Admin Panel -> Problems -> Email shows what went wrong sending or receiving: a send the mail server refused or could not reach, an IMAP mailbox that cannot be read (never with its password), an unreadable email, an email for a board that no longer takes email. Attempts stay in Problems -> Security. The inbound email endpoints no longer need the whole REST API turned on. Runtime tests run WeKan's own transports against local SMTP and IMAP servers over TCP, a real Sandstorm Maildir, the webhook over HTTP and signed SNS messages; UI tests drive the Email and Chat views, the email-to-card settings and the Bounces page. They found and this fixes: every whole-message parse failed in the server bundle (nodemailer's addressparser resolved to its ESM build), the Chat view's drag and drop never started (dragscroll took the mouse) and dropped a card into the target's previous list, and the Chat panes did not follow a change to a right-to-left language. Thanks to xet7 ! Fixes #794, Fixes #3948.
66 lines
2.6 KiB
JavaScript
66 lines
2.6 KiB
JavaScript
// A local SMTP server for the email runtime tests: WeKan's real mail
|
|
// transport (nodemailer, as the Admin Panel's SMTP settings install it) talks
|
|
// to it over a real TCP socket, and every message it accepts is kept for the
|
|
// test to read. `reject` makes it refuse the message after DATA, the way a
|
|
// mail server refuses a sender or a size. Nothing is relayed anywhere.
|
|
import net from 'node:net';
|
|
|
|
export function startFakeSmtpServer({ reject = null } = {}) {
|
|
const messages = [];
|
|
const sockets = new Set();
|
|
let rejectWith = reject;
|
|
const server = net.createServer(socket => {
|
|
sockets.add(socket);
|
|
socket.on('close', () => sockets.delete(socket));
|
|
socket.on('error', () => {});
|
|
socket.setEncoding('utf8');
|
|
const send = line => socket.write(`${line}\r\n`);
|
|
send('220 localhost fake SMTP');
|
|
let pending = '';
|
|
let data = null;
|
|
let envelope = { from: '', to: [] };
|
|
socket.on('data', chunk => {
|
|
pending += chunk;
|
|
let end;
|
|
while ((end = pending.indexOf('\r\n')) !== -1) {
|
|
const line = pending.slice(0, end);
|
|
pending = pending.slice(end + 2);
|
|
if (data !== null) {
|
|
if (line === '.') {
|
|
const raw = data.join('\r\n');
|
|
data = null;
|
|
if (rejectWith) {
|
|
send(rejectWith);
|
|
} else {
|
|
messages.push({ ...envelope, raw });
|
|
send('250 2.0.0 queued');
|
|
}
|
|
envelope = { from: '', to: [] };
|
|
} else {
|
|
data.push(line.startsWith('..') ? line.slice(1) : line);
|
|
}
|
|
continue;
|
|
}
|
|
const command = line.slice(0, 4).toUpperCase();
|
|
if (command === 'EHLO') { send('250-localhost'); send('250 8BITMIME'); }
|
|
else if (command === 'HELO') send('250 localhost');
|
|
else if (command === 'MAIL') { envelope.from = (line.match(/<([^>]*)>/) || [])[1] || ''; send('250 OK'); }
|
|
else if (command === 'RCPT') { envelope.to.push((line.match(/<([^>]*)>/) || [])[1] || ''); send('250 OK'); }
|
|
else if (command === 'DATA') { data = []; send('354 go ahead'); }
|
|
else if (command === 'QUIT') { send('221 bye'); socket.end(); }
|
|
else if (command === 'RSET') { envelope = { from: '', to: [] }; send('250 OK'); }
|
|
else send('250 OK');
|
|
}
|
|
});
|
|
});
|
|
return new Promise(resolve => server.listen(0, '127.0.0.1', () => resolve({
|
|
port: server.address().port,
|
|
messages,
|
|
rejectWith(line) { rejectWith = line; },
|
|
close() {
|
|
for (const socket of sockets) socket.destroy();
|
|
return new Promise(done => server.close(() => done()));
|
|
},
|
|
})));
|
|
}
|