const { messages, nextCursor, unreadCount } =
await box.messages.list({ folder: "inbox", limit: 40, unread: true });
while (nextCursor) {
const page = await box.messages.list({ folder: "inbox", cursor: nextCursor });
}page = box.messages.list(folder="inbox", limit=40, unread=True)
messages, next_cursor, unread_count = page["messages"], page.get("nextCursor"), page.get("unreadCount")
while next_cursor:
page = box.messages.list(folder="inbox", cursor=next_cursor)
next_cursor = page.get("nextCursor")folderstringinboxinbox · sent · drafts · spam · trash.
limitinteger40How many.
cursorstringFrom the previous page's nextCursor.
unreadbooleanfalseOnly unread.
A date, not a page number
A message arriving between two pages pushes everything down, so page two repeats the last of page one. A date cursor is immune: it means « older than this », and new mail lands above it.
A summary is not the message
Sender, subject, date, flags, and the sender's picture. No body, no HTML, and attachments is a count — a page of forty full messages would be enormous for a list nobody reads in full.
The sender's picture is in the list
Which is where it is most useful. It is resolved when the message is delivered, not when it is read — so reading a folder is a read of our own data, with nothing fetched from outside.
unreadCount is for the folder
Not for the page. It is the number a badge should show.