Add refused-email view

This commit is contained in:
Son NK 2020-03-14 16:10:09 +01:00
parent 0de13ca4d9
commit c3b85115ca
4 changed files with 89 additions and 0 deletions

View File

@ -17,4 +17,5 @@ from .views import (
mailbox,
deleted_alias,
mailbox_detail,
refused_email,
)

View File

@ -0,0 +1,39 @@
{% extends 'default.html' %}
{% block title %}
Refused Emails
{% endblock %}
{% set active_page = "setting" %}
{% block default_content %}
<div style="max-width: 60em; margin: auto">
<h1 class="h3 mb-5"> Refused Emails </h1>
{% if fels|length == 0 %}
<div class="my-4 p-4 card">
You don't have any refused email.
</div>
{% endif %}
{% for fel in fels %}
{% set refused_email = fel.refused_email %}
{% set forward = fel.forward %}
<div class="card p-4 shadow-sm {% if fel.id == highlight_fel_id %} highlight-row {% endif %}">
From: {{ forward.website_from or forward.website_email }} <br>
To: {{ forward.gen_email.email }} <br>
<div class="small-text">
Sent {{ refused_email.created_at | dt }}
</div>
<a href="{{ refused_email.get_url() }}" class="mt-4">View →</a>
<div class="small-text">This will download a ".eml" file that you can open in your favorite email client</div>
</div>
{% endfor %}
</div>
{% endblock %}

View File

@ -183,6 +183,25 @@
</div>
</div>
<div class="card">
<div class="card-body">
<div class="card-title">Refused Emails
<div class="small-text mt-1 mb-3" style="max-width: 40rem">
When an email sent to your alias is classified as spam or refused by your email provider,
it usually means your alias has been leaked to a spammer. <br>
In this case SimpleLogin will keep a copy of this email (so it isn't lost)
and notify you so you can take a look at its content and take appropriate actions. <br>
The emails are deleted in 7 days.
This is an exceptional case where SimpleLogin stores the email.
</div>
</div>
<a href="{{ url_for('dashboard.refused_email_route') }}" class="btn btn-outline-primary">
See refused emails
</a>
</div>
</div>
<div class="card">
<div class="card-body">
<div class="card-title">Export Data

View File

@ -0,0 +1,30 @@
from flask import render_template, request
from flask_login import login_required
from app.dashboard.base import dashboard_bp
from app.models import ForwardEmailLog
@dashboard_bp.route("/refused_email", methods=["GET", "POST"])
@login_required
def refused_email_route():
# Highlight a refused email
highlight_fel_id = request.args.get("highlight_fel_id")
if highlight_fel_id:
highlight_fel_id = int(highlight_fel_id)
fels: [ForwardEmailLog] = ForwardEmailLog.query.filter(
ForwardEmailLog.refused_email_id != None
).all()
# make sure the highlighted fel is the first fel
highlight_index = None
for ix, fel in enumerate(fels):
if fel.id == highlight_fel_id:
highlight_index = ix
break
if highlight_index:
fels.insert(0, fels.pop(highlight_index))
return render_template("dashboard/refused_email.html", **locals())