Hacking Gmail

(Grace) #1

Chapter 12 — Addressing Addresses 181


Exporting Contacts.


Gmail is a bit greedy here. There are ample opportunities to import contacts to


the system. As you’ve seen, you can do it with comma-separated value files or via


the script in Listing 12-1. But if you want to get your contacts out again, and into
a desktop address book, you’re stuck.


Not quite. In Listing 12-3, there’s a script to export your contacts into a large
vCard file. All the modern address book or e-mail clients will be able to under-


stand the vCard file, and re-import your addresses. It’s also useful for backups, if
you ever get wary of Google’s ability to do that for you.


Here’s the listing, and then you’ll see how it works.


Listing 12-3: Exporting Contacts as vCards

use Utils;


$gmail = login();


open VCARDS, “>contacts.vcf”;


(@contacts) = @{ $gmail->getcontacts() }; # simply get all
contacts
foreach (@contacts) { # and iterate
though them
print VCARDS “BEGIN:VCARD\nVERSION:3.0\n”;
print VCARDS “FN:”. $
->{“name1”}. “\n”;
print VCARDS “EMAIL;type=INTERNET:”. $_->{“email”}.
“\n”;
print VCARDS “END:VCARD\n”;
print VCARDS “\n”;
}


close VCARDS;


A vCard is a small text file containing address data. The entire standard is complex


and extensive, defined in RFC2425; you can read about it at http://www.imc.org/pdi/
vcardoverview.html.

Free download pdf