diff options
author | Jannis M. Hoffmann <jannis@fehcom.de> | 2024-04-10 14:29:38 +0200 |
---|---|---|
committer | Jannis M. Hoffmann <jannis@fehcom.de> | 2024-04-10 14:29:38 +0200 |
commit | 54cb677a1606ae705a761c74a215b2b0161f0553 (patch) | |
tree | 87491cbf68db755f29c822171fa1701f5b97e488 | |
parent | f618ebc8a181256458099ed74d978a06dd1a75b0 (diff) |
bug fixes for sending mail and increased page size
-rw-r--r-- | src/jwebmail/__init__.py | 2 | ||||
-rw-r--r-- | src/jwebmail/templates/displayheaders.html | 14 | ||||
-rw-r--r-- | src/jwebmail/translations/de/LC_MESSAGES/messages.po | 52 | ||||
-rw-r--r-- | src/jwebmail/translations/en/LC_MESSAGES/messages.po | 42 | ||||
-rw-r--r-- | src/jwebmail/webmail.py | 53 |
5 files changed, 102 insertions, 61 deletions
diff --git a/src/jwebmail/__init__.py b/src/jwebmail/__init__.py index 88309ff..03f62ef 100644 --- a/src/jwebmail/__init__.py +++ b/src/jwebmail/__init__.py @@ -35,7 +35,7 @@ else: toml_read_file = dict(load=toml_load, text=True) -__version__ = "2.2.1.dev2" +__version__ = "2.2.1.dev3" csrf = CSRFProtect() diff --git a/src/jwebmail/templates/displayheaders.html b/src/jwebmail/templates/displayheaders.html index ce9ea6e..7125a12 100644 --- a/src/jwebmail/templates/displayheaders.html +++ b/src/jwebmail/templates/displayheaders.html @@ -10,11 +10,15 @@ {% include '_folders.html' %} - {% if loginmessage is defined %} - <p id=loginmessage> - {{ loginmessage }} - </p> - {% endif %} + {% with messages = get_flashed_messages() %} + {% if messages %} + {% for message in messages %} + <p class="notification is-info"> + {{ message }} + </p> + {% endfor %} + {% endif %} + {% endwith %} {% include '_top_nav.html' %} diff --git a/src/jwebmail/translations/de/LC_MESSAGES/messages.po b/src/jwebmail/translations/de/LC_MESSAGES/messages.po index 48b1dca..7bc8ef6 100644 --- a/src/jwebmail/translations/de/LC_MESSAGES/messages.po +++ b/src/jwebmail/translations/de/LC_MESSAGES/messages.po @@ -5,70 +5,74 @@ # msgid "" msgstr "" -"Project-Id-Version: PROJECT VERSION\n" -"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2023-12-04 22:59+0100\n" +"Project-Id-Version: 2.2.1\n" +"Report-Msgid-Bugs-To: jannis@fehcom.de\n" +"POT-Creation-Date: 2024-04-10 14:23+0200\n" "PO-Revision-Date: 2023-11-23 12:18+0100\n" -"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" +"Last-Translator: Jannis Hoffmann <jannis@fehcom.de>\n" "Language: de\n" "Language-Team: de <LL@li.org>\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" -"Generated-By: Babel 2.13.1\n" +"Generated-By: Babel 2.14.0\n" -#: src/jwebmail/render_mail.py:67 +#: src/jwebmail/render_mail.py:70 msgid "Attachment {filename} of type {filetype}" msgstr "Anhang {filename} des types {filetype}" -#: src/jwebmail/render_mail.py:117 +#: src/jwebmail/render_mail.py:121 msgid "From" msgstr "Von" -#: src/jwebmail/render_mail.py:118 +#: src/jwebmail/render_mail.py:122 msgid "To" msgstr "Für" -#: src/jwebmail/render_mail.py:119 +#: src/jwebmail/render_mail.py:123 msgid "CC" msgstr "" -#: src/jwebmail/render_mail.py:120 +#: src/jwebmail/render_mail.py:124 msgid "BCC" msgstr "" -#: src/jwebmail/render_mail.py:147 +#: src/jwebmail/render_mail.py:151 msgid "Unsupported MIME type of {mime_type}." msgstr "Nicht unterstützter MIME-Typ {mime_type}." -#: src/jwebmail/webmail.py:27 +#: src/jwebmail/webmail.py:36 msgid "Username" msgstr "Nutzername" -#: src/jwebmail/webmail.py:29 +#: src/jwebmail/webmail.py:38 msgid "Password" msgstr "Passwort" -#: src/jwebmail/webmail.py:64 +#: src/jwebmail/webmail.py:73 msgid "login failed!" msgstr "Login fehlgeschlagen!" -#: src/jwebmail/webmail.py:111 +#: src/jwebmail/webmail.py:120 msgid "displaying <b>{start} - {end}</b> of <b>{total}</b> {record_name}" msgstr "zeige <b>{start} - {end}</b> von <b>{total}</b> {record_name} an" -#: src/jwebmail/webmail.py:164 +#: src/jwebmail/webmail.py:204 msgid "succ_move" msgstr "erfolgreich Verschoben" -#: src/jwebmail/webmail.py:211 -msgid "error_send" -msgstr "Fehler beim senden" +#: src/jwebmail/webmail.py:235 +msgid "invalid mimetype" +msgstr "unbekannter Mime Typ" -#: src/jwebmail/webmail.py:213 +#: src/jwebmail/webmail.py:243 src/jwebmail/webmail.py:263 msgid "succ_send" -msgstr "erfolgreich Verschoben" +msgstr "Erfolgreich gesendet" + +#: src/jwebmail/webmail.py:259 +msgid "error_send" +msgstr "Fehler beim senden" #: src/jwebmail/templates/_bot_nav.html:11 msgid "Move to" @@ -146,7 +150,7 @@ msgstr "Sender" msgid "Login" msgstr "Anmelden" -#: src/jwebmail/templates/displayheaders.html:25 +#: src/jwebmail/templates/displayheaders.html:29 msgid "This folder is empty!" msgstr "Dieses Verzeichnis ist leer!" @@ -163,7 +167,7 @@ msgid "start page" msgstr "Startseite" #: src/jwebmail/templates/readmail.html:12 -#: src/jwebmail/templates/writemail.html:78 +#: src/jwebmail/templates/writemail.html:80 msgid "back" msgstr "zurück" @@ -171,7 +175,7 @@ msgstr "zurück" msgid "attach file" msgstr "Datei anhängen" -#: src/jwebmail/templates/writemail.html:71 +#: src/jwebmail/templates/writemail.html:73 msgid "Send" msgstr "Senden" diff --git a/src/jwebmail/translations/en/LC_MESSAGES/messages.po b/src/jwebmail/translations/en/LC_MESSAGES/messages.po index 5b1e43a..c1ade47 100644 --- a/src/jwebmail/translations/en/LC_MESSAGES/messages.po +++ b/src/jwebmail/translations/en/LC_MESSAGES/messages.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: EMAIL@ADDRESS\n" -"POT-Creation-Date: 2023-12-06 23:44+0100\n" +"POT-Creation-Date: 2024-04-10 14:23+0200\n" "PO-Revision-Date: 2023-12-07 19:04+0100\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Language: en\n" @@ -16,60 +16,64 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" -"Generated-By: Babel 2.13.1\n" +"Generated-By: Babel 2.14.0\n" -#: src/jwebmail/render_mail.py:67 +#: src/jwebmail/render_mail.py:70 msgid "Attachment {filename} of type {filetype}" msgstr "" -#: src/jwebmail/render_mail.py:117 +#: src/jwebmail/render_mail.py:121 msgid "From" msgstr "" -#: src/jwebmail/render_mail.py:118 +#: src/jwebmail/render_mail.py:122 msgid "To" msgstr "" -#: src/jwebmail/render_mail.py:119 +#: src/jwebmail/render_mail.py:123 msgid "CC" msgstr "" -#: src/jwebmail/render_mail.py:120 +#: src/jwebmail/render_mail.py:124 msgid "BCC" msgstr "" -#: src/jwebmail/render_mail.py:147 +#: src/jwebmail/render_mail.py:151 msgid "Unsupported MIME type of {mime_type}." msgstr "" -#: src/jwebmail/webmail.py:25 +#: src/jwebmail/webmail.py:36 msgid "Username" msgstr "" -#: src/jwebmail/webmail.py:27 +#: src/jwebmail/webmail.py:38 msgid "Password" msgstr "" -#: src/jwebmail/webmail.py:62 +#: src/jwebmail/webmail.py:73 msgid "login failed!" msgstr "" -#: src/jwebmail/webmail.py:109 +#: src/jwebmail/webmail.py:120 msgid "displaying <b>{start} - {end}</b> of <b>{total}</b> {record_name}" msgstr "" -#: src/jwebmail/webmail.py:162 +#: src/jwebmail/webmail.py:204 msgid "succ_move" msgstr "" -#: src/jwebmail/webmail.py:209 -msgid "error_send" +#: src/jwebmail/webmail.py:235 +msgid "invalid mimetype" msgstr "" -#: src/jwebmail/webmail.py:211 +#: src/jwebmail/webmail.py:243 src/jwebmail/webmail.py:263 msgid "succ_send" msgstr "" +#: src/jwebmail/webmail.py:259 +msgid "error_send" +msgstr "" + #: src/jwebmail/templates/_bot_nav.html:11 msgid "Move to" msgstr "" @@ -146,7 +150,7 @@ msgstr "" msgid "Login" msgstr "" -#: src/jwebmail/templates/displayheaders.html:25 +#: src/jwebmail/templates/displayheaders.html:29 msgid "This folder is empty!" msgstr "" @@ -163,7 +167,7 @@ msgid "start page" msgstr "" #: src/jwebmail/templates/readmail.html:12 -#: src/jwebmail/templates/writemail.html:78 +#: src/jwebmail/templates/writemail.html:80 msgid "back" msgstr "" @@ -171,7 +175,7 @@ msgstr "" msgid "attach file" msgstr "" -#: src/jwebmail/templates/writemail.html:71 +#: src/jwebmail/templates/writemail.html:73 msgid "Send" msgstr "" diff --git a/src/jwebmail/webmail.py b/src/jwebmail/webmail.py index 7e63307..518710c 100644 --- a/src/jwebmail/webmail.py +++ b/src/jwebmail/webmail.py @@ -1,18 +1,21 @@ -from urllib.parse import urlparse +import mimetypes +from email.message import EmailMessage +from io import BytesIO from smtplib import ( SMTP_SSL, - SMTPHeloError, SMTPAuthenticationError, - SMTPNotSupportedError, SMTPException, + SMTPHeloError, + SMTPNotSupportedError, ) -from email.message import EmailMessage +from urllib.parse import urlparse from flask import abort, current_app, flash, redirect, render_template, request, url_for from flask_babel import gettext, lazy_gettext from flask_login import current_user, login_user, logout_user from flask_paginate import Pagination, get_page_parameter, get_per_page_parameter from flask_wtf import FlaskForm +from werkzeug.utils import secure_filename from wtforms import ( EmailField, MultipleFileField, @@ -106,7 +109,7 @@ def displayheaders(folder=""): count = get_read_mails_logged_in().count(folder) page = request.args.get(get_page_parameter(), type=int, default=1) - per_page = request.args.get(get_per_page_parameter(), type=int, default=10) + per_page = request.args.get(get_per_page_parameter(), type=int, default=25) pgn = Pagination( page=page, @@ -208,15 +211,38 @@ def sendmail(): if not form.validate(): abort(400) - # mail = { "attach": form.attachments.data } mail = EmailMessage() - mail["to"] = form.answer_to.data - mail["subject"] = form.subject.data - mail["cc"] = form.cc.data - mail["bcc"] = form.bcc.data - mail["reply"] = form.answer_to.data + mail["To"] = form.send_to.data + mail["Subject"] = form.subject.data + + if form.cc.data: + mail["Cc"] = form.cc.data + if form.bcc.data: + mail["Bcc"] = form.bcc.data + if form.answer_to.data: + mail["Reply"] = form.answer_to.data + mail.set_content(form.content.data) + for f in form.attachments.data: + if not f.filename: + continue + bio = BytesIO() + f.save(bio) + fname = secure_filename(f.filename) + mt, _ce = mimetypes.guess_type(fname) + if mt is None: + abort(400, gettext("invalid mimetype")) + maintype, subtype = mt.split("/") + mail.add_attachment( + bio.getvalue(), maintype, subtype, cte="base64", filename=fname + ) + + if current_app.config["JWEBMAIL"]["WRITE_MAILS"].get("DEBUG"): + print(mail.as_string()) + flash(gettext("succ_send")) + return redirect(url_for("displayheaders"), 303) + try: with SMTP_SSL( current_app.config["JWEBMAIL"]["WRITE_MAILS"]["SMTPS_SERVER"] @@ -229,7 +255,10 @@ def sendmail(): SMTPNotSupportedError, SMTPException, ): - return render_template("writemail.html", form=form, warning=gettext("error_send")), 400 + return ( + render_template("writemail.html", form=form, warning=gettext("error_send")), + 400, + ) flash(gettext("succ_send")) return redirect(url_for("displayheaders"), 303) |