Skip to content

Commit 58ac708

Browse files
Sai Sridharclaude
andcommitted
Fix Gmail sync: fetch recent emails instead of unread-only, run AI on manual sync
- Remove is:unread filter — was blocking sync for users with no unread emails - Default to last 7 days (after:YYYY/MM/DD) to limit scope without missing read emails - Manual /sync now calls _process_user_emails (with AI) instead of _sync_user_emails so emails appear categorized in priority inbox immediately after sync Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 7776090 commit 58ac708

2 files changed

Lines changed: 8 additions & 9 deletions

File tree

backend/routes/emails.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from services.ai_processor import process_email
1616
from services.gmail_service import send_gmail_reply, get_email_attachments, get_attachment_data
1717
from services.razorpay_service import PLAN_LIMITS
18-
from workers.email_listener import _sync_user_emails
18+
from workers.email_listener import _process_user_emails
1919

2020
logger = logging.getLogger(__name__)
2121
router = APIRouter(prefix="/emails", tags=["emails"])
@@ -158,7 +158,7 @@ async def sync_emails(
158158
current_user: Annotated[dict, Depends(get_current_user)],
159159
):
160160
"""Manually trigger a Gmail sync for the current user."""
161-
background_tasks.add_task(_sync_user_emails, _current_user_id(current_user))
161+
background_tasks.add_task(_process_user_emails, _current_user_id(current_user))
162162
return {"message": "Gmail sync started."}
163163

164164

backend/services/gmail_service.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ def _extract_body(payload: dict) -> str:
329329

330330
def _build_gmail_query(filters: dict) -> tuple[str, int]:
331331
"""Build Gmail search query and maxResults from user sync_filters."""
332-
parts = ["is:unread"]
332+
parts = []
333333

334334
# Label/folder filter — default to inbox
335335
labels = filters.get("sync_labels") or []
@@ -353,12 +353,11 @@ def _build_gmail_query(filters: dict) -> tuple[str, int]:
353353
else:
354354
parts.append("in:inbox")
355355

356-
# Date range
357-
days_back = filters.get("sync_days_back")
358-
if days_back and isinstance(days_back, int) and days_back > 0:
359-
from datetime import timedelta, timezone as _tz
360-
cutoff = (datetime.now(_tz.utc) - timedelta(days=days_back)).strftime("%Y/%m/%d")
361-
parts.append(f"after:{cutoff}")
356+
# Date range — default 7 days if not configured
357+
days_back = filters.get("sync_days_back") or 7
358+
from datetime import timedelta, timezone as _tz
359+
cutoff = (datetime.now(_tz.utc) - timedelta(days=int(days_back))).strftime("%Y/%m/%d")
360+
parts.append(f"after:{cutoff}")
362361

363362
# Sender allowlist (from:a OR from:b)
364363
allowlist = filters.get("sync_sender_allowlist") or []

0 commit comments

Comments
 (0)