Addex/Output/Mutt.pm

filter: Statementstmt 100% 59 / 59 Branchbran 86.3% 19 / 22 Conditioncond 40.0% 2 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 90.9% 90 / 99 CC 20 SCAR 22.4
CC
20
Cov
93%
process_entry
15.0
_is_group
4.1
_aliasify
3.1
CRAP 9.4
↑ Summary Addex.pm »
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package App::Addex::Output::Mutt 0.027;
5 # ABSTRACT: generate mutt configuration from an address book
6  
7 1 ▶use parent qw(App::Addex::Output::ToFile);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use Text::Unidecode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 #pod =head1 DESCRIPTION
12 #pod
13 #pod This plugin produces a file that contains a list of alias lines. The first
14 #pod email address for each entry will be aliased to the entry's aliasified nickname
15 #pod and name. Every other address will be aliased to one of those with an
16 #pod appended, incrementing counter. The entry's name is added as the alias's "real
17 #pod name."
18 #pod
19 #pod If the entry has a "folder" value (given as a line in the card's "notes" that
20 #pod looks like "folder: value") a save-hook is created to save mail from the entry
21 #pod to that folder and a mailboxes line is created for the folder. If the entry
22 #pod has a "sig" value, a send-hook is created to use that signature when composing
23 #pod a message to the entry.
24 #pod
25 #pod =head1 CONFIGURATION
26 #pod
27 #pod The valid configuration parameters for this plugin are:
28 #pod
29 #pod filename - the filename to which to write the Mutt configuration
30 #pod
31 #pod unidecode - if set (to 1) this will transliterate all aliases to ascii before
32 #pod adding them to the file
33 #pod
34 #pod =cut
35  
36 1 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
Pod documented
37 1 my ($class, $arg) = @_;
38 1 ▶ $arg ||= {};
Condition50%1/2
$arg ||= {}
l!l
10
MC/DC0%0/1
$arg ||= {}
$arg
Truth table50%1/2
A
A= $arg
Aresult
11
00
39  
40 1 my $self = $class->SUPER::new($arg);
41  
42 1 $self->{unidecode} = $arg->{unidecode};
43  
44 1 return $self;
45 }
46  
47 #pod =method process_entry
48 #pod
49 #pod $mutt_outputter->process_entry($addex, $entry);
50 #pod
51 #pod This method does the actual writing of configuration to the file.
52 #pod
53 #pod =cut
54  
55 9 ▶sub _aliasify {
Subroutine _aliasify: called CC=3 SCAR=11.3
56 9 my ($self, $text) = @_;
57  
58 9 ▶ return unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 9 9
59 9 $text =~ tr/ .'//d;
60 9 ▶ Text::Unidecode::unidecode($text) if $self->{unidecode};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"unidecode"} 0 9 9
61 9 return lc $text;
62 }
63  
64 20 ▶sub _is_group {
Subroutine _is_group: called CC=3 SCAR=14.2
65 20 ▶ return($_[0] =~ /;$/ && $_[0] =~ /:/ ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ /;$/ && $_[0] =~ /:/ ? : 0 20 20
Condition33%1/3
$_[0] =~ /;$/ and $_[0] =~ /:/
!ll&&!rl&&r
2000
MC/DC0%0/2
$_[0] =~ /;$/ and $_[0] =~ /:/
$_[0] =~ /;$/ $_[0] =~ /:/
Truth table33%1/3
A and B
A= $_[0] =~ /;$/B= $_[0] =~ /:/
ABresult
0X0
100
111
66 }
67  
68 6 ▶sub process_entry {
Subroutine process_entry: called CC=15 SCAR=27.1
Pod documented
69 6 my ($self, $addex, $entry) = @_;
70  
71 6 my $name = $entry->name;
72 6 my @emails = $entry->emails;
73  
74 6 my $folder = $entry->field('folder');
75 6 my $sig = $entry->field('sig');
76  
77 6 ▶ if ($folder) {
Branch: 1 branch
BranchTrueFalseTotal
if ($folder) 3 3 6
78 3 $folder =~ tr{/}{.};
79 3 $self->output("save-hook ~f$_ =$folder") for grep { $_->sends } @emails;
80 $self->output("mailboxes =$folder")
81 3 ▶ unless $self->{_saw_folder}{$folder}++;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_saw_folder"}{$folder}++ 2 1 3
82 }
83  
84 6 ▶ if ($sig) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sig) 1 5 6
85 $self->output(qq{send-hook ~t$_ set signature="~/.sig/$sig"})
86 1 for grep { $_->receives } @emails;
87 }
88  
89 my @aliases =
90 6 map { $self->_aliasify($_) } grep { defined } $entry->nick, $name;
91  
92 6 my @name_strs = (qq{"$name" }, q{});
93  
94 6 my ($rcpt_email) = grep { $_->receives } @emails;
95 $self->output("alias $_ $name_strs[_is_group($rcpt_email)]<$rcpt_email>")
96 6 for @aliases;
97  
98 # It's not that you're expected to -use- these aliases, but they allow
99 # mutt's reverse_alias to do its thing.
100 6 ▶ if (@emails > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@emails > 1) 2 4 6
101 2 my %label_count;
102  
103 2 ▶ if (defined(my $label = $rcpt_email->label)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $label = $rcpt_email->label)) 1 1 2
104 $self->output("alias $_-$label $name_strs[_is_group($rcpt_email)]<$rcpt_email>")
105 1 for @aliases;
106  
107 1 $label_count{$label} = 1;
108 }
109  
110 2 my @rcpt_emails = grep { $_->receives } @emails;
111 2 for my $i (1 .. $#rcpt_emails) {
112 6 my $label = $rcpt_emails[$i]->label;
113 6 ▶ $label = '' unless defined $label;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $label 1 5 6
114 6 $label_count{$label}++;
115  
116 6 for my $id (@aliases) {
117 9 ▶ my $alias = length $label ? "$id-$label" : $id;
Branch: 1 branch
BranchTrueFalseTotal
length $label ? : 7 2 9
118 9 ▶ $alias .= "-" . ($label_count{$label} - 1) if $label_count{$label} > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $label_count{$label} > 1 3 6 9
119  
120 9 $self->output("alias $alias $name_strs[_is_group($rcpt_emails[$i])]<$rcpt_emails[$i]>");
121 }
122 }
123 }
124 }
125  
126 1 1;
127  
128 __END__
↑ Summary Addex.pm »