[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
This commit is contained in:
Antonio Espinosa 2015-12-14 12:37:02 +01:00 committed by Martin Trigaux
parent 5425316eff
commit fc3c0b22f9
1 changed files with 9 additions and 0 deletions

View File

@ -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)