package Sietima::Role::AvoidDups; use Moo::Role; use Sietima::Policy; use Email::Address; use namespace::clean; # VERSION # ABSTRACT: prevent people from receiving the same message multiple times =head1 SYNOPSIS my $sietima = Sietima->with_traits('AvoidDups')->new(\%args); =head1 DESCRIPTION A L<< C >> list with this role applied will not send a message to a subscriber, if that subscriber is already mentioned in the C or C header fields, because they can be assumed to be already receiving the message directly from the sender. =modif C Filters out subscribers that L the addresses in the C or C headers of the incoming email. =cut around subscribers_to_send_to => sub ($orig,$self,$mail) { my @already_receiving = map { Email::Address->parse($_) } $mail->header_str('to'),$mail->header_str('cc'); my %already_receiving = map { $_->address => 1 } @already_receiving; return [ grep { not $already_receiving{$_->address} } $self->$orig($mail)->@*, ]; }; 1;