Search code examples
imapgmail-imap

Imap search command to get the most recent message?


Is there a command to do this? I can get messages since a certain date, or RECENT or UNSEEN, but I can't find any way to just get the newest message and only the newest message.


Solution

  • When you connect, the server gives you an EXISTS, telling you how many messages you have. Take that number (say, 62), and fetch that message: tag FETCH 62 (whatever). That's the most recent message that's been added to the mailbox.