Lp 1801163: Switch to Email::MIME in SendEmail A/T Reactor
authorJason Stephenson <jason@sigio.com>
Fri, 8 Feb 2019 20:47:41 +0000 (15:47 -0500)
committerJason Boyer <JBoyer@eoli.info>
Thu, 23 Jan 2020 12:30:14 +0000 (07:30 -0500)
Switch from Email::Simple to Email::MIME Perl module in the SendEmail
Action/Trigger Reactor.  Email::MIME properly encodes unescaped header
fields when added to the message with the header_str_set method.

We allow only 1 of each address field to be created while doing the
encoding, so that messages conform to RFC 2822.

This commit adds a new prerequisite as mentioned in the release notes,
so be sure to install the prerequisites for your Linux distribution
before installing.

You can test this with concerto data from a fresh installation by:

1. Configuring your test system to send email.

2. Updating all actor.usr entries to have your email address.

3. Updating the New User Created Welcome Notice event definiton to
   active = true.

4. Run the action_trigger_runner with --process-hooks --run-pending.

5. You should get 237 new user welcome emails.  The exact number is
   subject to change.

Signed-off-by: Jason Stephenson <jason@sigio.com>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>
Signed-off-by: Jason Boyer <JBoyer@eoli.info>

Open-ILS/src/extras/install/Makefile.debian-jessie
Open-ILS/src/extras/install/Makefile.debian-stretch
Open-ILS/src/extras/install/Makefile.ubuntu-bionic
Open-ILS/src/extras/install/Makefile.ubuntu-xenial
Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Reactor/SendEmail.pm
docs/RELEASE_NOTES_NEXT/Administration/sendemail-reactor-mime.adoc [new file with mode: 0644]

index 21da86c..d30fa4d 100644 (file)
@@ -38,6 +38,7 @@ export DEBS = \
        libdbi-dev\
        libdbi1\
        libemail-simple-perl\
+       libemail-mime-perl\
        libexcel-writer-xlsx-perl\
        libgd-graph3d-perl\
        liblocale-maketext-lexicon-perl\
index e1491d1..d16e1a5 100644 (file)
@@ -38,6 +38,7 @@ export DEBS = \
        libdbi-dev\
        libdbi1\
        libemail-simple-perl\
+       libemail-mime-perl\
        libexcel-writer-xlsx-perl\
        libgd-graph3d-perl\
        liblocale-maketext-lexicon-perl\
index 35c42fd..f1478a3 100644 (file)
@@ -37,6 +37,7 @@ export DEBS = \
        libdbi-dev\
        libdbi1\
        libemail-simple-perl\
+       libemail-mime-perl\
        libexcel-writer-xlsx-perl\
        libgd-graph3d-perl\
        liblocale-maketext-lexicon-perl\
index 8802f24..e8251b7 100644 (file)
@@ -38,6 +38,7 @@ export DEBS = \
        libdbi-dev\
        libdbi1\
        libemail-simple-perl\
+       libemail-mime-perl\
        libexcel-writer-xlsx-perl\
        libgd-graph3d-perl\
        liblocale-maketext-lexicon-perl\
index 9dd76ee..675ab69 100644 (file)
@@ -3,7 +3,7 @@ use strict; use warnings;
 use Error qw/:try/;
 use Data::Dumper;
 use Email::Send;
-use Email::Simple;
+use Email::MIME;
 use OpenSRF::Utils::SettingsClient;
 use OpenILS::Application::Trigger::Reactor;
 use OpenSRF::Utils::Logger qw/:logger/;
@@ -29,7 +29,7 @@ Email is encoded in UTF-8 and the corresponding MIME-Version, Content-Type,
 and Content-Transfer-Encoding headers are set to help mail user agents
 decode the content.
 
-The From, To, Subject, Bcc, Cc, Reply-To and Sender -fields are
+The From, To, Bcc, Cc, Reply-To, Sender, and Subject fields are
 automatically MIME-encoded.
 
 No default template is assumed, and all information other than the
@@ -56,13 +56,20 @@ sub handler {
     my $stat;
     my $err;
 
-    my $email = Email::Simple->new($text);
+    my $email = Email::MIME->new($text);
 
-    for my $hfield (qw/From To Subject Bcc Cc Reply-To Sender/) {
-       my @headers = $email->header($hfield);
-       $email->header_set($hfield => map { encode("MIME-Header", $_) } @headers) if ($headers[0]);
+    # Handle the address fields.  In addition to encoding the values
+    # properly, we make sure there is only 1 each.
+    for my $hfield (qw/From To Bcc Cc Reply-To Sender/) {
+        my @headers = $email->header($hfield);
+        $email->header_str_set($hfield => join(',', @headers)) if ($headers[0]);
     }
 
+    # Handle the Subject field.  Again, the standard says there can be
+    # only one.
+    my @headers = $email->header('Subject');
+    $email->header_str_set('Subject' => $headers[0]) if ($headers[0]);
+
     $email->header_set('MIME-Version' => '1.0');
     $email->header_set('Content-Type' => "text/plain; charset=UTF-8");
     $email->header_set('Content-Transfer-Encoding' => '8bit');
diff --git a/docs/RELEASE_NOTES_NEXT/Administration/sendemail-reactor-mime.adoc b/docs/RELEASE_NOTES_NEXT/Administration/sendemail-reactor-mime.adoc
new file mode 100644 (file)
index 0000000..b6cb8d5
--- /dev/null
@@ -0,0 +1,8 @@
+SendEmail Reactor Updated to use Email::MIME
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+The SendEmail reactor for Action/Trigger has been updated to use the
+Email::MIME Perl module for proper encoding of the email message
+header fields.  You should notice no functional difference in the
+sending of emails.  This change does add a new prerequisite package,
+so be sure to run the prerequisite installation procedure for your
+Linux distribution before upgrading Evergreen.