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:
@@ -0,0 +1,38 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { normalizeOutgoingAttachments, serializeOutgoingAttachments } = require('../desktop/mail-attachments.cjs');
|
||||
|
||||
test('normalizes attachment metadata and round-trips bytes through serialized drafts and sends', () => {
|
||||
const bytes = Buffer.from([0, 1, 2, 127, 128, 255]);
|
||||
const [file] = normalizeOutgoingAttachments([{
|
||||
filename: 'folder\\report.bin',
|
||||
contentType: 'APPLICATION/OCTET-STREAM',
|
||||
size: 999,
|
||||
contentBase64: bytes.toString('base64')
|
||||
}]);
|
||||
|
||||
assert.equal(file.filename, 'report.bin');
|
||||
assert.equal(file.contentType, 'application/octet-stream');
|
||||
assert.equal(file.size, bytes.length);
|
||||
assert.deepEqual(file.content, bytes);
|
||||
const [serialized] = serializeOutgoingAttachments([file]);
|
||||
assert.equal(serialized.contentBase64, bytes.toString('base64'));
|
||||
assert.equal('content' in serialized, false);
|
||||
});
|
||||
|
||||
test('rejects malformed attachment data and unsafe content types', () => {
|
||||
assert.throws(() => normalizeOutgoingAttachments({}), /attachment list is invalid/);
|
||||
assert.throws(() => normalizeOutgoingAttachments([{ filename: 'x', contentBase64: '***=' }]), /contents.*invalid/);
|
||||
assert.throws(() => normalizeOutgoingAttachments([{
|
||||
filename: 'x',
|
||||
contentType: 'text/plain\r\nBcc: bad@example.com',
|
||||
contentBase64: ''
|
||||
}]), /content type.*invalid/);
|
||||
});
|
||||
|
||||
test('uses fallback names and MIME types for empty metadata', () => {
|
||||
const [file] = normalizeOutgoingAttachments([{ contentBase64: '' }]);
|
||||
assert.equal(file.filename, 'attachment');
|
||||
assert.equal(file.contentType, 'application/octet-stream');
|
||||
assert.equal(file.size, 0);
|
||||
});
|
||||
Reference in New Issue
Block a user