Get your evolution emails to a long text list
Use these scripts to get all your emails out of your evolution vcards you export, or have elsewhere. I’m keeping them in pieces because their functionality is useful in other places as well. For example, the vcard2pair.pl is useful for vcards and the exportevolution.py dumps evolution’s addressbook to text vcard.
I use these scripts to generate a static list of all of my contacts for hard copy firstname lastname.
I’m sure there is a really short way to do this. I snapped these pieces together over the last year and figured it is useful to several people out there.
#!/usr/bin/python2
import bsddb, os, re
home = os.getenv('HOME')
# This is the only variable you should change. If you do not know the
# location of your evloution address book, use `locate addressbook.db`
# to find it
dbname = '%s/.evolution/addressbook/local/system/addressbook.db' % home
# .evolution/addressbook/local/system/addressbook.db
db = bsddb.hashopen(dbname, 'r')
for k in db.keys():
for line in db[k].split('n'):
print line
db.close()
#!/usr/bin/perl
#
# The author(s) have made the contents of this file
# available under a CC-GNU-GPL license:
#
# http://creativecommons.org/licenses/GPL/2.0/
#
# A copy of the full license can be found as part of this
# distribution in the file COPYING.
#
# You may use this software in accordance with the
# terms of this license. You agree that you are solely
# responsible for your use of this software and you
# represent and warrant to the author(s) that your use
# of the ccHost software will comply with the CC-GNU-GPL.
#
# Copyright 2005-2006, Jon Phillips.
#
# $Header$
#
# vcard2pair.pl
#
# This program takes a bunch of text vcards and extracts emails from them.
#
use strict;
my $line;
my $name;
my @emails;
while ( $line = ) {
chomp ($line);
chop ($line) ; # trailing ^M
# BEGIN:VCARD
if ( $line eq "BEGIN:VCARD" ) {
$name = "";
undef(@emails);
}
# X-EVOLUTION-FILE-AS:
if ( $line =~ /^X-EVOLUTION-FILE-AS:.*/ ) {
$line =~ s/^X-EVOLUTION-FILE-AS://g;
$name = $line;
$name =~ s/[']//g;
}
# EMAIL
if ( $line =~ /.*EMAIL/ ) {
$line =~ s/.*EMAIL.*://g;
if ( $line =~ /.+@.+/ ) {
push @emails, $line;
}
}
# END:VCARD
if ( $line eq "END:VCARD" )
{
if ( $name ne "" && scalar @emails > 0 ) {
foreach my $email (@emails) {
print "$name < $email>n";
}
}
}
}
#!/usr/bin/perl -t
# changes:
# lastname, firstname # to: # firstname lastname
use strict;
while ( my $line = ) {
chomp ($line);
$line =~ s/^(S+), (S+)/$2 $1/;
print "$linen";
}
#!/bin/bash # # Converts entire addressbook into a list with each line like so: # # firstname lastname EMAIL_LOG=/tmp/tmp_email.log exportevolution.py > $EMAIL_LOG cat $EMAIL_LOG | vcard2pair.pl | lnfn2fnln.pl | sort | uniq rm $EMAIL_LOG
Usage:
print_all_emails > somefile.txt


