I recently experimented with a simple bash script, inotifywait and smtpd_recipient_restrictions (check_recipient_access) to map email users who have exceeded the quota.
Well, during testing, i’ve noticed when using hash/texthash lookup tables, it needed to be reloaded in order smtpd detect changes in table.so i’ve made quick test on mysql_tables it seem updating record on tables will immediately able to be queried
Mapping can be done as follows:
main.cf:
1 | smtpd_recipient_restrictions = |
2 | check_recipient_access mysql:/etc/postfix/mysql_quota_access.cf, |
mysql_quota_access.cf
5 | query = SELECT qaction FROM quota WHERE username='%s' |
create mysql table called quota:
2 | id INT NOT NULL AUTO_INCREMENT PRIMARY KEY , |
Here’s the idea, inotifywait will continuously monitor the maildir directory recursively, and updates “qaction” field on “quota” mysql table whenever new mail arrived or whenever there is email deleted from the maildir.
initial map, can be produced by retrieving user information from database.for example, username information in the database “postfixdb” with the table name “mailbox” and field “username”.
With this script,value of qaction field on mysql quota table will change continuously as the user’s maildir contents that keeps changing.