Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions apps/hub/src/artifacts/materials.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { expect, test } from "bun:test";
import { mailAttachmentName } from "./materials.ts";

test("a mailed attachment's name is the person's, made US-ASCII", () => {
// macOS names a screenshot with a narrow no-break space before AM.
expect(
mailAttachmentName("Screenshot 2026-11-03 at 8.51.17\u202fAM.png"),
).toBe("Screenshot 2026-11-03 at 8.51.17 AM.png");
expect(mailAttachmentName("r\u00e9sum\u00e9 \u2014 final.pdf")).toBe(
"resume final.pdf",
);
expect(mailAttachmentName('say "hi".txt')).toBe("say 'hi'.txt");
expect(mailAttachmentName("plain-name.png")).toBe("plain-name.png");
expect(mailAttachmentName("\u5831\u544a.pdf")).toBe(".pdf");
});
16 changes: 16 additions & 0 deletions apps/hub/src/artifacts/materials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,22 @@ export function materialMimeType(file: { name: string; type: string }): string {
return declared;
}

// A mailed attachment's name sits in a signed MIME header with no encoding, so the assembler takes
// US-ASCII only; the validator the hub runs first does not check that. The material keeps the
// person's name; the mailed copy carries this one, which the coordinator still reads as the file.
const ASCII_SPACE_LIKE = /[\u00a0\u2000-\u200b\u202f\u205f\u3000]/g;

/** The name a file is mailed under: the person's, with every non-ASCII character made plain. */
export function mailAttachmentName(name: string): string {
const plain = name
.replace(ASCII_SPACE_LIKE, " ")
.normalize("NFKD")
.replace(/[^\x20-\x7e]/g, "")
.replace(/"/g, "'")
.trim();
return plain === "" ? "attachment" : plain;
}

function utf8(bytes: Uint8Array): string | undefined {
try {
return new TextDecoder("utf-8", { fatal: true }).decode(bytes);
Expand Down
7 changes: 6 additions & 1 deletion apps/hub/src/artifacts/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ import { materialsNote } from "../config/materials.ts";
import { servingOffering } from "../workflows/install-for-tenant.ts";
import {
acceptedMaterials,
mailAttachmentName,
materialContent,
materialMimeType,
} from "./materials.ts";
Expand Down Expand Up @@ -1238,7 +1239,11 @@ export function createArtifactService(
await mailRun(
coordinator.runId,
message.trim() || materialsNote(inputs.map((input) => input.name)),
inputs.map((input) => ({ ...input, data: base64Encode(input.data) })),
inputs.map((input) => ({
name: mailAttachmentName(input.name),
mimeType: input.mimeType,
data: base64Encode(input.data),
})),
);
return { materials };
},
Expand Down