From c0f66d6c2dceda0ff0073dccce08af961e858672 Mon Sep 17 00:00:00 2001 From: len-odoo Date: Fri, 9 Nov 2018 12:09:48 +0000 Subject: [PATCH] [FIX] mail: create attachments with the correct filename when using the popup editor Send a message using the popup editor. Drag and drop an image into the message content. It will create an attachment for the inlined image. To generate the values for the attachment, a regex is used to parse the content. Besides summoning Eldritch abominations, it didnt't take into account the original filename, whereas the default one (image) would have no extension. We extend the regex to capture the filename and use it. opw 1903194 closes odoo/odoo#28527 --- addons/mail/models/mail_message.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/mail/models/mail_message.py b/addons/mail/models/mail_message.py index 146ef168ed9..3fbbc500d36 100644 --- a/addons/mail/models/mail_message.py +++ b/addons/mail/models/mail_message.py @@ -12,7 +12,7 @@ from odoo.exceptions import UserError, AccessError from odoo.osv import expression _logger = logging.getLogger(__name__) -_image_dataurl = re.compile(r'(data:image/[a-z]+?);base64,([a-z0-9+/\n]{3,}=*)\n*([\'"])', re.I) +_image_dataurl = re.compile(r'(data:image/[a-z]+?);base64,([a-z0-9+/\n]{3,}=*)\n*([\'"])(?: data-filename="([^"]*)")?', re.I) class Message(models.Model): @@ -762,7 +762,7 @@ class Message(models.Model): def base64_to_boundary(match): key = match.group(2) if not data_to_url.get(key): - name = 'image%s' % len(data_to_url) + name = match.group(4) if match.group(4) else 'image%s' % len(data_to_url) attachment = Attachments.create({ 'name': name, 'datas': match.group(2),