1
0
mirror of https://github.com/mail-in-a-box/mailinabox.git synced 2026-04-19 00:17:23 +02:00

Implemented quota.

- Implemented quota to management.
- Quota to have 0 as default, added more description.
This commit is contained in:
Rainulf Pineda
2016-01-05 16:05:45 -05:00
parent cb162da5fe
commit 590321fcb7
7 changed files with 138 additions and 16 deletions

View File

@@ -102,8 +102,13 @@ sed -i "s/#port = 110/port = 0/" /etc/dovecot/conf.d/10-master.conf
# The risk is that if the connection is silent for too long it might be reset
# by a peer. See [#129](https://github.com/mail-in-a-box/mailinabox/issues/129)
# and [How bad is IMAP IDLE](http://razor.occams.info/blog/2014/08/09/how-bad-is-imap-idle/).
tools/editconf.py /etc/dovecot/conf.d/20-imap.conf \
imap_idle_notify_interval="4 mins"
# Also added imap_quota for quota display on roundcube.
cat > /etc/dovecot/conf.d/20-imap.conf << EOF;
imap_idle_notify_interval=4 mins
protocol imap {
mail_plugins = \$mail_plugins antispam imap_quota
}
EOF
# Set POP3 UIDL.
# UIDLs are used by POP3 clients to keep track of what messages they've downloaded.
@@ -115,7 +120,34 @@ tools/editconf.py /etc/dovecot/conf.d/20-pop3.conf \
# Full Text Search - Enable full text search of mail using dovecot's lucene plugin,
# which *we* package and distribute (dovecot-lucene package).
tools/editconf.py /etc/dovecot/conf.d/10-mail.conf \
mail_plugins="\$mail_plugins fts fts_lucene"
mail_plugins="\$mail_plugins fts fts_lucene quota"
# Configure a simple usage of quota.
# See this: http://wiki2.dovecot.org/Quota/Configuration
#
# dovecot quota as policy-service for postfix instead of dovecot to bounce it
# See this: https://sys4.de/en/blog/2013/04/08/postfix-dovecot-mailbox-quota/
cat > /etc/dovecot/conf.d/90-quota.conf << EOF;
plugin {
quota = maildir:User quota
#quota_rule = *:storage=1M
#quota_rule2 = Trash:storage=+100M
quota_grace = 10%%
quota_status_success = DUNNO
quota_status_nouser = DUNNO
quota_status_overquota = "552 5.2.2 Mailbox is full"
}
service quota-status {
executable = quota-status -p postfix
inet_listener {
port = 12340
}
client_limit = 1
}
EOF
cat > /etc/dovecot/conf.d/90-plugin-fts.conf << EOF;
plugin {
fts = lucene

View File

@@ -200,7 +200,7 @@ tools/editconf.py /etc/postfix/main.cf virtual_transport=lmtp:[127.0.0.1]:10025
# "450 4.7.1 Client host rejected: Service unavailable". This is a retry code, so the mail doesn't properly bounce. #NODOC
tools/editconf.py /etc/postfix/main.cf \
smtpd_sender_restrictions="reject_non_fqdn_sender,reject_unknown_sender_domain,reject_authenticated_sender_login_mismatch,reject_rhsbl_sender dbl.spamhaus.org" \
smtpd_recipient_restrictions=permit_sasl_authenticated,permit_mynetworks,"reject_rbl_client zen.spamhaus.org",reject_unlisted_recipient,"check_policy_service inet:127.0.0.1:10023"
smtpd_recipient_restrictions=permit_sasl_authenticated,permit_mynetworks,"reject_rbl_client zen.spamhaus.org",reject_unlisted_recipient,"check_policy_service inet:127.0.0.1:10023","check_policy_service inet:127.0.0.1:12340"
# Postfix connects to Postgrey on the 127.0.0.1 interface specifically. Ensure that
# Postgrey listens on the same interface (and not IPv6, for instance).

View File

@@ -20,7 +20,7 @@ db_path=$STORAGE_ROOT/mail/users.sqlite
# Create an empty database if it doesn't yet exist.
if [ ! -f $db_path ]; then
echo Creating new user database: $db_path;
echo "CREATE TABLE users (id INTEGER PRIMARY KEY AUTOINCREMENT, email TEXT NOT NULL UNIQUE, password TEXT NOT NULL, extra, privileges TEXT NOT NULL DEFAULT '');" | sqlite3 $db_path;
echo "CREATE TABLE users (id INTEGER PRIMARY KEY AUTOINCREMENT, email TEXT NOT NULL UNIQUE, password TEXT NOT NULL, quota NUMERIC NOT NULL DEFAULT 0, extra, privileges TEXT NOT NULL DEFAULT '');" | sqlite3 $db_path;
echo "CREATE TABLE aliases (id INTEGER PRIMARY KEY AUTOINCREMENT, source TEXT NOT NULL UNIQUE, destination TEXT NOT NULL, permitted_senders TEXT);" | sqlite3 $db_path;
fi
@@ -40,6 +40,7 @@ passdb {
userdb {
driver = sql
args = /etc/dovecot/dovecot-sql.conf.ext
default_fields = uid=mail gid=mail home=$STORAGE_ROOT/mail/mailboxes/%d/%n
}
EOF
@@ -48,6 +49,7 @@ cat > /etc/dovecot/dovecot-sql.conf.ext << EOF;
driver = sqlite
connect = $db_path
default_pass_scheme = SHA512-CRYPT
user_query = SELECT '*:storage=' || quota || 'M' AS quota_rule FROM users WHERE email='%u';
password_query = SELECT email as user, password FROM users WHERE email='%u';
user_query = SELECT email AS user, "mail" as uid, "mail" as gid, "$STORAGE_ROOT/mail/mailboxes/%d/%n" as home FROM users WHERE email='%u';
iterate_query = SELECT email AS user FROM users;
@@ -148,5 +150,3 @@ EOF
restart_service postfix
restart_service dovecot

View File

@@ -148,6 +148,12 @@ def migration_11(env):
# meh
pass
def migration_12(env):
# Add quota column to `users` table for quota implementation per user.
# Note that the numeric value represents megabyte. 0 is unlimited.
db = os.path.join(env["STORAGE_ROOT"], 'mail/users.sqlite')
shell("check_call", ["sqlite3", db, "ALTER TABLE users ADD quota NUMERIC NOT NULL DEFAULT 0"])
def get_current_migration():
ver = 0
while True:
@@ -225,4 +231,3 @@ if __name__ == "__main__":
elif sys.argv[-1] == "--migrate":
# Perform migrations.
run_migrations()