mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
Email shows the board as a Gmail-like mailbox in the board's own theme: the Inbox is the list email to card puts new cards in, Sent and All mail follow the cards' email, the board's lists are folders and its labels are Gmail labels, coloured on every message. The messages are the shared table page, newest first, paged on the server; a message opens as the card popup, its comments the conversation. Compose and Reply send From the member's own board address, so the answer returns to this board, and by In-Reply-To to the same card as a comment. Chat shows the board as a Slack / Rocket.Chat workspace in the current theme: a tree of Workspaces, boards, swimlanes, lists and cards as channels; the selected card in the middle; its comments as chat on the other side. Tree | card | chat left to right, mirrored right to left. Each pane folds, the two borders drag (and move with the arrow keys), and widths and folds are saved on the member's profile. Swimlanes, lists, cards, workspaces and boards reorder by drag and drop through the same paths the board and All Boards use. The new strings are translated in every locale. Thanks to xet7 !
106 lines
5.9 KiB
JavaScript
106 lines
5.9 KiB
JavaScript
'use strict';
|
|
|
|
// Board View / Email (#794): folders, search, what may be sent, threading,
|
|
// and that the view is wired like every other board view.
|
|
// Run: node tests/emailView.test.cjs
|
|
|
|
const { test } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
const {
|
|
parseFolder, emailFolderSelector, emailSearchSelector, cleanOutgoingEmail, snippet, MAX_RECIPIENTS,
|
|
} = require('../models/lib/emailView');
|
|
const { fromProviderFields, messageIds } = require('../server/lib/inboundEmailPayload');
|
|
|
|
const ROOT = path.join(__dirname, '..');
|
|
const read = file => fs.readFileSync(path.join(ROOT, file), 'utf8');
|
|
|
|
test('folders: Inbox is the email list without what was sent, then Sent, All mail, lists and labels', () => {
|
|
const base = { boardId: 'B', archived: false, type: { $nin: ['template-container'] } };
|
|
assert.deepEqual(emailFolderSelector('B', 'inbox', { inboxListId: 'L' }), { ...base, listId: 'L', 'email.direction': { $ne: 'out' } });
|
|
assert.deepEqual(emailFolderSelector('B', 'sent'), { ...base, 'email.direction': 'out' });
|
|
assert.deepEqual(emailFolderSelector('B', 'all'), { ...base, email: { $exists: true } });
|
|
assert.deepEqual(emailFolderSelector('B', 'list:L2'), { ...base, listId: 'L2' });
|
|
assert.deepEqual(emailFolderSelector('B', 'label:x1'), { ...base, labelIds: 'x1' });
|
|
// A board without a list has an empty Inbox, not every card.
|
|
assert.equal(emailFolderSelector('B', 'inbox').listId, '__none__');
|
|
});
|
|
|
|
test('a folder that is not one of those is the Inbox, never a selector of its own (negative)', () => {
|
|
for (const folder of ['list:', 'list:{"$ne":1}', 'label:a b', 'card:x', '', null, { $ne: 1 }, 'list:x:y']) {
|
|
const parsed = parseFolder(folder);
|
|
assert.ok(parsed.kind === 'inbox' || /^[A-Za-z0-9_-]+$/.test(parsed.id), String(folder));
|
|
}
|
|
assert.equal(parseFolder('list:{"$ne":1}').kind, 'inbox');
|
|
assert.equal(parseFolder({ $ne: 1 }).kind, 'inbox');
|
|
});
|
|
|
|
test('search is plain text: regex characters are escaped, empty searches everything', () => {
|
|
assert.deepEqual(emailSearchSelector(' '), {});
|
|
const s = emailSearchSelector('a.b*(c');
|
|
assert.equal(s.$or[0].title.$regex, 'a\\.b\\*\\(c');
|
|
assert.equal(s.$or.length, 4);
|
|
assert.equal(emailSearchSelector('x'.repeat(500)).$or[0].title.$regex.length, 200);
|
|
});
|
|
|
|
test('what may be sent: addresses checked, duplicates dropped, subject on one line', () => {
|
|
assert.deepEqual(cleanOutgoingEmail({ to: ['Ann@X.org, b@y.org'], cc: ['b@y.org', 'c@z.org'], subject: ' Hi\r\nBcc: evil@x.org ', text: 'T' }),
|
|
{ to: ['ann@x.org', 'b@y.org'], cc: ['c@z.org'], subject: 'Hi Bcc: evil@x.org', text: 'T' });
|
|
});
|
|
|
|
test('a header cannot be injected and the limits hold (negative)', () => {
|
|
for (const [input, code] of [
|
|
[{ to: [], subject: 's' }, 'email-view-no-recipient'],
|
|
[{ to: ['a@x.org'], subject: ' ' }, 'email-view-no-subject'],
|
|
[{ to: ['a@x.org\r\nBcc: e@x.org'], subject: 's' }, 'email-view-invalid-address'],
|
|
[{ to: ['"Ann" <a@x.org>'], subject: 's' }, 'email-view-invalid-address'],
|
|
[{ to: ['a@localhost'], subject: 's' }, 'email-view-invalid-address'],
|
|
[{ to: Array.from({ length: MAX_RECIPIENTS + 1 }, (_, i) => `u${i}@x.org`), subject: 's' }, 'email-view-too-many-recipients'],
|
|
]) {
|
|
assert.throws(() => cleanOutgoingEmail(input), new RegExp(code));
|
|
}
|
|
});
|
|
|
|
test('a row preview leaves out the sender line and is one line', () => {
|
|
assert.equal(snippet('From: Ann <a@x>\n\nHello\nthere'), 'Hello there');
|
|
assert.equal(snippet('x'.repeat(200), 10), `${'x'.repeat(9)}…`);
|
|
assert.equal(snippet(undefined), '');
|
|
});
|
|
|
|
test('threading: In-Reply-To and References are read from every provider shape', () => {
|
|
assert.deepEqual(messageIds('<a@x> <b@y>\r\n <c@z>'), ['<a@x>', '<b@y>', '<c@z>']);
|
|
assert.deepEqual(messageIds('no ids'), []);
|
|
const mailgun = fromProviderFields({ 'In-Reply-To': '<a@x>', References: '<r@x> <a@x>' });
|
|
assert.deepEqual([mailgun.inReplyTo, mailgun.references], [['<a@x>'], ['<r@x>', '<a@x>']]);
|
|
const postmark = fromProviderFields({ Headers: [{ Name: 'In-Reply-To', Value: '<p@x>' }] });
|
|
assert.deepEqual(postmark.inReplyTo, ['<p@x>']);
|
|
});
|
|
|
|
test('wired like every other board view', () => {
|
|
const bvs = require('../models/lib/boardViewSettings');
|
|
assert.ok(bvs.BOARD_VIEWS.some(v => v.view === 'board-view-email' && v.icon === 'fa-envelope'));
|
|
assert.match(read('client/components/boards/boardBody.jade'), /else if isViewEmail\n\s*\+emailView/);
|
|
assert.match(read('client/components/boards/boardHeader.js'), /'click \.js-open-email-view'/);
|
|
const features = read('client/features/boards.js');
|
|
for (const f of ['emailView.jade', 'emailView.js', 'emailView.css']) assert.ok(features.includes(`/client/components/boards/${f}`), f);
|
|
assert.match(read('server/imports.js'), /import '\/server\/emailView';/);
|
|
// The shared table page, as Table.md requires - not a table of its own.
|
|
const jade = read('client/components/boards/emailView.jade');
|
|
assert.match(jade, /\+tablePage\(tablePageData\)/);
|
|
assert.doesNotMatch(jade, /^\s*table\b/m);
|
|
});
|
|
|
|
test('server: the page is server-side and access-checked, From is the member\'s own board address (negative)', () => {
|
|
const server = read('server/emailView.js');
|
|
assert.match(server, /board\.isVisibleBy\(user\)/, 'only a board the user may see');
|
|
assert.match(server, /skip: \(page - 1\) \* TABLE_PAGE_ROWS_PER_PAGE/);
|
|
assert.match(server, /publishReportPage\(this, EMAIL_VIEW_PAGE_ID, docs\)/);
|
|
assert.match(server, /allowIsBoardMemberWithWriteAccess\(userId, board\)/, 'sending needs write access');
|
|
assert.match(server, /const from = boardAddress\(row\.token, inboundMail\.domain\)/);
|
|
assert.doesNotMatch(server, /from:\s*input\./, 'From never comes from the form');
|
|
assert.match(server, /cleanOutgoingEmail\(input\)/);
|
|
// The receiver threads replies onto the card whose conversation they answer.
|
|
assert.match(read('server/emailToCard.js'), /'email\.threadIds': \{ \$in: threadKeys \}/);
|
|
});
|