diff --git a/include/class.format.php b/include/class.format.php
index 70b06a8a37c09f05f0e27017f9d520c08f99cd29..cfb2df4f072abbf38fb2f71d628a19ef243e61a8 100644
--- a/include/class.format.php
+++ b/include/class.format.php
@@ -194,6 +194,9 @@ class Format {
 
     function html2text($html, $width=74, $tidy=true) {
 
+        if (!$html)
+            return $html;
+
 
         # Tidy html: decode, balance, sanitize tags
         if($tidy)
@@ -201,8 +204,9 @@ class Format {
 
         # See if advanced html2text is available (requires xml extension)
         if (function_exists('convert_html_to_text')
-                && extension_loaded('dom'))
-            return convert_html_to_text($html, $width);
+                && extension_loaded('dom')
+                && ($text = convert_html_to_text($html, $width)))
+                return $text;
 
         # Try simple html2text  - insert line breaks after new line tags.
         $html = preg_replace(
diff --git a/include/html2text.php b/include/html2text.php
index 2863e10524cac3e7d500ad5e6b9710c5eb0db21e..d8ef77c5e77c51284a0fa9e304c6989754873f58 100644
--- a/include/html2text.php
+++ b/include/html2text.php
@@ -181,7 +181,7 @@ class HtmlInlineElement {
     }
 
     function traverse($node) {
-        if ($node->hasChildNodes()) {
+        if ($node && $node->hasChildNodes()) {
             for ($i = 0; $i < $node->childNodes->length; $i++) {
                 $n = $node->childNodes->item($i);
                 $this->children[] = identify_node($n, $this);
@@ -194,7 +194,9 @@ class HtmlInlineElement {
         $after_block = false;
         $this->ws = $this->getStyle('white-space', 'normal');
         // Direction
-        $dir = $this->node->getAttribute('dir');
+        if ($this->node)
+            $dir = $this->node->getAttribute('dir');
+
         // Ensure we have a value, but don't emit a control char unless
         // direction is declared
         $this->dir = $dir ?: 'ltr';
@@ -287,10 +289,11 @@ class HtmlInlineElement {
         if ($this->style && $this->style->has($property))
             return $this->style->get($property, $default);
 
-        if ($tag === false)
+        if ($this->node && $tag === false)
             $tag = $this->node->nodeName;
+
         if ($classes === false) {
-            if ($c = $this->node->getAttribute('class'))
+            if ($this->node && ($c = $this->node->getAttribute('class')))
                 $classes = explode(' ', $c);
             else
                 $classes = array();