From cda1d3b20cae212570f1ff79c95abcb8100c23cb Mon Sep 17 00:00:00 2001
From: Jesse Norell <jesse@kci.net>
Date: Wed, 9 Oct 2019 16:37:36 -0600
Subject: [PATCH] implement dovecot quota-status policy daemon (#4649)

---
 install/sql/incremental/upd_dev_collection.sql |  3 +++
 install/sql/ispconfig3.sql                     |  1 +
 install/tpl/debian6_dovecot2.conf.master       | 15 +++++++++++++++
 install/tpl/debian_dovecot2.conf.master        | 15 +++++++++++++++
 install/tpl/debian_postfix.conf.master         |  3 ++-
 install/tpl/fedora_dovecot2.conf.master        | 15 +++++++++++++++
 install/tpl/fedora_postfix.conf.master         |  3 ++-
 install/tpl/gentoo_postfix.conf.master         |  3 ++-
 install/tpl/master_cf_amavis10025.master       |  1 +
 install/tpl/master_cf_amavis10027.master       |  1 +
 install/tpl/opensuse_dovecot2.conf.master      | 15 +++++++++++++++
 install/tpl/opensuse_postfix.conf.master       |  3 ++-
 12 files changed, 74 insertions(+), 4 deletions(-)

diff --git a/install/sql/incremental/upd_dev_collection.sql b/install/sql/incremental/upd_dev_collection.sql
index 659708c685..91db879d0c 100644
--- a/install/sql/incremental/upd_dev_collection.sql
+++ b/install/sql/incremental/upd_dev_collection.sql
@@ -26,3 +26,6 @@ ALTER TABLE `mail_user`
 
 -- doveadm should be enabled for all mailboxes
 UPDATE `mail_user` set `disabledoveadm` = 'n';
+
+-- add disablequota-status for quota-status policy daemon
+ALTER TABLE `mail_user` ADD `disablequota-status` ENUM('n','y') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'n' AFTER `disabledoveadm`;
diff --git a/install/sql/ispconfig3.sql b/install/sql/ispconfig3.sql
index 4965358bc6..cc266ff235 100644
--- a/install/sql/ispconfig3.sql
+++ b/install/sql/ispconfig3.sql
@@ -1062,6 +1062,7 @@ CREATE TABLE `mail_user` (
   `disablelda` enum('n','y') NOT NULL default 'n',
   `disablelmtp` enum('n','y') NOT NULL default 'n',
   `disabledoveadm` enum('n','y') NOT NULL default 'n',
+  `disablequota-status` enum('n','y') NOT NULL default 'n',
   `last_quota_notification` date NULL default NULL,
   `backup_interval` VARCHAR( 255 ) NOT NULL default 'none',
   `backup_copies` INT NOT NULL DEFAULT '1',
diff --git a/install/tpl/debian6_dovecot2.conf.master b/install/tpl/debian6_dovecot2.conf.master
index 76d168cd7d..1f51f23ad3 100644
--- a/install/tpl/debian6_dovecot2.conf.master
+++ b/install/tpl/debian6_dovecot2.conf.master
@@ -85,6 +85,21 @@ protocol lmtp {
 #2.3+     }
 #2.3+ }
 
+service quota-status {
+  executable = quota-status -p postfix
+  inet_listener {
+    # separate multiple addresses with space:
+    address = 127.0.0.1
+    port = 10060
+  }
+  client_limit = 1
+}
+plugin {
+  quota_status_success = DUNNO
+  quota_status_nouser = DUNNO
+  quota_status_overquota = "552 5.2.2 Mailbox is full"
+}
+
 imap_capability=+SEPCIAL-USE XLIST
 namespace inbox {
   inbox = yes
diff --git a/install/tpl/debian_dovecot2.conf.master b/install/tpl/debian_dovecot2.conf.master
index 24bf07393f..b71ede7534 100644
--- a/install/tpl/debian_dovecot2.conf.master
+++ b/install/tpl/debian_dovecot2.conf.master
@@ -81,3 +81,18 @@ protocol lmtp {
 #2.3+         mode = 0660
 #2.3+     }
 #2.3+ }
+
+service quota-status {
+  executable = quota-status -p postfix
+  inet_listener {
+    # separate multiple addresses with space:
+    address = 127.0.0.1
+    port = 10060
+  }
+  client_limit = 1
+}
+plugin {
+  quota_status_success = DUNNO
+  quota_status_nouser = DUNNO
+  quota_status_overquota = "552 5.2.2 Mailbox is full"
+}
diff --git a/install/tpl/debian_postfix.conf.master b/install/tpl/debian_postfix.conf.master
index b7dbea6300..4d03dfd005 100644
--- a/install/tpl/debian_postfix.conf.master
+++ b/install/tpl/debian_postfix.conf.master
@@ -15,7 +15,8 @@ broken_sasl_auth_clients = yes
 smtpd_sasl_authenticated_header = yes
 smtpd_restriction_classes = greylisting
 greylisting = check_policy_service inet:127.0.0.1:10023 
-smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination{rbl_list}, check_recipient_access mysql:{config_dir}/mysql-virtual_recipient.cf{greylisting}
+smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination{rbl_list}, check_recipient_access mysql:{config_dir}/mysql-virtual_recipient.cf{greylisting}, check_policy_service inet:127.0.0.1:10060
+smtpd_end_of_data_restrictions = check_policy_service inet:127.0.0.1:10060
 smtpd_use_tls = yes
 smtpd_tls_security_level = may
 smtpd_tls_cert_file = {config_dir}/smtpd.cert
diff --git a/install/tpl/fedora_dovecot2.conf.master b/install/tpl/fedora_dovecot2.conf.master
index 56d304a761..9115404d9f 100644
--- a/install/tpl/fedora_dovecot2.conf.master
+++ b/install/tpl/fedora_dovecot2.conf.master
@@ -80,6 +80,21 @@ mail_plugins = $mail_plugins quota
 #2.3+     }
 #2.3+ }
 
+service quota-status {
+  executable = quota-status -p postfix
+  inet_listener {
+    # separate multiple addresses with space:
+    address = 127.0.0.1
+    port = 10060
+  }
+  client_limit = 1
+}
+plugin {
+  quota_status_success = DUNNO
+  quota_status_nouser = DUNNO
+  quota_status_overquota = "552 5.2.2 Mailbox is full"
+}
+
 imap_capability=+SEPCIAL-USE XLIST
 namespace inbox {
   inbox = yes
diff --git a/install/tpl/fedora_postfix.conf.master b/install/tpl/fedora_postfix.conf.master
index f06af82288..8bda2b7dcc 100644
--- a/install/tpl/fedora_postfix.conf.master
+++ b/install/tpl/fedora_postfix.conf.master
@@ -11,7 +11,8 @@ broken_sasl_auth_clients = yes
 smtpd_sasl_authenticated_header = yes
 smtpd_restriction_classes = greylisting
 greylisting = check_policy_service inet:127.0.0.1:10023
-smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination{rbl_list}, check_recipient_access mysql:{config_dir}/mysql-virtual_recipient.cf{greylisting}
+smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination{rbl_list}, check_recipient_access mysql:{config_dir}/mysql-virtual_recipient.cf{greylisting}, check_policy_service inet:127.0.0.1:10060
+smtpd_end_of_data_restrictions = check_policy_service inet:127.0.0.1:10060
 smtpd_use_tls = yes
 smtpd_tls_security_level = may
 smtpd_tls_cert_file = {config_dir}/smtpd.cert
diff --git a/install/tpl/gentoo_postfix.conf.master b/install/tpl/gentoo_postfix.conf.master
index dc20e02c13..79a9dcd63d 100644
--- a/install/tpl/gentoo_postfix.conf.master
+++ b/install/tpl/gentoo_postfix.conf.master
@@ -10,7 +10,8 @@ broken_sasl_auth_clients = yes
 smtpd_sasl_authenticated_header = yes
 smtpd_restriction_classes = greylisting
 greylisting = check_policy_service inet:127.0.0.1:10023
-smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination{rbl_list}, check_recipient_access mysql:{config_dir}/mysql-virtual_recipient.cf{greylisting}
+smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination{rbl_list}, check_recipient_access mysql:{config_dir}/mysql-virtual_recipient.cf{greylisting}, check_policy_service inet:127.0.0.1:10060
+smtpd_end_of_data_restrictions = check_policy_service inet:127.0.0.1:10060
 smtpd_use_tls = yes
 smtpd_tls_security_level = may
 smtpd_tls_cert_file = {config_dir}/smtpd.cert
diff --git a/install/tpl/master_cf_amavis10025.master b/install/tpl/master_cf_amavis10025.master
index 43f362d5c0..6dee892264 100644
--- a/install/tpl/master_cf_amavis10025.master
+++ b/install/tpl/master_cf_amavis10025.master
@@ -8,6 +8,7 @@
         -o smtpd_helo_restrictions=
         -o smtpd_sender_restrictions=
         -o smtpd_recipient_restrictions=permit_mynetworks,reject
+        -o smtpd_end_of_data_restrictions=
         -o mynetworks=127.0.0.0/8
         -o strict_rfc821_envelopes=yes
         -o receive_override_options=no_unknown_recipient_checks,no_header_body_checks
diff --git a/install/tpl/master_cf_amavis10027.master b/install/tpl/master_cf_amavis10027.master
index f9fdf1cf60..640902d52e 100644
--- a/install/tpl/master_cf_amavis10027.master
+++ b/install/tpl/master_cf_amavis10027.master
@@ -8,6 +8,7 @@
         -o smtpd_helo_restrictions=
         -o smtpd_sender_restrictions=
         -o smtpd_recipient_restrictions=permit_mynetworks,reject
+        -o smtpd_end_of_data_restrictions=
         -o mynetworks=127.0.0.0/8
         -o strict_rfc821_envelopes=yes
         -o receive_override_options=no_unknown_recipient_checks,no_header_body_checks
diff --git a/install/tpl/opensuse_dovecot2.conf.master b/install/tpl/opensuse_dovecot2.conf.master
index d9f29a41e1..7fb51246f9 100644
--- a/install/tpl/opensuse_dovecot2.conf.master
+++ b/install/tpl/opensuse_dovecot2.conf.master
@@ -79,6 +79,21 @@ mail_plugins = $mail_plugins quota
 #2.3+     }
 #2.3+ }
 
+service quota-status {
+  executable = quota-status -p postfix
+  inet_listener {
+    # separate multiple addresses with space:
+    address = 127.0.0.1
+    port = 10060
+  }
+  client_limit = 1
+}
+plugin {
+  quota_status_success = DUNNO
+  quota_status_nouser = DUNNO
+  quota_status_overquota = "552 5.2.2 Mailbox is full"
+}
+
 imap_capability=+SEPCIAL-USE XLIST
 namespace inbox {
   inbox = yes
diff --git a/install/tpl/opensuse_postfix.conf.master b/install/tpl/opensuse_postfix.conf.master
index 4192f988b5..6661bffd98 100644
--- a/install/tpl/opensuse_postfix.conf.master
+++ b/install/tpl/opensuse_postfix.conf.master
@@ -13,7 +13,8 @@ broken_sasl_auth_clients = yes
 smtpd_sasl_authenticated_header = yes
 smtpd_restriction_classes = greylisting
 greylisting = check_policy_service inet:127.0.0.1:10023
-smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination{rbl_list}, check_recipient_access mysql:{config_dir}/mysql-virtual_recipient.cf{greylisting}
+smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination{rbl_list}, check_recipient_access mysql:{config_dir}/mysql-virtual_recipient.cf{greylisting}, check_policy_service inet:127.0.0.1:10060
+smtpd_end_of_data_restrictions = check_policy_service inet:127.0.0.1:10060
 smtpd_use_tls = yes
 smtpd_tls_security_level = may
 smtpd_tls_cert_file = {config_dir}/smtpd.cert
-- 
GitLab