summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorDavid Baker <dave@matrix.org>2016-04-28 10:55:08 +0100
committerDavid Baker <dave@matrix.org>2016-04-28 10:55:08 +0100
commit9dba1b668ce1d2ea4db1fb6bfae3df319e7c76d4 (patch)
tree5ecad42afb2d97e2e178dd0ed25008c22f74fd42 /synapse
parentRun filter_events_for_client (diff)
downloadsynapse-9dba1b668ce1d2ea4db1fb6bfae3df319e7c76d4.tar.xz
Linkify plain text messages too
Diffstat (limited to 'synapse')
-rw-r--r--synapse/push/mailer.py13
1 files changed, 12 insertions, 1 deletions
diff --git a/synapse/push/mailer.py b/synapse/push/mailer.py
index afdf439664..7ef64f8f6d 100644
--- a/synapse/push/mailer.py
+++ b/synapse/push/mailer.py
@@ -219,7 +219,7 @@ class Mailer(object):
         if msgformat == "org.matrix.custom.html":
             ret["body_text_html"] = safe_markup(event.content["formatted_body"])
         else:
-            ret["body_text_plain"] = event.content["body"]
+            ret["body_text_html"] = safe_text(event.content["body"])
 
         return ret
 
@@ -301,6 +301,17 @@ def safe_markup(raw_html):
     )))
 
 
+def safe_text(raw_text):
+    """
+    Process text: treat it as HTML but escape any tags (ie. just escape the
+    HTML) then linkify it.
+    """
+    return jinja2.Markup(bleach.linkify(bleach.clean(
+        raw_text, tags=[], attributes={},
+        strip=False
+    )))
+
+
 def deduped_ordered_list(l):
     seen = set()
     ret = []