From 5714403976b949538f360e135bc6769a9a2cb9e3 Mon Sep 17 00:00:00 2001 From: Son Nguyen Kim Date: Thu, 24 Aug 2023 22:47:31 +0200 Subject: [PATCH] Can use generic subject without pgp (#1847) * improve wording for hide my subject option * can use generic subject on a non-pgp mailbox --------- Co-authored-by: Son NK --- app/dashboard/views/mailbox_detail.py | 13 +- email_handler.py | 25 +-- templates/dashboard/mailbox_detail.html | 204 ++++++++++++------------ 3 files changed, 113 insertions(+), 129 deletions(-) diff --git a/app/dashboard/views/mailbox_detail.py b/app/dashboard/views/mailbox_detail.py index a2e85587..06527b49 100644 --- a/app/dashboard/views/mailbox_detail.py +++ b/app/dashboard/views/mailbox_detail.py @@ -191,25 +191,16 @@ def mailbox_detail_route(mailbox_id): ) elif request.form.get("form-name") == "generic-subject": if request.form.get("action") == "save": - if not mailbox.pgp_enabled(): - flash( - "Generic subject can only be used on PGP-enabled mailbox", - "error", - ) - return redirect( - url_for("dashboard.mailbox_detail_route", mailbox_id=mailbox_id) - ) - mailbox.generic_subject = request.form.get("generic-subject") Session.commit() - flash("Generic subject for PGP-encrypted email is enabled", "success") + flash("Generic subject is enabled", "success") return redirect( url_for("dashboard.mailbox_detail_route", mailbox_id=mailbox_id) ) elif request.form.get("action") == "remove": mailbox.generic_subject = None Session.commit() - flash("Generic subject for PGP-encrypted email is disabled", "success") + flash("Generic subject is disabled", "success") return redirect( url_for("dashboard.mailbox_detail_route", mailbox_id=mailbox_id) ) diff --git a/email_handler.py b/email_handler.py index 7db73bc6..4ccba49f 100644 --- a/email_handler.py +++ b/email_handler.py @@ -878,21 +878,22 @@ def forward_email_to_mailbox( headers_to_keep.append(headers.AUTHENTICATION_RESULTS) delete_all_headers_except(msg, headers_to_keep) + if mailbox.generic_subject: + LOG.d("Use a generic subject for %s", mailbox) + orig_subject = msg[headers.SUBJECT] + orig_subject = get_header_unicode(orig_subject) + add_or_replace_header(msg, "Subject", mailbox.generic_subject) + sender = msg[headers.FROM] + sender = get_header_unicode(sender) + msg = add_header( + msg, + f"""Forwarded by SimpleLogin to {alias.email} from "{sender}" with "{orig_subject}" as subject""", + f"""Forwarded by SimpleLogin to {alias.email} from "{sender}" with {orig_subject} as subject""", + ) + # create PGP email if needed if mailbox.pgp_enabled() and user.is_premium() and not alias.disable_pgp: LOG.d("Encrypt message using mailbox %s", mailbox) - if mailbox.generic_subject: - LOG.d("Use a generic subject for %s", mailbox) - orig_subject = msg[headers.SUBJECT] - orig_subject = get_header_unicode(orig_subject) - add_or_replace_header(msg, "Subject", mailbox.generic_subject) - sender = msg[headers.FROM] - sender = get_header_unicode(sender) - msg = add_header( - msg, - f"""Forwarded by SimpleLogin to {alias.email} from "{sender}" with "{orig_subject}" as subject""", - f"""Forwarded by SimpleLogin to {alias.email} from "{sender}" with {orig_subject} as subject""", - ) try: msg = prepare_pgp_message( diff --git a/templates/dashboard/mailbox_detail.html b/templates/dashboard/mailbox_detail.html index 9c6687a7..61a2c059 100644 --- a/templates/dashboard/mailbox_detail.html +++ b/templates/dashboard/mailbox_detail.html @@ -137,123 +137,115 @@ -
-
- {{ csrf_form.csrf_token }} - -
-
- Hide email subject when PGP is enabled -
- When PGP is enabled, you can choose to use a generic subject for the forwarded emails. - The original subject is then added into the email body. -
- As PGP does not encrypt the email subject and the email subject might contain sensitive information, - this option will allow a further protection of your email content. -
-
-
- As the email is encrypted, a subject like "Email for you" - will probably be rejected by your mailbox since it sounds like a spam. -
- Something like "Encrypted Email" would work much better :). -
-
- - -
- - {% if mailbox.generic_subject %} - - - {% endif %} -
-
-
- -
-

Advanced Options

- {% if spf_available %} - -
-
- {{ csrf_form.csrf_token }} - -
-
- Enforce SPF -
- To avoid email-spoofing, SimpleLogin blocks email that - seems to come from your - mailbox - but sent from unknown - IP address. -
- Only turn off this option if you know what you're doing :). -
-
- -
-
-
- {% endif %} -
+
+
+
+ {{ csrf_form.csrf_token }} +
- Authorized addresses -
- Emails sent from these addresses to a reverse-alias are considered as being sent - from {{ mailbox.email }} + Hide email subject +
+ The original subject will be added to the email body and all forwarded emails will have the generic subject. +
+ This option is often used when PGP is enabled. + As PGP does not encrypt the email subject, it allows a further protection of your email content.
- {% if mailbox.authorized_addresses | length == 0 %} +
+ + +
+ + {% if mailbox.generic_subject %} - {% else %} -
    - {% for authorized_address in mailbox.authorized_addresses %} - -
  • - {{ authorized_address.email }} - - {{ csrf_form.csrf_token }} - - - -
  • - - {% endfor %} -
+ {% endif %} -
- {{ csrf_form.csrf_token }} - - - -
+ +
+
+

Advanced Options

+ {% if spf_available %} + +
+
+ {{ csrf_form.csrf_token }} + +
+
+ Enforce SPF +
+ To avoid email-spoofing, SimpleLogin blocks email that + seems to come from your + mailbox + but sent from unknown + IP address. +
+ Only turn off this option if you know what you're doing :). +
+
+ +
+
+
+ {% endif %} +
+
+
+ Authorized addresses +
+ Emails sent from these addresses to a reverse-alias are considered as being sent + from {{ mailbox.email }} +
+
+ {% if mailbox.authorized_addresses | length == 0 %} + + {% else %} +
    + {% for authorized_address in mailbox.authorized_addresses %} + +
  • + {{ authorized_address.email }} +
    + {{ csrf_form.csrf_token }} + + + +
    +
  • + {% endfor %} +
+ {% endif %} +
+ {{ csrf_form.csrf_token }} + + + +
- {% endblock %} - {% block script %} - - + - {% endblock %} + +{% endblock %}