summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristophe Matthieu <chm@odoo.com>2018-07-11 15:37:38 +0200
committerChristophe Matthieu <chm@odoo.com>2018-07-12 08:25:47 +0200
commita729669a10d0f4daf71863223a96a32f7b71642e (patch)
tree04f064703d75e85d315fce3185023c884491a8f7
parent8a21e27377bb65c03ca9b4a67b228ce21519a3e9 (diff)
[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.
-rw-r--r--addons/mail/models/mail_mail.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/addons/mail/models/mail_mail.py b/addons/mail/models/mail_mail.py
index d8abbd1f06f..23e154e83c9 100644
--- a/addons/mail/models/mail_mail.py
+++ b/addons/mail/models/mail_mail.py
@@ -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 = []