Add conversation threads and prepare 0.6.0
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -88,7 +88,9 @@ test('Android OpenPGP encrypts MIME attachments and decrypts with a recipient ke
|
||||
|
||||
const built = await sender.api.buildOutgoing({
|
||||
to: 'Bob <bob@example.test>', cc: '', subject: 'Secret note', text: 'hello from Android',
|
||||
messageId: '<test-message@example.test>', pgp: { encrypt: true, sign: true, passphrase: 'alice test passphrase' },
|
||||
messageId: '<test-message@example.test>', inReplyTo: '<parent@example.test>',
|
||||
references: '<root@example.test> <parent@example.test>',
|
||||
pgp: { encrypt: true, sign: true, passphrase: 'alice test passphrase' },
|
||||
attachments: [
|
||||
{ filename: 'note.txt', contentType: 'text/plain', contentBase64: Buffer.from('private attachment').toString('base64') },
|
||||
{ filename: 'charlie.asc', contentType: 'application/pgp-keys', contentBase64: Buffer.from(await thirdParty.api.exportPublic(charlie.key.fingerprint)).toString('base64') }
|
||||
@@ -97,6 +99,8 @@ test('Android OpenPGP encrypts MIME attachments and decrypts with a recipient ke
|
||||
assert.ok(built.rawBase64);
|
||||
saveMimeFixture('encrypted-signed', built.rawBase64);
|
||||
const raw = Buffer.from(built.rawBase64, 'base64').toString('utf8');
|
||||
assert.match(raw, /\r\nIn-Reply-To: <parent@example\.test>\r\n/);
|
||||
assert.match(raw, /\r\nReferences: <root@example\.test> <parent@example\.test>\r\n/);
|
||||
assert.match(raw, /multipart\/encrypted; protocol="application\/pgp-encrypted"/i);
|
||||
assert.doesNotMatch(raw, /hello from Android|private attachment/);
|
||||
recipient.setMessage({ rawBase64: built.rawBase64 });
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { groupMessages, messageIds, replyHeaders } = require('../conversation-threads.js');
|
||||
|
||||
test('groups linked messages transitively in the original order, including absent ancestors', () => {
|
||||
const messages = [
|
||||
{ id: 1, messageId: '<one@example>', references: '<root@example>' },
|
||||
{ id: 2, messageId: '<other@example>', subject: 'Same subject' },
|
||||
{ id: 3, messageId: '<three@example>', inReplyTo: '<one@example>' },
|
||||
{ id: 4, messageId: '<four@example>', references: ['<root@example>', '<missing@example>'] }
|
||||
];
|
||||
assert.deepEqual(groupMessages(messages).map(group => group.map(message => message.id)), [[1, 3, 4], [2]]);
|
||||
});
|
||||
|
||||
test('messages without reference headers do not group by subject or invalid IDs', () => {
|
||||
const messages = [
|
||||
{ id: 1, subject: 'Hello', messageId: 'not-an-id' },
|
||||
{ id: 2, subject: 'Re: Hello', inReplyTo: 'not-an-id' }
|
||||
];
|
||||
assert.deepEqual(groupMessages(messages).map(group => group.length), [1, 1]);
|
||||
assert.deepEqual(messageIds('<a@example>\r\nBcc: <b@example>'), ['<a@example>', '<b@example>']);
|
||||
assert.deepEqual(messageIds(`<${'a'.repeat(255)}@example>`), []);
|
||||
});
|
||||
|
||||
test('reply headers retain the parent and bounded ancestry', () => {
|
||||
assert.deepEqual(replyHeaders({ messageId: '<parent@example>', references: ['<root@example>', '<parent@example>'] }), {
|
||||
inReplyTo: '<parent@example>', references: '<root@example> <parent@example>'
|
||||
});
|
||||
assert.deepEqual(replyHeaders({ references: '<root@example>' }), { inReplyTo: '', references: '' });
|
||||
const result = replyHeaders({
|
||||
messageId: '<parent@example>',
|
||||
references: Array.from({ length: 100 }, (_, i) => `<${i}@example.test>`)
|
||||
});
|
||||
assert.ok(result.references.length <= 900);
|
||||
assert.ok(result.references.startsWith('<0@example.test>'));
|
||||
assert.ok(result.references.endsWith('<parent@example>'));
|
||||
});
|
||||
@@ -0,0 +1,43 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const vm = require('node:vm');
|
||||
const path = require('node:path');
|
||||
const threads = require('../conversation-threads.js');
|
||||
|
||||
test('conversation toggle hides older messages, clears their selection and preserves scroll', () => {
|
||||
const source = fs.readFileSync(path.join(__dirname, '..', 'app.js'), 'utf8');
|
||||
const code = source.slice(source.indexOf('const collapsedThreads = new Set();'), source.indexOf('function openMessage(id)'));
|
||||
const list = { innerHTML: '', scrollTop: 42 };
|
||||
const state = {
|
||||
activeFolder: 'Inbox', query: '', activeMessage: null, selectedIds: new Set([1, 2]),
|
||||
messages: [
|
||||
{ id: 1, messageId: '<one@test>', inReplyTo: '<root@test>', subject: 'Re: Topic', unread: true },
|
||||
{ id: 2, messageId: '<root@test>', subject: 'Topic' }
|
||||
]
|
||||
};
|
||||
let handler;
|
||||
const context = {
|
||||
state, window: { epMailConversationThreads: threads },
|
||||
document: { body: { classList: { remove() {} } } },
|
||||
esc: value => String(value).replace(/&/g, '&').replace(/</g, '<').replace(/"/g, '"'),
|
||||
$: selector => selector === '#message-list' ? list : {},
|
||||
$$: selector => selector === '.conversation-toggle' ? [{
|
||||
dataset: { thread: '0' },
|
||||
getAttribute: () => list.innerHTML.includes('aria-expanded="true"') ? 'true' : 'false',
|
||||
addEventListener(_type, callback) { handler = callback; }
|
||||
}] : [],
|
||||
emptyReader: () => '', openMessage() {}
|
||||
};
|
||||
vm.runInNewContext(`${code}\nrenderList();`, context);
|
||||
assert.match(list.innerHTML, /aria-expanded="true"/);
|
||||
assert.match(list.innerHTML, /2 messages · 1 unread/);
|
||||
handler();
|
||||
assert.match(list.innerHTML, /aria-expanded="false"/);
|
||||
assert.match(list.innerHTML, /class="conversation-replies" hidden/);
|
||||
assert.deepEqual([...state.selectedIds], [1]);
|
||||
assert.equal(list.scrollTop, 42);
|
||||
handler();
|
||||
assert.match(list.innerHTML, /aria-expanded="true"/);
|
||||
assert.doesNotMatch(list.innerHTML, /class="conversation-replies" hidden/);
|
||||
});
|
||||
@@ -9,7 +9,7 @@ const mailSource = fs.readFileSync(path.join(root, 'mail-ui.js'), 'utf8');
|
||||
const pgpSource = fs.readFileSync(path.join(root, 'pgp-mail-ui.js'), 'utf8');
|
||||
const setupSource = mailSource.slice(mailSource.indexOf('function setupDraftComposer()'), mailSource.indexOf('\nasync function syncMailbox('));
|
||||
|
||||
function harness(initialDraft = null) {
|
||||
function harness(initialDraft = null, reply = null, forward = false) {
|
||||
const saved = [];
|
||||
const deleted = [];
|
||||
const toasts = [];
|
||||
@@ -40,7 +40,7 @@ function harness(initialDraft = null) {
|
||||
appShell: { wrapShowCompose(fn) { wrapped = fn(() => {}); } },
|
||||
selectMailUi: selector => selector === '#modal-root' ? modalRoot : elements.get(selector),
|
||||
document: { createElement: node },
|
||||
window: { crypto: { randomUUID: () => 'new-id' }, daybreakMail: {
|
||||
window: { epMailConversationThreads: require('../conversation-threads.js'), crypto: { randomUUID: () => 'new-id' }, daybreakMail: {
|
||||
saveDraft: values => saveDraft(values),
|
||||
async deleteDraft(id) { deleted.push(id); }
|
||||
} },
|
||||
@@ -52,7 +52,7 @@ function harness(initialDraft = null) {
|
||||
btoa: value => Buffer.from(value, 'binary').toString('base64')
|
||||
};
|
||||
vm.runInNewContext(`${setupSource}\nsetupDraftComposer();`, context);
|
||||
wrapped(null, false, initialDraft);
|
||||
wrapped(reply, forward, initialDraft);
|
||||
return {
|
||||
modal, modalRoot, elements, saved, deleted, toasts,
|
||||
setSave(fn) { saveDraft = fn; },
|
||||
@@ -85,6 +85,19 @@ test('reopening a draft restores fields, attachments, and its identity', () => {
|
||||
assert.equal(h.elements.get('.modal-head span').textContent, 'Edit draft');
|
||||
});
|
||||
|
||||
test('reply draft preserves thread headers when saved and restored; forwards do not inherit them', async () => {
|
||||
const h = harness(null, { messageId: '<parent@example.test>', references: '<root@example.test>' });
|
||||
h.elements.get('#compose-body').value = 'Reply';
|
||||
h.modal.dispatch('input');
|
||||
await h.runTimers();
|
||||
assert.equal(h.saved[0].inReplyTo, '<parent@example.test>');
|
||||
assert.equal(h.saved[0].references, '<root@example.test> <parent@example.test>');
|
||||
const restored = harness(h.saved[0]);
|
||||
assert.equal(restored.modal._replyHeaders.inReplyTo, '<parent@example.test>');
|
||||
const forward = harness(null, { messageId: '<parent@example.test>' }, true);
|
||||
assert.equal(forward.modal._replyHeaders.inReplyTo, '');
|
||||
});
|
||||
|
||||
test('blank and whitespace-only new messages are not saved on close or manual save', async () => {
|
||||
const h = harness();
|
||||
h.elements.get('#compose-body').value = ' \n ';
|
||||
|
||||
@@ -71,6 +71,7 @@ test('validates channel-specific field shapes, limits, and enums', () => {
|
||||
test('prevents renderer-supplied raw SMTP messages while accepting standard compose fields', () => {
|
||||
assert.doesNotThrow(() => validateIpcArguments('mail:send', [{
|
||||
to: 'friend@example.test', cc: '', subject: 'Hello', text: 'Body',
|
||||
inReplyTo: '<parent@example.test>', references: '<root@example.test> <parent@example.test>',
|
||||
attachments: [{ filename: 'note.txt', contentBase64: 'aGVsbG8=' }],
|
||||
pgp: { encrypt: true, sign: false, passphrase: null }
|
||||
}]));
|
||||
|
||||
@@ -82,6 +82,20 @@ test('reports Sent-copy failures without retrying a message accepted by SMTP', a
|
||||
assert.equal(calls.appended.length, 0);
|
||||
});
|
||||
|
||||
test('preserves reply headers in the SMTP message and Sent copy', async () => {
|
||||
const { sendMailNow, calls } = makeSender();
|
||||
await sendMailNow({ email: 'sender@example.com' }, {
|
||||
to: 'recipient@example.com',
|
||||
inReplyTo: '<parent@example.test>',
|
||||
references: '<root@example.test> <parent@example.test>'
|
||||
});
|
||||
assert.equal(calls.smtp[0].inReplyTo, '<parent@example.test>');
|
||||
assert.deepEqual(calls.smtp[0].references, ['<root@example.test>', '<parent@example.test>']);
|
||||
const saved = JSON.parse(calls.appended[0].content.toString());
|
||||
assert.equal(saved.inReplyTo, calls.smtp[0].inReplyTo);
|
||||
assert.deepEqual(saved.references, calls.smtp[0].references);
|
||||
});
|
||||
|
||||
test('closes SMTP transport and reports send failures', async () => {
|
||||
const { sendMailNow, calls } = makeSender({ smtpFails: true });
|
||||
await assert.rejects(
|
||||
|
||||
@@ -32,11 +32,16 @@ test('encrypts and signs for a recipient and the sender can read the copy', asyn
|
||||
const alice = await actor('Alice', 'alice@example.com');
|
||||
const bob = await actor('Bob', 'bob@example.com');
|
||||
await exchange(alice, bob);
|
||||
const { raw, envelope } = await alice.mail.build(sendOptions(alice, 'Bob <bob@example.com>', { encrypt: true, sign: true, passphrase: alice.passphrase }));
|
||||
const { raw, envelope } = await alice.mail.build(sendOptions(alice, 'Bob <bob@example.com>', {
|
||||
encrypt: true, sign: true, passphrase: alice.passphrase,
|
||||
inReplyTo: '<parent@example.test>', references: '<root@example.test> <parent@example.test>'
|
||||
}));
|
||||
assert.deepEqual(envelope.to, ['bob@example.com']);
|
||||
assert.ok(!raw.toString('latin1').includes('Top secret'));
|
||||
const parsed = await simpleParser(raw);
|
||||
assert.equal(parsed.subject, 'Héllo secrèt');
|
||||
assert.equal(parsed.inReplyTo, '<parent@example.test>');
|
||||
assert.deepEqual(parsed.references, ['<root@example.test>', '<parent@example.test>']);
|
||||
assert.equal(detect(parsed), 'encrypted-mime');
|
||||
await assert.rejects(() => bob.mail.decrypt(parsed), error => error.code === 'PASSPHRASE_REQUIRED');
|
||||
await assert.rejects(() => bob.mail.decrypt(parsed, { passphrase: 'wrong wrong' }), error => error.code === 'BAD_PASSPHRASE');
|
||||
|
||||
@@ -55,7 +55,7 @@ test('desktop, Android web generation, and offline cache include renderer suppor
|
||||
const buildFiles = require(path.join(root, 'package.json')).build.files;
|
||||
const androidAssets = read('scripts/prepare-android-web.cjs');
|
||||
const worker = read('service-worker.js');
|
||||
for (const file of ['renderer-state.js', 'mail-content-security.js', 'renderer-mail-api.js', 'platform-bridge-loader.js']) {
|
||||
for (const file of ['renderer-state.js', 'conversation-threads.js', 'mail-content-security.js', 'renderer-mail-api.js', 'platform-bridge-loader.js']) {
|
||||
assert.ok(buildFiles.includes(file), `Electron package is missing ${file}`);
|
||||
assert.ok(androidAssets.includes(`'${file}'`), `Android web generator is missing ${file}`);
|
||||
assert.ok(worker.includes(`'./${file}'`), `service worker is missing ${file}`);
|
||||
|
||||
Reference in New Issue
Block a user