Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(email): preserve Bcc recipients in Sent copies

Afloat81706a6a0c87
diff --git a/server/email/client.ts b/server/email/client.ts
index 16a64dfd78..a0bc770821 100644
--- a/server/email/client.ts
+++ b/server/email/client.ts
@@ -438,7 +438,9 @@ export async function sendMessage(account: EmailAccount, guard: EmailGuard, inpu
filed = await imapSession(account, guard, async (client) => {
const sentBox = (await client.list()).find((box) => box.specialUse === "\\Sent");
if (!sentBox) return false;
- await client.append(sentBox.path, raw, ["\\Seen"]);
+ // Bcc belongs in the private Sent copy, never in the SMTP message.
+ composed.keepBcc = true;
+ await client.append(sentBox.path, input.bcc?.length ? await composed.build() : raw, ["\\Seen"]);
return true;
});
} catch {}
diff --git a/server/email/inline-images.test.ts b/server/email/inline-images.test.ts
index 11cf6cfa70..fd2f6e0648 100644
--- a/server/email/inline-images.test.ts
+++ b/server/email/inline-images.test.ts
@@ -23,7 +23,17 @@ const image = { cid: "logo", data_base64: png.toString("base64") };
const account = { address: "[email protected]", username: "fake", password: "fake", smtp: { host: "fake.invalid", port: 465, secure: true }, imap: { host: "fake.invalid", port: 993, secure: true } } as EmailAccount;
const input = { to: ["[email protected]"], cc: ["[email protected]"], bcc: ["[email protected]"], subject: "test", text: "plain" };
beforeEach(() => { fake.fail = false; fake.smtpCalls = 0; fake.imapCalls = 0; fake.readCalls = 0; });
-it("composes alternatives, original PNG CID bytes, recipients and reply headers; files the identical raw", async () => {
+async function sentCopy() {
+ const sent = await simpleParser(fake.raw, { skipImageLinks: true });
+ const filed = await simpleParser(fake.filed, { skipImageLinks: true });
+ expect(sent.bcc).toBeUndefined();
+ for (const key of ["messageId", "date", "from", "to", "cc", "subject", "text", "html", "inReplyTo", "references", "attachments"] as const) {
+ expect(filed[key], key).toEqual(sent[key]);
+ }
+ return filed;
+}
+
+it("composes alternatives, original PNG CID bytes, recipients and reply headers; keeps Bcc only in Sent", async () => {
const result = await sendMessage(account, openGuard, { ...input, html: '<p>rich<img src="cid:logo"></p>', inline_images: [image], inReplyTo: "<[email protected]>" });
const parsed = await simpleParser(fake.raw, { skipImageLinks: true });
expect(fake.raw.toString()).toContain("multipart/alternative");
@@ -34,9 +44,22 @@ it("composes alternatives, original PNG CID bytes, recipients and reply headers;
expect(parsed.inReplyTo).toBe("<[email protected]>");
expect(parsed.references).toBe("<[email protected]>");
expect(fake.envelope.to).toEqual([...input.to, ...input.cc, ...input.bcc]);
- expect(fake.filed).toEqual(fake.raw);
+ expect((await sentCopy()).bcc).toMatchObject({ value: [{ address: input.bcc[0] }] });
expect(result.filed).toBe(true);
});
+it("preserves named blind-copy recipients in a plain-text Sent copy", async () => {
+ const result = await sendMessage(account, openGuard, { ...input, bcc: ['"Hidden, Name" <[email protected]>', "隐名 <[email protected]>"] });
+ expect((await sentCopy()).bcc).toMatchObject({ value: [
+ { address: "[email protected]", name: "Hidden, Name" }, { address: "[email protected]", name: "隐名" },
+ ] });
+ expect(fake.envelope.to).toEqual([...input.to, ...input.cc, "[email protected]", "[email protected]"]);
+ expect(result.filed).toBe(true);
+});
+it.each([undefined, []])("files the identical raw when Bcc is %j", async (bcc) => {
+ await sendMessage(account, openGuard, { ...input, bcc });
+ expect((await sentCopy()).bcc).toBeUndefined();
+ expect(fake.filed).toEqual(fake.raw);
+});
it("keeps old text calls and reports failed filing", async () => {
fake.fail = true;
expect((await sendMessage(account, openGuard, input)).filed).toBe(false);
@@ -102,7 +125,7 @@ it("preserves HTML and inline PNG bytes through the native host and client", asy
expect(parsed.references).toBe("<[email protected]>");
expect(parsed.to).toMatchObject({ value: [{ address: input.to[0] }] });
expect(parsed.cc).toMatchObject({ value: [{ address: input.cc[0] }] });
- expect(fake.filed).toEqual(fake.raw);
+ expect((await sentCopy()).bcc).toMatchObject({ value: [{ address: input.bcc[0] }] });
expect(fake.smtpCalls).toBe(1); expect(fake.imapCalls).toBe(1);
});
});
@@ -141,7 +164,7 @@ it("passes the maximum declared aggregate through harnessMcpRequest and rejects
expect(parsed.inReplyTo).toBe(replyMessageId);
expect(parsed.references).toBe(replyMessageId);
expect(parsed.html).toBe(args.html);
- expect(fake.filed).toEqual(fake.raw);
+ expect((await sentCopy()).bcc).toMatchObject({ value: [{ address: input.bcc[0] }] });
expect(JSON.parse(valid.result.content[0]!.text).filed).toBe(true);
fake.smtpCalls = 0; fake.imapCalls = 0; fake.readCalls = 0;
const over = { ...args, html: args.html + "x" };