Fix: Sort emails by date instead of UID order#98
Merged
Wh1isper merged 1 commit intoai-zerolab:mainfrom Jan 15, 2026
Merged
Conversation
The order parameter was sorting by IMAP UID order, which doesn't guarantee chronological order on all servers. ProtonMail Bridge (and potentially others) assign UIDs in non-chronological order, causing order=desc to return oldest emails instead of newest. This fix: - Fetches metadata for all matching emails - Sorts by the actual email Date header - Applies pagination after sorting Fixes ai-zerolab#97 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Wh1isper
approved these changes
Jan 15, 2026
Member
Wh1isper
left a comment
There was a problem hiding this comment.
I'm concerned about potential performance issues when dealing with a large number of files, but we can merge it first.
jbkjr
pushed a commit
to jbkjr/mcp-email-server
that referenced
this pull request
Jan 15, 2026
Addresses performance concern raised in ai-zerolab#98 review. The previous fix fetched headers for ALL emails before sorting, causing O(n) network calls for large mailboxes. Changes: - Add SORT capability detection (RFC 5256) - When SORT supported: server-side sorting, fetch only page headers - Fallback: batch fetch Date headers, sort, fetch page headers - Reduces network calls from O(n) to O(2) for any mailbox size Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
4 tasks
Contributor
Author
|
@Wh1isper Good catch on the performance concern! I've addressed this in #100 which:
This reduces network calls from O(n) to O(1) — for a mailbox with 10,000 emails requesting page 1, we now make 2 IMAP calls instead of 10,000. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
orderparameter inlist_emails_metadatato sort by actual email date instead of IMAP UID orderChanges
DateheaderTest plan
order=descshould return newest emails firstFixes #97