Allow selective mailbox and folder indexing for Context Chat
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 1k
- Forks
- 348
- Avg merge
- 12h 28m
- Merged PRs (30d)
- 91
Description
Title
Allow selective mailbox and folder indexing for Context Chat
Description
The Mail app currently appears to submit messages from all available mailboxes and folders to the mail__mail Context Chat provider.
I would like administrators and/or users to control which mail content is made available to Context Chat. The main requirement is an allowlist-based configuration where only explicitly selected folders are indexed.
For example:
Account: user@example.com
Include:
- Inbox
- Projects
- Projects/Client A
Exclude everything else
Filtering options could include:
- Specific mail accounts
- Specific mailbox or folder names
- Inbox only
- Selected folders only
- Excluding Sent, Drafts, Junk, Trash and Archive
- Per-user configuration
- Administrator-defined defaults or restrictions
The filtering should apply consistently to:
- Initial and scheduled imports
- Newly synchronized messages
- Existing mailbox indexing tasks
- Messages moved between included and excluded folders
When a message is moved out of an included folder, its indexed content should be removed from Context Chat. When moved into an included folder, it should become eligible for indexing.
Motivation
Mailboxes can contain large amounts of private, irrelevant or sensitive content. Enabling Context Chat should not necessarily mean making every message from every account and folder available for indexing.
Selective indexing would:
- Reduce unnecessary indexing and backend load
- Improve retrieval relevance
- Give users and administrators better privacy controls
- Restrict Context Chat to business-relevant folders
Suggested behaviour
A safe default would be:
Mail indexing disabled unless explicitly enabled.
When enabled:
Index only selected accounts and folders.
An allowlist is preferable to exclusions because new or renamed folders would remain excluded until deliberately selected.
Describe the solution you'd like
Add Context Chat indexing controls to the Mail app settings.
Users should be able to:
- Enable or disable Mail indexing.
- Select which mail accounts may be indexed.
- Select one or more folders within each account.
- Choose an “Inbox only” option.
- Optionally define excluded folders.
Administrators could additionally configure:
- Default folder-selection policy
- Mandatory exclusions for folders such as Junk or Trash
- Whether users may override the defaults
- An organization-wide allowlist
The selected policy should be enforced before Mail creates Context Chat indexing tasks and checked again before content is submitted.
Folder selection should preferably use stable mailbox identifiers rather than display names where possible.
Describe alternatives you've considered
The alternatives considered were:
- Disabling Mail integration with Context Chat entirely
- Manually moving relevant messages into a dedicated folder
- Filtering or discarding messages in a custom Context Chat backend
- Applying a local patch to the Mail app
Backend filtering is less suitable because the mail content has already left the Mail app by that stage. It would also duplicate account and mailbox logic that the Mail app already understands.
A local patch is possible, but a supported upstream configuration would be safer, maintainable across upgrades and useful to other privacy-conscious deployments.
Additional context
The relevant Mail implementation appears to be located in:
lib/BackgroundJob/ContextChat/ScheduleJob.php
lib/BackgroundJob/ContextChat/SubmitContentJob.php
lib/ContextChat/ContextChatProvider.php
lib/Service/ContextChat/ContextChatSettingsService.php
ScheduleJob currently iterates through all mailboxes returned for an account without applying folder-selection rules.
The same policy should be applied to both scheduled imports and the NewMessagesSynchronized event path so that newly synchronized messages cannot bypass the configured filters.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with lib/BackgroundJob/ContextChat/ScheduleJob.php and trace how it iterates mailboxes, then inspect SubmitContentJob.php, ContextChatProvider.php, and ContextChatSettingsService.php. Compare the scheduled import path with the NewMessagesSynchronized event path. Done means an explicit account/folder policy is enforced before tasks and submission, including removal when messages leave included folders.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100