import { describe, expect, it } from "vitest";
import type { MailboxConfig } from "../src/config.js";
import { buildRawMessage } from "../src/mail/mime.js";

const mailbox: MailboxConfig = {
  id: "mailbox-1",
  label: "Example",
  address: "sender@example.test",
  aliases: [],
  imap: {
    host: "mail.example.test",
    port: 993,
    secure: true,
    user: "sender@example.test",
    passwordEnv: "MAIL_PASSWORD",
  },
  folders: {},
  imapPassword: "secret",
};

const message = {
  mailbox_id: "mailbox-1",
  to: ["to@example.test"],
  cc: [],
  bcc: ["hidden@example.test"],
  subject: "Test",
  text: "Hello",
  references: [],
};

describe("MIME composition", () => {
  it("keeps Bcc in drafts but strips it from messages sent over SMTP", async () => {
    const draft = await buildRawMessage(mailbox, message, "draft");
    const outgoing = await buildRawMessage(mailbox, message, "send");

    expect(draft.raw.toString()).toContain("Bcc: hidden@example.test");
    expect(outgoing.raw.toString()).not.toContain("Bcc: hidden@example.test");
    expect(outgoing.envelope.to).toContain("hidden@example.test");
  });
});
