add List-Unsubscribe-Post header. Block alias directly if POST, otherwise ask user confirmation.
This commit is contained in:
parent
cb14277bc7
commit
837e1ffcf6
|
@ -250,7 +250,7 @@
|
||||||
|
|
||||||
$(".trigger-email").on("click", function (e) {
|
$(".trigger-email").on("click", function (e) {
|
||||||
notie.confirm({
|
notie.confirm({
|
||||||
text: "SimpleLogin server will send an email to this alias and it should arrive to your inbox, please confirm",
|
text: "SimpleLogin server will send an email to this alias and it should arrive to your inbox, please confirm",
|
||||||
cancelCallback: () => {
|
cancelCallback: () => {
|
||||||
// nothing to do
|
// nothing to do
|
||||||
},
|
},
|
||||||
|
@ -264,9 +264,9 @@
|
||||||
var message = "";
|
var message = "";
|
||||||
|
|
||||||
if (e.target.checked) {
|
if (e.target.checked) {
|
||||||
message = `After this, you will start receiving email sent to this email address, please confirm`;
|
message = `After this, you will start receiving email sent to this alias, please confirm`;
|
||||||
} else {
|
} else {
|
||||||
message = `After this, you will stop receiving email sent to this email address, please confirm`;
|
message = `After this, you will stop receiving email sent to this alias, please confirm`;
|
||||||
}
|
}
|
||||||
|
|
||||||
notie.confirm({
|
notie.confirm({
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
{% extends 'default.html' %}
|
||||||
|
|
||||||
|
{% set active_page = "dashboard" %}
|
||||||
|
|
||||||
|
{% block title %}
|
||||||
|
Block an alias
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block default_content %}
|
||||||
|
|
||||||
|
<div class="col-md-8 offset-md-2 text-center">
|
||||||
|
<h1 class="h3">
|
||||||
|
Block alias
|
||||||
|
</h1>
|
||||||
|
<p>
|
||||||
|
You are about to block the alias <a href="mailto:{{alias}}">{{alias}}</a>
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
After this, you will stop receiving all emails sent to this alias, please confirm
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<form method="post">
|
||||||
|
<button class="btn btn-warning">Confirm</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
Allow user to "unsubscribe", aka block an email alias
|
Allow user to "unsubscribe", aka block an email alias
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from flask import redirect, url_for, flash
|
from flask import redirect, url_for, flash, request, render_template
|
||||||
from flask_login import login_required, current_user
|
from flask_login import login_required, current_user
|
||||||
|
|
||||||
from app.dashboard.base import dashboard_bp
|
from app.dashboard.base import dashboard_bp
|
||||||
|
@ -11,7 +11,7 @@ from app.extensions import db
|
||||||
from app.models import GenEmail
|
from app.models import GenEmail
|
||||||
|
|
||||||
|
|
||||||
@dashboard_bp.route("/unsubscribe/<gen_email_id>", methods=["GET"])
|
@dashboard_bp.route("/unsubscribe/<gen_email_id>", methods=["GET", "POST"])
|
||||||
@login_required
|
@login_required
|
||||||
def unsubscribe(gen_email_id):
|
def unsubscribe(gen_email_id):
|
||||||
gen_email = GenEmail.get(gen_email_id)
|
gen_email = GenEmail.get(gen_email_id)
|
||||||
|
@ -26,9 +26,13 @@ def unsubscribe(gen_email_id):
|
||||||
)
|
)
|
||||||
return redirect(url_for("dashboard.index"))
|
return redirect(url_for("dashboard.index"))
|
||||||
|
|
||||||
gen_email.enabled = False
|
# automatic unsubscribe, according to https://tools.ietf.org/html/rfc8058
|
||||||
flash(f"Alias {gen_email.email} has been blocked", "success")
|
if request.method == "POST":
|
||||||
db.session.commit()
|
gen_email.enabled = False
|
||||||
|
flash(f"Alias {gen_email.email} has been blocked", "success")
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
notify_admin(f"User {current_user.email} has unsubscribed an alias")
|
notify_admin(f"User {current_user.email} has unsubscribed an alias")
|
||||||
return redirect(url_for("dashboard.index"))
|
return redirect(url_for("dashboard.index"))
|
||||||
|
else: # ask user confirmation
|
||||||
|
return render_template("dashboard/unsubscribe.html", alias=gen_email.email)
|
||||||
|
|
|
@ -161,6 +161,7 @@ class MailHandler:
|
||||||
# add List-Unsubscribe header
|
# add List-Unsubscribe header
|
||||||
unsubscribe_link = f"{URL}/dashboard/unsubscribe/{gen_email.id}"
|
unsubscribe_link = f"{URL}/dashboard/unsubscribe/{gen_email.id}"
|
||||||
add_or_replace_header(msg, "List-Unsubscribe", f"<{unsubscribe_link}>")
|
add_or_replace_header(msg, "List-Unsubscribe", f"<{unsubscribe_link}>")
|
||||||
|
add_or_replace_header(msg, "List-Unsubscribe-Post", "List-Unsubscribe=One-Click")
|
||||||
|
|
||||||
original_subject = msg["Subject"]
|
original_subject = msg["Subject"]
|
||||||
LOG.d(
|
LOG.d(
|
||||||
|
@ -201,6 +202,7 @@ class MailHandler:
|
||||||
# add List-Unsubscribe header
|
# add List-Unsubscribe header
|
||||||
unsubscribe_link = f"{URL}/dashboard/unsubscribe/{forward_email.gen_email_id}"
|
unsubscribe_link = f"{URL}/dashboard/unsubscribe/{forward_email.gen_email_id}"
|
||||||
add_or_replace_header(msg, "List-Unsubscribe", f"<{unsubscribe_link}>")
|
add_or_replace_header(msg, "List-Unsubscribe", f"<{unsubscribe_link}>")
|
||||||
|
add_or_replace_header(msg, "List-Unsubscribe-Post", "List-Unsubscribe=One-Click")
|
||||||
|
|
||||||
LOG.d(
|
LOG.d(
|
||||||
"send email from %s to %s, mail_options:%s,rcpt_options:%s",
|
"send email from %s to %s, mail_options:%s,rcpt_options:%s",
|
||||||
|
|
Loading…
Reference in New Issue