Add outgoing mail attachments
Support multiple attachments in desktop and Android compose, persist them in drafts and offline queues, and include them in desktop OpenPGP protection. Update docs and tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
+30
-1
@@ -75,6 +75,29 @@ test('encrypts to several recipients and each can decrypt', async () => {
|
||||
}
|
||||
});
|
||||
|
||||
test('encrypts and signs outgoing attachments with the message body', async () => {
|
||||
const alice = await actor('Alice', 'alice@example.com');
|
||||
const bob = await actor('Bob', 'bob@example.com');
|
||||
await exchange(alice, bob);
|
||||
const contents = Buffer.from([0, 1, 2, 127, 128, 255]);
|
||||
const { raw } = await alice.mail.build(sendOptions(alice, 'bob@example.com', {
|
||||
encrypt: true,
|
||||
sign: true,
|
||||
passphrase: alice.passphrase,
|
||||
attachments: [{ filename: 'binary-data.bin', contentType: 'application/octet-stream', content: contents }]
|
||||
}));
|
||||
assert.ok(!raw.toString('latin1').includes(contents.toString('latin1')));
|
||||
|
||||
const parsed = await simpleParser(raw);
|
||||
const decrypted = await bob.mail.decrypt(parsed, { passphrase: bob.passphrase });
|
||||
assert.equal(decrypted.parsed.text.trim(), 'Top secret ✓\nline two');
|
||||
assert.equal(decrypted.parsed.attachments.length, 1);
|
||||
assert.equal(decrypted.parsed.attachments[0].filename, 'binary-data.bin');
|
||||
assert.equal(decrypted.parsed.attachments[0].contentType, 'application/octet-stream');
|
||||
assert.deepEqual(decrypted.parsed.attachments[0].content, contents);
|
||||
assert.equal(decrypted.signatures[0].status, 'valid');
|
||||
});
|
||||
|
||||
test('detects tampered and corrupted encrypted messages', async () => {
|
||||
const alice = await actor('Alice', 'alice@example.com');
|
||||
const bob = await actor('Bob', 'bob@example.com');
|
||||
@@ -112,10 +135,16 @@ test('signs without encrypting and verifies PGP/MIME signatures', async () => {
|
||||
const alice = await actor('Alice', 'alice@example.com');
|
||||
const bob = await actor('Bob', 'bob@example.com');
|
||||
await bob.keyStore.addContact({ armoredKey: await alice.keyStore.exportPublic(alice.key.fingerprint) });
|
||||
const { raw } = await alice.mail.build(sendOptions(alice, 'bob@example.com', { sign: true, passphrase: alice.passphrase }));
|
||||
const attachment = Buffer.from('signed attachment data');
|
||||
const { raw } = await alice.mail.build(sendOptions(alice, 'bob@example.com', {
|
||||
sign: true,
|
||||
passphrase: alice.passphrase,
|
||||
attachments: [{ filename: 'signed.txt', contentType: 'text/plain', content: attachment }]
|
||||
}));
|
||||
const parsed = await simpleParser(raw);
|
||||
assert.equal(detect(parsed), 'signed-mime');
|
||||
assert.match(parsed.text, /Top secret/);
|
||||
assert.deepEqual(parsed.attachments[0].content, attachment);
|
||||
const [signature] = await bob.mail.verifySigned(parsed, raw);
|
||||
assert.equal(signature.status, 'valid');
|
||||
const altered = Buffer.from(raw.toString('latin1').replace('Content-Type: text/plain', 'Content-Type: text/plain'), 'latin1');
|
||||
|
||||
Reference in New Issue
Block a user