Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(email): stop pinning one person's name onto every email from a shared sender (#7058)
teo6e32002336bd
diff --git a/apps/web/src/features/entity/extractors/entity-email-participants.tsx b/apps/web/src/features/entity/extractors/entity-email-participants.tsxindex 1f5182e094..db620840f3 100644--- a/apps/web/src/features/entity/extractors/entity-email-participants.tsx+++ b/apps/web/src/features/entity/extractors/entity-email-participants.tsx@@ -27,19 +27,24 @@ function getEmailLocalPart(email: string): string {/*** Resolves the best display name for a participant- * Priority: macroDisplayName > participant.name > email local part+ * Priority: participant.name > macroDisplayName > email local part+ *+ * `participant.name` is the From display name of that sender's message in+ * this thread, so it comes first: the Macro lookup is keyed by address alone+ * and falls back to the viewer's address book, which pins one person's name+ * onto every message from a shared sender such as [email protected].*/function resolveParticipantName(participant: EmailThreadParticipants[number],macroDisplayName?: string): string {- if (macroDisplayName && !isLikelyEmail(macroDisplayName)) {- return macroDisplayName;- }const participantFullName = participant.name ?? '';if (participantFullName && !isLikelyEmail(participantFullName)) {return participantFullName;}+ if (macroDisplayName && !isLikelyEmail(macroDisplayName)) {+ return macroDisplayName;+ }return getEmailLocalPart(participant.email);}diff --git a/apps/web/src/features/entity/tests/entity-email-participants.test.tsx b/apps/web/src/features/entity/tests/entity-email-participants.test.tsxnew file mode 100644index 0000000000..58043838e6--- /dev/null+++ b/apps/web/src/features/entity/tests/entity-email-participants.test.tsx@@ -0,0 +1,108 @@+import { cleanup, render } from '@solidjs/testing-library';+import { afterEach, describe, expect, it, vi } from 'vitest';+import { EntityEmailParticipants } from '../extractors/entity-email-participants';+import type { EmailEntity } from '../types/entity';++// The viewer's address book knows [email protected] as "Nathan Flurry"+// (the first person who booked through it) and [email protected] as a Macro user.+const addressBook: Record<string, string> = {+ 'macro|[email protected]': 'Nathan Flurry',+ 'macro|[email protected]': 'Wolf Ryan',+};++vi.mock('@core/user', () => ({+ emailToMacroId: (email: string) => `macro|${email.toLowerCase()}`,+ getDisplayName: (id: string) => addressBook[id] ?? id.replace('macro|', ''),+}));+vi.mock('@core/context/user', () => ({+ useEmail: () => () => '[email protected]',+}));+vi.mock('@core/component/HoverCard', () => ({+ HoverCard: (props: { trigger: unknown }) => <>{props.trigger}</>,+}));+vi.mock('@core/component/UserTooltip', () => ({+ UserTooltip: () => null,+}));+vi.mock('@core/component/Toast/Toast', () => ({+ toast: { success: () => {} },+}));+vi.mock(+ '@core/component/LexicalMarkdown/component/core/StaticMarkdown',+ () => ({+ StaticMarkdown: (props: { markdown: string }) => <>{props.markdown}</>,+ })+);+vi.mock('@core/component/LexicalMarkdown/theme', () => ({+ unifiedListMarkdownTheme: {},+}));++afterEach(cleanup);++const emailEntity = (+ participants: NonNullable<EmailEntity['participants']>+): EmailEntity =>+ ({+ id: 'thread-1',+ type: 'email',+ name: 'Subject',+ participants,+ }) as unknown as EmailEntity;++describe('EntityEmailParticipants', () => {+ it('shows the From display name of the message, not the address-book name of a shared sender', () => {+ const { container } = render(() => (+ <EntityEmailParticipants+ entity={emailEntity([+ { email: '[email protected]', name: 'Cal.com' },+ ])}+ />+ ));++ expect(container.textContent).toBe('Cal.com');+ });++ it('keeps distinct From names apart for messages from the same shared address', () => {+ const { container } = render(() => (+ <EntityEmailParticipants+ entity={emailEntity([+ { email: '[email protected]', name: 'Cal.com' },+ { email: '[email protected]', name: 'Nathan Flurry' },+ ])}+ />+ ));++ expect(container.textContent).toBe('Cal.com, Nathan');+ });++ it('falls back to the Macro display name when the message carries no From name', () => {+ const { container } = render(() => (+ <EntityEmailParticipants+ entity={emailEntity([{ email: '[email protected]' }])}+ />+ ));++ expect(container.textContent).toBe('Wolf Ryan');+ });++ it('falls back to the address local part when neither source has a name', () => {+ const { container } = render(() => (+ <EntityEmailParticipants+ entity={emailEntity([{ email: '[email protected]' }])}+ />+ ));++ expect(container.textContent).toBe('someone');+ });++ it('ignores names that are just an email address', () => {+ const { container } = render(() => (+ <EntityEmailParticipants+ entity={emailEntity([+ { email: '[email protected]', name: '[email protected]' },+ ])}+ />+ ));++ expect(container.textContent).toBe('Nathan Flurry');+ });+});diff --git a/services/email_service/src/util/sync_contacts.rs b/services/email_service/src/util/sync_contacts.rsindex 2490cb5dc3..78554236dc 100644--- a/services/email_service/src/util/sync_contacts.rs+++ b/services/email_service/src/util/sync_contacts.rs@@ -126,7 +126,12 @@ async fn fetch_new_contacts_from_google({Ok(contact_list) => {new_other_contacts_token = Some(contact_list.next_sync_token);- all_new_contacts.extend(contact_list.contacts);+ all_new_contacts.extend(+ contact_list+ .contacts+ .into_iter()+ .map(normalize_other_contact),+ );}Err(e) => {tracing::debug!(error = ?e, link_id = %link.id, "Failed to get other contacts");@@ -148,6 +153,18 @@ enum ContactListKind {Other,}+/// Google builds "other contacts" from mail headers, not from anything the+/// user saved, so their names get the same treatment as header names at+/// message ingest. Without it, a shared sender such as `[email protected]`+/// keeps the name of the first person who wrote through it, and the address+/// book then pins that person onto every message the address sends.+fn normalize_other_contact(mut contact: Contact) -> Contact {+ if let Some(email) = &contact.email_address {+ contact.name = email_utils::normalize_contact_name(email, contact.name.as_deref());+ }+ contact+}+/// Lists one contact collection, retrying once from scratch when the stored/// sync token has expired.///diff --git a/services/email_service/src/util/sync_contacts/test.rs b/services/email_service/src/util/sync_contacts/test.rsindex ef1f55ca08..fd215499dc 100644--- a/services/email_service/src/util/sync_contacts/test.rs+++ b/services/email_service/src/util/sync_contacts/test.rs@@ -107,6 +107,58 @@ fn assert_published_batches(thread_count: usize, expected_batch_sizes: &[usize])assert_eq!(published_thread_ids, thread_ids);}+fn other_contact(email: Option<&str>, name: Option<&str>) -> Contact {+ Contact {+ id: Uuid::from_u128(1),+ link_id: Uuid::from_u128(2),+ name: name.map(str::to_owned),+ email_address: email.map(str::to_owned),+ original_photo_url: None,+ sfs_photo_url: None,+ }+}++#[test]+fn other_contact_at_a_shared_sender_address_keeps_no_name() {+ let contact = normalize_other_contact(other_contact(+ Some("[email protected]"),+ Some("Nathan Flurry"),+ ));++ assert_eq!(contact.name, None);+ assert_eq!(+ contact.email_address.as_deref(),+ Some("[email protected]")+ );+}++#[test]+fn other_contact_at_a_personal_address_keeps_its_name() {+ let contact = normalize_other_contact(other_contact(+ Some("[email protected]"),+ Some("Nathan Flurry"),+ ));++ assert_eq!(contact.name.as_deref(), Some("Nathan Flurry"));+}++#[test]+fn other_contact_drops_the_relay_suffix_from_its_name() {+ let contact = normalize_other_contact(other_contact(+ Some("[email protected]"),+ Some("Nathan Flurry via Cal.com"),+ ));++ assert_eq!(contact.name.as_deref(), Some("Nathan Flurry"));+}++#[test]+fn other_contact_without_an_address_is_left_alone() {+ let contact = normalize_other_contact(other_contact(None, Some("Nathan Flurry")));++ assert_eq!(contact.name.as_deref(), Some("Nathan Flurry"));+}+#[tokio::test]async fn publishes_no_batches_for_zero_threads() {assert_published_batches(0, &[]);