Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(mail): 限制每封邮件的头像自动查询数量

Dashd2906c0fc9e0
diff --git a/apps/desktop/src/renderer/features/right-sidebar/plugins/mail-preview/MailConversationView.tsx b/apps/desktop/src/renderer/features/right-sidebar/plugins/mail-preview/MailConversationView.tsx
index a8f723a7c9..b61a4c52be 100644
--- a/apps/desktop/src/renderer/features/right-sidebar/plugins/mail-preview/MailConversationView.tsx
+++ b/apps/desktop/src/renderer/features/right-sidebar/plugins/mail-preview/MailConversationView.tsx
@@ -10,7 +10,7 @@ import { useChatSessionFile } from '@/components/chat/ChatSessionFileContext';
import { UserMessageUrlLink } from '@/components/chat/UserMessageUrlLink';
import { findLinkifyMatches } from '@/components/chat/userMessageLinkify';
import { Button } from '@/components/ui/button';
-import { MailParticipants } from './MailParticipant';
+import { MailParticipants, mailAvatarLimits } from './MailParticipant';
type Props = {
mail: MailMessage;
@@ -19,7 +19,7 @@ type Props = {
retry: () => void;
};
-function MessageBody({ mail }: { mail: MailMessage }) {
+function MessageBody({ mail, avatarLimits }: { mail: MailMessage; avatarLimits: ReturnType<typeof mailAvatarLimits> }) {
const { t } = useTranslation();
const fields = mailMessageFields(mail, key => t(`mailReader.${key}`));
const values = Object.fromEntries(fields.map(f => [f.name, f.value]));
@@ -37,7 +37,7 @@ function MessageBody({ mail }: { mail: MailMessage }) {
{mail.markReadFailed && <p role="status" className="mb-2 text-12 text-muted-foreground">{t('mailReader.markReadFailed')}</p>}
<div className="mb-3 space-y-1 border-b border-border pb-3 text-12 text-muted-foreground">
{fields.filter(f => f.kind === 'recipients' && f.value.trim()).map(f => <div key={f.name} className="flex gap-2">
- <span className="shrink-0 pt-0.5">{f.label}</span><MailParticipants value={f.value} photos={mail.participantPhotos} />
+ <span className="shrink-0 pt-0.5">{f.label}</span><MailParticipants value={f.value} photos={mail.participantPhotos} avatarLimit={avatarLimits[f.name as 'to' | 'cc' | 'bcc']} />
</div>)}
</div>
{mail.bodyHtml ? <MailHtmlPreview value={mail.bodyHtml} images={mailPreviewImages(values)} reading />
@@ -74,6 +74,7 @@ function MessageRow({ summary, initial, selected, initiallyExpanded, accountId,
const validDate = !Number.isNaN(date.getTime());
const formatted = validDate ? new Intl.DateTimeFormat(i18n?.language, { dateStyle: 'medium', timeStyle: 'short' }).format(date) : dateText;
const from = message?.from || summary.from;
+ const avatarLimits = mailAvatarLimits({ from, to: message?.to || '', cc: message?.cc || '', bcc: message?.bcc || '' });
return <section className="my-3 overflow-hidden rounded-xl border border-border bg-[var(--mail-paper)] dark:bg-[var(--surface)]"
style={{ '--mail-paper': MAIL_PAPER_COLOR } as CSSProperties} data-mail-message-id={summary.messageId}>
<button type="button" aria-expanded={expanded} aria-label={t(expanded ? 'mailReader.collapseMessage' : 'mailReader.expandMessage', { from })}
@@ -81,7 +82,7 @@ function MessageRow({ summary, initial, selected, initiallyExpanded, accountId,
{expanded ? <ChevronDown className="mt-1 h-3.5 w-3.5 shrink-0 text-muted-foreground" /> : <ChevronRight className="mt-1 h-3.5 w-3.5 shrink-0 text-muted-foreground" />}
<span className="min-w-0 flex-1">
<span className="flex flex-wrap items-baseline justify-between gap-x-3 gap-y-1">
- <span className="min-w-0 text-13 font-medium text-foreground"><MailParticipants value={from || t('mailReader.title')} photos={message?.participantPhotos} compact={false} /></span>
+ <span className="min-w-0 text-13 font-medium text-foreground"><MailParticipants value={from || t('mailReader.title')} photos={message?.participantPhotos} compact={false} avatarLimit={avatarLimits.from} /></span>
<span className="flex items-center gap-2 text-12 text-muted-foreground">
{selected && <span>{t('mailReader.currentMessage')}</span>}
{dateText && <time dateTime={validDate ? date.toISOString() : undefined} title={dateText}>{formatted}</time>}
@@ -91,7 +92,7 @@ function MessageRow({ summary, initial, selected, initiallyExpanded, accountId,
</span>
</button>
{expanded && <div className="px-3 pb-3 pt-1">
- {message ? <MessageBody mail={message} /> : <div className="py-3 text-13 text-muted-foreground" role="status">
+ {message ? <MessageBody mail={message} avatarLimits={avatarLimits} /> : <div className="py-3 text-13 text-muted-foreground" role="status">
{t(failed ? 'mailReader.failed' : 'mailReader.loading')}
{failed && <Button className="ml-2" variant="secondary" size="sm" onClick={() => setAttempt(n => n + 1)}>{t('mailReader.retry')}</Button>}
</div>}
diff --git a/apps/desktop/src/renderer/features/right-sidebar/plugins/mail-preview/MailParticipant.tsx b/apps/desktop/src/renderer/features/right-sidebar/plugins/mail-preview/MailParticipant.tsx
index 3364ce4965..8b9ccdce64 100644
--- a/apps/desktop/src/renderer/features/right-sidebar/plugins/mail-preview/MailParticipant.tsx
+++ b/apps/desktop/src/renderer/features/right-sidebar/plugins/mail-preview/MailParticipant.tsx
@@ -2,6 +2,19 @@ import { useEffect, useState } from 'react';
import { ghostCardRecipients } from '@cindy/maker-shared/ghost-card-form';
import { mailParticipantEmail, type MailMessage } from '@cindy/maker-shared/mail-message';
+const maxMailAvatars = 12;
+
+/** Count positions, including duplicates, so all header rows share one budget. */
+export function mailAvatarLimits(mail: Pick<MailMessage, 'from' | 'to' | 'cc' | 'bcc'>) {
+ let remaining = maxMailAvatars;
+ const limits = { from: 0, to: 0, cc: 0, bcc: 0 };
+ for (const key of ['from', 'to', 'cc', 'bcc'] as const) {
+ limits[key] = remaining ? Math.min(remaining, ghostCardRecipients(mail[key]).length) : 0;
+ remaining -= limits[key];
+ }
+ return limits;
+}
+
// A mailbox provider's logo is not the identity of everyone using its service.
const publicMailDomains = new Set(('gmail.com googlemail.com outlook.com hotmail.com live.com msn.com ' +
'icloud.com me.com mac.com yahoo.com yahoo.co.uk yahoo.co.jp ymail.com rocketmail.com aol.com ' +
@@ -49,15 +62,16 @@ function Avatar({ email, label, photo, compact }: { email?: string; label: strin
}
/** Shared sender/recipient presentation; the full address remains visible on hover. */
-export function MailParticipants({ value, photos, compact = true }: {
- value: string; photos?: MailMessage['participantPhotos']; compact?: boolean;
+export function MailParticipants({ value, photos, compact = true, avatarLimit = maxMailAvatars }: {
+ value: string; photos?: MailMessage['participantPhotos']; compact?: boolean; avatarLimit?: number;
}) {
return <span className="inline-flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1.5">
{ghostCardRecipients(value).map(({ address, label }, index) => {
const email = mailParticipantEmail(address);
- const photo = photos?.find(item => item.email === email)?.url;
+ const avatarEmail = index < avatarLimit ? email : undefined;
+ const photo = avatarEmail ? photos?.find(item => item.email === avatarEmail)?.url : undefined;
return <span key={`${address}:${index}`} title={address} className="inline-flex min-w-0 max-w-full items-center gap-1.5">
- <Avatar key={`${email}:${photo}`} email={email} label={label} photo={photo} compact={compact} />
+ <Avatar key={`${avatarEmail}:${photo}`} email={avatarEmail} label={label} photo={photo} compact={compact} />
<span className="min-w-0 break-words [overflow-wrap:anywhere]">{compact ? address : label}
{!compact && email && email !== label && <span className="block text-12 font-normal text-muted-foreground">{email}</span>}
</span>
diff --git a/apps/desktop/src/renderer/features/right-sidebar/plugins/mail-preview/MailPreview.test.tsx b/apps/desktop/src/renderer/features/right-sidebar/plugins/mail-preview/MailPreview.test.tsx
index 2117de1e0f..1326795add 100644
--- a/apps/desktop/src/renderer/features/right-sidebar/plugins/mail-preview/MailPreview.test.tsx
+++ b/apps/desktop/src/renderer/features/right-sidebar/plugins/mail-preview/MailPreview.test.tsx
@@ -45,6 +45,32 @@ it('shows sender and recipient avatars and falls back without requesting public
expect(screen.getByText('P')).toBeTruthy();
expect(screen.getByText('O')).toBeTruthy();
});
+// The real reader must bound all header positions, not just unique addresses
+// or each recipient field separately; every surplus address stays visible.
+it.each(['body', 'summary'])('bounds avatar lookups across all headers and duplicates, with sender from %s', async source => {
+ const digest = vi.fn(async (_algorithm: string, bytes: Uint8Array) => Uint8Array.from(createHash('sha256').update(bytes).digest()).buffer);
+ vi.stubGlobal('crypto', { subtle: { digest } });
+ const recipients = Array.from({ length: 50 }, () => 'Repeated <[email protected]>').join(', ');
+ h.read.mockResolvedValue({ message: { ...mail('Many recipients'), from: source === 'body' ? 'Owner <[email protected]>' : '',
+ to: recipients, cc: 'CC <[email protected]>', bcc: 'BCC <[email protected]>',
+ participantPhotos: [{ email: '[email protected]', url: 'https://lh3.googleusercontent.com/budget-exceeded' }],
+ ...(source === 'summary' ? { conversation: { threadId: 'thread', messages: [{ messageId: 'Many recipients',
+ url: 'https://mail.example/a', from: 'Owner <[email protected]>', date: '', subject: '', snippet: '' }] } } : {}) } });
+ const view = render(<MailPreviewBody state={{ url: 'https://mail.example/a' }} ctx={ctx} />);
+ await act(async () => {});
+ expect(digest).toHaveBeenCalledTimes(12);
+ expect(view.container.querySelectorAll('img')).toHaveLength(12);
+ expect(screen.getAllByText('Repeated <[email protected]>')).toHaveLength(50);
+ expect(screen.getByText('CC <[email protected]>')).toBeTruthy();
+ expect(screen.getByText('BCC <[email protected]>')).toBeTruthy();
+ await act(async () => { view.container.querySelectorAll('img').forEach(image => fireEvent.error(image)); });
+ expect(view.container.querySelectorAll('img')).toHaveLength(12);
+ expect([...view.container.querySelectorAll('img')].every(image => image.src.includes('icons.duckduckgo.com'))).toBe(true);
+ await act(async () => { view.container.querySelectorAll('img').forEach(image => fireEvent.error(image)); });
+ expect(view.container.querySelectorAll('img')).toHaveLength(0);
+ expect(digest).toHaveBeenCalledTimes(12);
+});
+
// Unit: plain-text mail previously had no clickable URLs. Only web URLs may
// become actions; local paths and task deep links from senders remain text.
it('makes plain-text mail URLs clickable without interpreting other content', async () => {
diff --git a/docs/dev-rules/protocol-compatibility.md b/docs/dev-rules/protocol-compatibility.md
index 517f1ed9cb..2ae2b87572 100644
--- a/docs/dev-rules/protocol-compatibility.md
+++ b/docs/dev-rules/protocol-compatibility.md
@@ -3187,6 +3187,9 @@ It travels in the existing message response/resource with no new IPC or permissi
Desktop uses it before Gravatar (SHA-256 normalized email), a fixed DuckDuckGo domain
favicon endpoint for non-public mailbox domains, and initials. External avatars use
no referrer and bounded load fallbacks; they do not enable remote images in the body.
+Desktop loads avatar sources for at most the first 12 participant positions per
+message, shared across from/to/cc/bcc; duplicates also consume a position. Remaining
+participants use initials and retain their complete addresses, without photo or hash lookups.
Domain icons are presentation, not authenticated sender identity. Other clients may
continue displaying addresses alone. Provider contact enrichment must remain optional
when new contact scopes are missing; Gmail bounds its lookup budget and account cache.