From b1849f532e6f7a4152f8ca7b74f13362b82afd0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Maes?= Date: Tue, 6 Oct 2015 15:02:18 +0200 Subject: [PATCH] [FIX] mail : posting message with mention and clickable url Posting message is done in 'html' since mention add html tag in body. Clickable url is done server to allow link in mail and chat message. Plaintext are transform into html, and html message are simply parsed to transform url into clickable link. --- addons/mail/models/mail_thread.py | 2 ++ addons/mail/static/src/js/chat_manager.js | 2 +- addons/mail/static/src/js/chatter.js | 2 +- openerp/tools/mail.py | 22 +++++++++++++--------- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index e0ae94a07da..ba652d9ce48 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -1569,6 +1569,8 @@ class MailThread(models.AbstractModel): # 1: Handle content subtype: if plaintext, converto into HTML if content_subtype == 'plaintext': body = tools.plaintext2html(body) + else: + body = tools.html_keep_url(body) # 2: Private message: add recipients (recipients and author of parent message) - current author # + legacy-code management (! we manage only 4 and 6 commands) diff --git a/addons/mail/static/src/js/chat_manager.js b/addons/mail/static/src/js/chat_manager.js index 6b42ddc9234..0f8a0223260 100644 --- a/addons/mail/static/src/js/chat_manager.js +++ b/addons/mail/static/src/js/chat_manager.js @@ -127,7 +127,7 @@ function add_channel_to_message (message, channel_id) { function post_channel_message (data) { return ChannelModel.call('message_post', [data.channel_id], { message_type: 'comment', - content_subtype: 'plaintext', + content_subtype: 'html', partner_ids: data.partner_ids, body: _.str.trim(data.content), subtype: 'mail.mt_comment', diff --git a/addons/mail/static/src/js/chatter.js b/addons/mail/static/src/js/chatter.js index 8e256377d40..bdee2fe06dc 100644 --- a/addons/mail/static/src/js/chatter.js +++ b/addons/mail/static/src/js/chatter.js @@ -484,7 +484,7 @@ var ChatterComposer = ChatComposer.extend({ subtype_id: false, subtype: 'mail.mt_comment', message_type: 'comment', - content_subtype: 'plaintext', + content_subtype: 'html', }); // Subtype diff --git a/openerp/tools/mail.py b/openerp/tools/mail.py index 09010efe0e7..bfd011fc42c 100644 --- a/openerp/tools/mail.py +++ b/openerp/tools/mail.py @@ -462,6 +462,18 @@ def html_email_clean(html, remove=False, shorten=False, max_length=300, expand_o # HTML/Text management #---------------------------------------------------------- +def html_keep_url(text): + """ Transform the url into clickable link with tag """ + idx = 0 + final = '' + link_tags = re.compile(r'(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?') + for item in re.finditer(link_tags, text): + final += text[idx:item.start()] + final += '%s' % (item.group(0), item.group(0)) + idx = item.end() + final += text[idx:] + return final + def html2plaintext(html, body_id=None, encoding='utf-8'): """ From an HTML text, convert the HTML to plain text. If @param body_id is provided then this is the tag where the @@ -543,15 +555,7 @@ def plaintext2html(text, container_tag=False): text = text.replace('\r', '
') # 2. clickable links - idx = 0 - final = '' - link_tags = re.compile(r'(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?') - for item in re.finditer(link_tags, text): - final += text[idx:item.start()] - final += '%s' % (item.group(0), item.group(0)) - idx = item.end() - final += text[idx:] - text = final + text = html_keep_url(text) # 3-4: form paragraphs idx = 0