diff --git a/app/app/dashboard/views/mailbox_detail.py b/app/app/dashboard/views/mailbox_detail.py index a2e8558..06527b4 100644 --- a/app/app/dashboard/views/mailbox_detail.py +++ b/app/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/app/app/errors.py b/app/app/errors.py index b951eb1..113b248 100644 --- a/app/app/errors.py +++ b/app/app/errors.py @@ -121,3 +121,10 @@ class AccountAlreadyLinkedToAnotherUserException(LinkException): class AccountIsUsingAliasAsEmail(LinkException): def __init__(self): super().__init__("Your account has an alias as it's email address") + + +class ProtonAccountNotVerified(LinkException): + def __init__(self): + super().__init__( + "The Proton account you are trying to use has not been verified" + ) diff --git a/app/app/proton/proton_client.py b/app/app/proton/proton_client.py index 9f4beac..f06325b 100644 --- a/app/app/proton/proton_client.py +++ b/app/app/proton/proton_client.py @@ -7,11 +7,12 @@ from typing import Optional from app.account_linking import SLPlan, SLPlanType from app.config import PROTON_EXTRA_HEADER_NAME, PROTON_EXTRA_HEADER_VALUE +from app.errors import ProtonAccountNotVerified from app.log import LOG _APP_VERSION = "OauthClient_1.0.0" -PROTON_ERROR_CODE_NOT_EXISTS = 2501 +PROTON_ERROR_CODE_HV_NEEDED = 9001 PLAN_FREE = 1 PLAN_PREMIUM = 2 @@ -57,6 +58,15 @@ def convert_access_token(access_token_response: str) -> AccessCredentials: ) +def handle_response_not_ok(status: int, body: dict, text: str) -> Exception: + if status == HTTPStatus.UNPROCESSABLE_ENTITY: + res_code = body.get("Code") + if res_code == PROTON_ERROR_CODE_HV_NEEDED: + return ProtonAccountNotVerified() + + return Exception(f"Unexpected status code. Wanted 200 and got {status}: " + text) + + class ProtonClient(ABC): @abstractmethod def get_user(self) -> Optional[UserInformation]: @@ -124,11 +134,11 @@ class HttpProtonClient(ProtonClient): @staticmethod def __validate_response(res: Response) -> dict: status = res.status_code - if status != HTTPStatus.OK: - raise Exception( - f"Unexpected status code. Wanted 200 and got {status}: " + res.text - ) as_json = res.json() + if status != HTTPStatus.OK: + raise HttpProtonClient.__handle_response_not_ok( + status=status, body=as_json, text=res.text + ) res_code = as_json.get("Code") if not res_code or res_code != 1000: raise Exception( diff --git a/app/email_handler.py b/app/email_handler.py index 7db73bc..4ccba49 100644 --- a/app/email_handler.py +++ b/app/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/app/templates/dashboard/alias_contact_manager.html b/app/templates/dashboard/alias_contact_manager.html index a9b355d..2a2bc1d 100644 --- a/app/templates/dashboard/alias_contact_manager.html +++ b/app/templates/dashboard/alias_contact_manager.html @@ -133,6 +133,7 @@
- In the future, we are going to support Monero as well. In the meantime, please send us an email at support@simplelogin.zendesk.com if you want to use this cryptocurrency. + In the future, we are going to support Monero as well. In the meantime, please send us an email at support@simplelogin.zendesk.com if you want to use this cryptocurrency.
- Please send us an email at support@simplelogin.zendesk.com for more info. + Please send us an email at support@simplelogin.zendesk.com for more info.
We used to offer free premium accounts for students but this program ended at June 17 2021. Please note this doesn't affect existing accounts who have already benefited from the program or requests sent before this date. @@ -708,7 +692,7 @@ data-parent="#pricing-faq">
- No we don't have a family plan but offer 30% reduction for additional subscriptions. Please contact us at support@simplelogin.zendesk.com for more information. + No we don't have a family plan but offer 30% reduction for additional subscriptions. Please contact us at support@simplelogin.zendesk.com for more information.
You are about to block the alias - {{ alias }} + {{ alias }}
After this, you will stop receiving all emails sent to this alias, please confirm.