diff --git a/.env.example b/.env.example index 6b060098..aaeb00d5 100644 --- a/.env.example +++ b/.env.example @@ -29,6 +29,10 @@ EMAIL_SERVERS_WITH_PRIORITY=[(10, "email.hostname.")] # these emails are ignored when computing stats # IGNORED_EMAILS = ["my_email@domain.com"] +# By default, new aliases must end with ".{random_word}". This is to avoid a person taking all "nice" aliases. +# this option doesn't make sense in self-hosted. Set this variable to disable this option. +# DISABLE_ALIAS_SUFFIX=1 + # the DKIM private key used to compute DKIM-Signature DKIM_PRIVATE_KEY_PATH=local_data/dkim.key diff --git a/README.md b/README.md index 66e46207..4ccba13a 100644 --- a/README.md +++ b/README.md @@ -291,6 +291,7 @@ EMAIL_SERVERS_WITH_PRIORITY=[(10, "app.mydomain.com.")] DKIM_PRIVATE_KEY_PATH=/dkim.key DKIM_PUBLIC_KEY_PATH=/dkim.pub.key DB_URI=postgresql://myuser:mypassword@sl-db:5432/simplelogin +DISABLE_ALIAS_SUFFIX=1 ``` diff --git a/app/config.py b/app/config.py index 3473ce8d..0e9ccb7d 100644 --- a/app/config.py +++ b/app/config.py @@ -58,6 +58,9 @@ if os.environ.get("IGNORED_EMAILS"): else: IGNORED_EMAILS = [] +# disable the alias suffix, i.e. the ".random_word" part +DISABLE_ALIAS_SUFFIX = "DISABLE_ALIAS_SUFFIX" in os.environ + DKIM_PRIVATE_KEY_PATH = get_abs_path(os.environ["DKIM_PRIVATE_KEY_PATH"]) DKIM_PUBLIC_KEY_PATH = get_abs_path(os.environ["DKIM_PUBLIC_KEY_PATH"]) DKIM_SELECTOR = b"dkim" diff --git a/app/dashboard/templates/dashboard/custom_alias.html b/app/dashboard/templates/dashboard/custom_alias.html index e6644892..a3dd7126 100644 --- a/app/dashboard/templates/dashboard/custom_alias.html +++ b/app/dashboard/templates/dashboard/custom_alias.html @@ -35,7 +35,7 @@

- .{{ email_suffix }}@{{ EMAIL_DOMAIN }} + {{ email_suffix }}@{{ EMAIL_DOMAIN }}

diff --git a/app/dashboard/views/custom_alias.py b/app/dashboard/views/custom_alias.py index eecb5354..8ea9cb73 100644 --- a/app/dashboard/views/custom_alias.py +++ b/app/dashboard/views/custom_alias.py @@ -1,7 +1,7 @@ from flask import render_template, redirect, url_for, flash, request, session from flask_login import login_required, current_user -from app.config import EMAIL_DOMAIN, HIGHLIGHT_GEN_EMAIL_ID +from app.config import EMAIL_DOMAIN, HIGHLIGHT_GEN_EMAIL_ID, DISABLE_ALIAS_SUFFIX from app.dashboard.base import dashboard_bp from app.extensions import db from app.log import LOG @@ -27,18 +27,20 @@ def custom_alias(): email_prefix = convert_to_id(email_prefix) email_suffix = request.form.get("email-suffix") - # verify email_suffix - if not word_exist(email_suffix): - flash( - "nice try :). The suffix is there so no one can take all the *nice* aliases though", - "warning", - ) - return redirect(url_for("dashboard.custom_alias")) + # verify email_suffix: do not verify when DISABLE_ALIAS_SUFFIX is set + if not DISABLE_ALIAS_SUFFIX: + # email suffix must be in the format ".{word}" + if email_suffix[0] != "." or not word_exist(email_suffix[1:]): + flash( + "nice try :). The suffix is there so no one can take all the *nice* aliases though", + "warning", + ) + return redirect(url_for("dashboard.custom_alias")) if not email_prefix: error = "alias prefix cannot be empty" else: - full_email = f"{email_prefix}.{email_suffix}@{EMAIL_DOMAIN}" + full_email = f"{email_prefix}{email_suffix}@{EMAIL_DOMAIN}" # check if email already exists if GenEmail.get_by(email=full_email) or DeletedAlias.get_by( email=full_email @@ -95,7 +97,7 @@ def custom_alias(): session[HIGHLIGHT_GEN_EMAIL_ID] = gen_email.id return redirect(url_for("dashboard.index")) - email_suffix = random_word() + email_suffix = "" if DISABLE_ALIAS_SUFFIX else "." + random_word() return render_template( "dashboard/custom_alias.html", error=error,