From 96aacbd4845ca40c78d0674d78ad580e6c66d4f7 Mon Sep 17 00:00:00 2001 From: Antoine Nguyen Date: Tue, 26 Nov 2013 10:23:52 +0100 Subject: [PATCH] force html links to open in a new tab. --- modoboa/lib/emailutils.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/modoboa/lib/emailutils.py b/modoboa/lib/emailutils.py index b18e2c48d..0f298d9bd 100644 --- a/modoboa/lib/emailutils.py +++ b/modoboa/lib/emailutils.py @@ -147,10 +147,16 @@ class Email(object): return path def map_cid(self, url): - m = re.match(".*cid:(.+)", url) - if m: - if m.group(1) in self.attached_map: - return self.attached_map[m.group(1)] + """Replace attachment links. + + :param str url: original url + :rtype: string + :return: internal link + """ + match = re.match(".*cid:(.+)", url) + if match is not None: + if match.group(1) in self.attached_map: + return self.attached_map[match.group(1)] return url def render_headers(self, **kwargs): @@ -172,6 +178,8 @@ class Email(object): html.rewrite_links(lambda x: None) else: html.rewrite_links(self.map_cid) + for link in html.iterlinks(): + link[0].set('target', '_blank') body = html.find("body") if body is None: body = lxml.html.tostring(html)