extend prototype for qmail toggling
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
"""Provide basic settings and views"""
|
"""Provide basic settings and views"""
|
||||||
|
|
||||||
|
import fileinput
|
||||||
import re
|
import re
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from flask import request, render_template
|
from flask import request, render_template
|
||||||
@@ -8,10 +9,13 @@ from autoreply_editor import app
|
|||||||
|
|
||||||
basic_auth = BasicAuth(app)
|
basic_auth = BasicAuth(app)
|
||||||
|
|
||||||
|
qmail_prefix = f"{str(Path.home())}/.qmail-"
|
||||||
|
maildrop_line = "|maildrop $HOME/.filter-autoreply"
|
||||||
|
|
||||||
def qmail_status(user):
|
def qmail_status(user):
|
||||||
"""Find out whether the filter is currently activated for the given mail 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:
|
with open(f"{qmail_prefix}{user}", encoding="utf8") as dotqmail:
|
||||||
|
# TODO: RE not necessary here
|
||||||
if not re.search(
|
if not re.search(
|
||||||
r"^\|maildrop \$HOME/\.filter-autoreply$", dotqmail.read(), re.MULTILINE
|
r"^\|maildrop \$HOME/\.filter-autoreply$", dotqmail.read(), re.MULTILINE
|
||||||
):
|
):
|
||||||
@@ -37,11 +41,34 @@ def index_post():
|
|||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
if request.form["action"] == "message":
|
if request.form["action"] == "message":
|
||||||
input_message = request.form["message"]
|
input_message = request.form["message"]
|
||||||
with open(app.config.get("MESSAGE_FILE"), "w", encoding="utf-8") as messagefile:
|
with open(
|
||||||
|
app.config.get("MESSAGE_FILE"), "w", encoding="utf-8"
|
||||||
|
) as messagefile:
|
||||||
messagefile.write(str(input_message))
|
messagefile.write(str(input_message))
|
||||||
result = "Success: The autoreply message has been updated!"
|
result = "Success: The autoreply message has been updated!"
|
||||||
|
|
||||||
if request.form["action"] == "qmail":
|
if request.form["action"] == "qmail":
|
||||||
|
# define whether to set a comment
|
||||||
|
if request.form["status"] == "on":
|
||||||
|
preis = "#"
|
||||||
|
preshould = ""
|
||||||
|
else:
|
||||||
|
preis = ""
|
||||||
|
preshould = "#"
|
||||||
|
|
||||||
|
with fileinput.FileInput(
|
||||||
|
f"{qmail_prefix}{app.config.get('MAIL_USER')}",
|
||||||
|
inplace=True,
|
||||||
|
backup=".bak",
|
||||||
|
) as dotqmail:
|
||||||
|
for line in dotqmail:
|
||||||
|
print(
|
||||||
|
line.replace(
|
||||||
|
f"{preis}{maildrop_line}", f"{preshould}{maildrop_line}"
|
||||||
|
),
|
||||||
|
end="",
|
||||||
|
)
|
||||||
|
|
||||||
result = f"Success: the autoreply is now {request.form['status']}."
|
result = f"Success: the autoreply is now {request.form['status']}."
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
<h2>Toggle autoreply message</h2>
|
<h2>Toggle autoreply message</h2>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Currently, autoreply: {{ qmail_status }}
|
The autoreply is <strong>{%if qmail_status%}active{%else%}inactive{%endif%}</strong>
|
||||||
</p>
|
</p>
|
||||||
<form method="POST">
|
<form method="POST">
|
||||||
<input type="hidden" name="action" value="qmail" />
|
<input type="hidden" name="action" value="qmail" />
|
||||||
|
|||||||
Reference in New Issue
Block a user