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:
+14
-2
@@ -9,6 +9,7 @@ const { createDAVClient } = require('tsdav');
|
||||
const ICAL = require('ical.js');
|
||||
const openpgp = require('openpgp');
|
||||
const { createKeyServerService, listServers, MAX_CUSTOM_SERVERS, normalizeCustomServer } = require('./pgp-keyservers.cjs');
|
||||
const { normalizeOutgoingAttachments, serializeOutgoingAttachments } = require('./mail-attachments.cjs');
|
||||
|
||||
const credentialsPath = () => path.join(app.getPath('userData'), 'mail-account.enc');
|
||||
const davCredentialsPath = () => path.join(app.getPath('userData'), 'dav-accounts.enc');
|
||||
@@ -1027,6 +1028,7 @@ ipcMain.handle('mail:save-draft', async (_event, input) => {
|
||||
cc: String(input?.cc || '').slice(0, 4000),
|
||||
subject: String(input?.subject || '').slice(0, 998),
|
||||
text: String(input?.text || '').slice(0, 500000),
|
||||
attachments: serializeOutgoingAttachments(normalizeOutgoingAttachments(input?.attachments)),
|
||||
updatedAt: Date.now()
|
||||
};
|
||||
await updateAccountStore(store => {
|
||||
@@ -1594,6 +1596,7 @@ ipcMain.handle('mail:sync-inbox', async () => {
|
||||
async function sendMailNow(account, message) {
|
||||
const to = String(message?.to || '').trim();
|
||||
if (!to) throw new Error('Add at least one recipient.');
|
||||
const attachments = normalizeOutgoingAttachments(message?.attachments);
|
||||
const transport = smtpTransport(account);
|
||||
const sentMessageId = String(message.messageId || `<${require('node:crypto').randomUUID()}@ep-mail.local>`);
|
||||
const fromName = String(account.displayName || message.displayName || account.email).replace(/[\r\n]+/g, ' ').trim().slice(0, 80) || account.email;
|
||||
@@ -1605,7 +1608,12 @@ async function sendMailNow(account, message) {
|
||||
cc: String(message.cc || '').trim() || undefined,
|
||||
subject: String(message.subject || '(no subject)').slice(0, 998),
|
||||
text: signature ? `${body}${body.trim() ? '\n\n' : ''}${signature}`.slice(0, 505000) : body,
|
||||
messageId: sentMessageId
|
||||
messageId: sentMessageId,
|
||||
attachments: attachments.map(file => ({
|
||||
filename: file.filename,
|
||||
contentType: file.contentType,
|
||||
content: file.content
|
||||
}))
|
||||
};
|
||||
const rawMessage = message.rawBase64 ? Buffer.from(String(message.rawBase64), 'base64') : null;
|
||||
try {
|
||||
@@ -1644,6 +1652,8 @@ ipcMain.handle('mail:send', async (event, message) => {
|
||||
if (!account) throw new Error('Add a mail account before sending.');
|
||||
const pgpOptions = message?.pgp && (message.pgp.encrypt || message.pgp.sign) ? message.pgp : null;
|
||||
const queuedMessage = { ...message, messageId: message?.messageId || `<${randomUUID()}@ep-mail.local>` };
|
||||
const attachments = normalizeOutgoingAttachments(message?.attachments);
|
||||
queuedMessage.attachments = serializeOutgoingAttachments(attachments);
|
||||
delete queuedMessage.pgp;
|
||||
if (!pgpOptions?.encrypt) {
|
||||
const recipients = [queuedMessage.to, queuedMessage.cc].filter(Boolean);
|
||||
@@ -1677,11 +1687,13 @@ ipcMain.handle('mail:send', async (event, message) => {
|
||||
messageId: queuedMessage.messageId,
|
||||
encrypt: Boolean(pgpOptions.encrypt),
|
||||
sign: Boolean(pgpOptions.sign),
|
||||
passphrase: typeof pgpOptions.passphrase === 'string' && pgpOptions.passphrase ? pgpOptions.passphrase : null
|
||||
passphrase: typeof pgpOptions.passphrase === 'string' && pgpOptions.passphrase ? pgpOptions.passphrase : null,
|
||||
attachments: attachments.map(({ filename, contentType, content }) => ({ filename, contentType, content }))
|
||||
});
|
||||
queuedMessage.rawBase64 = built.raw.toString('base64');
|
||||
queuedMessage.envelope = built.envelope;
|
||||
queuedMessage.text = '';
|
||||
queuedMessage.attachments = [];
|
||||
} catch (error) {
|
||||
if (error instanceof PgpError) return pgpFailure(error);
|
||||
throw error;
|
||||
|
||||
Reference in New Issue
Block a user