[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
This commit is contained in:
len-odoo
2018-11-09 12:09:51 +00:00
parent 5c2f96d0dd
commit c0f66d6c2d
+2 -2
View File
@@ -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),