I've been a developer for almost 10years now, yet I haven't done any implementation of an address book importer. Well, this is the first time. :)

Since I started using symfony, I started to love its framework. Later on, I moved to using Ruby on Rails. Ever since, I loved working on Rails, and see myself wanting to create more Rails applications that would be better and more beautiful each time. That is why I always welcome the things I don't know. I want to spend more time learning than simply perfecting what I already know.

Enter Rails address book importer.

After some sort of quick and short research on what may be available on the net as an importer (and also based from an officemate's suggestion), I went by use of the Contact gem as my means. At first, when I found that it did not support AOL, I was not daunted. Sure, its gonna take me some time, but I'll be able to extend it and I'll be happy to contribute to the community.

sudo gem install contacts

It supports retrieving of address book entries from Yahoo, Gmail and Hotmail accounts only. At that time, I still needed the extra AOL support. But since I had to deliver a product first, I pushed through with using this gem. I found it easy to integrate with the rest of the application.

Contacts::Hotmail.new(login, password).contacts
Contacts::Yahoo.new(login, password).contacts 
Contacts::Gmail.new(login, password).contacts 
Contacts.new(:gmail, login, password).contacts 
Contacts.new(:hotmail, login, password).contacts 
Contacts.new(:yahoo, login, password).contacts 

Each of these would return an array of arrays:

[["name", "foo@bar.com"], ["another name", "bow@wow.com"]]

It worked well for me, up until QA time. I didn't notice that what I was getting from Contacts gem is actually good and bad in a certain way.

  • Good: It actually weeds out entries that do not have email fields
  • Bad: You won't get the actual count of entries vs the good clean ones

Hard to find out? Well, not exactly. Contacts gem worked very well for Gmail and Hotmail accounts simply because they both add in entries in the address book only if they had the email field. Now what's so different with Yahoo! is that you actually have the capacity to find your friends in your messenger list inside your address book without having to explicitly add them there. And so, since Yahoo! uses a single key access for all their services, the username serves as the email address. Catch? The address book in Yahoo! Mail contains all the Yahoo! Messenger friends list but without the email addresses.

Huh.. now how would an import work without the address itself? Of course it won't. That is why Contacts gem does the weeding out of such entries for you. Neat, yeah.. but it hid some data from you. I didn't want that. I made further researches, and found the Blackbook gem.

Sample blackbook return

I like the Blackbook gem for the following reasons:

  • It gave me instant support for AOL accounts
  • It was actually more active than Contacts gem
  • It returns all contacts regardless if its clean or not. (its good for me)
  • It returns an array of hashes (which is actually more ruby-ish)
  • It provides you with a format for export (xml, vcf, or the array of hashes by default)
  • It is more email type agnostic. I really didn't have to pass around the email type, as long as I passed it the correct username/account
  • Its raises (exceptions) are more readable and easy to understand

Yeah, I liked it better. But there is just one cons that I found (there might be more soon, but for now, I'm happy with just one). Usually, when the entry doesn't really have an explicit name attached to the email, then the email is duplicated in the name position.

{:email => "maker@sweetperceptions.com", :name => ""}
{:email => "maker@sweetperceptions.com", :name => "maker@sweetperceptions.com"}

But, for Hotmail only, I found that if the name field is blank, the email field is promoted to the name position.. which is bad. Wrong. It becomes like this:

{:email => "", :name => "maker@sweetperceptions.com"}

And then if you must clean your data before processing it, then I suggest make an extra special case for Hotmail. Switch their places first.

sudo gem install blackbook

Maybe it'll be good in the future to support other email providers too. You can read the sample code here: http://pastie.org/315399