Статья в продолжении статьи
Установка и настройка почтовой связки на основе Postfix+Dovecot+MySQL+PostfixAdmin+Roundcube на Debian 7/ Ubuntu 14.04
Настройка PostfixAdmin
1 |
# nano /usr/share/postfixadmin/config.inc.php |
1 2 3 4 5 6 7 |
$CONF['maxquota'] = '0'; $CONF['domain_quota_default'] = '0'; $CONF['quota'] = 'YES'; $CONF['domain_quota'] = 'NO'; $CONF['quota_multiplier'] = '1024000'; $CONF['used_quotas'] = 'YES'; $CONF['new_quota_table'] = 'YES'; |
Перезапуск Nginx/Apache сервера
Настройка Dovecot
1 |
# nano /etc/dovecot/conf.d/10-mail.conf |
1 |
mail_plugins = $mail_plugins quota |
1 |
# nano /etc/dovecot/conf.d/20-imap.conf |
1 2 3 |
protocol imap { mail_plugins = $mail_plugins imap_quota } |
1 |
# nano /etc/dovecot/conf.d/10-master.conf |
1 2 3 4 5 6 |
service dict { unix_listener dict { mode = 0660 user = vmail group = mail } |
1 |
# nano /etc/dovecot/conf.d/90-quota.conf |
1 2 3 |
plugin { quota = dict:User quota::proxy::quota } |
1 |
# nano /etc/dovecot/dovecot.conf |
1 2 3 |
dict { quota = mysql:/etc/dovecot/dovecot-dict-sql.conf.ext } |
1 |
# nano /etc/dovecot/dovecot-dict-sql.conf.ext |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
connect = host=localhost dbname=postfix user=postfixuser password=postfixpassword map { pattern = priv/quota/storage table = quota2 username_field = username value_field = bytes } map { pattern = priv/quota/messages table = quota2 username_field = username value_field = messages } |
Для Dovecot версии 1.2 и выше используется таблица quota2 вместо таблицы quota
1 |
# nano /etc/dovecot/dovecot-sql.conf.ext |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
driver = mysql connect = host=localhost dbname=postfix user=postfixuser password=postfixapassword default_pass_scheme = MD5-CRYPT user_query = \ SELECT '/var/vmail/%d/%n' as home, \ 'maildir:/var/vmail/%d/%n' as mail, \ 1150 AS uid, 8 AS gid, concat('*:bytes=', quota) AS quota_rule \ FROM mailbox WHERE username = '%u' AND active = '1' password_query = \ SELECT username as user, password, '/var/vmail/%d/%n' as userdb_home, \ 'maildir:/var/vmail/%d/%n' as userdb_mail, 1150 as userdb_uid, 8 as userdb_gid \ FROM mailbox WHERE username = '%u' AND active = '1' |
Применяем сделанные настройки
1 |
# systemctl restart dovecot |
Пересчет квоты пользователей
1 |
# for user in `mysql -Bse "select username from postfix.mailbox"`; do doveadm quota recalc -u $user; done |
Просмотр квоты пользователя(также можно просмотреть в WEB-интерфейсе PostfixAdmin)
1 |
# doveadm quota get -u username@example.com |
Пересчитать квоту для конкретного пользователя
1 |
# doveadm quota recalc -u username@example.com |
Включение оповещений при превышении квоты
1 |
# nano /etc/dovecot/conf.d/90-quota.conf |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
plugin { quota = dict:User quota::proxy::quota quota_warning = storage=100%% quota-exceeded 100 %u quota_warning2 = storage=90%% quota-warning 90 %u quota_warning3 = storage=80%% quota-warning 50 %u } service quota-warning { executable = script /etc/dovecot/quota-warning.sh unix_listener quota-warning { user = vmail group = mail mode = 0660 } } service quota-exceeded { executable = script /etc/dovecot/quota-exceeded.sh unix_listener quota-exceeded { user = vmail group = mail mode = 0660 } } |
1 |
# nano /etc/dovecot/quota-warning.sh |
1 2 3 4 5 6 7 8 9 10 11 |
PERCENT=$1 USER=$2 cat << EOF | /usr/lib/dovecot/dovecot-lda -d $USER -o "plugin/quota=maildir:User quota:noenforcing" From: postmaster@example.com Subject: Quota warning X-Priority: 2 Your mailbox is now about/over $PERCENT% full. Please, remove unnecessary mails/attachment from your mailbox, clean folder TRASH and restart mail user agent (Thunderbird/Bat etc) EOF |
1 |
# nano /etc/dovecot/quota-exceeded.sh |
1 2 3 4 5 6 7 8 9 10 11 |
PERCENT=$1 USER=$2 cat << EOF | /usr/lib/dovecot/dovecot-lda -d $USER -o "plugin/quota=maildir:User quota:noenforcing" From: postmaster@example.com Subject: Quota exceeded X-Priority: 2 Your mailbox is now $PERCENT% full. You won't be able to get any new mail messages until the size of your mailbox is over mail quota Please, remove unnecessary mails/attachment from your mailbox, clean folder TRASH and restart mail user agent (Thunderbird/Bat etc) EOF |
1 |
# chmod +x /etc/dovecot/quota*sh |
1 |
# chown vmail:mail /etc/dovecot/quota*sh |
1 |
# systemctl restart dovecot |
Источник:
Содержимое файла /usr/share/postfixadmin/DOCUMENTS/DOVECOT.txt
http://wiki2.dovecot.org/Quota
http://forum.lissyara.su/viewtopic.php?t=40932
http://blog.shines.me.uk/configuring-domain-user-mailbox-quotas-in-dovecot-via-postfixadmin-on-ubuntu-12-04lts/
Удаление писем старше 1 дня из каталога Trash
1 |
# nano /etc/dovecot/conf.d/15-mailboxes.conf |
1 2 3 4 |
mailbox Trash { special_use = \Trash autoexpunge=1d } |
1 |
# systemctl restart dovecot |
Для IMAP/POP3 это происходит после отключения клиента (закрытия почтового клиента)
Именно после этого происходит автоматический перерасчет квоты
Принудительная очистка каталога Trash(при этом происходит автоматический перерасчет квоты)
для конкретного пользователя (/var/vmail/example.com/username/.Trash/{cur,new,tmp})
1 |
# dovecot expunge -u username@example.com mailbox Trash all |
для всех пользователей
1 |
# dovecot expunge -A mailbox Trash all |
Очистка писем в каталоге Trash для всех пользователей старше 30 дней
1 |
# dovecot expunge -A mailbox Trash savedbefore 30d |
Настройка trash-плагина — автоматическое удаление писем из каталогов корзина, спам, черновики при превышении квоты
1 |
# nano /etc/dovecot/conf.d/10-mail.conf |
1 |
mail_plugins = $mail_plugins quota trash |
1 |
# nano /etc/dovecot/conf.d/90-plugin.conf |
1 2 3 |
plugin { trash = /etc/dovecot/dovecot-trash.conf.ext } |
1 |
# nano /etc/dovecot/dovecot-trash.conf.ext |
1 2 3 |
1 Trash 2 Junk 3 Draft |
1 |
# systemctl restart dovecot |
Источник: