diff --git a/app/dashboard/templates/dashboard/domain_detail/info.html b/app/dashboard/templates/dashboard/domain_detail/info.html index d0852635..d97f29ac 100644 --- a/app/dashboard/templates/dashboard/domain_detail/info.html +++ b/app/dashboard/templates/dashboard/domain_detail/info.html @@ -12,23 +12,13 @@
Created {{ custom_domain.created_at | dt }}. {{ nb_alias }} aliases

-

Catch All

-
- Create aliases on the fly. +

Auto create/on the fly alias

- Simply use anything@{{ custom_domain.domain }} - next time you need an alias: it'll be automatically - created the first time it receives an email.
- The new alias will belong to - {% for mailbox in custom_domain.mailboxes %} - {{ mailbox.email }} - {% if not loop.last %},{% endif %} - {% endfor %} -
+
+
+ Simply use anything@{{ custom_domain.domain }} + next time you need an alias: it'll be automatically + created the first time it receives an email. + To have more fine-grained control, you can also use the + regular expression . +
+ +
+ Advanced
+ You can also set a regular expression (regex): if an alias matches the expression, it'll be automatically created. +
+ Please note that only the local part of the alias (i.e. @{{ custom_domain.domain }} is ignored) during the + regex + test. + +
+ +
+ +
+ + {% if custom_domain.auto_create_regex %} + + {% endif %} +
+ + For example, if you want aliases that starts with prefix. to be automatically created, you can set the + regex to prefix\..* +
+ + If you want aliases that ends with .suffix to be automatically created, you can use the regex + .*\.suffix +
+ + To test out regex, we recommend using regex tester tool like https://regex101.com↗ +
+ +
+ The new alias will belong to + {% for mailbox in custom_domain.mailboxes %} + {{ mailbox.email }} + {% if not loop.last %},{% endif %} + {% endfor %} +
-
+
Auto-created aliases are automatically owned by these mailboxes
{% set domain_mailboxes=custom_domain.mailboxes %}
diff --git a/app/dashboard/views/domain_detail.py b/app/dashboard/views/domain_detail.py index dcfeb02e..ca4b4957 100644 --- a/app/dashboard/views/domain_detail.py +++ b/app/dashboard/views/domain_detail.py @@ -158,7 +158,7 @@ def domain_detail_dns(custom_domain_id): @dashboard_bp.route("/domains//info", methods=["GET", "POST"]) @login_required def domain_detail(custom_domain_id): - custom_domain = CustomDomain.get(custom_domain_id) + custom_domain: CustomDomain = CustomDomain.get(custom_domain_id) mailboxes = current_user.mailboxes() if not custom_domain or custom_domain.user_id != current_user.id: @@ -261,6 +261,26 @@ def domain_detail(custom_domain_id): return redirect( url_for("dashboard.domain_detail", custom_domain_id=custom_domain.id) ) + elif request.form.get("form-name") == "set-auto_create_regex": + if request.form.get("action") == "save": + auto_create_regex = request.form.get("auto_create_regex") + if auto_create_regex: + custom_domain.auto_create_regex = auto_create_regex + db.session.commit() + flash("The auto create regex has been updated", "success") + else: + flash("The auto create regex cannot be empty", "error") + else: + custom_domain.auto_create_regex = None + db.session.commit() + flash( + f"The auto create regex has been has been removed", + "info", + ) + return redirect( + url_for("dashboard.domain_detail", custom_domain_id=custom_domain.id) + ) + elif request.form.get("form-name") == "delete": name = custom_domain.domain LOG.d("Schedule deleting %s", custom_domain) diff --git a/app/models.py b/app/models.py index 49517a56..da9b5596 100644 --- a/app/models.py +++ b/app/models.py @@ -1848,6 +1848,10 @@ class CustomDomain(db.Model, ModelMixin): user = db.relationship(User, foreign_keys=[user_id]) + @property + def auto_create_alias_enabled(self) -> bool: + return self.catch_all or self.auto_create_regex is not None + @property def mailboxes(self): if self._mailboxes: diff --git a/static/style.css b/static/style.css index 18ba81da..dd196eac 100644 --- a/static/style.css +++ b/static/style.css @@ -169,4 +169,8 @@ textarea.parsley-error { .domain_detail_content { font-size: 15px; +} + +.domain_detail_content .parsley-errors-list { + max-width: 20em; } \ No newline at end of file