diff --git a/plugins/mailhandler/commands/MailhandlerCommandsDefault.class.php b/plugins/mailhandler/commands/MailhandlerCommandsDefault.class.php
index bce2100..70871c4 100644
--- a/plugins/mailhandler/commands/MailhandlerCommandsDefault.class.php
+++ b/plugins/mailhandler/commands/MailhandlerCommandsDefault.class.php
@@ -24,7 +24,7 @@ class MailhandlerCommandsDefault extends MailhandlerCommands {
     $commands = $this->getCommands($message['body_text']);
     $this->commands = $commands;
     foreach ($commands as $key => $value) {
-      $message['body_html'] = preg_replace('/' . $key . ': ' . $value . '/', '', $message['body_html'], 1);
+      $message['body_html'] = str_replace($key . ': ' . $value, '', $message['body_html']); // Replaces preg_replace which had issues with values containing unescaped characters
       $message['body_html'] = preg_replace('/<br[^>\r\n]*>/', '', $message['body_html'], 1);
     }
     if ($message['authenticated_uid'] == 0) {
@@ -107,10 +107,16 @@ class MailhandlerCommandsDefault extends MailhandlerCommands {
     // Collect the commands and locate signature.
     $lines = explode("\n", $string);
     foreach ($lines as $i => $line) {
-      $line = explode(':', $line);
-      if (count($line) == 2) {
-        $key = trim($line[0]);
-        $value = trim($line[1]);
+      /* 
+       * Replace only the first instance of text followed by a colon (i.e. the actual command).
+       * Regex replace is not linked to any validation performed when adding the commands themselves
+       * because I couldn't find any - with that in mind, the regex pattern is not very fussy.
+       */
+      preg_match('/^([a-zA-Z0-9_-\s\.]+):{1}\s*(.+)$/', $line, $matches);
+      
+      if (count($matches) == 3) {
+        $key = trim($matches[1]); // trim seems redundant now, keep it just in case
+        $value = trim($matches[2]);
         $commands[$key] = $value;
       }
       elseif (!empty($commands) || $i == 0) {
@@ -122,4 +128,4 @@ class MailhandlerCommandsDefault extends MailhandlerCommands {
     return $commands;
   }
 
-}
+}
\ No newline at end of file
