开发者

Find Gmail url-IDs via IMAP

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 I would like to do is write a script that accesses my Gmail account via IMAP and creates an HTML page with links like the above to each message I am interested in.

However, it seems there is no way to find the "124c8f386d41fd3a" ID from the IMAP envelope or UUID properties. All the message-ids and uuids I am finding are of a different format and can't be used to produce valid links to my inbox.

Does anybody know how to find those url-IDs in IMAP?

-- Felix Geisendörfer aka the_undefined

PS: I am using Ruby and my previous attempts included:

imap.fetch(message_id, "UID")
imap.fetch(message_id, "ENVELOPE")
imap.fetch(message_id, ...)

I tried all properties listed for FetchData in the ruby imap 开发者_Go百科docs


Gmail provides an attribute: X-GM-THRID for thread id.

You can use imap fetch function for getting the thread id.

Also see the documentation here.


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


Seems that the google link (https://mail.google.com/mail/#all/124c8f386d41fd3a) points to the whole conversation.

IMAP itself does not have such feature (grouping conversations)

[Update]

It is possible with X-GM-THRID Gmail's IMAP extension.

124c8f386d41fd3a is Gmail's thread-id in hex.

You can read more here: http://www.limilabs.com/blog/create-gmail-url-id-via-imap


This seems to be something internal to GMail's web UI. I can imagine a workaround like this:

  • log in to GMail using the basic HTML mode, and grab the session cookie
  • 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 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.


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.


It's been a while but anyone who finds themselves looking for this information should read this:

Gmail provides a unique message ID for each email so that a unique message may be identified across multiple folders. Retrieval of this message ID is supported via the X-GM-MSGID attribute on the FETCH command. 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.

The following is an example transcript of a call to retrieve the X-GM-MSGID of a message with the FETCH command:

a006 FETCH 1 (X-GM-MSGID)
* 1 FETCH (X-GM-MSGID 1278455344230334865) a006 OK FETCH (Success)

The X-GM-MSGID attribute may also be used in the SEARCH or UID SEARCH commands to find the sequence numbers or UID of a message given Gmail's message ID. The following is an example transcript of a call to retrieve the UID of a message using the UID SEARCH command:

 a007 UID SEARCH X-GM-MSGID 1278455344230334865
 * SEARCH 1 a007 OK SEARCH (Success)

the above is an extract from the following source: https://developers.google.com/gmail/imap_extensions?csw=1#access_to_the_gmail_unique_message_id_x-gm-msgid


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


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...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