Skip to content

Add filter for attachments - #100

Open
timrettop wants to merge 2 commits into
Gururagavendra:mainfrom
timrettop:attachment-filter
Open

Add filter for attachments#100
timrettop wants to merge 2 commits into
Gururagavendra:mainfrom
timrettop:attachment-filter

Conversation

@timrettop

@timrettop timrettop commented Mar 1, 2026

Copy link
Copy Markdown

Description

This adds a filter for whether emails have or do not have attachments, with the default option of "Any"

Checklist

  • I have tested my changes locally
  • Docker build works (if modified)

Related Issues

Fixes #99

  • Added attachment-based filtering to Gmail Cleaner allowing filters: Any (default), Has attachment, No attachment.
  • Backend: added optional has_attachment field to FiltersModel (app/models/schemas.py) with validator enforcing allowed values ("has" or "none").
  • Query builder: build_gmail_query() (app/services/gmail/helpers.py) maps has_attachment to Gmail syntax (has:attachment or -has:attachment).
  • Frontend: UI dropdown for attachment filter added to templates/index.html.
  • Client-side: static/js/filters.js updated to include has_attachment in filter payload and to reset the attachment control.
  • Docs: docs/index.html updated to mention attachment presence in Smart Filters.
  • Fixes issue [Feature]: Filter has or doesn't have attachment #99.

@coderabbitai

coderabbitai Bot commented Mar 1, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 692f48b and 7ee2aec.

📒 Files selected for processing (1)
  • docs/index.html

Walkthrough

Adds an optional has_attachment filter across stack: schema field and validator, Gmail query builder handling, frontend input and payload wiring, UI select for attachment presence, and documentation update.

Changes

Cohort / File(s) Summary
Backend Schema
app/models/schemas.py
Added optional has_attachment: Optional[str] to FiltersModel and a field validator enforcing allowed values "has" or "none", accepting null/empty.
Gmail Query Builder
app/services/gmail/helpers.py
Extended build_gmail_query to append has:attachment when has_attachment == "has" or -has:attachment when has_attachment == "none".
Frontend Logic
static/js/filters.js
Read filterAttachment input into local var and include has_attachment in the filter object returned by GmailCleaner.Filters.get(); clear filterAttachment in clear().
UI Template
templates/index.html
Inserted a new select element (filterAttachment) with options: Any, Has attachment, No attachment in the global filter bar.
Docs
docs/index.html
Updated Smart Filters description to mention filtering by label and attachment presence.

Sequence Diagram(s)

sequenceDiagram
    actor User
    participant UI as Filter UI
    participant JS as Frontend JS
    participant API as Backend API
    participant Service as Gmail Service
    participant Gmail as Gmail

    User->>UI: choose attachment filter ("Has"/"No"/"Any")
    UI->>JS: read `filterAttachment`
    JS->>JS: assemble filter object (includes `has_attachment`)
    JS->>API: submit filters
    API->>Service: pass filters
    Service->>Service: build Gmail query (append has:attachment or -has:attachment)
    Service->>Gmail: execute query / return built query
    API->>JS: return results
    JS->>UI: render filtered emails
Loading

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

✉️ A tiny flag for attachment’s fate,
From schema, service, front, to state,
Pick "has" or "none", send the query through,
Inbox neat — the picker knew! 📎

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add filter for attachments' directly and concisely describes the main change in the PR: adding attachment filtering capability.
Linked Issues check ✅ Passed The PR implements the core requirement from issue #99: adding has:attachment and -has:attachment filtering for emails, with UI controls and backend logic.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing the attachment filter feature; no unrelated or out-of-scope modifications are present.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
docs/index.html (1)

168-168: Consider improving the wording for clarity.

The phrase "has or doesn't have attachment" is slightly awkward. A cleaner alternative might be: "label, and attachment presence."

✏️ Suggested improvement
-                    <p class="text-[`#6B7A8F`] leading-relaxed">Filter by age (7d, 30d, 90d), size (1MB, 5MB, 10MB), category (Promotions, Social, Updates), label and has or doesn't have attachment.</p>
+                    <p class="text-[`#6B7A8F`] leading-relaxed">Filter by age (7d, 30d, 90d), size (1MB, 5MB, 10MB), category (Promotions, Social, Updates), label, and attachment presence.</p>
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/index.html` at line 168, Update the wording in the paragraph element
with class "text-[`#6B7A8F`] leading-relaxed" to replace the awkward phrase "has
or doesn't have attachment" with a clearer alternative such as "label, and
attachment presence" so the sentence reads: "Filter by age (7d, 30d, 90d), size
(1MB, 5MB, 10MB), category (Promotions, Social, Updates), label, and attachment
presence."
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@docs/index.html`:
- Line 168: Update the wording in the paragraph element with class
"text-[`#6B7A8F`] leading-relaxed" to replace the awkward phrase "has or doesn't
have attachment" with a clearer alternative such as "label, and attachment
presence" so the sentence reads: "Filter by age (7d, 30d, 90d), size (1MB, 5MB,
10MB), category (Promotions, Social, Updates), label, and attachment presence."

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a497fc7 and 692f48b.

📒 Files selected for processing (5)
  • app/models/schemas.py
  • app/services/gmail/helpers.py
  • docs/index.html
  • static/js/filters.js
  • templates/index.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Filter has or doesn't have attachment

1 participant