File Coverage

blib/lib/Sietima/Role/AvoidDups.pm
Criterion Covered Total %
statement 12 12 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 16 16 100.0


line stmt bran cond sub pod time code
1             package Sietima::Role::AvoidDups;
2 1     1   585 use Moo::Role;
  1         2  
  1         7  
3 1     1   374 use Sietima::Policy;
  1         2  
  1         29  
4 1     1   15 use Email::Address;
  1         2  
  1         26  
5 1     1   5 use namespace::clean;
  1         2  
  1         6  
6              
7             our $VERSION = '1.0.4'; # VERSION
8             # ABSTRACT: prevent people from receiving the same message multiple times
9              
10              
11             around subscribers_to_send_to => sub ($orig,$self,$mail) {
12             my @already_receiving = map {
13             Email::Address->parse($_)
14             } $mail->header_str('to'),$mail->header_str('cc');
15              
16             my %already_receiving = map {
17             $_->address => 1
18             } @already_receiving;
19              
20             return [
21             grep {
22             not $already_receiving{$_->address}
23             }
24             $self->$orig($mail)->@*,
25             ];
26             };
27              
28             1;
29              
30             __END__
31              
32             =pod
33              
34             =encoding UTF-8
35              
36             =head1 NAME
37              
38             Sietima::Role::AvoidDups - prevent people from receiving the same message multiple times
39              
40             =head1 VERSION
41              
42             version 1.0.4
43              
44             =head1 SYNOPSIS
45              
46             my $sietima = Sietima->with_traits('AvoidDups')->new(\%args);
47              
48             =head1 DESCRIPTION
49              
50             A L<< C<Sietima> >> list with this role applied will not send a
51             message to a subscriber, if that subscriber is already mentioned in
52             the C<To:> or C<Cc:> header fields, because they can be assumed to be
53             already receiving the message directly from the sender.
54              
55             =head1 MODIFIED METHODS
56              
57             =head2 C<subscribers_to_send_to>
58              
59             Filters out subscribers that L<match|Sietima::Subscriber/match> the
60             addresses in the C<To:> or C<Cc:> headers of the incoming email.
61              
62             =head1 AUTHOR
63              
64             Gianni Ceccarelli <dakkar@thenautilus.net>
65              
66             =head1 COPYRIGHT AND LICENSE
67              
68             This software is copyright (c) 2017 by Gianni Ceccarelli <dakkar@thenautilus.net>.
69              
70             This is free software; you can redistribute it and/or modify it under
71             the same terms as the Perl 5 programming language system itself.
72              
73             =cut