Adds a "Send email to group" action (To / Cc / Bcc) that opens the composer
pre-filled with the group's members in the chosen field, preserving each
member's display name. It is available both in the group context menu (between
"Edit Group" and "Delete") and in the group detail panel's header (shown when
the group has at least one member with an email). The single-contact "Send
email" button in the contact detail panel uses the same path.
Routing is internal, not via mailto:. Contacts is its own route and the composer
lives in the mail route, so the handoff stashes the recipients
(savePendingMailto) and does a client-side router.push("/"); the main route's
existing consumePendingMailto effect opens the composer in the current account.
This avoids the OS mailto handler (which could open a different mail app) and
the protocol round-trip's full-page reload, which dropped the in-memory
per-account JMAP clients of a multi-account session (a logout).
- contacts/page.tsx: openComposeInApp(recipients, field) shared helper;
handleComposeGroupFromSidebar (deduped "Name <email>" members, empty -> toast)
and handleComposeContact; wired to the sidebar, group detail, contact detail.
- contact-group-detail.tsx: onComposeGroup(field) prop + To/Cc/Bcc header control
(shown when the group has emailable members).
- contacts-sidebar.tsx: onComposeGroup(groupId, field) prop + "Send email to
group" submenu between Edit and Delete.
- contact-detail.tsx: onCompose() prop; the button is no longer a mailto: link.
- mailto.ts: recipient splitter is quote-aware (reuses the composer's
splitRecipients) so a comma in a display name survives — still useful for real
OS mailto: links.
- i18n: contacts.groups.send_email{,_to,_cc,_bcc} and no_member_emails across all
locales.
Display names round-trip via formatRecipient -> parseRecipientList.
39 lines
1.6 KiB
TypeScript
39 lines
1.6 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import { parseMailto } from "@/lib/protocol-handlers/mailto";
|
|
import { formatRecipient, parseRecipientList } from "@/lib/email-composer-utils";
|
|
|
|
// Build a mailto: URL the way a recipient picker encodes one: each recipient
|
|
// percent-encoded and comma-joined, To in the path, Cc/Bcc in a query param.
|
|
// Used only to exercise parseMailto's quote-aware recipient splitting.
|
|
function encodeMailto(recipients: string[], field: "to" | "cc" | "bcc"): string {
|
|
const encoded = recipients.map((r) => encodeURIComponent(r)).join(",");
|
|
return field === "to" ? `mailto:${encoded}` : `mailto:?${field}=${encoded}`;
|
|
}
|
|
|
|
describe("parseMailto display-name handling", () => {
|
|
it("preserves display names through the mailto round-trip", () => {
|
|
const recipients = [
|
|
formatRecipient("Alice Smith", "alice@x.com"),
|
|
formatRecipient("Bob", "bob@y.com"),
|
|
];
|
|
const parsed = parseMailto(encodeMailto(recipients, "to"));
|
|
expect(parseRecipientList(parsed!.to.join(", "))).toEqual([
|
|
{ name: "Alice Smith", email: "alice@x.com" },
|
|
{ name: "Bob", email: "bob@y.com" },
|
|
]);
|
|
});
|
|
|
|
it("keeps a display name containing a comma intact (quote-aware split)", () => {
|
|
const recipients = [
|
|
formatRecipient("Doe, John", "john@doe.org"), // -> "Doe, John" <john@doe.org>
|
|
"alice@x.com",
|
|
];
|
|
const parsed = parseMailto(encodeMailto(recipients, "cc"));
|
|
expect(parsed!.cc).toEqual(['"Doe, John" <john@doe.org>', "alice@x.com"]);
|
|
expect(parseRecipientList(parsed!.cc.join(", "))).toEqual([
|
|
{ name: "Doe, John", email: "john@doe.org" },
|
|
{ email: "alice@x.com" },
|
|
]);
|
|
});
|
|
});
|