1

I'm trying to implement the quota warning to users over quota with Dovecot following this tip. I've added the following to my /etc/dovecot/conf.d/30-overquota.conf (any modication in the original /etc/dovecot/dovecot.conf is said would be removed in case of update).

plugin {
  quota = dict:user::file:/var/vmail/%d/%n/.quotausage
  sieve=/var/vmail/%d/%n/.sieve

quota_warning = storage=50%% quota-warning 50 %u
quota_warning2 = storage=80%% quota-warning 80 %u
quota_warning3 = -storage=100%% quota-warning below %u # user is no longer over quota

}

service quota-warning {
  executable = script /opt/extra-script/quota-warning.sh
  user = root
  unix_listener quota-warning {
        user = root
        mode = 0600
  }
}

then I created the /opt/extra-script/quota-warning.sh, chmodding it to 755

#!/bin/sh
PERCENT=$1
USER=$2
cat << EOF | /usr/libexec/dovecot/dovecot-lda -d $USER -o "plugin/quota=maildir:User quota:noenforcing"
From: noreply@domain.it
Subject: Mailbox piena

La tua casella è piena al $PERCENT%. Cancellare i messaggi vecchi.
EOF

Unfortunately, this is not working as it should, since I'm not receiving any message on a test mail box of 1MB full at 95% (and the limit in my 30-overquota.conf was set at 50% on line 5).

Can anyone help me to configure properly the service? here follows the dovecot -n output which, as far as I can understand, confirms my extra config is included in the running service (but without any desired effect)

root@centos1670:~# dovecot -n
# 2.2.18: /etc/dovecot/dovecot.conf
# Pigeonhole version 0.4.8 (0c4ae064f307+)
# OS: Linux 2.6.32-642.15.1.el6.x86_64 x86_64 CentOS release 6.8 (Final) ext3
auth_mechanisms = plain login digest-md5 cram-md5 apop
auth_username_chars = abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890&.-_@'
disable_plaintext_auth = no
first_valid_uid = 30
imap_client_workarounds = delay-newmail
imap_logout_format = rcvd=%i, sent=%o
mail_home = /var/qmail/mailnames/%Ld/%Ln
mail_location = maildir:/var/qmail/mailnames/%Ld/%Ln/Maildir
mail_log_prefix = "service=%s, user=%u, ip=[%r]. "
mail_plugins = " quota"
managesieve_logout_format = rcvd=%i, sent=%o
managesieve_notify_capability = mailto
managesieve_sieve_capability = fileinto reject envelope encoded-character vacation subaddress comparator-i;ascii-numeric relational regex imap4flags copy include variables body enotify environment mailbox date index ihave duplicate imapflags notify
namespace inbox {
  inbox = yes
  location = 
  prefix = INBOX.
  separator = .
}
passdb {
  driver = plesk
}
plugin {
  quota = dict:user::file:/var/vmail/%d/%n/.quotausage
  quota_grace = 0
  quota_warning = storage=50%% quota-warning 50 %u
  quota_warning2 = storage=80%% quota-warning 80 %u
  quota_warning3 = -storage=100%% quota-warning below %u
  sieve = ~/.dovecot.sieve
  sieve_dir = ~/sieve
  sieve_extensions = +notify +imapflags
}
pop3_client_workarounds = outlook-no-nuls oe-ns-eoh
pop3_logout_format = rcvd=%i, sent=%o, top=%t/%p, retr=%r/%b, del=%d/%m, size=%s
protocols = imap pop3 sieve
service auth-worker {
  group = 
  user = 
}
service auth {
  group = 
  unix_listener auth-userdb {
    group = popuser
    mode = 0600
    user = popuser
  }
  user = 
}
service quota-warning {
  executable = script /opt/extra-script/quota-warning.sh
  unix_listener quota-warning {
    mode = 0600
    user = root
  }
  user = root
}
ssl_cert = </etc/dovecot/private/ssl-cert-and-key.pem
ssl_key = </etc/dovecot/private/ssl-cert-and-key.pem
userdb {
  args = uid=popuser gid=popuser
  driver = static
}
protocol imap {
  mail_plugins = " quota imap_quota"
}
protocol pop3 {
  pop3_uidl_format = UID%u-%v
}
protocol lda {
  mail_plugins = " quota sieve"
}

