KartikTalwar/gmail.js — pull request #51 by g8g3 (2014-04-23 09:36:18+00:00)
Title: Added `api.get.displayed_email_data()`

4 new functions:
* `api.get.displayed_email_data()`: returns the whole thread data if convo is on, or _only one_ email data (the one displayed) if convo is off ;
* `api.check.is_conversation_view()`: returns _true_ or _false_ if convo is respectively _on_ / _off_. If it can't be defined, returns _undefined_ ;
* `api.tools.extract_email_address(str)`: returns the first email address found in string ;
* `api.tools.extract_name(str)`: returns the first name found in string ;

-
`api.get.displayed_email_data()` takes care of filtering all the thread metadata. Its email counter is fixed at 1, and both `threads` and `total_threads` contain a single element.

I could have been more generic and proposed a way of keeping "any email that is displayed", instead of "one email only".
That would be necessary if non-convo view allowed several emails in a view, which I think can't happen. (Well, previous emails nested in the current email don't count.) That's why I kept it that way.

The `subject` property is the one of the thread ; no "Re: " prepended even if there's one on the current email.

The `people_involved` array is re-built with what is found in the thread considered displayed: `from`, `from_email` and every element of `to` (from which we extract a name and an email address, to look like what `api.get.email_data()` returns).

-
To figure out if an email is displayed, provided its `id`, we use the `$('.ii.gt[class*="' + id + '"]')` jQuery selector.
As only one email is supposed to be (fully) displayed, its id is supposed to be embedded in the DOM.

-
I don't know if creating that branch directly on `KartikTalwar/gmail.js` would have been possible/relevant (never done on GitHub [: ). Anyway I did it as before, it's almost as easy.