Support + and # as directory separator

This commit is contained in:
Son NK 2020-01-19 22:06:36 +01:00
parent 70e16bb415
commit 6f414ba405
3 changed files with 25 additions and 8 deletions

View File

@ -11,15 +11,20 @@
<h1 class="h3"> Directories </h1>
{% if not current_user.is_premium() %}
<div class="alert alert-danger" role="alert">
This feature is only available in premium plan.
</div>
<div class="alert alert-danger" role="alert">
This feature is only available in premium plan.
</div>
{% endif %}
<div class="alert alert-primary" role="alert">
Directory allows you to create aliases <b>on the fly</b>. <br>
Simply use <em>directory/<b>anything</b>@{{ EMAIL_DOMAIN }}</em>
Directory allows you to create aliases <b>on the fly</b>. Simply use <br>
<div class="pl-3 py-2 bg-white">
<em>directory/<b>anything</b>@{{ EMAIL_DOMAIN }}</em> or <br>
<em>directory+<b>anything</b>@{{ EMAIL_DOMAIN }}</em> or <br>
<em>directory#<b>anything</b>@{{ EMAIL_DOMAIN }}</em> <br>
</div>
next time you need an email address. <br>
<em><b>anything</b></em> could really be anything, it's up to you to invent the most creative alias 😉. <br>
The alias will be created the first time it receives an email.
</div>

View File

@ -51,6 +51,11 @@ def directory():
if Directory.get_by(name=new_dir_name):
flash(f"{new_dir_name} already added", "warning")
elif new_dir_name == "reply":
flash(
"directory name cannot be *reply*, please choose another name",
"warning",
)
else:
new_dir = Directory.create(
name=new_dir_name, user_id=current_user.id

View File

@ -121,13 +121,20 @@ class MailHandler:
# check if alias belongs to a directory, ie having directory/anything@EMAIL_DOMAIN format
if alias.endswith(EMAIL_DOMAIN):
if "/" in alias:
directory_name = alias[: alias.find("/")]
if "/" in alias or "+" in alias or "#" in alias:
if "/" in alias:
sep = "/"
elif "+" in alias:
sep = "+"
else:
sep = "#"
directory_name = alias[: alias.find(sep)]
LOG.d("directory_name %s", directory_name)
directory = Directory.get_by(name=directory_name)
# Only premium user can continue using the directory feature
# Only premium user can use the directory feature
if directory:
dir_user = directory.user
if dir_user.is_premium():