diff --git a/modules/contacts/js_modules/route_handlers.js b/modules/contacts/js_modules/route_handlers.js
index e7a5133443..a00e5ee9d7 100644
--- a/modules/contacts/js_modules/route_handlers.js
+++ b/modules/contacts/js_modules/route_handlers.js
@@ -30,4 +30,11 @@ function applyContactsPageHandlers() {
         return false;
     });
     contact_import_pagination();
+}
+
+function applyContactsAutocompleteComposePageHandlers() {
+    $('.compose_to').on('keyup', function(e) { autocomplete_contact(e, '.compose_to', '#to_contacts'); });
+    $('.compose_cc').on('keyup', function(e) { autocomplete_contact(e, '.compose_cc', '#cc_contacts'); });
+    $('.compose_bcc').on('keyup', function(e) { autocomplete_contact(e, '.compose_bcc', '#bcc_contacts'); });
+    $('.compose_to').focus();
 }
\ No newline at end of file
diff --git a/modules/contacts/site.js b/modules/contacts/site.js
index e4ebfd0f79..92e31cf3e1 100644
--- a/modules/contacts/site.js
+++ b/modules/contacts/site.js
@@ -87,35 +87,32 @@ var autocomplete_contact = function(e, class_name, list_div) {
             [{'name': 'hm_ajax_hook', 'value': 'ajax_autocomplete_contact'},
             {'name': 'contact_value', 'value': fld_val}],
             function(res) {
-                var active = $(document.activeElement).attr('class');
-                if (active == 'compose_to' || active == 'compose_bcc' || active == 'compose_cc') {
-                    if (res.contact_suggestions) {
-                        var i;
-                        var count = 0;
-                        $(list_div).html('');
-                        for (i in res.contact_suggestions) {
-                            var suggestion = JSON.parse(res.contact_suggestions[i].replace(/"/g, '"'))
-
-                            div.html(suggestion.contact);
-                            if ($(class_name).val().match(div.text())) {
-                                continue;
-                            }
-                            if (count == 0) {
-                                first = 'first ';
-                            }
-                            else {
-                                first = '';
-                            }
-                            count++;
-                            $(list_div).append('<a tabindex="1" href="#" class="'+first+'contact_suggestion" data-id="'+suggestion.contact_id+'" data-type="'+suggestion.type+'" data-source="'+suggestion.source+'" unread_link">'+suggestion.contact+'</a>');
+                if (res.contact_suggestions) {
+                    var i;
+                    var count = 0;
+                    $(list_div).html('');
+                    for (i in res.contact_suggestions) {
+                        var suggestion = JSON.parse(res.contact_suggestions[i].replace(/&quot;/g, '"'))
+                        
+                        div.html(suggestion.contact);
+                        if ($(class_name).val().match(div.text())) {
+                            continue;
                         }
-                        if (count > 0) {
-                            $(list_div).show();
-                            setup_autocomplete_events(class_name, list_div, fld_val);
+                        if (count == 0) {
+                            first = 'first ';
                         }
                         else {
-                            $(list_div).hide();
+                            first = '';
                         }
+                        count++;
+                        $(list_div).append('<a tabindex="1" href="#" class="'+first+'contact_suggestion" data-id="'+suggestion.contact_id+'" data-type="'+suggestion.type+'" data-source="'+suggestion.source+'" unread_link">'+suggestion.contact+'</a>');
+                    }
+                    if (count > 0) {
+                        $(list_div).show();
+                        setup_autocomplete_events(class_name, list_div, fld_val);
+                    }
+                    else {
+                        $(list_div).hide();
                     }
                 }
             }, [], true
diff --git a/modules/core/js_modules/route_handlers.js b/modules/core/js_modules/route_handlers.js
index 782d9b9a24..f68d1265f1 100644
--- a/modules/core/js_modules/route_handlers.js
+++ b/modules/core/js_modules/route_handlers.js
@@ -100,3 +100,10 @@ function applyMessagePageHandlers(routeParams) {
             break;
     }
 }
+
+function applyComposePageHandlers(routeParams) {
+    applySmtpComposePageHandlers(routeParams);
+    if (hm_module_is_supported('contacts')) {
+        applyContactsAutocompleteComposePageHandlers(routeParams);
+    }
+}
diff --git a/modules/core/message_functions.php b/modules/core/message_functions.php
index 1eaac26d58..6ab2664a0c 100644
--- a/modules/core/message_functions.php
+++ b/modules/core/message_functions.php
@@ -449,8 +449,7 @@ class HTMLToText {
 
     function __construct($html) {
         $doc = new DOMDocument();
-        $html = mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8');
-        $doc->loadHTML(htmlentities($html, ENT_QUOTES, 'UTF-8'));
+        $doc->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'));
         if (trim($html) && $doc->hasChildNodes()) {
             $this->parse_nodes($doc->childNodes);
         }
diff --git a/modules/smtp/js_modules/route_handlers.js b/modules/smtp/js_modules/route_handlers.js
index 7849599571..5179c5e495 100644
--- a/modules/smtp/js_modules/route_handlers.js
+++ b/modules/smtp/js_modules/route_handlers.js
@@ -1,5 +1,5 @@
 // TODO: This function is too large for a route handler, decouple it into multiple functions with action scope focused.
-function applyComposePageHandlers() {
+function applySmtpComposePageHandlers() {
     init_resumable_upload()
 
     if (window.HTMLEditor) {
@@ -245,11 +245,6 @@ function applyComposePageHandlers() {
         });
     }
 
-    $('.compose_to').on('keyup', function(e) { autocomplete_contact(e, '.compose_to', '#to_contacts'); });
-    $('.compose_cc').on('keyup', function(e) { autocomplete_contact(e, '.compose_cc', '#cc_contacts'); });
-    $('.compose_bcc').on('keyup', function(e) { autocomplete_contact(e, '.compose_bcc', '#bcc_contacts'); });
-    $('.compose_to').focus();
-
     if (window.pgpComposePageHandler) pgpComposePageHandler();
     if (window.profilesComposePageHandler) profilesComposePageHandler();
 }
\ No newline at end of file