Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove images from message notification e-mails. #17598

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/17598.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove images from message notification e-mails.
15 changes: 1 addition & 14 deletions synapse/res/templates/notif.html
Original file line number Diff line number Diff line change
@@ -1,19 +1,6 @@
{%- for message in notif.messages %}
<tr class="{{ "historical_message" if message.is_historical else "message" }}">
<td class="sender_avatar">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we remove this column entirely?

{%- if loop.index0 == 0 or notif.messages[loop.index0 - 1].sender_name != notif.messages[loop.index0].sender_name %}
{%- if message.sender_avatar_url %}
<img alt="" class="sender_avatar" src="{{ message.sender_avatar_url|mxc_to_http(32,32) }}" />
{%- else %}
{%- if message.sender_hash % 3 == 0 %}
<img class="sender_avatar" src="https://riot.im/img/external/avatar-1.png" />
{%- elif message.sender_hash % 3 == 1 %}
<img class="sender_avatar" src="https://riot.im/img/external/avatar-2.png" />
{%- else %}
<img class="sender_avatar" src="https://riot.im/img/external/avatar-3.png" />
{%- endif %}
{%- endif %}
{%- endif %}
</td>
<td class="message_contents">
{%- if loop.index0 == 0 or notif.messages[loop.index0 - 1].sender_name != notif.messages[loop.index0].sender_name %}
Expand All @@ -30,7 +17,7 @@
{%- elif message.msgtype == "m.notice" %}
{{ message.body_text_html }}
{%- elif message.msgtype == "m.image" and message.image_url %}
<img src="{{ message.image_url|mxc_to_http(640, 480, 'scale') }}" />
<span class="filename">{{ message.body_text_plain }} (image)</span>
{%- elif message.msgtype == "m.file" %}
<span class="filename">{{ message.body_text_plain }}</span>
{%- else %}
Expand Down
11 changes: 0 additions & 11 deletions synapse/res/templates/room.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
<table class="room">
<tr class="room_header">
<td class="room_avatar">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise here.

{%- if room.avatar_url %}
<img alt="" src="{{ room.avatar_url|mxc_to_http(48,48) }}" />
{%- else %}
{%- if room.hash % 3 == 0 %}
<img alt="" src="https://riot.im/img/external/avatar-1.png" />
{%- elif room.hash % 3 == 1 %}
<img alt="" src="https://riot.im/img/external/avatar-2.png" />
{%- else %}
<img alt="" src="https://riot.im/img/external/avatar-3.png" />
{%- endif %}
{%- endif %}
</td>
<td class="room_name" colspan="2">
{{ room.title }}
Expand Down
38 changes: 0 additions & 38 deletions tests/push/test_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,44 +338,6 @@ def test_multiple_rooms(self) -> None:
# We should get emailed about those messages
self._check_for_mail()

def test_room_notifications_include_avatar(self) -> None:
# Create a room and set its avatar.
room = self.helper.create_room_as(self.user_id, tok=self.access_token)
self.helper.send_state(
room, "m.room.avatar", {"url": "mxc://DUMMY_MEDIA_ID"}, self.access_token
)

# Invite two other uses.
for other in self.others:
self.helper.invite(
room=room, src=self.user_id, tok=self.access_token, targ=other.id
)
self.helper.join(room=room, user=other.id, tok=other.token)

# The other users send some messages.
# TODO It seems that two messages are required to trigger an email?
self.helper.send(room, body="Alpha", tok=self.others[0].token)
self.helper.send(room, body="Beta", tok=self.others[1].token)

# We should get emailed about those messages
args, kwargs = self._check_for_mail()

# That email should contain the room's avatar
msg: bytes = args[5]
# Multipart: plain text, base 64 encoded; html, base 64 encoded

# Extract the html Message object from the Multipart Message.
# We need the asserts to convince mypy that this is OK.
html_message = email.message_from_bytes(msg).get_payload(i=1)
assert isinstance(html_message, email.message.Message)

# Extract the `bytes` from the html Message object, and decode to a `str`.
html = html_message.get_payload(decode=True)
assert isinstance(html, bytes)
html = html.decode()

self.assertIn("_matrix/media/v1/thumbnail/DUMMY_MEDIA_ID", html)

def test_empty_room(self) -> None:
"""All users leaving a room shouldn't cause the pusher to break."""
# Create a simple room with two users
Expand Down
Loading