aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authordakkar <dakkar@thenautilus.net>2016-06-19 17:55:45 +0100
committerdakkar <dakkar@thenautilus.net>2016-06-19 17:56:35 +0100
commit4ba7568909fe620ee9fb99cb6bbe058df8c0061c (patch)
tree0e311c42a6901e2ccc6528ad56a54339e78871de /lib
parentNoMail role (diff)
downloadSietima-4ba7568909fe620ee9fb99cb6bbe058df8c0061c.tar.gz
Sietima-4ba7568909fe620ee9fb99cb6bbe058df8c0061c.tar.bz2
Sietima-4ba7568909fe620ee9fb99cb6bbe058df8c0061c.zip
AvoidDups role
Diffstat (limited to 'lib')
-rw-r--r--lib/Sietima.pm9
-rw-r--r--lib/Sietima/Role/AvoidDups.pm26
-rw-r--r--lib/Sietima/Role/NoMail.pm8
3 files changed, 35 insertions, 8 deletions
diff --git a/lib/Sietima.pm b/lib/Sietima.pm
index 1e463ec..704d4f8 100644
--- a/lib/Sietima.pm
+++ b/lib/Sietima.pm
@@ -54,11 +54,11 @@ sub handle_mail {
return;
}
-sub addresses_to_send_to {
+sub subscribers_to_send_to {
state $check = compile(Object,EmailMIME);
my ($self,$incoming_mail) = $check->(@_);
- return [ map { $_->address } @{$self->subscribers} ];
+ return $self->subscribers;
}
sub munge_mail {
@@ -68,7 +68,10 @@ sub munge_mail {
return Sietima::Message->new({
mail => $incoming_mail,
from => $self->return_path,
- to => $self->addresses_to_send_to($incoming_mail),
+ to => [
+ map { $_->address }
+ @{$self->subscribers_to_send_to($incoming_mail)},
+ ],
});
}
diff --git a/lib/Sietima/Role/AvoidDups.pm b/lib/Sietima/Role/AvoidDups.pm
new file mode 100644
index 0000000..da1af00
--- /dev/null
+++ b/lib/Sietima/Role/AvoidDups.pm
@@ -0,0 +1,26 @@
+package Sietima::Role::AvoidDups;
+use 5.020;
+use Moo::Role;
+use Email::Address;
+use namespace::clean;
+
+around subscribers_to_send_to => sub {
+ my ($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;
diff --git a/lib/Sietima/Role/NoMail.pm b/lib/Sietima/Role/NoMail.pm
index 233f6b9..a0753b9 100644
--- a/lib/Sietima/Role/NoMail.pm
+++ b/lib/Sietima/Role/NoMail.pm
@@ -3,15 +3,13 @@ use 5.020;
use Moo::Role;
use namespace::clean;
-around addresses_to_send_to => sub {
+around subscribers_to_send_to => sub {
my ($orig,$self,@etc) = @_;
return [
- map { $_->address }
- grep { $_->prefs->{wants_mail} // 1 }
- @{$self->subscribers},
+ grep { $_->prefs->{wants_mail} // 1 }
+ @{$self->$orig(@etc)},
];
};
1;
-