Files
wekan/tests/inboundEmailQuoteStrip.test.cjs
T
Lauri Ojansivu 0c7524db05 Add reply-by-email: replying to a notification email comments on the card.
WeKan only ever sent email; there was no way to receive it, so replying to a
notification email went nowhere. This adds the webhook-based half of #2414 -
not an IMAP-polling mail client, which would need a running mailbox,
credentials and a polling loop the self-hoster would have to operate. Instead
a self-hoster points a mail provider's inbound-parse webhook (Mailgun Routes,
SendGrid Inbound Parse, Postmark inbound - documented in
docs/Features/Email/Reply-By-Email.md) at a new POST /api/inbound-email.

Every outbound notification email's Reply-To now carries
reply+<cardId>-<hmac>@<domain> (server/lib/inboundEmailReplyToken.js), the
HMAC keyed by INBOUND_EMAIL_HMAC_SECRET so it cannot be forged or guessed.
The webhook verifies that token, resolves the card, strips the reply's quoted
text (server/lib/inboundEmailQuoteStrip.js), matches the sender's address to
an existing WeKan user (server/lib/inboundEmailUserMatch.js - no match is
rejected, never an anonymous comment), and inserts a CardComments document.

Unauthenticated by design, so every rejection (bad/forged token, unmatched
sender) is logged via securityLog under the new authn.inbound-email catalog
key, wrapped so logging can never break the guard.

Both INBOUND_EMAIL_HMAC_SECRET and INBOUND_EMAIL_DOMAIN are opt-in; unset
(the default), no Reply-To is added and existing installs are unchanged.

Thanks to vasyugan and xet7 !

Closes #2414,
2026-09-10 20:51:52 +03:00

50 lines
2.0 KiB
JavaScript

'use strict';
// Plain-Node unit test (no Meteor) for #2414 reply-by-email's reply-quote
// stripping heuristic: server/lib/inboundEmailQuoteStrip.js.
// Run: node tests/inboundEmailQuoteStrip.test.cjs
const assert = require('assert');
const { stripQuotedReply } = require('../server/lib/inboundEmailQuoteStrip.js');
let passed = 0;
function test(name, fn) { fn(); passed += 1; console.log(' ok -', name); }
test('cuts at "On ... wrote:" (Gmail/Apple Mail style)', () => {
const body = 'Sounds good, will do.\n\nOn Tue, Sep 9, 2026 at 3:00 PM Alice <alice@example.com> wrote:\n> original message text\n> more quoted text';
assert.strictEqual(stripQuotedReply(body), 'Sounds good, will do.');
});
test('cuts at a ">" quoted line', () => {
const body = 'My reply text here.\n> quoted line one\n> quoted line two';
assert.strictEqual(stripQuotedReply(body), 'My reply text here.');
});
test('cuts at "-----Original Message-----" (Outlook style)', () => {
const body = 'Thanks, looks fine.\n-----Original Message-----\nFrom: bob@example.com\nSubject: Re: card';
assert.strictEqual(stripQuotedReply(body), 'Thanks, looks fine.');
});
test('cuts at a "From:" header block (Outlook style)', () => {
const body = 'Approved.\nFrom: carol@example.com\nSent: Tuesday';
assert.strictEqual(stripQuotedReply(body), 'Approved.');
});
test('a body with no quote markers is kept, only trimmed', () => {
const body = ' Just a plain reply, no quoting. \n\n';
assert.strictEqual(stripQuotedReply(body), 'Just a plain reply, no quoting.');
});
test('multi-line reply above the quote is fully kept', () => {
const body = 'Line one.\nLine two.\nLine three.\n\nOn Mon wrote:\n> quoted';
assert.strictEqual(stripQuotedReply(body), 'Line one.\nLine two.\nLine three.');
});
test('non-string input returns empty string, never throws', () => {
assert.strictEqual(stripQuotedReply(null), '');
assert.strictEqual(stripQuotedReply(undefined), '');
assert.strictEqual(stripQuotedReply(42), '');
});
console.log(`inboundEmailQuoteStrip: ${passed} passed`);