From 76504725f8ef7751866788e493c6aae64c3bf949 Mon Sep 17 00:00:00 2001
From: Guillaume Rousse <guillaume.rousse@renater.fr>
Date: Tue, 7 Nov 2017 10:12:16 +0100
Subject: [PATCH] drop recipient filtering code, mails are sent to admins only
 anyway

---
 lib/IdPAccountManager/Tools.pm      | 37 ++---------------------------
 lib/IdPAccountManager/WebRequest.pm | 15 ++++++------
 2 files changed, 9 insertions(+), 43 deletions(-)

diff --git a/lib/IdPAccountManager/Tools.pm b/lib/IdPAccountManager/Tools.pm
index b21dbb3..b6507fe 100644
--- a/lib/IdPAccountManager/Tools.pm
+++ b/lib/IdPAccountManager/Tools.pm
@@ -114,45 +114,12 @@ sub mail_notice {
     my $mail_data = $args{data};
     my $logger    = $args{logger};
 
-    my $notice_email = $args{to} || $args{admin_email};
-    $mail_data->{to} = $notice_email;
-
-    ## Protection to prevent notifications during test dev phases
-    ## Notify only admin_email or dev_sp_contact addresses
-    if ($args{dev_no_mail_outside}) {
-        my %rcpt = map { $_ => 1 } split(/,/, $notice_email);
-        my %authorized_rcpt = map { $_ => 1 } split(
-            /,/,
-            join(',',
-                $args{admin_email},
-                $args{dev_sp_contact})
-        );
-
-        my $change_rcpt = 0;
-        foreach my $email (keys %rcpt) {
-            unless ($authorized_rcpt{$email}) {
-                $change_rcpt = 1;
-                last;
-            }
-        }
-
-        if ($change_rcpt) {
-            $logger->infof(
-                "no_mail_outside option set; notification for %s rerouted to admins ; ",
-                $notice_email
-            );
-            $notice_email = $args{admin_email};
-        }
-    }
-
     $logger->tracef(
-        sprintf('(template=%s, to=%s)', $args{template}, $mail_data->{to})
+        sprintf('(template=%s, to=%s)', $args{template}, $args{to})
     );
 
     open SENDMAIL,
-        "|/usr/sbin/sendmail -f "
-      . $args{notice_from}
-      . " $notice_email";
+        "|/usr/sbin/sendmail -f $args{from} $args{to}";
 
     my $tt2 = Template->new({
         FILTERS      => { qencode => [ \&qencode, 0 ] },
diff --git a/lib/IdPAccountManager/WebRequest.pm b/lib/IdPAccountManager/WebRequest.pm
index 2028a4d..2b107f0 100755
--- a/lib/IdPAccountManager/WebRequest.pm
+++ b/lib/IdPAccountManager/WebRequest.pm
@@ -186,14 +186,12 @@ sub respond {
     if (@errors_admin) {
         $self->{out}->{subject} = 'Error notification - web interface';
         IdPAccountManager::Tools::mail_notice(
-            template            => 'mail/notification_generic_error.tt2.eml',
-            templates_dir       => $self->{configuration}->{templates_dir},
-            data                => $self->{out},
-            logger              => $self->{logger},
-            admin_email         => $self->{configuration}->{admin_email},
-            dev_no_mail_outside => $self->{configuration}->{dev_no_mail_outside},
-            dev_sp_contact      => $self->{configuration}->{dev_sp_contact},
-            notice_from         => $self->{configuration}->{notice_from}
+            template      => 'mail/notification_generic_error.tt2.eml',
+            templates_dir => $self->{configuration}->{templates_dir},
+            data          => $self->{out},
+            logger        => $self->{logger},
+            to            => $self->{configuration}->{admin_email},
+            from          => $self->{configuration}->{notice_from}
         );
     }
 }
@@ -414,6 +412,7 @@ sub req_generate_token {
     IdPAccountManager::Tools::mail_notice(
         template      => 'mail/send_authentication_token.tt2.eml',
         templates_dir => $self->{configuration}->{templates_dir},
+        from          => $self->{configuration}->{notice_from}
         to            => $self->{in}->{email_address},
         data          => $self->{out},
         logger        => $self->{logger}
-- 
GitLab