Calculate and display mailbox sizes in user list

This commit is contained in:
John Supplee 2019-01-29 19:18:48 +02:00
parent c5c7de8b2b
commit f68ef70b94
2 changed files with 20 additions and 0 deletions

View File

@ -132,10 +132,27 @@ def get_mail_users_ex(env, with_archived=False):
for email, privileges, quota in c.fetchall():
active_accounts.add(email)
(user, domain) = email.split('@')
box_size = 0
box_count = 0
box_quota = ''
try:
with open('/home/user-data/mail/mailboxes/%s/%s/maildirsize' % (domain, user), 'r') as f:
box_quota = f.readline()
for line in f.readlines():
(size, count) = line.split(' ')
box_size += int(size)
box_count += int(count)
except:
box_size = '?'
user = {
"email": email,
"privileges": parse_privs(privileges),
"quota": quota,
"box_quota": box_quota,
"box_size": '%iK' % int(box_size / 1024),
"box_count": box_count,
"status": "active",
}
users.append(user)

View File

@ -42,6 +42,7 @@
<thead>
<tr>
<th width="35%">Email Address</th>
<th>Box Size</th>
<th>Quota</th>
<th>Actions</th>
</tr>
@ -55,6 +56,7 @@
<tr id="user-template">
<td class='address'>
</td>
<td class="box-size"></td>
<td class="quota">
</td>
<td class='actions'>
@ -161,6 +163,7 @@ function show_users() {
n.attr('data-email', user.email);
n.attr('data-quota', user.quota);
n.find('.address').text(user.email);
n.find('.box-size').text(user.box_size);
n.find('.quota').text((user.quota == '0') ? 'unlimited' : user.quota);
n2.find('.restore_info tt').text(user.mailbox);