From 06a8ce1c9de7fa98619699dda2c7a4f53f7d483b Mon Sep 17 00:00:00 2001 From: Joshua Tauberer Date: Tue, 7 Oct 2014 20:24:11 +0000 Subject: [PATCH] in the admin, show user mailbox sizes, fixes #210 --- management/daemon.py | 2 +- management/mailconfig.py | 23 +++++++++---- management/templates/system-backup.html | 7 +++- management/templates/users.html | 44 +++++++++++++++++-------- management/utils.py | 19 +++++++++++ 5 files changed, 72 insertions(+), 23 deletions(-) diff --git a/management/daemon.py b/management/daemon.py index 695b2a1a..69bb9294 100755 --- a/management/daemon.py +++ b/management/daemon.py @@ -98,7 +98,7 @@ def me(): @authorized_personnel_only def mail_users(): if request.args.get("format", "") == "json": - return json_response(get_mail_users_ex(env, with_archived=True)) + return json_response(get_mail_users_ex(env, with_archived=True, with_slow_info=True)) else: return "".join(x+"\n" for x in get_mail_users(env)) diff --git a/management/mailconfig.py b/management/mailconfig.py index 74b3c715..603934d4 100755 --- a/management/mailconfig.py +++ b/management/mailconfig.py @@ -53,7 +53,7 @@ def get_mail_users(env): users = [ row[0] for row in c.fetchall() ] return utils.sort_email_addresses(users, env) -def get_mail_users_ex(env, with_archived=False): +def get_mail_users_ex(env, with_archived=False, with_slow_info=False): # Returns a complex data structure of all user accounts, optionally # including archived (status="inactive") accounts. # @@ -86,15 +86,20 @@ def get_mail_users_ex(env, with_archived=False): c.execute('SELECT email, privileges FROM users') for email, privileges in c.fetchall(): active_accounts.add(email) - users.append({ + + user = { "email": email, "privileges": parse_privs(privileges), "status": "active", - "aliases": [ + } + users.append(user) + + if with_slow_info: + user["aliases"] = [ (alias, sorted(evaluate_mail_alias_map(alias, aliases, env))) for alias in aliases.get(email.lower(), []) ] - }) + user["mailbox_size"] = utils.du(os.path.join(env['STORAGE_ROOT'], 'mail/mailboxes', *reversed(email.split("@")))) # Add in archived accounts. if with_archived: @@ -102,13 +107,17 @@ def get_mail_users_ex(env, with_archived=False): for domain in os.listdir(root): for user in os.listdir(os.path.join(root, domain)): email = user + "@" + domain + mbox = os.path.join(root, domain, user) if email in active_accounts: continue - users.append({ + user = { "email": email, "privileges": "", "status": "inactive", - "mailbox": os.path.join(root, domain, user), - }) + "mailbox": mbox, + } + users.append(user) + if with_slow_info: + user["mailbox_size"] = utils.du(mbox) # Group by domain. domains = { } diff --git a/management/templates/system-backup.html b/management/templates/system-backup.html index 8f01243b..2b1ad465 100644 --- a/management/templates/system-backup.html +++ b/management/templates/system-backup.html @@ -39,7 +39,12 @@ function nice_size(bytes) { bytes /= 1024; powers.shift(); } - return (Math.round(bytes*10)/10) + " " + powers[0]; + // round to have three significant figures but at most one decimal place + if (bytes >= 100) + bytes = Math.round(bytes) + else + bytes = Math.round(bytes*10)/10; + return bytes + " " + powers[0]; } function show_system_backup() { diff --git a/management/templates/users.html b/management/templates/users.html index 8b07af64..3f54cac9 100644 --- a/management/templates/users.html +++ b/management/templates/users.html @@ -1,8 +1,8 @@

Users