App-Addex
view release on metacpan or search on metacpan
lib/App/Addex/Output/Mutt.pm view on Meta::CPAN
use strict;
use warnings;
package App::Addex::Output::Mutt 0.027;
# ABSTRACT: generate mutt configuration from an address book
use parent qw(App::Addex::Output::ToFile);
use Text::Unidecode ();
#pod =head1 DESCRIPTION
#pod
#pod This plugin produces a file that contains a list of alias lines. The first
#pod email address for each entry will be aliased to the entry's aliasified nickname
#pod and name. Every other address will be aliased to one of those with an
#pod appended, incrementing counter. The entry's name is added as the alias's "real
#pod name."
#pod
#pod If the entry has a "folder" value (given as a line in the card's "notes" that
#pod looks like "folder: value") a save-hook is created to save mail from the entry
#pod to that folder and a mailboxes line is created for the folder. If the entry
#pod has a "sig" value, a send-hook is created to use that signature when composing
#pod a message to the entry.
#pod
#pod =head1 CONFIGURATION
#pod
#pod The valid configuration parameters for this plugin are:
#pod
#pod filename - the filename to which to write the Mutt configuration
#pod
#pod unidecode - if set (to 1) this will transliterate all aliases to ascii before
#pod adding them to the file
#pod
#pod =cut
sub new {
my ($class, $arg) = @_;
$arg ||= {};
my $self = $class->SUPER::new($arg);
$self->{unidecode} = $arg->{unidecode};
return $self;
}
#pod =method process_entry
#pod
#pod $mutt_outputter->process_entry($addex, $entry);
#pod
#pod This method does the actual writing of configuration to the file.
#pod
#pod =cut
sub _aliasify {
my ($self, $text) = @_;
return unless defined $text;
$text =~ tr/ .'//d;
Text::Unidecode::unidecode($text) if $self->{unidecode};
return lc $text;
}
sub _is_group {
return($_[0] =~ /;$/ && $_[0] =~ /:/ ? 1 : 0);
}
sub process_entry {
my ($self, $addex, $entry) = @_;
my $name = $entry->name;
my @emails = $entry->emails;
my $folder = $entry->field('folder');
my $sig = $entry->field('sig');
if ($folder) {
$folder =~ tr{/}{.};
$self->output("save-hook ~f$_ =$folder") for grep { $_->sends } @emails;
$self->output("mailboxes =$folder")
unless $self->{_saw_folder}{$folder}++;
}
if ($sig) {
$self->output(qq{send-hook ~t$_ set signature="~/.sig/$sig"})
for grep { $_->receives } @emails;
}
my @aliases =
map { $self->_aliasify($_) } grep { defined } $entry->nick, $name;
my @name_strs = (qq{"$name" }, q{});
my ($rcpt_email) = grep { $_->receives } @emails;
$self->output("alias $_ $name_strs[_is_group($rcpt_email)]<$rcpt_email>")
for @aliases;
# It's not that you're expected to -use- these aliases, but they allow
# mutt's reverse_alias to do its thing.
if (@emails > 1) {
( run in 1.505 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )