-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Don't summarize our own emails in digest #780
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,8 @@ import { aiSummarizeEmailForDigest } from "@/utils/ai/digest/summarize-email-for | |
| import { getEmailAccountWithAi } from "@/utils/user/get"; | ||
| import type { StoredDigestContent } from "@/app/api/resend/digest/validation"; | ||
| import { withError } from "@/utils/middleware"; | ||
| import { isAssistantEmail } from "@/utils/assistant/is-assistant-email"; | ||
| import { env } from "@/env"; | ||
|
|
||
| export const POST = withError( | ||
| verifySignatureAppRouter(async (request: Request) => { | ||
|
|
@@ -28,6 +30,22 @@ export const POST = withError( | |
| throw new Error("Email account not found"); | ||
| } | ||
|
|
||
| // Don't summarize Digest emails (this will actually block all emails that we send, but that's okay) | ||
| if (message.from === env.RESEND_FROM_EMAIL) { | ||
| logger.info("Skipping digest item because it is from us"); | ||
| return new NextResponse("OK", { status: 200 }); | ||
| } | ||
|
Comment on lines
+33
to
+37
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainMake “from us” check robust to display names/casing Direct string equality may miss cases like different display names or casing. Normalize to the bare address before compare. Apply: - // Don't summarize Digest emails (this will actually block all emails that we send, but that's okay)
- if (message.from === env.RESEND_FROM_EMAIL) {
+ // Don't summarize any emails we send ourselves
+ const fromAddr =
+ (message.from?.match(/<([^>]+)>/)?.[1] ?? message.from)?.toLowerCase();
+ const resendAddr =
+ (env.RESEND_FROM_EMAIL?.match(/<([^>]+)>/)?.[1] ??
+ env.RESEND_FROM_EMAIL)?.toLowerCase();
+ if (fromAddr && resendAddr && fromAddr === resendAddr) {
logger.info("Skipping digest item because it is from us");
return new NextResponse("OK", { status: 200 });
}You may want to also check Reply-To/Sender if those can differ from From in your pipeline. 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "=== Print file (if exists) ==="
if [ -f "apps/web/app/api/ai/digest/route.ts" ]; then
sed -n '1,240p' apps/web/app/api/ai/digest/route.ts
else
echo "FILE_NOT_FOUND: apps/web/app/api/ai/digest/route.ts"
fi
echo
echo "=== Search for RESEND_FROM_EMAIL across repo ==="
rg -n --hidden --no-ignore-vcs 'RESEND_FROM_EMAIL' || true
echo
echo "=== Search for 'message.from' usage across repo ==="
rg -n --hidden --no-ignore-vcs '\bmessage\.from\b' || true
echo
echo "=== Show surrounding lines for 'message.from' matches (in file if present) ==="
rg -n -C3 '\bmessage\.from\b' apps -S || true
echo
echo "=== Show env exports / definitions that reference RESEND_FROM_EMAIL (common places) ==="
rg -n --hidden --no-ignore-vcs 'RESEND_FROM_EMAIL' -S || trueLength of output: 9624 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "=== rg digestBody ==="
rg -n 'digestBody' -S || true
echo
echo "=== validation file (if exists) ==="
if [ -f "apps/web/app/api/ai/digest/validation.ts" ]; then
sed -n '1,240p' apps/web/app/api/ai/digest/validation.ts
else
echo "NOT_FOUND: apps/web/app/api/ai/digest/validation.ts"
fi
echo
echo "=== env.ts ==="
sed -n '1,240p' apps/web/env.ts || true
echo
echo "=== resend summary route (around 220-260) ==="
sed -n '200,300p' apps/web/app/api/resend/summary/route.ts || true
echo
echo "=== resend digest route (around 270-300) ==="
sed -n '260,320p' apps/web/app/api/resend/digest/route.ts || true
echo
echo "=== outlook message mapping (around 320-360) ==="
sed -n '320,380p' apps/web/utils/outlook/message.ts || true
echo
echo "=== microsoft email parsing (around 740-780) ==="
sed -n '720,800p' apps/web/utils/email/microsoft.ts || true
echo
echo "=== assistant is-assistant-email utility ==="
sed -n '1,240p' apps/web/utils/assistant/is-assistant-email.ts || true
echo
echo "=== ai group find-receipts snippet (around 120-140) ==="
sed -n '110,140p' apps/web/utils/ai/group/find-receipts.ts || trueLength of output: 21445 Make “from us” check robust to display names/casing Strict equality fails because env.RESEND_FROM_EMAIL defaults to a display-name form (e.g. "Inbox Zero updates@transactional.getinboxzero.com") while incoming messages may have only the bare address. Normalize to the bare address before comparing. File: apps/web/app/api/ai/digest/route.ts (around lines 33–37) — add import: Replace the equality check with: // Don't summarize any emails we send ourselves
const fromAddr =
extractEmailAddress(message.from)?.toLowerCase() ??
message.from?.toLowerCase();
const resendAddr =
extractEmailAddress(env.RESEND_FROM_EMAIL)?.toLowerCase() ??
env.RESEND_FROM_EMAIL?.toLowerCase();
if (fromAddr && resendAddr && fromAddr === resendAddr) {
logger.info("Skipping digest item because it is from us");
return new NextResponse("OK", { status: 200 });
}Also consider checking Reply-To / Sender if those can differ in your pipeline. 🤖 Prompt for AI Agents |
||
|
|
||
| const isFromAssistant = isAssistantEmail({ | ||
| userEmail: emailAccount.email, | ||
| emailToCheck: message.from, | ||
| }); | ||
|
|
||
| if (isFromAssistant) { | ||
| logger.info("Skipping digest item because it is from the assistant"); | ||
| return new NextResponse("OK", { status: 200 }); | ||
| } | ||
|
|
||
| const ruleName = await resolveRuleName(actionId); | ||
| const summary = await aiSummarizeEmailForDigest({ | ||
| ruleName, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| v2.9.26 | ||
| v2.9.27 |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normalize From and RESEND_FROM_EMAIL to bare, lowercase addresses before comparing; strict equality will miss cases with display names or different casing and fail to skip our own emails.
Prompt for AI agents