2018-10-18 15:57:43 +02:00
|
|
|
from mailu import models
|
2018-09-27 16:09:38 +02:00
|
|
|
from mailu.internal import internal
|
2018-10-18 15:57:43 +02:00
|
|
|
from flask import current_app as app
|
2018-09-27 16:09:38 +02:00
|
|
|
|
|
|
|
import flask
|
2018-10-17 21:21:00 +02:00
|
|
|
import socket
|
2018-10-31 17:47:05 +02:00
|
|
|
import os
|
2022-11-03 18:50:39 +02:00
|
|
|
import sqlalchemy.exc
|
2018-09-27 16:09:38 +02:00
|
|
|
|
2019-01-04 19:01:46 +02:00
|
|
|
@internal.route("/dovecot/passdb/<path:user_email>")
|
2018-09-27 16:09:38 +02:00
|
|
|
def dovecot_passdb_dict(user_email):
|
|
|
|
user = models.User.query.get(user_email) or flask.abort(404)
|
2018-10-17 21:21:00 +02:00
|
|
|
allow_nets = []
|
2018-12-03 03:16:53 +02:00
|
|
|
allow_nets.append(app.config["SUBNET"])
|
2020-02-03 23:53:04 +02:00
|
|
|
if app.config["SUBNET6"]:
|
|
|
|
allow_nets.append(app.config["SUBNET6"])
|
2018-09-27 16:09:38 +02:00
|
|
|
return flask.jsonify({
|
2018-10-17 21:21:00 +02:00
|
|
|
"password": None,
|
|
|
|
"nopassword": "Y",
|
|
|
|
"allow_nets": ",".join(allow_nets)
|
2018-09-27 16:09:38 +02:00
|
|
|
})
|
|
|
|
|
2022-10-30 21:15:10 +02:00
|
|
|
@internal.route("/dovecot/userdb/")
|
|
|
|
def dovecot_userdb_dict_list():
|
|
|
|
return flask.jsonify([
|
|
|
|
user[0] for user in models.User.query.filter(models.User.enabled.is_(True)).with_entities(models.User.email).all()
|
|
|
|
])
|
2018-09-27 16:09:38 +02:00
|
|
|
|
2019-01-04 19:01:46 +02:00
|
|
|
@internal.route("/dovecot/userdb/<path:user_email>")
|
2018-09-27 16:09:38 +02:00
|
|
|
def dovecot_userdb_dict(user_email):
|
2022-11-03 18:45:21 +02:00
|
|
|
try:
|
|
|
|
quota = models.User.query.filter(models.User.email==user_email).with_entities(models.User.quota_bytes).one_or_none() or flask.abort(404)
|
2022-11-03 18:50:39 +02:00
|
|
|
except sqlalchemy.exc.StatementError as exc:
|
2022-11-03 18:45:21 +02:00
|
|
|
flask.abort(404)
|
2018-09-27 16:09:38 +02:00
|
|
|
return flask.jsonify({
|
2022-11-03 18:37:21 +02:00
|
|
|
"quota_rule": f"*:bytes={quota[0]}"
|
2018-09-27 16:09:38 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
|
2019-01-04 19:01:46 +02:00
|
|
|
@internal.route("/dovecot/quota/<ns>/<path:user_email>", methods=["POST"])
|
2018-09-27 16:09:38 +02:00
|
|
|
def dovecot_quota(ns, user_email):
|
|
|
|
user = models.User.query.get(user_email) or flask.abort(404)
|
|
|
|
if ns == "storage":
|
|
|
|
user.quota_bytes_used = flask.request.get_json()
|
2022-10-28 10:05:47 +02:00
|
|
|
user.dont_change_updated_at()
|
2018-10-18 15:57:43 +02:00
|
|
|
models.db.session.commit()
|
2018-09-27 16:09:38 +02:00
|
|
|
return flask.jsonify(None)
|
|
|
|
|
|
|
|
|
2019-01-04 19:01:46 +02:00
|
|
|
@internal.route("/dovecot/sieve/name/<script>/<path:user_email>")
|
2018-09-27 16:09:38 +02:00
|
|
|
def dovecot_sieve_name(script, user_email):
|
|
|
|
return flask.jsonify(script)
|
|
|
|
|
|
|
|
|
2019-01-04 19:01:46 +02:00
|
|
|
@internal.route("/dovecot/sieve/data/default/<path:user_email>")
|
2018-09-27 16:09:38 +02:00
|
|
|
def dovecot_sieve_data(user_email):
|
|
|
|
user = models.User.query.get(user_email) or flask.abort(404)
|
|
|
|
return flask.jsonify(flask.render_template("default.sieve", user=user))
|