Skip to content

perf: Optimize Encrypted Email detection via server-side Content-Class filter [v4.2.3] - #166

Merged
embiway merged 4 commits into
google:mainfrom
rishiksingh11:perf/encrypted-emails-server-filter
Sep 11, 2026
Merged

embiway merged 4 commits into
google:mainfrom
rishiksingh11:perf/encrypted-emails-server-filter

Conversation

@rishiksingh11

@rishiksingh11 rishiksingh11 commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer: @NityamPareek

Proposed Release Tag:

This PR proposes and tags release **** for Migration Planner.
Tag reference:


PR Description: Optimize Encrypted Email Detection via Server-Side MAPI Filter

Summary of Changes

Replaces the client-side email-by-email pagination scan (Option C introduced in PR #100) with a server-side indexed MAPI filter on Microsoft Graph API.

Problem with Previous Approach (PR #100)

  • Scanned entire mailboxes by iterating every single email in pages of 500 ($expand=attachments($select=name)&$top=500&$select=id).
  • For large mailboxes (e.g. 30k–50k+ messages), required tens to hundreds of sequential paginated batch requests downloading large payloads.
  • Required displaying a performance warning to users and caused multi-minute delays per user (projected 45+ minutes for 440,000 messages across 5 users).

New Approach: Server-Side MAPI Extended Property Filter

Exchange Online / Microsoft Purview / OME stamps encrypted messages with the internet header Content-Class: rpmsg.message, mapped to MAPI named property:

String {00020386-0000-0000-C000-000000000046} Name Content-Class

We query Graph API using an indexed OData filter:

GET /v1.0/users/{user_id}/messages?$filter=singleValueExtendedProperties/Any(ep: ep/id eq 'String {00020386-0000-0000-C000-000000000046} Name Content-Class' and ep/value eq 'rpmsg.message')&$count=true&$top=1&$select=id
Headers:
  ConsistencyLevel: eventual
  • 0 emails downloaded: Fetches the count directly from @odata.count in a single batch request, matching how contacts, calendars, and normal messages are retrieved.
  • Accuracy: Accurately counts native encrypted messages, including messages where hasAttachments == false (where Exchange treats .rpmsg as an alternative body wrapper rather than a user file attachment).

Performance Benchmarks

Metric Previous Approach (PR #100) New Server-Side MAPI Filter Improvement
Single User (31,837 emails) > 5 minutes (64 paginated batch requests) 0.87 seconds (1 batch request) > 350x faster
5 Users (441,477 emails) ~45+ minutes 8.05 seconds > 330x faster
Payload Transferred Full attachment metadata per email Single @odata.count header > 99.9% reduction
Accurate Encrypted Count Counted .rpmsg file attachments 31,792 true encrypted messages Identical / Higher Fidelity

Trial Run Demo (Screencast)

Below is an end-to-end screencast of a trial run using the new code: entering credentials, selecting CSV input, toggling Encrypted Emails under Advanced Settings, scanning the mailbox in real-time, and rendering the final Corpus Report and Timeline:

Trial Run Demo


UI Changes & Screenshots

  1. Configuration Screen: "Encrypted Emails" toggle is seamlessly integrated under Advanced Settings without needing a slow scan warning dialog.
    ![Configuration Screen](Configuration Screen)

  2. Results View: Displays detected encrypted emails along with total emails and timeline projection.
    ![Results Screen](Results Screen)


Verification

  • Validated against test tenant rishiksingh@rishiktest.onmicrosoft.com (verified counts, @odata.count consistency, and timing).
  • Validated UI updates, stats accumulation, and report generation in ui/exchange_online_ui.py.
  • python3 -m py_compile checks passed with zero errors.
@rishiksingh11 rishiksingh11 changed the title perf: Optimize Encrypted Email detection via server-side Content-Class filter Sep 11, 2026
@rishiksingh11

Copy link
Copy Markdown
Contributor Author

cc @NityamPareek for review!

@NityamPareek
NityamPareek self-requested a review September 11, 2026 08:26
@embiway
embiway merged commit 3c6c381 into google:main Sep 11, 2026
6 checks passed
@NityamPareek

Copy link
Copy Markdown
Collaborator

@rishiksingh11 please ensure that you also clean up the dead code which is now not required after these changes.

@rishiksingh11

Copy link
Copy Markdown
Contributor Author

Addressed in follow-up PR #167: #167 - cleaned up the unused parameter and dead callback check.

@rishiksingh11
rishiksingh11 deleted the perf/encrypted-emails-server-filter branch September 11, 2026 11:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants