Fix problems with users that do not have maildirsize file
This commit is contained in:
parent
8bd9cf38ab
commit
a8f02c1eb0
10
README.md
10
README.md
|
@ -8,6 +8,16 @@ There is baisc support for quotas in the control panel now. To set quotas from
|
||||||
column for the user in the `users.sqlite` database. The `quota` column is text and allows for the `M` and `G` suffixes
|
column for the user in the `users.sqlite` database. The `quota` column is text and allows for the `M` and `G` suffixes
|
||||||
for megabytes and gigabytes respectively. No spaces should be used in the quota value (e.g. `2G` or `100M`).
|
for megabytes and gigabytes respectively. No spaces should be used in the quota value (e.g. `2G` or `100M`).
|
||||||
|
|
||||||
|
Todo
|
||||||
|
----
|
||||||
|
|
||||||
|
* Get `postfix` to support quotas. See https://blog.sys4.de/postfix-dovecot-mailbox-quota-en.html for a start. Right
|
||||||
|
now the quota message store size is not calculated unless the user accesses the IMAP server (Dovecot). Right now postfix
|
||||||
|
does not take quotas into account before delivering a message.
|
||||||
|
|
||||||
|
* Allow Trash to have a grace percentage to allow users whose quota is full to delete messages.
|
||||||
|
|
||||||
|
|
||||||
\[BEGIN Official README]
|
\[BEGIN Official README]
|
||||||
|
|
||||||
Mail-in-a-Box
|
Mail-in-a-Box
|
||||||
|
|
|
@ -105,6 +105,18 @@ def get_mail_users(env):
|
||||||
users = [ row[0] for row in c.fetchall() ]
|
users = [ row[0] for row in c.fetchall() ]
|
||||||
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 get_mail_users_ex(env, with_archived=False):
|
def get_mail_users_ex(env, with_archived=False):
|
||||||
# Returns a complex data structure of all user accounts, optionally
|
# Returns a complex data structure of all user accounts, optionally
|
||||||
# including archived (status="inactive") accounts.
|
# including archived (status="inactive") accounts.
|
||||||
|
@ -136,22 +148,24 @@ def get_mail_users_ex(env, with_archived=False):
|
||||||
box_size = 0
|
box_size = 0
|
||||||
box_count = 0
|
box_count = 0
|
||||||
box_quota = ''
|
box_quota = ''
|
||||||
# try:
|
try:
|
||||||
# with open('/home/user-data/mail/mailboxes/%s/%s/maildirsize' % (domain, user), 'r') as f:
|
dirsize_file = os.path.join(env['STORAGE_ROOT'], 'mail/mailboxes/%s/%s/maildirsize' % (domain, user))
|
||||||
# box_quota = f.readline()
|
with open(dirsize_file, 'r') as f:
|
||||||
# for line in f.readlines():
|
box_quota = f.readline()
|
||||||
# (size, count) = line.split(' ')
|
for line in f.readlines():
|
||||||
# box_size += int(size)
|
(size, count) = line.split(' ')
|
||||||
# box_count += int(count)
|
box_size += int(size)
|
||||||
# except:
|
box_count += int(count)
|
||||||
# box_size = '?'
|
except:
|
||||||
|
box_size = '?'
|
||||||
|
box_count = '?'
|
||||||
|
|
||||||
user = {
|
user = {
|
||||||
"email": email,
|
"email": email,
|
||||||
"privileges": parse_privs(privileges),
|
"privileges": parse_privs(privileges),
|
||||||
"quota": quota,
|
"quota": quota,
|
||||||
"box_quota": box_quota,
|
"box_quota": box_quota,
|
||||||
"box_size": '%iK' % int(box_size / 1024),
|
"box_size": sizeof_fmt(box_size) if box_size != '?' else box_size,
|
||||||
"box_count": box_count,
|
"box_count": box_count,
|
||||||
"status": "active",
|
"status": "active",
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,8 @@
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th width="35%">Email Address</th>
|
<th width="35%">Email Address</th>
|
||||||
<th>Box Size</th>
|
<th>Messages</th>
|
||||||
|
<th>Size</th>
|
||||||
<th>Quota</th>
|
<th>Quota</th>
|
||||||
<th>Actions</th>
|
<th>Actions</th>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -56,6 +57,7 @@
|
||||||
<tr id="user-template">
|
<tr id="user-template">
|
||||||
<td class='address'>
|
<td class='address'>
|
||||||
</td>
|
</td>
|
||||||
|
<td class="box-count"></td>
|
||||||
<td class="box-size"></td>
|
<td class="box-size"></td>
|
||||||
<td class="quota">
|
<td class="quota">
|
||||||
</td>
|
</td>
|
||||||
|
@ -163,6 +165,7 @@ function show_users() {
|
||||||
n.attr('data-email', user.email);
|
n.attr('data-email', user.email);
|
||||||
n.attr('data-quota', user.quota);
|
n.attr('data-quota', user.quota);
|
||||||
n.find('.address').text(user.email);
|
n.find('.address').text(user.email);
|
||||||
|
n.find('.box-count').text(user.box_count);
|
||||||
n.find('.box-size').text(user.box_size);
|
n.find('.box-size').text(user.box_size);
|
||||||
n.find('.quota').text((user.quota == '0') ? 'unlimited' : user.quota);
|
n.find('.quota').text((user.quota == '0') ? 'unlimited' : user.quota);
|
||||||
n2.find('.restore_info tt').text(user.mailbox);
|
n2.find('.restore_info tt').text(user.mailbox);
|
||||||
|
|
Loading…
Reference in New Issue