Here is a little script I wrote, but I won't sing it note for note (even if it is intended for Opera). Opera exports its contacts to an .adr file. To import it to other mail clients I had to convert it to a CSV list.
The script extracts all fields that are marked as contacts and ignores folders and Trash.
#!/usr/bin/perl
#
#
use strict;
use warnings;
use Getopt::Long;
use Pod::Usage;
my $input = '';
my $output = 'addresses.csv';
my $delimiter = "##";
GetOptions(
'i|input=s' => \$input,
'o|output=s' => \$output,
'd|delimiter=s' => \$delimiter
);
pod2usage( -message => "Missing input file name :\n", -verbose => 1 )
if ( $input eq '' );
my ( @table, @cols );
my %cols;
open( my $in, "<", $input ) or die "Can not open $input ", $!, " \n";
local $/;
my $content = <$in>;
close $in;
open( my $out, '>', $output ) or die "Can not open $output", $!, "\n";
if ( $content =~ /\t/ ) {
$content =~ s/\t//g;
}
my @chunks = split '#', $content;
for my $line (@chunks) {
my %data;
if ( $line =~ /CONTACT/ ) {
$line =~ s/CONTACT//;
if ( $line =~ /\n/ ) {
my @line = split /\n/, $line;
for my $line (@line) {
chomp $line;
if ( $line =~ /(.+?)=.+/ ) {
unless ( $cols{$1} and $cols{$1} == 1 ) {
$cols{ ucfirst lc $1 } = 1;
push @cols, ucfirst lc $1;
}
my @fields = split '=', $line;
if ( $fields[1] ) {
$data{ ucfirst lc $fields[0] } = $fields[1];
}
}
}
}
}
push @table, \%data if (%data);
}
print $out join $delimiter, @cols, "\n";
for my $row (@table) {
my @rows;
for (@cols) {
if ( $$row{$_} ) {
push @rows, $$row{$_};
}
}
print $out join $delimiter, @rows, "\n";
}
close $out;
__END__
=head1 NAME
operaadr2csv.pl - Converts Opera .adr files to csv file
=head1 SYNOPSIS
operaadr2csv.pl -i [inputfile] [options]
Options:
-i | input
-d | -delimiter
-o | -output
=head1 OPTIONS
=over 8
=item -i
Sets the name of the input file. This option is mandatory.
=item -d
Sets a delimiter. The default delimiter is ##
=item -o
Sets a name for the outputfile. The default name for the output file i
+s addresses.csv
=back
=head1 DESCRIPTION
This program will convert contacts from opera browser .adr fileformat
+to a csv list. The delimiter for the creation of the csv file can be
+changed.
=cut