From fc3c0b22f9d3a16a0b7aefde68a278dd9fff9789 Mon Sep 17 00:00:00 2001 From: Antonio Espinosa Date: Mon, 14 Dec 2015 12:37:02 +0100 Subject: [PATCH] [FIX] mass_mailing: absolute URLs to email images Partial backport of 9.0 commit a14f89c8 to 8.0 are not well supported in some webmails Replace absolute URLs by full path appending the domain. Closes #10062 --- addons/mass_mailing/models/mail_mail.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/addons/mass_mailing/models/mail_mail.py b/addons/mass_mailing/models/mail_mail.py index 651d8f07729..c2775ad019b 100644 --- a/addons/mass_mailing/models/mail_mail.py +++ b/addons/mass_mailing/models/mail_mail.py @@ -21,6 +21,7 @@ import urlparse import werkzeug.urls +import re from openerp.tools.translate import _ from openerp import tools @@ -80,6 +81,14 @@ class MailMail(osv.Model): base = "" % domain body = tools.append_content_to_html(base, body, plaintext=False, container_tag='div') + # resolve relative image url to absolute for outlook.com + def _sub_relative2absolute(match): + return match.group(1) + urlparse.urljoin(domain, match.group(2)) + # Regex: https://regex101.com/r/aE8uG5/3 + body = re.sub('(]*\ssrc=["\'])(/[^/][^"\']+)', _sub_relative2absolute, body) + # Regex: https://regex101.com/r/kT3lD5/2 + body = re.sub(r'(<[^>]+\bstyle=["\'][^"\']+\burl\([\'"]?)(/[^/\'"][^\'")]+)', _sub_relative2absolute, body) + # generate tracking URL if mail.statistics_ids: tracking_url = self._get_tracking_url(cr, uid, mail, partner, context=context)