Browse Source

[FIX] mass_mailing: absolute URLs to email images

Partial backport of 9.0 commit a14f89c8 to 8.0
<base href=""> are not well supported in some webmails
Replace absolute URLs by full path appending the domain.

Closes #10062
master
Antonio Espinosa 6 years ago
committed by Martin Trigaux
parent
commit
fc3c0b22f9
  1. 9
      addons/mass_mailing/models/mail_mail.py

9
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 = "<base href='%s'>" % 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('(<img(?=\s)[^>]*\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)

Loading…
Cancel
Save