mirror of
https://github.com/mail-in-a-box/mailinabox.git
synced 2025-04-01 23:57:05 +00:00
Merge remote-tracking branch 'upstream/main' into quota
# Conflicts: # management/daemon.py # management/mailconfig.py # management/templates/users.html # setup/bootstrap.sh # setup/mail-dovecot.sh # setup/mail-postfix.sh # setup/mail-users.sh
This commit is contained in:
commit
40d0d06a35
@ -286,6 +286,18 @@ def get_mail_users(env, as_map=False, map_by="maildrop"):
|
|||||||
return utils.sort_email_addresses(users, env)
|
return utils.sort_email_addresses(users, env)
|
||||||
|
|
||||||
|
|
||||||
|
def sizeof_fmt(num):
|
||||||
|
for unit in ['','K','M','G','T']:
|
||||||
|
if abs(num) < 1024.0:
|
||||||
|
if abs(num) > 99:
|
||||||
|
return "%3.0f%s" % (num, unit)
|
||||||
|
else:
|
||||||
|
return "%2.1f%s" % (num, unit)
|
||||||
|
|
||||||
|
num /= 1024.0
|
||||||
|
|
||||||
|
return str(num)
|
||||||
|
|
||||||
def sizeof_fmt(num):
|
def sizeof_fmt(num):
|
||||||
for unit in ['','K','M','G','T']:
|
for unit in ['','K','M','G','T']:
|
||||||
if abs(num) < 1024.0:
|
if abs(num) < 1024.0:
|
||||||
@ -794,6 +806,14 @@ def add_mail_user(email, pw, privs, quota, display_name, env):
|
|||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
return (str(e), 400)
|
return (str(e), 400)
|
||||||
|
|
||||||
|
if quota is None:
|
||||||
|
quota = '0'
|
||||||
|
|
||||||
|
try:
|
||||||
|
quota = validate_quota(quota)
|
||||||
|
except ValueError as e:
|
||||||
|
return (str(e), 400)
|
||||||
|
|
||||||
# get the database
|
# get the database
|
||||||
conn = open_database(env)
|
conn = open_database(env)
|
||||||
|
|
||||||
@ -867,6 +887,8 @@ def add_mail_user(email, pw, privs, quota, display_name, env):
|
|||||||
|
|
||||||
dovecot_quota_recalc(email)
|
dovecot_quota_recalc(email)
|
||||||
|
|
||||||
|
dovecot_quota_recalc(email)
|
||||||
|
|
||||||
# Update things in case any new domains are added.
|
# Update things in case any new domains are added.
|
||||||
if domain_added:
|
if domain_added:
|
||||||
return kick(env, return_status)
|
return kick(env, return_status)
|
||||||
@ -976,6 +998,40 @@ def validate_quota(quota):
|
|||||||
|
|
||||||
return quota
|
return quota
|
||||||
|
|
||||||
|
|
||||||
|
def get_mail_quota(email, env):
|
||||||
|
user = find_mail_user(env, email, ['mailboxQuota'])
|
||||||
|
if user is None:
|
||||||
|
return ("That's not a user (%s)." % email, 400)
|
||||||
|
if len(user['mailboxQuota'])==0:
|
||||||
|
return '0'
|
||||||
|
else:
|
||||||
|
return user['mailboxQuota'][0]
|
||||||
|
|
||||||
|
def set_mail_quota(email, quota, env):
|
||||||
|
# validate that password is acceptable
|
||||||
|
quota = validate_quota(quota)
|
||||||
|
|
||||||
|
# update the database
|
||||||
|
conn = open_database(env)
|
||||||
|
user = find_mail_user(env, email, ['mailboxQuota'], conn)
|
||||||
|
if user is None:
|
||||||
|
return ("That's not a user (%s)." % email, 400)
|
||||||
|
|
||||||
|
conn.modify_record(user, { 'mailboxQuota': quota })
|
||||||
|
dovecot_quota_recalc(email)
|
||||||
|
return "OK"
|
||||||
|
|
||||||
|
def dovecot_quota_recalc(email):
|
||||||
|
# dovecot processes running for the user will not recognize the new quota setting
|
||||||
|
# a reload is necessary to reread the quota setting, but it will also shut down
|
||||||
|
# running dovecot processes. Email clients generally log back in when they lose
|
||||||
|
# a connection.
|
||||||
|
# subprocess.call(['doveadm', 'reload'])
|
||||||
|
|
||||||
|
# force dovecot to recalculate the quota info for the user.
|
||||||
|
subprocess.call(["doveadm", "quota", "recalc", "-u", email])
|
||||||
|
|
||||||
def get_mail_password(email, env):
|
def get_mail_password(email, env):
|
||||||
# Gets the hashed passwords for a user. In ldap, userPassword is
|
# Gets the hashed passwords for a user. In ldap, userPassword is
|
||||||
# multi-valued and each value can have different hash. This
|
# multi-valued and each value can have different hash. This
|
||||||
|
@ -93,8 +93,8 @@ user_filter = (&(objectClass=mailUser)(|(mail=%u)(maildrop=%u)))
|
|||||||
user_attrs = maildrop=user, \
|
user_attrs = maildrop=user, \
|
||||||
mailboxQuota=quota_rule=*:bytes=%\$, \
|
mailboxQuota=quota_rule=*:bytes=%\$, \
|
||||||
=quota_rule2=Trash:storage=+100M, \
|
=quota_rule2=Trash:storage=+100M, \
|
||||||
=quota_rule3=Drafts:ignore, \
|
=quota_rule3=Drafts:storage=+25M, \
|
||||||
=quota_rule4=Sent:ignore
|
=quota_rule4=Sent:storage=+50M
|
||||||
|
|
||||||
# Account iteration for various dovecot tools (doveadm)
|
# Account iteration for various dovecot tools (doveadm)
|
||||||
iterate_filter = (objectClass=mailUser)
|
iterate_filter = (objectClass=mailUser)
|
||||||
|
@ -178,17 +178,16 @@ installed_state_compare() {
|
|||||||
|
|
||||||
# s2: re-sort aliases
|
# s2: re-sort aliases
|
||||||
jq -c ".[] | .aliases | sort_by(.address) | .[] | {address:.address, forwards_to:.forwards_to, permitted_senders:.permitted_senders, auto:.auto, description:.description}" "$s2/aliases.json" > "$s2/aliases-cmp.json"
|
jq -c ".[] | .aliases | sort_by(.address) | .[] | {address:.address, forwards_to:.forwards_to, permitted_senders:.permitted_senders, auto:.auto, description:.description}" "$s2/aliases.json" > "$s2/aliases-cmp.json"
|
||||||
fi
|
|
||||||
|
|
||||||
if [ $MIGRATION_ML_VERSION_A -le 2 -a $MIGRATION_ML_VERSION_B -ge 3 ]; then
|
if [ $MIGRATION_ML_VERSION_A -le 2 -a $MIGRATION_ML_VERSION_B -ge 3 ]; then
|
||||||
# miabldap migration level <=2 does not have quota fields, so
|
# miabldap migration level <=2 does not have quota fields, so
|
||||||
# remove them from the comparison
|
# remove them from the comparison
|
||||||
grep -vE '"(quota|box_quota|box_size|percent)":' "$s2/users-cmp.json" > "$s2/users-cmp2.json" || changed="true"
|
grep -vE '"(quota|box_quota|box_size|percent)":' "$s2/users-cmp.json" > "$s2/users-cmp2.json" || changed="true"
|
||||||
cp "$s2/users-cmp2.json" "$s2/users-cmp.json" && rm -f "$s2/users-cmp2.json"
|
cp "$s2/users-cmp2.json" "$s2/users-cmp.json" && rm -f "$s2/users-cmp2.json"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# users
|
# users
|
||||||
#
|
#
|
||||||
|
Loading…
Reference in New Issue
Block a user