Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Matrix
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Container Registry
Model registry
Operate
Environments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Matrix
Commits
4ed1e458
Commit
4ed1e458
authored
8 years ago
by
David Baker
Browse files
Options
Downloads
Patches
Plain Diff
Make html messages work
parent
87810839
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
synapse/push/mailer.py
+21
-10
21 additions, 10 deletions
synapse/push/mailer.py
with
21 additions
and
10 deletions
synapse/push/mailer.py
+
21
−
10
View file @
4ed1e458
...
...
@@ -59,7 +59,8 @@ ALLOWED_ATTRS = {
# would make sense if we did
"
img
"
:
[
"
src
"
],
}
ALLOWED_SCHEMES
=
[
"
http
"
,
"
https
"
,
"
ftp
"
,
"
mailto
"
]
# When bleach release a version with this option, we can specify schemes
#ALLOWED_SCHEMES = ["http", "https", "ftp", "mailto"]
class
Mailer
(
object
):
...
...
@@ -184,7 +185,15 @@ class Mailer(object):
defer
.
returnValue
(
ret
)
def
get_message_vars
(
self
,
notif
,
event
,
room_state
):
msgtype
=
event
.
content
[
"
msgtype
"
]
if
event
.
type
!=
"
m.room.message
"
:
return
None
if
event
.
content
[
"
msgtype
"
]
!=
"
m.text
"
:
return
None
if
"
format
"
in
event
.
content
:
msgformat
=
event
.
content
[
"
format
"
]
else
:
msgformat
=
None
sender_state_event
=
room_state
[(
"
m.room.member
"
,
event
.
sender
)]
sender_name
=
name_from_member_event
(
sender_state_event
)
...
...
@@ -195,7 +204,7 @@ class Mailer(object):
sender_hash
=
string_ordinal_total
(
event
.
sender
)
ret
=
{
"
msgtype
"
:
msgtype
,
"
format
"
:
msgformat
,
"
is_historical
"
:
event
.
event_id
!=
notif
[
'
event_id
'
],
"
ts
"
:
event
.
origin_server_ts
,
"
sender_name
"
:
sender_name
,
...
...
@@ -203,10 +212,10 @@ class Mailer(object):
"
sender_hash
"
:
sender_hash
,
}
if
msgtype
==
"
m.text
"
:
ret
[
"
body_text_plain
"
]
=
event
.
content
[
"
body
"
]
elif
msgtype
==
"
org.matrix.custom.html
"
:
if
msgformat
==
"
org.matrix.custom.html
"
:
ret
[
"
body_text_html
"
]
=
safe_markup
(
event
.
content
[
"
formatted_body
"
])
else
:
ret
[
"
body_text_plain
"
]
=
event
.
content
[
"
body
"
]
return
ret
...
...
@@ -263,14 +272,14 @@ class Mailer(object):
def
make_unsubscribe_link
(
self
):
return
"
https://vector.im/#/settings
"
# XXX: matrix.to
def
mxc_to_http_filter
(
self
,
value
,
width
,
height
,
resize
M
ethod
=
"
crop
"
):
def
mxc_to_http_filter
(
self
,
value
,
width
,
height
,
resize
_m
ethod
=
"
crop
"
):
if
value
[
0
:
6
]
!=
"
mxc://
"
:
return
""
serverAndMediaId
=
value
[
6
:]
params
=
{
"
width
"
:
width
,
"
height
"
:
height
,
"
method
"
:
resize
M
ethod
,
"
method
"
:
resize
_m
ethod
,
}
return
"
%s_matrix/media/v1/thumbnail/%s?%s
"
%
(
self
.
hs
.
config
.
public_baseurl
,
...
...
@@ -279,10 +288,12 @@ class Mailer(object):
)
def
safe_markup
(
self
,
raw_html
):
def
safe_markup
(
raw_html
):
return
jinja2
.
Markup
(
bleach
.
linkify
(
bleach
.
clean
(
raw_html
,
tags
=
ALLOWED_TAGS
,
attributes
=
ALLOWED_ATTRS
,
protocols
=
ALLOWED_SCHEMES
,
strip
=
True
# bleach master has this, but it isn't released yet
# protocols=ALLOWED_SCHEMES,
strip
=
True
)))
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment