Gathering Facebook Identities from Email

Looking at the announcement of the Facebook Graph API from Facebook F8 it seems like it will be a little easier to work with the Facebook system.

In Raindrop we already have some integration with Facebook in order to identify emails coming from the Facebook system and help you filter them out. But there is a lot more that can be done to help keep your email, Facebook, and other contacts in a cohesive form.

So here’s a quick code example written in Python to grab Facebook identities from emails sent by Facebook. This could be used to gather Facebook identities and then possibly merge those with twitter and email contacts.

First we need to import a couple things.

import email, json, urllib2

Then we’ll need to grab an email message.  I used Thunderbird to save a Facebook notification email message as an EML file locally, I called that file ‘facebook.eml’ as you can see below.

msg = email.message_from_file(open('facebook.eml'))

Now we have a parsed email message msg object and we want to look for the X-Facebook-Notify header in the email so we can extract what happened.

fb_notifiy = [tuple(t.strip().split("=")) for t in \

The object fb_notify contains tuples of information about the type of notification.  Here is an example of an object you might see.

 ('eid', '14102494623'),
 ('from', '21602578'),
 ('mailid', '12bf28cG149a112G63016bG21') ]

Using fb_notify we’ll do a really simple grab of the from attribute because that is what is going to be publicly available from the Facebook Graph.

from_identity = json.load(urllib2.urlopen("" % fb_notify[2][1]))

Here’s an example from_identity object:

{u'first_name': u'Bryan',
 u'last_name': u'Clark',
 u'id': u'21602578',
 u'name': u'Bryan Clark' }

The from_identity can be used to more clearly identify who Facebook is sending this notification on behalf of and we could try merging this Facebook identity with other identities we already have in our contacts.

I saved all this code into this gist if you want to take a look at it in code only form with syntax highlighting.


What are Attachments?

Should links inside emails be considered attachments?  In the technical sense of an email (like rfc 2183) links wouldn’t be considered a different content type.  The question isn’t whether they are technically attachments as much as if they should be attachment-like in the user interface.


Facebook handles links in a message almost like an attachment-object and will do some additional meta work on the link to provide a default photo and short description for it.

In the message list view Facebook offers an icon to note that a link attachment was included in a messages.

In the composition view Facebook also grabs links from inside the message and shows them separately as an attachment like thing.  In the screenshot below the composition window grabbed the link inside my message and pulled down a description and number of photos from the site.

link detected in the composition area

This kind of meta data around a link can be really beneficial.  The presentation of the link is better than a person naturally would and since it’s the information is retrieved automatically it only takes extra seconds  to make sure a good image and description appear.

Beyond just the benefits of better presentation is another hot topic in the Thunderbird world of offline support.  When reading mails offline it’s far better to have a more context about the link than none at all.  Even if I can’t bring up the link in an offline state the image, description and comment can help me to recall what the link is about.


When you’re using the rich editor for composing a message in Gmail and create a link it has some nice features for recognizing a link and helping you edit it.  Here are some screen shots of what Gmail is doing right now.

Popup indicates the link has been recognized in compose window

Editing a Link

Alternatively Editing an Email link

Pretty straightforward and simple stuff when compared to the extra things Facebook is doing.  Gmail doesn’t add meta-data about the links or make their inclusion visible in the message list.

Links as Attachments

If in Thunderbird we wanted to start treating links more like we treat attachments…

  • How do we present that to the user?
    • Both in terms of composing messages and when receiving links in messages.
  • Do we grab meta data for links sent to us?
    • assuming some kind of policy about what links we can do that with
  • And should we be making links available somehow in Firefox?