[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.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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
|
||||
|
||||
+13
-9
@@ -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 <a/> 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 += '<a href="%s" target="_blank">%s</a>' % (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', '<br/>')
|
||||
|
||||
# 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
|
||||
text = html_keep_url(text)
|
||||
|
||||
# 3-4: form paragraphs
|
||||
idx = 0
|
||||
|
||||
Reference in New Issue
Block a user