prototype qmail toggling
This commit is contained in:
@@ -1,25 +1,50 @@
|
|||||||
"""Provide basic settings and views"""
|
"""Provide basic settings and views"""
|
||||||
|
|
||||||
from flask import request, render_template, redirect
|
import re
|
||||||
|
from pathlib import Path
|
||||||
|
from flask import request, render_template
|
||||||
from flask_basicauth import BasicAuth
|
from flask_basicauth import BasicAuth
|
||||||
from autoreply_editor import app
|
from autoreply_editor import app
|
||||||
|
|
||||||
basic_auth = BasicAuth(app)
|
basic_auth = BasicAuth(app)
|
||||||
|
|
||||||
|
|
||||||
|
def qmail_status(user):
|
||||||
|
"""Find out whether the filter is currently activated for the given mail user"""
|
||||||
|
with open(f"{str(Path.home())}/.qmail-{user}", encoding="utf8") as dotqmail:
|
||||||
|
if not re.search(
|
||||||
|
r"^\|maildrop \$HOME/\.filter-autoreply$", dotqmail.read(), re.MULTILINE
|
||||||
|
):
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
@app.route("/")
|
@app.route("/")
|
||||||
def index():
|
def index():
|
||||||
with open(app.config.get("MESSAGE_FILE"), "r") as f:
|
with open(app.config.get("MESSAGE_FILE"), "r", encoding="utf-8") as messagefile:
|
||||||
message = f.read()
|
message = messagefile.read()
|
||||||
|
|
||||||
return render_template("index.html", message=message)
|
return render_template(
|
||||||
|
"index.html",
|
||||||
|
message=message,
|
||||||
|
qmail_status=qmail_status(app.config.get("MAIL_USER")),
|
||||||
|
)
|
||||||
|
|
||||||
@app.route('/', methods=['POST'])
|
|
||||||
|
@app.route("/", methods=["POST"])
|
||||||
def index_post():
|
def index_post():
|
||||||
input_message = request.form['message']
|
if request.method == "POST":
|
||||||
|
if request.form["action"] == "message":
|
||||||
|
input_message = request.form["message"]
|
||||||
|
with open(app.config.get("MESSAGE_FILE"), "w", encoding="utf-8") as messagefile:
|
||||||
|
messagefile.write(str(input_message))
|
||||||
|
result = "Success: The autoreply message has been updated!"
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.form["action"] == "qmail":
|
||||||
with open(app.config.get("MESSAGE_FILE"), 'w') as f:
|
result = f"Success: the autoreply is now {request.form['status']}."
|
||||||
f.write(str(input_message))
|
|
||||||
result = "Success: The autoreply message has been updated!"
|
|
||||||
|
|
||||||
return render_template("result.html", result=result)
|
try:
|
||||||
|
return render_template("result.html", result=result)
|
||||||
|
except UnboundLocalError:
|
||||||
|
return render_template("result.html", result="Something went terribly wrong!")
|
||||||
|
|||||||
@@ -6,11 +6,30 @@
|
|||||||
<body>
|
<body>
|
||||||
<h1>Autoreply Editor</h1>
|
<h1>Autoreply Editor</h1>
|
||||||
|
|
||||||
|
<h2>Toggle autoreply message</h2>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Currently, autoreply: {{ qmail_status }}
|
||||||
|
</p>
|
||||||
|
<form method="POST">
|
||||||
|
<input type="hidden" name="action" value="qmail" />
|
||||||
|
{% if qmail_status %}
|
||||||
|
<input type="hidden" name="status" value="off" />
|
||||||
|
<input type="submit" value="Deactivate">
|
||||||
|
{% else %}
|
||||||
|
<input type="hidden" name="status" value="on" />
|
||||||
|
<input type="submit" value="Activate">
|
||||||
|
{% endif %}
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<h2>Change autoreply message</h2>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Below you can see the current text of your autoreply message. You
|
Below you can see the current text of your autoreply message. You
|
||||||
can edit and update it directly below:
|
can edit and update it directly below:
|
||||||
</p>
|
</p>
|
||||||
<form action="" method="POST">
|
<form method="POST">
|
||||||
|
<input type="hidden" name="action" value="message" />
|
||||||
<textarea name="message" cols="120" rows="20">{{ message }}</textarea>
|
<textarea name="message" cols="120" rows="20">{{ message }}</textarea>
|
||||||
<br />
|
<br />
|
||||||
<input type="submit" value="Update">
|
<input type="submit" value="Update">
|
||||||
|
|||||||
Reference in New Issue
Block a user