One of my favourite features of Gmail is the ability to bookmark urls to certain messages like this:
https://mail.google.com/mail/#all/124c8f386d41fd3a
What
Found something. May be someone need. I don't know how to use ruby, I want use php, but don't know how to extend standart imap functions in php.
openssl s_client -crlf -connect imap.gmail.com:993
. login username password
. select inbox
. FETCH 1 (X-GM-THRID)
you'll get something like this * 1 FETCH (X-GM-THRID 1327644190303473294)
next you need to convert it from decimal to hexadecimal value:
<?php echo dechex(1327644190303473294); ?> //return 126cbd5b5f264e8e
I was struggling with this too, and then i found the UID is actually the same thing as the Google Message ID.
The UID is an Integer and the Google Message ID is the Hexadecimal version of the that.
Unsure about conversion in ruby, but try this: Converting an integer to a hexadecimal string in Ruby
This seems to be something internal to GMail's web UI. I can imagine a workaround like this:
use curl, wget or anything similar with this session cookie to fetch the page
https://mail.google.com/mail/h?s=q&q=2AE41111.1234123@gmail.com
where the thing after the 'q=' part is the Message-ID of the e-mail from IMAP.
Now you can scrape the "GMail ID" of the message you need from the HTML, search for a link with a target URL that looks like this:
?v=c&s=q&q=2AE41111.1234123%40gmail.com&th=124ae57b77769275
The part after the 'th' is what you need.
Nasty, probably very inefficient, but this may very well be the closest you get to a solution.
If you are not that desperate, you can use the search URL, which, in its most simple form, and using the standard UI, looks like this:
https://mail.google.com/mail/#search/2AE41111.1234123@gmail.com
The last part is the value of the Message-ID header field again. This way, you get a single search result, but you still have to click on it to view.
I use a Mac menu bar app called Notify which shows me new GMail messages, which I can double-click to be taken to them on the GMail web site. Both IMAP and POP are disabled in my GMail settings, so therein may be the solution.
The URL that takes me to the message looks like this:
http://mail.google.com/mail/?fs=1&source=atom#all/124fb7xxxxx06752
(somewhat redacted in case it's personal)
I wonder if source=atom
could be helpful to you, since this application seems to have access to the ID you are looking for.
Actually, the only official method for getting a direct link to a message is through the atom feed gmail provides for unread messages (https://gmail.google.com/gmail/feed/atom)... The only difficulty is that you have to authenticate, which is not so common using feeds, and there's currently a limitation of like 15 new messages, so any newer message will "kick out" the oldest! I hope they'll soon provide it in some other way, be it through IMAP or API...
I think the accepted answer is incorrect (at this point, maybe it was right at the time).
If you look at the atom feed (https://gmail.google.com/gmail/feed/atom), you'll see that the entries look like this:
http://mail.google.com/mail?account_id=[EMAIL_ADDRESS]&message_id=1353f6fb621714da&view=conv&extsrc=atom
The message_id is probably the X-GM-MSGID in hex. You can retrieve the X-GM-MSGID via IMAP, so you ought to be able to contruct the URLs you want via IMAP, without using the atom feed.