Skip to content

Commit

Permalink
fix(frontend/backend): restore the contacts autocompletion on the com…
Browse files Browse the repository at this point in the history
…pose form feature in the working state and ensure the reply to a message action does not include css styles in the body (#1410)

* fix(frontend): contacts autocomplete on the compose page

* fix(backend): strip out style attributes from the message text when replying to a message originally in HTML format
  • Loading branch information
mercihabam authored Dec 20, 2024
1 parent 5900008 commit 8c45018
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 33 deletions.
7 changes: 7 additions & 0 deletions modules/contacts/js_modules/route_handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
47 changes: 22 additions & 25 deletions modules/contacts/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions modules/core/js_modules/route_handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,10 @@ function applyMessagePageHandlers(routeParams) {
break;
}
}

function applyComposePageHandlers(routeParams) {
applySmtpComposePageHandlers(routeParams);
if (hm_module_is_supported('contacts')) {
applyContactsAutocompleteComposePageHandlers(routeParams);
}
}
3 changes: 1 addition & 2 deletions modules/core/message_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
7 changes: 1 addition & 6 deletions modules/smtp/js_modules/route_handlers.js
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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();
}

0 comments on commit 8c45018

Please sign in to comment.