fix: strip from/to names from forward-as-attachment filenames
buildForwardAsAttachmentPayload named the synthetic .eml attachment
using the user's own emailDownloadTemplate, which by default embeds
sender/recipient display names. Since this attachment can go to an
external recipient (e.g. an upstream spam gateway, or anyone else),
the filename now always renders as "{date}-{subject}.eml" regardless
of the user's configured template, while still honoring their
space/case/diacritics preferences.
This commit is contained in:
@@ -1,3 +1,6 @@
|
|||||||
|
// Pin TZ so the local-time date rendering in the filename test is deterministic.
|
||||||
|
process.env.TZ = 'UTC';
|
||||||
|
|
||||||
import { describe, it, expect } from 'vitest';
|
import { describe, it, expect } from 'vitest';
|
||||||
import { buildForwardAsAttachmentPayload } from '@/lib/forward-as-attachment';
|
import { buildForwardAsAttachmentPayload } from '@/lib/forward-as-attachment';
|
||||||
import type { Email } from '@/lib/jmap/types';
|
import type { Email } from '@/lib/jmap/types';
|
||||||
@@ -52,13 +55,30 @@ describe('buildForwardAsAttachmentPayload', () => {
|
|||||||
expect(payload?.subject).toBe('');
|
expect(payload?.subject).toBe('');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('honors a custom filename template, matching "Export as .eml" naming instead of always using the default', () => {
|
it('applies user space/case transforms but ignores a custom filename template, unlike "Export as .eml"', () => {
|
||||||
const email = makeEmail({ subject: 'Missed spam example' });
|
const email = makeEmail({ subject: 'Missed spam example' });
|
||||||
const payload = buildForwardAsAttachmentPayload(email, 'Fwd:', {
|
const payload = buildForwardAsAttachmentPayload(email, 'Fwd:', {
|
||||||
template: 'custom-{subject}',
|
template: 'custom-{subject}',
|
||||||
lowercase: true,
|
lowercase: true,
|
||||||
spaceReplacement: 'dash',
|
spaceReplacement: 'dash',
|
||||||
});
|
});
|
||||||
expect(payload?.attachment.name).toBe('custom-missed-spam-example.eml');
|
expect(payload?.attachment.name).toBe('2026-07-26-22.25.22-missed-spam-example.eml');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('uses a dash between date and subject by default', () => {
|
||||||
|
const email = makeEmail({ subject: 'Missed spam example' });
|
||||||
|
const payload = buildForwardAsAttachmentPayload(email, 'Fwd:');
|
||||||
|
expect(payload?.attachment.name).toBe('2026-07-26 22.25.22-Missed spam example.eml');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('never includes from/to in the filename, even with the default template, to avoid leaking names to the recipient', () => {
|
||||||
|
const email = makeEmail({
|
||||||
|
subject: 'Missed spam example',
|
||||||
|
from: [{ name: 'Alice Sender', email: 'alice@example.com' }],
|
||||||
|
to: [{ name: "'Bobby'", email: 'bob@example.com' }],
|
||||||
|
});
|
||||||
|
const payload = buildForwardAsAttachmentPayload(email, 'Fwd:');
|
||||||
|
expect(payload?.attachment.name).not.toContain('Alice');
|
||||||
|
expect(payload?.attachment.name).not.toContain('Bobby');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -24,12 +24,14 @@ export interface ForwardAsAttachmentPayload {
|
|||||||
* not per-email, so the same blobId a message already has can be attached
|
* not per-email, so the same blobId a message already has can be attached
|
||||||
* to a brand new outgoing email directly.
|
* to a brand new outgoing email directly.
|
||||||
*
|
*
|
||||||
* `filenameOptions`, when passed, should be the same options the caller
|
* `filenameOptions`, when passed, carries the user's configured space/case/
|
||||||
* uses for "Export as .eml" / drag-out (the user's configured filename
|
* diacritics transforms (see useSettingsStore's filenameSpaceReplacement
|
||||||
* template, space/case/diacritics transforms - see
|
* and friends) for consistency with "Export as .eml" / drag-out. Its
|
||||||
* useSettingsStore's emailDownloadTemplate and friends), so the two
|
* `template`, if any, is ignored: this attachment goes out to a possibly
|
||||||
* actions produce consistent filenames for the same message. Falls back
|
* external recipient (spam gateway, another person), so the filename is
|
||||||
* to emailExportFilename's own default template when omitted.
|
* always just "{date}-{subject}.eml" - never the user's own from/to naming
|
||||||
|
* template, which could otherwise leak sender/recipient names into an
|
||||||
|
* attachment filename visible to that recipient.
|
||||||
*
|
*
|
||||||
* Returns null when the email has no blobId (nothing to reference).
|
* Returns null when the email has no blobId (nothing to reference).
|
||||||
*/
|
*/
|
||||||
@@ -48,7 +50,7 @@ export function buildForwardAsAttachmentPayload(
|
|||||||
subject: email.subject ? buildForwardSubject(email.subject, forwardPrefix) : "",
|
subject: email.subject ? buildForwardSubject(email.subject, forwardPrefix) : "",
|
||||||
attachment: {
|
attachment: {
|
||||||
blobId: email.blobId,
|
blobId: email.blobId,
|
||||||
name: emailExportFilename(email, filenameOptions),
|
name: emailExportFilename(email, { ...filenameOptions, template: "{date}-{subject}" }),
|
||||||
type: "message/rfc822",
|
type: "message/rfc822",
|
||||||
size: email.size,
|
size: email.size,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user