Error downloading file: TypeError [ERR_INVALID_CHAR]: Invalid character in header content ["Content-Disposition"] #153

Open
opened 2026-04-05 16:16:46 +02:00 by MrUnknownDE · 0 comments
Owner

Originally created by @prinsss on 10/14/2025

Describe the bug

File names need to be properly encoded before setting to Content-Disposition header when downloading .eml files.

Currently, downloading any files with non-ASCII file names (e.g. Chinese) will fail.

1e048fdbc1/packages/backend/src/api/controllers/storage.controller.ts (L43)

To Reproduce

  1. Add a mailbox whose mailboxPath contains non-ASCII characters
  2. Start ingestion with IMAP connector
  3. The email is downloaded to open-archiver/Gmail-Test-b9a22256-a261-45a4-b212-506f919cac02/emails/[Gmail]/所有邮件<F0.72.12345.25F12345@ab.mta2vrest.cc.prd.sparkpost>.eml.
  4. Visit the detail page of that email and click "Download Email (.eml)" button.
  5. No file is downloaded and no error messages. DevTools shows that the download request failed with http status 500.

Here is a code snippet to demonstrate the issue:

const app = express();

app.get("/test", (req, res) => {
  const fileName = "所有邮件<F0.72.12345.25F12345@ab.mta2vrest.cc.prd.sparkpost>.eml";
  res.setHeader('Content-Disposition', `attachment; filename="${fileName}"`);
  res.send("Hello World!");
});

// TypeError: Invalid character in header content ["Content-Disposition"]
//     at unknown
//     at validateHeaderValue (node:_http_common:15:29)
//     at setHeader (node:_http_outgoing:168:50)
//     at <anonymous> (/app/index.ts:88:7)

Expected behavior

.eml files with non-ASCII path should be downloadable.

Screenshots

Image

System:

  • Open Archiver Version: 0.3.4

Relevant logs:

[1] packages/backend start: Error downloading file: TypeError [ERR_INVALID_CHAR]: Invalid character in header content ["Content-Disposition"]
[1] packages/backend start:     at ServerResponse.setHeader (node:_http_outgoing:703:3)
[1] packages/backend start:     at downloadFile (/app/packages/backend/dist/api/controllers/storage.controller.js:70:17) {
[1] packages/backend start:   code: 'ERR_INVALID_CHAR'
[1] packages/backend start: }

Additional context

*Originally created by @prinsss on 10/14/2025* **Describe the bug** File names need to be properly encoded before setting to `Content-Disposition` header when downloading .eml files. Currently, downloading any files with non-ASCII file names (e.g. Chinese) will fail. https://github.com/LogicLabs-OU/OpenArchiver/blob/1e048fdbc1d0e60b35a6c633309acd14927a6824/packages/backend/src/api/controllers/storage.controller.ts#L43 **To Reproduce** 1. Add a mailbox whose `mailboxPath` contains non-ASCII characters 2. Start ingestion with IMAP connector 3. The email is downloaded to `open-archiver/Gmail-Test-b9a22256-a261-45a4-b212-506f919cac02/emails/[Gmail]/所有邮件<F0.72.12345.25F12345@ab.mta2vrest.cc.prd.sparkpost>.eml`. 4. Visit the detail page of that email and click "Download Email (.eml)" button. 5. No file is downloaded and no error messages. DevTools shows that the download request failed with http status 500. Here is a code snippet to demonstrate the issue: ```ts const app = express(); app.get("/test", (req, res) => { const fileName = "所有邮件<F0.72.12345.25F12345@ab.mta2vrest.cc.prd.sparkpost>.eml"; res.setHeader('Content-Disposition', `attachment; filename="${fileName}"`); res.send("Hello World!"); }); // TypeError: Invalid character in header content ["Content-Disposition"] // at unknown // at validateHeaderValue (node:_http_common:15:29) // at setHeader (node:_http_outgoing:168:50) // at <anonymous> (/app/index.ts:88:7) ``` **Expected behavior** `.eml` files with non-ASCII path should be downloadable. **Screenshots** <img width="2600" height="1062" alt="Image" src="https://github.com/user-attachments/assets/a9f5dd41-cccf-4dd3-bd8e-ba8762d041d8" /> **System:** - Open Archiver Version: 0.3.4 **Relevant logs:** ``` [1] packages/backend start: Error downloading file: TypeError [ERR_INVALID_CHAR]: Invalid character in header content ["Content-Disposition"] [1] packages/backend start: at ServerResponse.setHeader (node:_http_outgoing:703:3) [1] packages/backend start: at downloadFile (/app/packages/backend/dist/api/controllers/storage.controller.js:70:17) { [1] packages/backend start: code: 'ERR_INVALID_CHAR' [1] packages/backend start: } ``` **Additional context** - [http.validateHeaderValue(name, value)](https://nodejs.org/api/http.html#httpvalidateheadervaluename-value) - [Content-Disposition filename in Chinese not supported - Stack Overflow](https://stackoverflow.com/questions/50408723/content-disposition-filename-in-chinese-not-supported)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/OpenArchiver#153