From: dbs Date: Fri, 18 Feb 2011 05:44:11 +0000 (+0000) Subject: Bolster SendEmail Reactor's handling of UTF-8 content X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=fd0fdda306859927af8e96df7fc1f7adf2032caf;p=evergreen%2Fbjwebb.git Bolster SendEmail Reactor's handling of UTF-8 content Use the Encode module and encode_utf8() instead of utf8 and utf8::encode. The utf8 module is meant for enabling UTF-8 content in source code. Also, add the MIME-Version / Content-type / charset headers that some mail user agents need to know that they're dealing with Unicode mail. git-svn-id: svn://svn.open-ils.org/ILS/trunk@19476 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/src/extras/Makefile.install b/Open-ILS/src/extras/Makefile.install index 1be7dc518..80c47b296 100644 --- a/Open-ILS/src/extras/Makefile.install +++ b/Open-ILS/src/extras/Makefile.install @@ -87,6 +87,7 @@ DEBS = \ libdatetime-set-perl\ libdbd-pg-perl\ libemail-send-perl\ + libemail-simple-perl\ libgd-graph3d-perl\ liblog-log4perl-perl\ libmarc-record-perl\ @@ -172,6 +173,7 @@ FEDORA_13_RPMS = \ perl-Business-ISBN-Data \ perl-DBD-Pg \ perl-Email-Send \ + perl-Email-Simple \ perl-GDGraph3d \ perl-Net-SSH2 \ perl-OLE-Storage_Lite \ diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Reactor/SendEmail.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Reactor/SendEmail.pm index 64826fda0..5cf08c3b7 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Reactor/SendEmail.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Trigger/Reactor/SendEmail.pm @@ -3,10 +3,11 @@ use strict; use warnings; use Error qw/:try/; use Data::Dumper; use Email::Send; +use Email::Simple; use OpenSRF::Utils::SettingsClient; use OpenILS::Application::Trigger::Reactor; use OpenSRF::Utils::Logger qw/:logger/; -use utf8; +use Encode; $Data::Dumper::Indent = 0; use base 'OpenILS::Application::Trigger::Reactor'; @@ -24,6 +25,10 @@ setting is used to send the email, and the value at /opensrf/default/email_notify/sender_address is passed into the template as the 'default_sender' variable. +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. + No default template is assumed, and all information other than the default_sender that the system provides is expected to be gathered by the Event Definition through either Environment or Parameter definitions. @@ -39,7 +44,7 @@ sub handler { my $smtp = $conf->config_value('email_notify', 'smtp_server'); $$env{default_sender} = $conf->config_value('email_notify', 'sender_address'); - my $text = $self->run_TT($env); + my $text = encode_utf8($self->run_TT($env)); return 0 if (!$text); my $sender = Email::Send->new({mailer => 'SMTP'}); @@ -48,10 +53,13 @@ sub handler { my $stat; my $err; - utf8::encode($text); # prevent "Wide character" errors in Email::Send + my $email = Email::Simple->new($text); + $email->header_set('MIME-Version' => '1.0'); + $email->header_set('Content-Type' => "text/plain; charset=UTF-8"); + $email->header_set('Content-Transfer-Encoding' => '8bit'); try { - $stat = $sender->send($text); + $stat = $sender->send($email); } catch Error with { $err = $stat = shift; $logger->error("SendEmail Reactor: Email failed with error: $err");