Skip to content

Instantly share code, notes, and snippets.

@cosimo
Created January 31, 2011 00:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cosimo/803454 to your computer and use it in GitHub Desktop.
Save cosimo/803454 to your computer and use it in GitHub Desktop.
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