Exim & dovecot user over quota: reject on send

dovecoteximmailboxquota

i have an exim + dovecot mailserver setup with per-user quota (via mysql lookup) running. the server rejects incoming mail from non-local senders when the targeted local mailbox is over quota. the local user can send out mails without restrictions eventho his mailbox is over quota.

i'd prefer the quota to be checked when the local user tries to send an email and return an error like "your account is over quota, please remove some mails first". incoming mails from non-local senders to a local mailbox should be accepted no matter of the quota.

there is a similar configuration described on "Setting up exim":

acl_check_rcpt:
#...
  # Deny sending for local users if almost at quota
        # only run for local domains
  deny  sender_domains = +local_domains
        # list all addresses that are aliases
        # though people shouldn't be sending as
        # them, many scripts do
        !senders = ^postmaster@.*:\
                   ^root@.*:\
                   ^webmaster@.*:\
                   ^error-.*@.*:\
                   ^bounce-.*@.*
        # might need to exclude webmail server here
        # if it does not report the error message
        # note: squirrelmail tested ok for me
        hosts = +local_hosts
        # verify your email client expunges on emptying the trash
        message = You have too much email stored. Please delete some\n\
                  and empty the trash. Then you can send.
        log_message = $sender_address_local_part is over send quota
        condition = ${run{sudo -u root /etc/exim/check-sendquota.sh $sender_address_local_part}{no}{yes}}

it uses a custom script to check the mailbox size – for performance reasons i'd rather use the already existing quota files/system, but i can't figure out the correct "condition" line. i can't see from the current config where exim actually checks for the mailbox size. the current config contains among other things:

exim4.conf:

local_delivery:
    driver = appendfile
    maildir_format
    user = mailserv
    group = mailserv
    mode = 0660
    mode_fail_narrower = false
    envelope_to_add = true
    return_path_add = true
    maildir_tag = ,S=$message_size
    quota_size_regex = ,S=(\d+)
    quota =  ${lookup mysql{SELECT CONCAT(quota, "M") FROM users WHERE account='${local_part}@${domain}'}{$value}{7M}}
    directory = ${lookup mysql{SELECT maildir FROM users WHERE account='${local_part}@${domain}'}}

dovecot.conf:

protocol imap {
    mail_plugins = quota imap_quota
}
plugin {
    quota = maildir:user
    quota_rule = *:storage=5GB
}

Best Answer

You need to add a similar quota check to your acl_not_smtp acl, this acl is used for all none smtp mail submitted by local users / processes

http://www.exim.org/exim-html-current/doc/html/spec_html/ch40.html