edit: as suggested by Jens Erat, root@centos1670:~# doveadm quota get actually produces the following output:

Quota name Type Value Limit %
user STORAGE 0 - 0
user MESSAGE 0 - 0

This seems to denote a defective configuration which might be fixed adding something like quota_rule = *:storage=1GB and enforcing quota recalculation. The problem in doing this is that the Dovecot setup I'm asking about is running under Plesk in which is possible to set different mailbox sizes per user, so the possibility to define the value for quota_rule in a parametric way would be appreciated.

  • 1
    Run manually quota-warning.sh 90 user@domain and see what happened. – Kondybas May 8 '17 at 10:02
  • great, your suggestion reveals that when called the script works as expected (I can receive the warning via email), so it seems the problem is that dovecot is not considering quota at all. Thanks again for your suggestion. – funkoolow May 8 '17 at 18:00
  • 1
    Now I realized that you seem to be missing a quota rule, something like ` quota_rule = *:storage=1GB`. Afterwards, enforce quota recalculation. Generally, I'd prefer the rather good Dovecot wiki for documentation. – Jens Erat May 8 '17 at 20:58
  • thanks, and what if the mailbox size is different for each user, since my dovecot runs via plesk under which is possible to set different maxsize per mailbox? in other words, can you also propose a way to make the storage value parametric? thanks again – funkoolow May 8 '17 at 22:57
  • 1
    You have to configure per-user quota in the user database driver. You will have to query the Plesk manual for how to do this. – Jens Erat May 9 '17 at 15:23
1

Dovecot only adds new changes to the user's quota usage unless explicitly asked to recalculate quota (which is an operation that might require quite some time for large user bases and mailboxes). So if you haven't enforced a quota recalculation, Dovecot might not be aware mailboxes passed the quota limit.

Use doveadm quota get to get a dump of the current quota database; doveadm quota recalc enforces quota recalculation.

| improve this answer | |
  • thanks for your answer, this is the output of the command you suggested: root@centos1670:~# doveadm quota get Quota name Type Value Limit % user STORAGE 0 - 0 user MESSAGE 0 - 0 I suppose this means that quote is not properly working (also tried "quota recalc" but result is the same), can you please confirm? - and sorry for code paging, it's impossible to do better than that commenting – funkoolow May 8 '17 at 17:54
  • Edit your question instead if you have additional information. Better formatting and keeps all relevant information together. – Jens Erat May 8 '17 at 20:51
1

Your problem is caused by wrong quota source definition.

Dovecot haven't passdb driver plesk at all. Possible drivers are: passwd, passwd-file, ldap, sql, dict and vpopmail. You have to refer to the plesk configuration and find out what kind of passdb is used by plesk. Then you have to add a corresponding lines to your dovecot config.

In general configuration for dovecot's quota should look like that:

quota           = maildir:User quota
quota_rule      = Junk:ignore
quota_rule2     = Trash:storage=+100M
quota_warning   = storage=90%% quota-warning 90 %u %d
quota_warning2  = storage=80%% quota-warning 80 %u %d
quota_exceeded_message = ERROR:422 - Mailbox full 

Here per-user quota is associated with user's credentials and stored along with login/pass and storage location in the same place. When dovecot's deliver refer to the passdb, it retreive the quota limit as well and compare it with actual mailbox size.

N.B.

Also you can notice that notification script quota-warning have three arguments instead of two - I've pass username and domain separately because multiple domains are served by one dovecot and few different domains may have the same users like webmaster or abuse. Having passed exact localpart and domain, dovecot can avoid ambiguation and store message in the correct mailbox.

| improve this answer | |
  • After some testing, it seems that quota about mailboxes on my machine is set via Plesk through SQL (it is possible to obtain infos on mailboxes via a standard query as reported on talk.plesk.com/threads/… ), this means that I have to amend the line quota = dict:user::file:/var/vmail/%d/%n/.quotausage setting it to use the SQL driver on the plugin section of my extra config reported in the question? – funkoolow May 11 '17 at 8:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.