From 2c18dc66435babb3619df30908dc1dec119f1178 Mon Sep 17 00:00:00 2001 From: koichirok Date: Fri, 29 Jul 2011 05:12:28 +0000 Subject: [PATCH] 2011-07-29 Koichiro Kikuchi * lib/PandoraFMS/Tools.pm: Send utf8 email properly. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4648 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_server/ChangeLog | 4 ++++ pandora_server/lib/PandoraFMS/Tools.pm | 10 +++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/pandora_server/ChangeLog b/pandora_server/ChangeLog index eb21123b98..f0c019f362 100644 --- a/pandora_server/ChangeLog +++ b/pandora_server/ChangeLog @@ -1,3 +1,7 @@ +2011-07-29 Koichiro Kikuchi + + * lib/PandoraFMS/Tools.pm: Send utf8 email properly. + 2011-07-27 Ramon Novoa * lib/PandoraFMS/Config.pm: Read configuration for the new enterprise diff --git a/pandora_server/lib/PandoraFMS/Tools.pm b/pandora_server/lib/PandoraFMS/Tools.pm index 2d9d8be444..ff66bcad99 100644 --- a/pandora_server/lib/PandoraFMS/Tools.pm +++ b/pandora_server/lib/PandoraFMS/Tools.pm @@ -23,6 +23,7 @@ use POSIX qw(setsid strftime); use POSIX; use PandoraFMS::Sendmail; use HTML::Entities; +use Encode; # New in 3.2. Used to sendmail internally, without external scripts # use Module::Loaded; @@ -333,13 +334,20 @@ sub pandora_sendmail { my %mail = ( To => $to_address, Message => $message, - Subject => $subject, + Subject => encode('MIME-Header', $subject), 'X-Mailer' => "Pandora FMS", Smtp => $pa_config->{"mta_address"}, Port => $pa_config->{"mta_port"}, From => $pa_config->{"mta_from"}, ); + # Check if message has non-ascii chars. + # non-ascii chars should be encoded in UTF-8. + if ($message =~ /[^[:ascii:]]/o) { + $mail{Message} = encode("UTF-8", $mail{Message}); + $mail{'Content-Type'} = 'text/plain; charset="UTF-8"'; + } + if ($pa_config->{"mta_user"} ne ""){ $mail{auth} = {user=>$pa_config->{"mta_user"}, password=>$pa_config->{"mta_pass"}, method=>$pa_config->{"mta_auth"}, required=>1 }; }