Modified the function "pandora_sendmail" to make it more flexible

This commit is contained in:
Alejandro Gallardo Escobar 2015-02-09 17:49:30 +01:00
parent c95401a251
commit 0bbe56c788
1 changed files with 12 additions and 2 deletions

View File

@ -325,6 +325,7 @@ sub pandora_daemonize {
# param2 - Destination email addres # param2 - Destination email addres
# param3 - Email subject # param3 - Email subject
# param4 - Email Message body # param4 - Email Message body
# param4 - Email content type
######################################################################## ########################################################################
sub pandora_sendmail { sub pandora_sendmail {
@ -333,9 +334,14 @@ sub pandora_sendmail {
my $to_address = $_[1]; my $to_address = $_[1];
my $subject = $_[2]; my $subject = $_[2];
my $message = $_[3]; my $message = $_[3];
my $content_type = $_[4];
$subject = decode_entities ($subject); $subject = decode_entities ($subject);
$message = decode_entities ($message);
# If content type is defined, the message will be custom
if (! defined($content_type)) {
$message = decode_entities ($message);
}
my %mail = ( To => $to_address, my %mail = ( To => $to_address,
Message => $message, Message => $message,
@ -346,9 +352,13 @@ sub pandora_sendmail {
From => $pa_config->{"mta_from"}, From => $pa_config->{"mta_from"},
); );
if (defined($content_type)) {
$mail{'Content-Type'} = $content_type;
}
# Check if message has non-ascii chars. # Check if message has non-ascii chars.
# non-ascii chars should be encoded in UTF-8. # non-ascii chars should be encoded in UTF-8.
if ($message =~ /[^[:ascii:]]/o) { if ($message =~ /[^[:ascii:]]/o && !defined($content_type)) {
$mail{Message} = encode("UTF-8", $mail{Message}); $mail{Message} = encode("UTF-8", $mail{Message});
$mail{'Content-Type'} = 'text/plain; charset="UTF-8"'; $mail{'Content-Type'} = 'text/plain; charset="UTF-8"';
} }