Skip to content

Allow selective mailbox and folder indexing for Context Chat #13120

Description

@ga-it

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:

  1. Enable or disable Mail indexing.
  2. Select which mail accounts may be indexed.
  3. Select one or more folders within each account.
  4. Choose an “Inbox only” option.
  5. 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.

Metadata

Metadata

Assignees

No one assigned

    Fields

    No fields configured for Enhancement.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions