[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:
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user