From 70f1fb159b02b80a9238315a56d42ea81dbf83c6 Mon Sep 17 00:00:00 2001
From: Hirofumi Kosaka <kosaka@rworks.jp>
Date: Tue, 13 Sep 2016 19:43:02 +0900
Subject: [PATCH] Determine eMail's Content-Type "text/html" if message has "<"
 and ">" at the beginning and the end.

---
 pandora_server/lib/PandoraFMS/Core.pm | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm
index c6078aeb0c..0795b3402b 100644
--- a/pandora_server/lib/PandoraFMS/Core.pm
+++ b/pandora_server/lib/PandoraFMS/Core.pm
@@ -1074,13 +1074,25 @@ sub pandora_execute_action ($$$$$$$$$;$) {
 		};
 		
 		# Default content type
-		my $content_type = 'text/html; charset="iso-8859-1"';
+		my $content_type;
+
+		# Check if message looks like html.
+		# Assume that html message starts with "<" and ends with ">".
+		if ($field3 =~ /^\s*<.*>\s*$/s ) {
+			$content_type = 'text/html;';
+		}
+		else {
+			$content_type = 'text/plain;';
+		}
 		
 		# Check if message has non-ascii chars.
 		# non-ascii chars should be encoded in UTF-8.
 		if ($field3 =~ /[^[:ascii:]]/o) {
 			$field3 = encode("UTF-8", $field3);
-			$content_type = 'text/plain; charset="UTF-8"';
+			$content_type .= ' charset="UTF-8"';
+		}
+		else {
+			$content_type .= ' charset="iso-8859-1"';
 		}
 		
 		# Build the mail with attached content