feat: add sort param to messages endpoint, default desc (newest first)

This commit is contained in:
James 2026-02-01 05:00:12 +00:00
parent 36637c0d70
commit b133ac7a8a
1 changed files with 10 additions and 1 deletions

View File

@ -17,8 +17,13 @@ async def list_messages(
from_addr: Optional[str] = Query(default=None, alias="from"),
limit: int = Query(default=50, le=200),
offset: int = Query(default=0),
sort: str = Query(default="desc", regex="^(asc|desc)$"),
) -> list[Message]:
"""List messages in a folder."""
"""List messages in a folder.
Args:
sort: Sort order by date. "desc" (default) = newest first, "asc" = oldest first
"""
config = get_config()
if account_id not in config.accounts:
@ -36,6 +41,10 @@ async def list_messages(
from_addr=from_addr,
)
# Sort by UID (higher UID = newer message)
if sort == "desc":
uids = list(reversed(uids))
# Apply pagination
total = len(uids)
uids = uids[offset:offset + limit]