{% extends "layout.html" %}

{% from "macros/form_inputs.html" import input_csrf_token with context %}
{% from "macros/general.html" import show_pages with context %}

{% from "macros/amavisd.html" import
        display_search_modal,
        display_idtabs_of_maillog,
        display_icon_of_account_profile,
        display_amavisd_quarantined_mails
        with context
        %}

{% from "macros/msg_handlers.html" import amavisd_msg_handler with context %}

{% block title %}{{ _('Quarantined Mails') }}{% endblock %}
{% block navlinks_activities %}class="active"{% endblock %}

{% block main %}
{# Show system message #}
{{ amavisd_msg_handler(msg) }}

    <div class="content-box">
        <div class="box-body">
            <div class="box-header clear">
                <ul class="tabs clear">
                    {% if account_type is sameas none %}
                        <li><a href="{{ctx.homepath}}/activities/admins">{{ _('Admin Log') }}</a></li>
                    {% endif %}

                    {{ display_idtabs_of_maillog(log_type='quarantined', account_type=account_type, account=account) }}
                </ul>

                <h2>
                    {% if account_type == 'domain' %}
                        {{ _('Quarantined Mails of Domain: %s') |format(account) }}
                        {% set pages_baseurl = ctx.homepath + '/activities/quarantined/domain/' + account %}
                    {% elif account_type == 'user' %}
                        {{ _('Quarantined Mails of User: %s') |format(account) }}
                        {% set pages_baseurl = ctx.homepath + '/activities/quarantined/user/' + account %}
                    {% else %}
                        {{ _('Quarantined Mails') }}
                        {% set pages_baseurl = ctx.homepath + '/activities/quarantined' %}
                    {% endif %}

                    {% if quarantined_type %}
                        {% set pages_baseurl = pages_baseurl + '/' + quarantined_type %}
                    {% endif %}

                    {% if total is defined and records|length > 0 %}
                        ({{ (cur_page-1) * page_size_limit + 1 }}-{{ (cur_page-1) * page_size_limit + records |length}}/{{ total }})
                    {% endif %}

                    <a href="#about-quarantining" class="label modal-link"><i class="fa fa-info-circle fa-lg"></i></a>
                    <a href="#search-inout-maillogs" class="label modal-link"><i class="fa fa-search-plus fa-lg" title="{{ _('Search') }}"></i></a>

                    {{ display_icon_of_account_profile(account_type=account_type, account=account) }}
                </h2>

                <div id="about-quarantining" class="modal-window modal-600">
                    <h2>{{ _('About quarantined mails') }}</h2>
                    <div class="rule3"></div>

                    <ul class="standard clean-padding bt-space10">
                        <li class="bt-space5">{{ _("Quarantined mails are not delivered to users' mailboxes yet, you can either delete them or release them. Mails will be delivered to user mailboxes after released.") }}</li>

                        {% if removeQuarantinedInDays > 0 %}
                            <li class="bt-space5">{{ _('Quarantined mails older than %d days will be deleted from database permanently.') |format(removeQuarantinedInDays) }}</li>
                        {% endif %}
                    </ul>
                    <div class="bt-space0">&nbsp;</div>
                </div>

                {{ display_search_modal() }}
            </div>{# .box-header #}

                <form name="quarantined" method="post" action="{{ pages_baseurl }}/page/{{ cur_page }}">

                    {{ input_csrf_token() }}

                    {{ display_amavisd_quarantined_mails(records,
                                                         account=account,
                                                         account_type=account_type,
                                                         sort_by_score=sort_by_score) }}

                    <div class="tab-footer clear f1">
                        <div class="fl">
                            <select name="action" class="fl-space">
                                <option>{{ _('Choose Action') }}</option>
                                <option disabled>----</option>
                                <option value="release">{{ _('Release selected') }}</option>
                                {% if session.get('amavisd_enable_policy_lookup') %}
                                    <option value="release_whitelist_sender">{{ _('Release selected, and whitelist sender(s)') }}</option>
                                    <option value="release_whitelist_sender_domain">{{ _('Release selected, and whitelist entire sender domain(s)') }}</option>
                                    <option value="release_whitelist_sender_subdomain">{{ _('Release selected, and whitelist sender domain(s) and all sub-domains') }}</option>
                                {% endif %}

                                <option disabled>----</option>
                                <option value="delete">{{ _('Delete selected') }}</option>
                                {% if session.get('amavisd_enable_policy_lookup') %}
                                    <option value="delete_blacklist_sender">{{ _('Delete selected, and blacklist sender(s)') }}</option>
                                    <option value="delete_blacklist_sender_domain">{{ _('Delete selected, and blacklist entire sender domain(s)') }}</option>
                                    <option value="delete_blacklist_sender_subdomain">{{ _('Delete selected, and blacklist sender domain(s) and all sub-domains') }}</option>
                                {% endif %}

                                {% if session.get('is_global_admin') %}
                                    {% if account_type is sameas none %}
                                        <option disabled>----</option>
                                        <option value="deleteAll">{{ _('Delete all in database') }}</option>
                                    {% endif %}
                                {% endif %}
                            </select>
                            <input type="submit" value="{{ _('Apply') }}" class="button fl-space" />
                        </div>

                        {% if sort_by_score %}
                            {{ show_pages(baseurl=pages_baseurl,
                                          total=total,
                                          cur_page=cur_page,
                                          url_suffix='?sort_by_score') }}
                        {% else %}
                            {{ show_pages(baseurl=pages_baseurl, total=total, cur_page=cur_page) }}
                        {% endif %}

                    </div>
                </form>

        </div>{# -- End .box-body -- #}
    </div> {# -- End .content-box -- #}

{% endblock main %}
