{% extends 'base.html' %}

{% block title %}
{{ address_name }} - Fake Email Server
{% endblock %}

{% block content %}


    {% if email_list %}
        <div id="nav">
        {% for message in email_list %}
            <a href='#{{ loop.index }}'>{{ loop.index }}</a>
        {% endfor %}
        </div>

        <table>
        <thead>
            <th>Msg ID</th>
            <th>Format</th>
            <th>Headers</th>
            {% for type in content_types %}
            <th>{{ type }}</th>
            {% endfor %}
        </thead>
            {% for msg in email_list %}
                <tr>
                    <td><a name='{{ loop.index }}'>{{ loop.index }}</a></td>
                    <td>{{ msg['content_type'] }}</td>
                    <td class="headers">
                        {% for header in msg['headers'] %}
                        {{header[0]}} {{header[1]}} <br />
                        {% endfor %}
                    </td>
                    {% for type in content_types %}
                    {% if type in msg and type != 'html' %}
                    <td class="payload">
                      {% if type.startswith('attachment') %}
                      <a href="file/{{msg[type]}}" target="_blank">
                        {{msg[type]}}
                      </a>
                      {% else %}
                      <pre>
                        {{msg[type]}}
                      </pre>
                      {% endif %}
                    </td>
                    {% elif type == 'html' %}
                    <td class="payload">
                     <iframe srcdoc='{{ msg['html']|e }}'>
                     </iframe>
                    </td>
                    {% endif %}

                    {% endfor %}
                </tr>
            {% endfor %}
        </table>
    {% else %}
        <pre>No emails recorded for this address</pre>
    {% endif %}


{% endblock %}
