[IMP] mail: don't send attachment if the link is in the email
If the user send an email with a '/web/content' or /web/image' link in the body, the attachment are not send by email to not to increase the size of the email unnecessarily.
This commit is contained in:
@@ -6,6 +6,7 @@ import datetime
|
||||
import logging
|
||||
import psycopg2
|
||||
import threading
|
||||
import re
|
||||
|
||||
from collections import defaultdict
|
||||
from email.utils import formataddr
|
||||
@@ -252,6 +253,7 @@ class MailMail(models.Model):
|
||||
@api.multi
|
||||
def _send(self, auto_commit=False, raise_exception=False, smtp_session=None):
|
||||
IrMailServer = self.env['ir.mail_server']
|
||||
IrAttachment = self.env['ir.attachment']
|
||||
for mail_id in self.ids:
|
||||
success_pids = []
|
||||
failure_type = 'NONE'
|
||||
@@ -263,11 +265,18 @@ class MailMail(models.Model):
|
||||
if mail.state != 'exception' and mail.auto_delete:
|
||||
mail.sudo().unlink()
|
||||
continue
|
||||
|
||||
# remove attachments if user send the link with the access_token
|
||||
body = mail.body_html or ''
|
||||
attachments = mail.attachment_ids
|
||||
for link in re.findall(r'/web/(?:content|image)/([0-9]+)', body):
|
||||
attachments = attachments - IrAttachment.browse(int(link))
|
||||
|
||||
# load attachment binary data with a separate read(), as prefetching all
|
||||
# `datas` (binary field) could bloat the browse cache, triggerring
|
||||
# soft/hard mem limits with temporary data.
|
||||
attachments = [(a['datas_fname'], base64.b64decode(a['datas']), a['mimetype'])
|
||||
for a in mail.attachment_ids.sudo().read(['datas_fname', 'datas', 'mimetype'])]
|
||||
for a in attachments.sudo().read(['datas_fname', 'datas', 'mimetype'])]
|
||||
|
||||
# specific behavior to customize the send email for notified partners
|
||||
email_list = []
|
||||
|
||||
Reference in New Issue
Block a user