De-duping your evolution addressbook - 05/22/2008
So I tried using gpilot to sync my phone and evolution this morning. Once it was done I had duplicate contacts in both my phone and my address book. This is what I did to clean it up, probably not the best solution, but quick and easy.
I copied .evolution/addressbook/local/system/addressbook.db to a test.db. I then ran the script below against it to create new.db. I backed up addressbook.db and copied new.db to addressbook.db. I then had to restart evolution including killing any evolution process that was running so that the contacts didn't stay in the cache. Hope this is useful to someone else out there with the same issue.
#!/usr/bin/ruby
require 'bdb'
db_old = BDB::Hash.open('test.db')
db_new = BDB::Hash.open('new.db', nil, 'w')
seen = Hash.new
keys = db_old.keys
x = 1
keys.each do |k|
record = db_old.get(k)
name = record.match('FN:(.*)').to_s
puts "#{x}. #{name}"
unless seen[name] == 1
db_new.store(k, record)
end
seen[name] = 1
x += 1
end
db_old.close()
db_new.close()
Post a Comment