Skip to content

Instantly share code, notes, and snippets.

@cosimo

cosimo/gist:803454

Created Jan 31, 2011
Embed
What would you like to do?
Opera contacts to Mutt aliases converter
#!/usr/bin/env perl
#
# Convert Opera contacts file (.adr) into
# mutt aliases file format.
#
# Usage:
# perl opera-adr-to-mutt-aliases.pl < ~/.opera/contacts.adr >> ~/.mutt/aliases
#
# Cosimo, 31/Jan/2011
#
use strict;
use warnings;
use utf8;
sub harvest ($) {
my ($contact_info) = @_;
my ($id) = $contact_info =~ m{^ \s+ ID = (.*) $}mx;
my ($name) = $contact_info =~ m{^ \s+ NAME = (.*) $}mx;
my ($email) = $contact_info =~ m{^ \s+ MAIL = (.*) $}mx;
return if ! $id and ! $email;
return {
ID => $id,
NAME => $name,
MAIL => $email,
};
}
my $adr_file_contents = q{};
$adr_file_contents .= $_ while <STDIN>;
my @contacts = split m{#CONTACT}, $adr_file_contents;
for (@contacts) {
my $contact = harvest($_) or next;
my ($first_word) = $contact->{MAIL} =~ m{ (\S+) \@ }x;
printf "alias %s %s <%s>\n",
lc($first_word), $contact->{NAME}, $contact->{MAIL};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment