Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/drafts-audit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,21 @@ export function hasOverlappingRecipients(a: Mailbox[], b: Mailbox[]): boolean {
return false;
}

const MAX_SENT_SEARCH_RECIPIENTS = 5;

export function buildSentSearchQuery(normalizedSubject: string, recipients: Mailbox[]): string | null {
const emails = extractEmailAddresses(recipients);
const emails = extractEmailAddresses(recipients).slice(0, MAX_SENT_SEARCH_RECIPIENTS);
const cleanSubject = normalizedSubject.replace(/"/g, " ").replace(/\s+/g, " ").trim();
if (!cleanSubject && emails.length === 0) return null;

const parts = ["in:sent"];
if (cleanSubject) {
parts.push(`subject:"${cleanSubject}"`);
}
if (emails.length > 0) {
if (emails.length === 1) {
parts.push(`to:${emails[0]}`);
} else if (emails.length > 1) {
parts.push(`(${emails.map((email) => `to:${email}`).join(" OR ")})`);
}
return parts.join(" ");
}
Expand Down
Loading
Loading