diff --git a/include/class.api.php b/include/class.api.php
index fff9c2dd3d5798dcc88e0f2985bb5127c55e4ab6..0612fce72ce2f2ef74208e4362a70c88fa943c40 100644
--- a/include/class.api.php
+++ b/include/class.api.php
@@ -310,6 +310,7 @@ class ApiXmlDataParser extends XmlDataParser {
      * XML data types
      */
     function fixup($current) {
+        global $cfg;
 
         if($current['ticket'])
             $current = $current['ticket'];
@@ -336,9 +337,18 @@ class ApiXmlDataParser extends XmlDataParser {
                 }
                 if (isset($value['encoding']))
                     $value['body'] = Format::utf8encode($value['body'], $value['encoding']);
-                if (!isset($value['type']) || $value['type'] != 'text/html')
+                // HTML-ize text if html is enabled
+                if ($cfg->isHtmlThreadEnabled()
+                        && (!isset($value['type'])
+                            || strcasecmp($value['type'], 'text/html')))
                     $value = sprintf('<pre>%s</pre>',
                         Format::htmlchars($value['body']));
+                // Text-ify html if html is disabled
+                elseif (!$cfg->isHtmlThreadEnabled()
+                        && !strcasecmp($value['type'], 'text/html'))
+                    $value = Format::html2text(Format::safe_html(
+                        $value['body']), 100, false);
+                // Noop if they content-type matches the html setting
                 else
                     $value = $value['body'];
             } else if ($key == "attachments") {
diff --git a/include/class.mailfetch.php b/include/class.mailfetch.php
index 824a0358e8462a2d67eb652bb760062937317f9b..3c1804a326220803c8cea9e4664cd8b26643e53c 100644
--- a/include/class.mailfetch.php
+++ b/include/class.mailfetch.php
@@ -437,16 +437,12 @@ class MailFetcher {
             }
         }
         else {
-            if ($body=$this->getPart($mid, 'text/plain', $this->charset)) {
-                $body = Format::htmlchars($body);
-            }
-            elseif ($body=$this->getPart($mid, 'text/html', $this->charset)) {
-                $body = Format::html2text(Format::safe_html($body), 100, false);
+            if (!($body=$this->getPart($mid, 'text/plain', $this->charset))) {
+                if ($body=$this->getPart($mid, 'text/html', $this->charset)) {
+                    $body = Format::html2text(Format::safe_html($body), 100, false);
+                }
             }
-            $body = trim($body)
-                ? sprintf('<pre>%s</pre>',
-                    $body)
-                : '--';
+            $body = trim($body) ? $body : '--';
         }
         return $body;
     }
diff --git a/include/class.mailparse.php b/include/class.mailparse.php
index 364d58d85213f9cc23d9c851abb56853167f3b03..32b0083a6df2c077defd19ac1560627b20ab877c 100644
--- a/include/class.mailparse.php
+++ b/include/class.mailparse.php
@@ -187,16 +187,12 @@ class Mail_Parse {
             }
         }
         else {
-            if ($body=$this->getPart($this->struct,'text/plain')) {
-                $body = Format::htmlchars($body);
-            }
-            elseif ($body=$this->getPart($this->struct,'text/html')) {
-                $body = Format::html2text(Format::safe_html($body), 100, false);
+            if (!($body=$this->getPart($this->struct,'text/plain'))) {
+                if ($body=$this->getPart($this->struct,'text/html')) {
+                    $body = Format::html2text(Format::safe_html($body), 100, false);
+                }
             }
-            $body = trim($body)
-                ? sprintf('<pre>%s</pre>',
-                    $body)
-                : '--';
+            $body = trim($body) ? $body : '--';
         }
         return $body;
     }
diff --git a/include/class.thread.php b/include/class.thread.php
index 0fca591d9fbfadc2c07a09ecb6953102aff00d36..13c2e0dfe5ef1c1f4c463ed83daff8c0c3e53fe4 100644
--- a/include/class.thread.php
+++ b/include/class.thread.php
@@ -776,14 +776,14 @@ Class ThreadEntry {
             unset($a);
         }
 
-        $vars['body'] = Format::sanitize($vars['body'],
-            !$cfg->isHtmlThreadEnabled());
         if (!$cfg->isHtmlThreadEnabled()) {
             // Data in the database is assumed to be HTML, change special
             // plain text XML characters
             $vars['title'] = Format::htmlchars($vars['title']);
-            $vars['body'] = Format::htmlchars($vars['body']);
+            $vars['body'] = sprintf('<pre>%s</pre>',
+                Format::htmlchars($vars['body']));
         }
+        $vars['body'] = Format::sanitize($vars['body']);
 
         $sql=' INSERT INTO '.TICKET_THREAD_TABLE.' SET created=NOW() '
             .' ,thread_type='.db_input($vars['type'])