tags:

views:

740

answers:

4

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 docs

A: 

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)

Pawel Lesnikowski
I'm not married to IMAP, but I do need some sort of way I can automate searching through my entire inbox and link to the matching items.
felixge
You would think that maybe all the mail items might have the same thread id.
wizard
+1  A: 

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&[email protected]

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/[email protected]

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.

AttishOculus
Ok, the search for message-id is somewhat acceptable. E-Mail /PM me and I'll send you a $15 gift cert for the cleanest partial solution, ok?
felixge
A: 

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.

carillonator
+1  A: 

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

Takhion
I guess that's the correct answer, unfortunately : ). I was hoping for a way to do it via IMAP.
felixge