Explorar o código

Support + and # as directory separator

Son NK %!s(int64=5) %!d(string=hai) anos
pai
achega
6f414ba405

+ 10 - 5
app/dashboard/templates/dashboard/directory.html

@@ -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>
 

+ 5 - 0
app/dashboard/views/directory.py

@@ -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

+ 10 - 3
email_handler.py

@@ -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():