fix: honor the user's filename template for forward-as-attachment

buildForwardAsAttachmentPayload called emailExportFilename(email) with
no options, always using the default naming template regardless of
the user's configured emailDownloadTemplate (and space/case/diacritics
transforms) - the same settings the neighboring "Export as .eml"
action already respects. That could produce inconsistent .eml
filenames between the two actions for the same message.

Accept an optional EmailFilenameOptions parameter and pass it through.
handleForwardAsAttachment now reads the same settings
email-viewer.tsx's emailFilenameOptions useMemo does, via
useSettingsStore.getState() (a one-off read inside an event handler,
matching this file's existing pattern, rather than a new reactive
subscription). Add a unit test covering a custom template.

Caught by GitHub Copilot's automated PR review.
This commit is contained in:
Aaron Guise
2026-07-27 16:45:53 +12:00
parent 351f2d4e26
commit 7a483b3dd4
3 changed files with 38 additions and 3 deletions
+18 -1
View File
@@ -1561,7 +1561,24 @@ export default function Home() {
// entirely, so the body starts blank instead of quoting the original.
const handleForwardAsAttachment = async () => {
if (!selectedEmail) return;
const payload = buildForwardAsAttachmentPayload(selectedEmail, t('email_composer.prefix.forward'));
// Same filename options "Export as .eml" uses (see emailFilenameOptions
// in email-viewer.tsx), so the two actions produce consistent filenames
// for the same message rather than the synthetic attachment silently
// ignoring the user's configured naming template.
const {
emailDownloadTemplate,
filenameSpaceReplacement,
filenameLowercase,
filenameStripDiacritics,
filenameCollapseSeparators,
} = useSettingsStore.getState();
const payload = buildForwardAsAttachmentPayload(selectedEmail, t('email_composer.prefix.forward'), {
template: emailDownloadTemplate,
spaceReplacement: filenameSpaceReplacement,
lowercase: filenameLowercase,
stripDiacritics: filenameStripDiacritics,
collapseSeparators: filenameCollapseSeparators,
});
if (!payload) return;
const ok = await emailHooks.onBeforeForward.intercept({