diff --git a/labertasche/blueprints/bp_comments/__init__.py b/labertasche/blueprints/bp_comments/__init__.py index 2e217b0..14fae8b 100644 --- a/labertasche/blueprints/bp_comments/__init__.py +++ b/labertasche/blueprints/bp_comments/__init__.py @@ -14,7 +14,7 @@ from flask_cors import cross_origin from sqlalchemy import exc from labertasche.database import labertasche_db as db from labertasche.helper import is_valid_json, default_timestamp, check_gravatar, export_location -from labertasche.mail import mail +from labertasche.mail import Mail from labertasche.models import TComments, TLocation, TEmail, TProjects from labertasche.settings import Smileys from secrets import compare_digest @@ -39,7 +39,7 @@ def check_and_insert_new_comment(name): if compare_digest(request.method, "POST"): smileys = Smileys() - sender = mail() + sender = Mail() # Check length of content and abort if too long or too short if request.content_length > 2048: diff --git a/labertasche/mail/__init__.py b/labertasche/mail/__init__.py index fdb4967..1f73966 100644 --- a/labertasche/mail/__init__.py +++ b/labertasche/mail/__init__.py @@ -18,10 +18,11 @@ from secrets import token_urlsafe from labertasche.models import TProjects from labertasche.database import labertasche_db as db from labertasche.settings import Settings -from flask import render_template +from labertasche.language import Language +from flask import render_template, request -class mail: +class Mail: def __init__(self): path = Path("/etc/labertasche/mail_credentials.json") @@ -76,6 +77,7 @@ class mail: return None, None settings = Settings() + language = Language(request) confirm_digest = token_urlsafe(48) delete_digest = token_urlsafe(48) @@ -83,11 +85,20 @@ class mail: confirm_url = f"{settings.weburl}/comments/{project.name}/confirm/{confirm_digest}" delete_url = f"{settings.weburl}/comments/{project.name}/delete/{delete_digest}" - txt_what = f"Hey there. You have made a comment on {project.blogurl}. Please confirm it by " \ - f"copying this link into your browser:\n{confirm_url}\n" \ - f"If you want to delete your comment for whatever reason, please use this link:\n{delete_url}" + html_tpl = f"mail/comment_confirmation_{language.browser_language}.html" + txt_tpl = f"mail/comment_confirmation_{language.browser_language}_txt.html" - html_what = render_template("comment_confirmation.html", + if not Path(f"./templates/{html_tpl}").exists(): + html_tpl = f"mail/comment_confirmation_en-US.html" + if not Path(f"./templates/{txt_tpl}").exists(): + html_tpl = f"mail/comment_confirmation_en-US_txt.html" + + txt_what = render_template(txt_tpl, + blogurl=project.blogurl, + confirmation_url=confirm_url, + deletion_url=delete_url).replace('
', "").replace('
', '') + + html_what = render_template(html_tpl, blogurl=project.blogurl, confirmation_url=confirm_url, deletion_url=delete_url) diff --git a/templates/mail/comment_confirmation_de-DE.html b/templates/mail/comment_confirmation_de-DE.html new file mode 100644 index 0000000..2c1a805 --- /dev/null +++ b/templates/mail/comment_confirmation_de-DE.html @@ -0,0 +1,40 @@ + + + + + + Dein Kommentar auf {{ blogurl }} + + + + + + + + + + + +
+

Dein Kommentar auf {{ blogurl }}

+
+

+ Hallo,

+ Du erhältst diese Email, weil du soeben einen Kommentar auf {{ blogurl }} hinterlassen hast. +

+ Wenn du deinen Kommentar veröffentlichen willst, klicke bitte auf diesen Link. +
+ Wenn du deinen Kommentar löschen willst, klicke bitte auf diesen Link. +

+ Wenn du glaubst, dass dies ein Fehler war oder jemand deine Email Adresse ohnen deinen Wissen verwendet hat, kontaktiere bitte + den Administrator von {{ blogurl }}. +

+
+

+ Powered by Labertasche, +  lizensiert via MIT license. +

+
+
+ diff --git a/templates/mail/comment_confirmation_de-DE_txt.html b/templates/mail/comment_confirmation_de-DE_txt.html new file mode 100644 index 0000000..0f9383d --- /dev/null +++ b/templates/mail/comment_confirmation_de-DE_txt.html @@ -0,0 +1,16 @@ +
+Hallo,
+Du erhältst diese Email, weil du soeben einen Kommentar auf {{ blogurl }} hinterlassen hast.
+
+Wenn du deinen Kommentar veröffentlichen willst, kopiere bitte diesen Link in deinen Browser:
+{{ confirmation_url }}
+
+Wenn du deinen Kommentar löschen willst, kopiere bitte diesen Link in deinen Browser:
+{{ deletion_url }}
+
+Wenn du glaubst, dass dies ein Fehler war oder jemand deine Email Adresse ohnen deinen Wissen verwendet hat,
+kontaktiere bitte den Administrator von {{ blogurl }}.
+
+--------------------------------------------------------------------------------------------------------
+Powered by Labertasche, lizensiert via MIT license: https://labertasche.tuxstash.de
+
diff --git a/templates/comment_confirmation.html b/templates/mail/comment_confirmation_en-US.html similarity index 93% rename from templates/comment_confirmation.html rename to templates/mail/comment_confirmation_en-US.html index aac523e..40e38b1 100644 --- a/templates/comment_confirmation.html +++ b/templates/mail/comment_confirmation_en-US.html @@ -17,13 +17,13 @@

Hey there,

- You are receiving this mail, because you have recently made a comment on {{ blogurl }}. + You are receiving this Mail, because you have recently made a comment on {{ blogurl }}.

If you wish to publish your comment, please click this link.
If you wish to delete your comment, please click this link.

- If this was in error or if someone used your mail address without your knowledge, please contact the site + If this was in error or if someone used your Mail address without your knowledge, please contact the site adminitrator at {{ blogurl }}.

diff --git a/templates/mail/comment_confirmation_en-US_txt.html b/templates/mail/comment_confirmation_en-US_txt.html new file mode 100644 index 0000000..52be8cc --- /dev/null +++ b/templates/mail/comment_confirmation_en-US_txt.html @@ -0,0 +1,16 @@ +
+Hey there,
+You are receiving this Mail, because you have recently made a comment on {{ blogurl }}.
+
+If you wish to publish your comment, please copy this into your browser:
+{{ confirmation_url }}
+
+If you wish to delete your comment, please copy this into your browser:
+{{ deletion_url }}
+
+If this was in error or if someone used your Mail address without your knowledge, please contact the site
+adminitrator at {{ blogurl }}.
+
+--------------------------------------------------------------------------------------------------------
+Powered by Labertasche, licensed via MIT license: https://labertasche.tuxstash.de
+