From 2a599051f741f6c55aa0272a4dbc0538b1b6c50c Mon Sep 17 00:00:00 2001 From: Guillaume Rousse <guillaume.rousse@renater.fr> Date: Fri, 3 Aug 2018 11:20:00 +0200 Subject: [PATCH] switch to Email::MIME, as MIME::Lite usage is discouraged --- README.md | 3 ++- conf/manager.conf.in | 2 -- lib/AccountManager/App.pm | 47 ++++++++++++++++++++++++--------------- 3 files changed, 31 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index c5a7316..9154e48 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,8 @@ It requires the following CPAN distributions: * List-MoreUtils * Locale-Maketext-Lexicon * Log-Any -* MIME-Lite +* Email-MIME +* Email-Sender * Rose-DB-Object * Template-Toolkit * Text-CSV diff --git a/conf/manager.conf.in b/conf/manager.conf.in index 8575761..99fa646 100644 --- a/conf/manager.conf.in +++ b/conf/manager.conf.in @@ -11,8 +11,6 @@ file = /var/log/access-check/manager.log level = info [mailer] -# path to sendmail executable -sendmail_path = /usr/sbin/sendmail # from field use by the account manager from = edugain-access-check.fqdn diff --git a/lib/AccountManager/App.pm b/lib/AccountManager/App.pm index b8462e9..7d2356c 100644 --- a/lib/AccountManager/App.pm +++ b/lib/AccountManager/App.pm @@ -602,27 +602,38 @@ sub req_complete_challenge { $tt2->process('send_authentication_token.tt2.html', $data, \$html_content); # wrap in message - eval "require MIME::Lite"; - eval "require Encode"; - - my $message = MIME::Lite->new( - From => sprintf('eduGAIN Access Check <%s>', $self->{configuration}->{mailer}->{from}), - To => $self->{in}->{email}, - Subject => Encode::encode("MIME-Header", sprintf('[eduGAIN Access Check] %s', $self->{lh}->maketext("Test accounts request"))), - Type => 'multipart/alternative', - ); - $message->attach( - Type =>'text/plain', - Data => $text_content - ); - $message->attach( - Type =>'text/html', - Data => $html_content + eval "require Email::MIME"; + eval "require Email::Sender::Simple"; + + my $email = Email::MIME->create( + header_str => [ + 'From' => sprintf('eduGAIN Access Check <%s>', $self->{configuration}->{mailer}->{from}), + 'To' => $self->{in}->{email}, + 'Subject' => sprintf('[eduGAIN Access Check] %s', $self->{lh}->maketext("Test accounts request")), + 'Content-Type' => 'multipart/alternative' + ], + parts => [ + Email::MIME->create( + attributes => { + content_type => "text/plain", + charset => 'utf-8', + encoding => 'quoted-printable' + }, + body_str => $text_content + ), + Email::MIME->create( + attributes => { + content_type => "text/html", + charset => 'utf-8', + encoding => 'quoted-printable' + }, + body_str => $html_content + ), + ] ); - # send message eval { - $message->send_by_sendmail(); + Email::Sender::Simple->send($email); }; if ($EVAL_ERROR) { $self->{logger}->errorf("Mail notification error: %s", $EVAL_ERROR); -- GitLab