Search code examples
gmailgmail-imapgoogle-api-clientgmail-api

Getting UID that you get for gmail IMAP using new REST API


Is it possible to get gmail UID that you get while using IMAP api by using new REST API. This would allow to keep some part of my IMAP code as it is and slowly migrate towards the new REST API.


Solution

  • Folder UIDs are IMAP protocol specific (and expensive to compute+maintain) so API server doesn't have those. However the X-GM-MSGID and X-GM-THRID Gmail IMAP extensions are indeed the same values the web UI and API use, just in decimal format not hex encoded and you can rely on them being the same according to docs:

    "The message ID is a 64-bit unsigned integer and is the decimal equivalent for the ID hex string used in the web interface and the Gmail API."

    from: https://developers.google.com/gmail/imap_extensions#access_to_the_gmail_unique_message_id_x-gm-msgid

    (Just need to trivially convert between decimal and hex string.)