From ed107eecedbb42a43b54e5eda64b4d72cdec6f08 Mon Sep 17 00:00:00 2001
From: "H.Shay"
Date: Mon, 9 Aug 2021 11:10:36 -0700
Subject: [PATCH 01/38] add jinja to setup
---
setup.py | 1 +
1 file changed, 1 insertion(+)
diff --git a/setup.py b/setup.py
index 034a4704..e1617d09 100644
--- a/setup.py
+++ b/setup.py
@@ -41,6 +41,7 @@ def read(fname):
description="Reference Matrix Identity Verification and Lookup Server",
python_requires=">=3.6",
install_requires=[
+ "jinja2",
"signedjson==1.1.1",
"unpaddedbase64==1.1.0",
"Twisted>=18.4.0",
From 338bd5dd1202dc815333566a49f85886b870b643 Mon Sep 17 00:00:00 2001
From: "H.Shay"
Date: Mon, 9 Aug 2021 11:11:33 -0700
Subject: [PATCH 02/38] update send_email function to render templates with
jinja
---
sydent/util/emailutils.py | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/sydent/util/emailutils.py b/sydent/util/emailutils.py
index e9de0ac6..597b333a 100644
--- a/sydent/util/emailutils.py
+++ b/sydent/util/emailutils.py
@@ -22,6 +22,8 @@
from html import escape
from typing import TYPE_CHECKING, Dict
+from jinja2 import Template
+
import twisted.python.log
from sydent.util import time_msec
@@ -73,7 +75,10 @@ def sendEmail(
# conflicting with it.
allSubstitutions["multipart_boundary"] = generateAlphanumericTokenOfLength(32)
- mailString = open(templateFile).read() % allSubstitutions
+ with open(templateFile) as file_:
+ template = Template(file_.read())
+ mailString = template.render(allSubstitutions)
+
parsedFrom = email.utils.parseaddr(mailFrom)[1]
parsedTo = email.utils.parseaddr(mailTo)[1]
if parsedFrom == "" or parsedTo == "":
From 589c396b1a5efc9d7cdf73d502f4e9ea2487bb33 Mon Sep 17 00:00:00 2001
From: "H.Shay"
Date: Mon, 9 Aug 2021 11:13:04 -0700
Subject: [PATCH 03/38] change templates to use jinja
---
.../res/is-test/invite_template.eml | 12 +++---
.../res/is-test/verification_template.eml | 2 +-
res/matrix-org/invite_template.eml | 38 ++++++++++---------
res/matrix-org/verification_template.eml | 26 ++++++-------
res/vector-im/invite_template.eml | 30 +++++++--------
res/vector-im/verification_template.eml | 20 +++++-----
sydent/terms/terms.py | 2 +-
7 files changed, 66 insertions(+), 64 deletions(-)
diff --git a/matrix_is_test/res/is-test/invite_template.eml b/matrix_is_test/res/is-test/invite_template.eml
index 557a88cb..0b09cb12 100644
--- a/matrix_is_test/res/is-test/invite_template.eml
+++ b/matrix_is_test/res/is-test/invite_template.eml
@@ -1,8 +1,8 @@
{
- "token": "%(token)s",
- "room_alias": "%(room_alias)s",
- "room_avatar_url": "%(room_avatar_url)s",
- "room_name": "%(room_name)s",
- "sender_display_name": "%(sender_display_name)s",
- "sender_avatar_url": "%(sender_avatar_url)s"
+ "token": "{{ token }}",
+ "room_alias": "{{ room_alias }}",
+ "room_avatar_url": "{{ room_avatar_url }}",
+ "room_name": "{{ room_name }}",
+ "sender_display_name": "{{ sender_display_name }}",
+ "sender_avatar_url": "{{ sender_avatar_url }}"
}
diff --git a/matrix_is_test/res/is-test/verification_template.eml b/matrix_is_test/res/is-test/verification_template.eml
index c75dd7dc..d74f9a83 100644
--- a/matrix_is_test/res/is-test/verification_template.eml
+++ b/matrix_is_test/res/is-test/verification_template.eml
@@ -1 +1 @@
-<<<%(token)s>>>
+<<<{{ token }}>>>
diff --git a/res/matrix-org/invite_template.eml b/res/matrix-org/invite_template.eml
index dfcd7216..f1205651 100644
--- a/res/matrix-org/invite_template.eml
+++ b/res/matrix-org/invite_template.eml
@@ -1,25 +1,25 @@
-Date: %(date)s
-From: %(from)s
-To: %(to)s
-Message-ID: %(messageid)s
-Subject: %(subject_header_value)s
+Date: {{ date }}
+From: {{ from }}
+To: {{ to }}
+Message-ID: {{ messageid }}
+Subject: {{ subject_header_value }}
MIME-Version: 1.0
Content-Type: multipart/alternative;
- boundary="%(multipart_boundary)s"
+ boundary="{{ multipart_boundary }}"
---%(multipart_boundary)s
+--{{ multipart_boundary }}
Content-Type: text/plain; charset=UTF-8
Content-Disposition: inline
Hi,
-%(sender_display_name)s %(bracketed_verified_sender)shas invited you into a room
-%(bracketed_room_name)son Matrix. To join the conversation, either pick a
+{{ sender_display_name }} {{ bracketed_verified_sender }}has invited you into a room
+{{ bracketed_room_name }}on Matrix. To join the conversation, either pick a
Matrix client from https://matrix.org/docs/projects/try-matrix-now.html or use
-the single-click link below to join via Element (requires Chrome, Firefox,
-Safari, iOS or Android)
+the single-click link below to join via Element requires Chrome, Firefox,
+Safari, iOS or Android
-%(web_client_location)/#/room/%(room_id_forurl)s?email=%(to_forurl)s&signurl=https%%3A%%2F%%2Fmatrix.org%%2F_matrix%%2Fidentity%%2Fapi%%2Fv1%%2Fsign-ed25519%%3Ftoken%%3D%(token)s%%26private_key%%3D%(ephemeral_private_key)s&room_name=%(room_name_forurl)s&room_avatar_url=%(room_avatar_url_forurl)s&inviter_name=%(sender_display_name_forurl)s&guest_access_token=%(guest_access_token_forurl)s&guest_user_id=%(guest_user_id_forurl)s
+{{ web_client_location }}/#/room/{{ room_id_forurl }}?email={{ to_forurl }}&signurl=https%%3A%%2F%%2Fmatrix.org%%2F_matrix%%2Fidentity%%2Fapi%%2Fv1%%2Fsign-ed25519%%3Ftoken%%3D{{ token }}%%26private_key%%3D{{ ephemeral_private_key }}&room_name={{ room_name_forurl }}&room_avatar_url={{ room_avatar_url_forurl }}&inviter_name={{ sender_display_name_forurl }}&guest_access_token={{ guest_access_token_forurl }}&guest_user_id={{ guest_user_id_forurl }}
About Matrix:
@@ -39,7 +39,7 @@ Thanks,
Matrix
---%(multipart_boundary)s
+--{{ multipart_boundary }}
Content-Type: text/html; charset=UTF-8
Content-Disposition: inline
@@ -83,6 +83,8 @@ pre, code {
text-align: right;
margin-left: 20px;
}
+
+
@@ -102,18 +104,18 @@ pre, code {
Hi,
-%(sender_display_name_forhtml)s %(bracketed_verified_sender_forhtml)s has invited you into a room %(bracketed_room_name_forhtml)s on
+
{{ sender_display_name_forhtml }} {{ bracketed_verified_sender_forhtml }} has invited you into a room {{ bracketed_room_name_forhtml }} on
Matrix. To join the conversation, either pick a Matrix client or use the single-click
-link below to join via Element (requires
+link below to join via Element requires
Chrome,
Firefox or
Safari on the web,
-or iOS or Android on mobile.)
+or iOS or Android on mobile.
Join the conversation.
+ href="https://app.element.io/#/room/{{ room_id_forurl }}?email={{ to_forurl }}&signurl=https%%3A%%2F%%2Fmatrix.org%%2F_matrix%%2Fidentity%%2Fapi%%2Fv1%%2Fsign-ed25519%%3Ftoken%%3D{{ token }}%%26private_key%%3D{{ ephemeral_private_key }}&room_name={{ room_name_forurl }}&room_avatar_url={{ room_avatar_url_forurl }}&inviter_name={{ sender_display_name_forurl }}&guest_access_token={{ guest_access_token_forurl }}&guest_user_id={{ guest_user_id_forurl }}">Join the conversation.
@@ -140,4 +142,4 @@ create new communication solutions or extend the capabilities and reach of exist