tags:

views:

20

answers:

2

Using standard spec IMAP commands, how can I determine the previous and next UIDs in a mailbox based on a passed UID, sorting the mailbox messages by date, newest first?

A: 

I'm not familiar with the exact commands, but have you checked out the RFC?

http://tools.ietf.org/html/rfc3501

Looks like there is a UIDNEXT command you can send that gives you the next UID.

Climber104
Actually, i'm pretty sure that the UIDNEXT response is only returned by the SELECT/EXAMINE commands on a specified mailbox, and it refers to the UID that will be given to the next message that gets added to that mailbox. I'm looking for the the next/previous UIDs of existing messages in a mailbox, relative to a passed UID. This would be implemented when viewing a message to enable navigating to the next/previous message.
Bill Dami
A: 

I think the only way would be to ask for all UIDs first:

UID SEARCH ALL

...and sort. Each message added to the mailbox is assigned a higher UID than the messages which were added previously.

So higher UID = newer email.

Pawel Lesnikowski
Yeah, thats what I was afraid of. Reason being this is a fairly expensive command to execute, mainly for large mailboxes (10K+ messages) which some users of the system (read: gmail accounts) will have. I was hoping there was a more efficient way to get this data.
Bill Dami
It's not expensive at all. For mailbox with 10399 emails it takes 0,254 seconds to execute and create a list of longs. At least with Mail.dll
Pawel Lesnikowski