[FIX] mail : clickable url in mail.message from channel, chat and chatter
html_escape_keep_url is now included in plaintext2html method (since the opposite method html2plaintext transform link tags into simple url text). Force the posted message to be plaintext (adding directly html is not safe), and trim the posted message before submitting it. The url are now clickable again in chat message, but also in chatter messages !
This commit is contained in:
@@ -119,9 +119,9 @@ 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: 'html',
|
||||
content_subtype: 'plaintext',
|
||||
partner_ids: data.partner_ids,
|
||||
body: data.content,
|
||||
body: _.str.trim(data.content),
|
||||
subtype: 'mail.mt_comment',
|
||||
attachment_ids: data.attachment_ids,
|
||||
});
|
||||
@@ -130,7 +130,7 @@ function post_channel_message (data) {
|
||||
function post_document_message (model_name, res_id, data) {
|
||||
var values = {
|
||||
attachment_ids: data.attachment_ids,
|
||||
body: data.content,
|
||||
body: _.str.trim(data.content),
|
||||
content_subtype: data.content_subtype,
|
||||
message_type: data.message_type,
|
||||
partner_ids: data.partner_ids,
|
||||
|
||||
@@ -484,7 +484,7 @@ var ChatterComposer = ChatComposer.extend({
|
||||
subtype_id: false,
|
||||
subtype: 'mail.mt_comment',
|
||||
message_type: 'comment',
|
||||
content_subtype: 'html',
|
||||
content_subtype: 'plaintext',
|
||||
});
|
||||
|
||||
// Subtype
|
||||
|
||||
+14
-20
@@ -525,29 +525,12 @@ def html2plaintext(html, body_id=None, encoding='utf-8'):
|
||||
|
||||
return html
|
||||
|
||||
def html_escape_keep_url(self, message):
|
||||
""" Escape the message and transform the url into clickable link
|
||||
:param string message: the message to escape url and transform them into clickable link
|
||||
:returns the escaped message
|
||||
:rtype : string
|
||||
"""
|
||||
safe_message = ""
|
||||
first = 0
|
||||
last = 0
|
||||
for m in re.finditer('(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?', message):
|
||||
last = m.start()
|
||||
safe_message += cgi.escape(message[first:last])
|
||||
safe_message += '<a href="%s" target="_blank">%s</a>' % (cgi.escape(m.group(0)), m.group(0))
|
||||
first = m.end()
|
||||
last = m.end()
|
||||
safe_message += cgi.escape(message[last:])
|
||||
return safe_message
|
||||
|
||||
def plaintext2html(text, container_tag=False):
|
||||
""" Convert plaintext into html. Content of the text is escaped to manage
|
||||
html entities, using cgi.escape().
|
||||
- all \n,\r are replaced by <br />
|
||||
- enclose content into <p>
|
||||
- convert url into clickable link
|
||||
- 2 or more consecutive <br /> are considered as paragraph breaks
|
||||
|
||||
:param string container_tag: container of the html; by default the
|
||||
@@ -559,7 +542,18 @@ def plaintext2html(text, container_tag=False):
|
||||
text = text.replace('\n', '<br/>')
|
||||
text = text.replace('\r', '<br/>')
|
||||
|
||||
# 2-3: form paragraphs
|
||||
# 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 += '<a href="%s" target="_blank">%s</a>' % (item.group(0), item.group(0))
|
||||
idx = item.end()
|
||||
final += text[idx:]
|
||||
text = final
|
||||
|
||||
# 3-4: form paragraphs
|
||||
idx = 0
|
||||
final = '<p>'
|
||||
br_tags = re.compile(r'(([<]\s*[bB][rR]\s*\/?[>]\s*){2,})')
|
||||
@@ -568,7 +562,7 @@ def plaintext2html(text, container_tag=False):
|
||||
idx = item.end()
|
||||
final += text[idx:] + '</p>'
|
||||
|
||||
# 4. container
|
||||
# 5. container
|
||||
if container_tag:
|
||||
final = '<%s>%s</%s>' % (container_tag, final, container_tag)
|
||||
return ustr(final)
|
||||
|
||||
Reference in New Issue
Block a user