diff --git a/app/admin_model.py b/app/admin_model.py index 517f07b6..7b53cd42 100644 --- a/app/admin_model.py +++ b/app/admin_model.py @@ -736,7 +736,8 @@ class InvalidMailboxDomainAdmin(SLModelView): class EmailSearchResult: no_match: bool = True alias: Optional[Alias] = None - mailbox: Optional[Mailbox] = None + mailbox: list[Mailbox] = [] + mailbox_count: int = 0 deleted_alias: Optional[DeletedAlias] = None deleted_custom_alias: Optional[DomainDeletedAlias] = None user: Optional[User] = None @@ -752,9 +753,12 @@ class EmailSearchResult: if user: output.user = user output.no_match = False - mailbox = Mailbox.get_by(email=email) - if mailbox: - output.mailbox = mailbox + mailboxes = ( + Mailbox.filter_by(email=email).order_by(Mailbox.id.desc()).limit(10).all() + ) + if mailboxes: + output.mailbox = mailboxes + output.mailbox_count = Mailbox.filter_by(email=email).count() output.no_match = False deleted_alias = DeletedAlias.get_by(email=email) if deleted_alias: @@ -779,11 +783,13 @@ class EmailSearchHelpers: @staticmethod def mailbox_count(user: User) -> int: - return Mailbox.filter_by(user_id=user.id).order_by(Mailbox.id.asc()).count() + return Mailbox.filter_by(user_id=user.id).order_by(Mailbox.id.desc()).count() @staticmethod def alias_list(user: User) -> list[Alias]: - return Alias.filter_by(user_id=user.id).order_by(Alias.id.asc()).limit(10).all() + return ( + Alias.filter_by(user_id=user.id).order_by(Alias.id.desc()).limit(10).all() + ) @staticmethod def alias_count(user: User) -> int: @@ -806,9 +812,8 @@ class EmailSearchAdmin(BaseView): @expose("/", methods=["GET", "POST"]) def index(self): search = EmailSearchResult() - email = "" - if request.form and request.form["email"]: - email = request.form["email"] + email = request.args.get("email") + if email is not None and len(email) > 0: email = email.strip() search = EmailSearchResult.from_email(email) diff --git a/templates/admin/email_search.html b/templates/admin/email_search.html index f0eddf62..49eef26d 100644 --- a/templates/admin/email_search.html +++ b/templates/admin/email_search.html @@ -19,7 +19,7 @@ {{ user.id }} - {{ user.email }} + {{ user.email }} {% if user.disabled %} Disabled @@ -32,7 +32,7 @@ {{ user.updated_at }} {% if pu %} - {{ pu.partner_email }} + {{ pu.partner_email }} {% else %} No {% endif %} @@ -43,7 +43,7 @@ {% macro list_mailboxes(mbox_count, mboxes) %}

{{ mbox_count }} Mailboxes found. - {% if mbox_count>10 %}Showing only the first 10.{% endif %} + {% if mbox_count>10 %}Showing only the last 10.{% endif %}

@@ -59,7 +59,7 @@ - +
{{ mailbox.id }}{{ mailbox.email }}{{mailbox.email}} {{ "Yes" if mailbox.verified else "No" }} {{ mailbox.created_at }} @@ -72,7 +72,7 @@ {% macro list_alias(alias_count, aliases) %}

{{ alias_count }} Aliases found. - {% if alias_count>10 %}Showing only the first 10.{% endif %} + {% if alias_count>10 %}Showing only the last 10.{% endif %}

@@ -95,7 +95,7 @@ {% for alias in aliases %} - + @@ -156,7 +156,7 @@ {% block body %}
-
+
Submit
- {% if no_match %} + {% if data.no_match and email %} @@ -190,14 +190,19 @@ {{ list_alias(helper.alias_count(data.user) ,helper.alias_list(data.user)) }}
{% endif %} - {% if data.mailbox %} + {% if data.mailbox_count > 10 %} +

Found more than 10 mailboxes for {{ email }}. Showing the last 10

+ {% elif data.mailbox_count > 0 %} +

Found {{ data.mailbox_count }} mailbox(es) for {{ email }}

+ {% endif %} + {% for mailbox in data.mailbox %}
-

Found Mailbox {{ data.mailbox.email }}

- {{ list_mailboxes(1, [data.mailbox]) }} - {{ show_user(data.mailbox.user) }} +

Found Mailbox {{ mailbox.email }}

+ {{ list_mailboxes(1, [mailbox]) }} + {{ show_user(mailbox.user) }}
- {% endif %} + {% endfor %} {% if data.deleted_alias %}
{{ alias.id }}{{ alias.email }}{{alias.email}} {{ "Yes" if alias.verified else "No" }} {{ alias.created_at }}