Recently I happened to obtain quite a few emails in case of which I wanted to preserve To or Cc list members in my addressbook. GMail interface makes it easy to do it for a few addresses, but very tedious when there are a lot of them (every address must be clicked separately).
I googled around, found this script, liked the idea, but was not 100% happy with the implementation. So I wrote my version. Like the original, it connects to GMail over IMAP (in fact, it should work against any sensible IMAP server), reads the message list, grabs all email addresses and prints them.
Contrary to the original my script does not handle date ranges (I did not need this feature, Google Contacts properly remove duplicates after import), but also has some new features:
scraps From, To, and Cc instead of scraping only From header,
reads not only addresses, but also names,
lets one specify address and port of scraped IMAP server (useful when GMail is behind some proxy/tunnel/port mapper, or when the script is being used against another IMAP server),
stores results as
.csvfile which can be directly imported to Google Contacts.
The script can be downloaded or cloned from here. Perl and some perl modules are required (in case of Debian and Ubuntu everything should be present in repos).