User Tools

Site Tools


start:howto:dovecot_plus_database_quota

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
start:howto:dovecot_plus_database_quota [2012/01/09 11:51]
aseques
start:howto:dovecot_plus_database_quota [2012/01/09 13:58]
aseques
Line 1: Line 1:
-**__ALERT: This is a document being rewritten, only experienced people should use this__**+**__ALERT: This document ​is currently ​being rewritten, only experienced people should use this__**
  
 ====== Dovecot modifications from default imscp install ====== ====== Dovecot modifications from default imscp install ======
Line 30: Line 30:
 You can do it by re-running the installer and changing the default imap server when asked you can choose between courier or dovecot. You can do it by re-running the installer and changing the default imap server when asked you can choose between courier or dovecot.
  
 +===== Optional features =====
  
-==== 1. Create a new table in ispcp called quota_dovecot ​====+==== Sieve filtering ==== 
 + 
 +Create the sieve script to redirect spam to junk folder 
 +**/​etc/​dovecot/​sieve/​dovecot.sieve**  
 +If you have a spam filter such as amavis, it will add the header "​X-Spam-Flag = yes", with this little sieve script all this mail will go to Junk folder (can be seen both in webmail or any IMAP client). It's really usefull because all the users can check their own spam without the need of the server admin. 
 + 
 +  mkdir /​etc/​dovecot/​sieve 
 +  chown -R vmail:mail /​etc/​dovecot/​sieve/​ 
 +  touch /​etc/​dovecot/​sieve/​dovecot.sieve 
 + 
 +  require "​fileinto";​ 
 +    if exists "​X-Spam-Flag"​ { 
 +            if header :contains "​X-Spam-Flag"​ "​NO"​ { 
 +            } else { 
 +            fileinto "​INBOX.Junk";​ 
 +            stop; 
 +            } 
 +    } 
 + 
 + 
 +Set correct permissions for dovecot.conf (the deliver command will access this file too) 
 + 
 +  chmod 0644 /​etc/​dovecot/​dovecot.conf 
 + 
 +==== Use domain alias as mail alias too ==== 
 + 
 +Making a small change in postfix configuration,​ we can use the domain alias as a mail ailas. 
 +Being example2.com an alias of example1.com,​ whenever I create a mailbox in example1.com the same mailbox in example2.com becomes a redirection. 
 +So creating [email protected] will also receive the mail from [email protected] automatically. 
 + 
 +/​etc/​postfix/​mysql_virtual_domains.cf 
 +<​code>​ 
 +user = ispcp_dovecot 
 +password = PASS_MAILRW 
 +hosts = 127.0.0.1 
 +dbname = ispcp 
 +query = (SELECT domain_name FROM domain_aliasses 
 +                INNER JOIN domain ​ ON domain_aliasses.domain_id=domain.domain_id  
 +                WHERE domain.domain_status='​ok'​ 
 +                        AND domain.domain_mailacc_limit > '​-1'​ 
 +                        AND domain_aliasses.alias_name='​%s'​) 
 +        UNION 
 +        (SELECT domain_name FROM domain 
 +                WHERE domain.domain_status='​ok'​ 
 +                        AND domain.domain_mailacc_limit > '​-1'​ 
 +                        AND domain_name='​%s'​) 
 +</​code>​ 
 + 
 + 
 +/​etc/​postfix/​mysql_virtual_forwards.cf 
 +<​code>​ 
 +user = ispcp_dovecot 
 +password = PASS_MAILRW 
 +hosts = 127.0.0.1 
 +dbname = ispcp 
 +query = 
 +        SELECT DISTINCT CONCAT(CONCAT(mail_users.mail_acc,​ "​@"​),​ domain.domain_name) from mail_users 
 +        INNER JOIN domain ON mail_users.domain_id = domain.domain_id 
 +        INNER JOIN domain_aliasses ON domain.domain_id = domain_aliasses.domain_id 
 +        WHERE domain_aliasses.alias_name = '​%d'​ AND mail_users.mail_acc = '​%u'​ 
 +</​code>​ 
 + 
 +==== Automatically alert user if his quota exceeds a critical limit ==== 
 +You can configure Dovecot to execute an external command if an user's quota exceeds a specified limit. In this example the user receives alert emails if his quota exceeds 80% / 95% percent. 
 + 
 +Append the following in your plugin section in **/​etc/​dovecot/​dovecot.conf**:​ 
 + 
 +  quota_warning = storage=95%% /​usr/​local/​bin/​dovecot-quota-warning.sh 95 
 +  quota_warning2 = storage=80%% /​usr/​local/​bin/​dovecot-quota-warning.sh 80 
 + 
 +If the user's quota reaches the limit the external script dovecot-quota-warning.sh is run. If you define quota warnings make sure that you start with the highest limit because Dovecot only runs the command for the first limit that is exceeded. 
 + 
 +Create **/​usr/​local/​bin/​dovecot-quota-warning.sh** 
 +<​code>​ 
 +#!/bin/sh 
 +PERCENT=$1 
 +cat << EOF | /​usr/​lib/​dovecot/​deliver -d $USER -c /​etc/​dovecot/​dovecot-no-quota-warning.conf 
 +From: [email protected] 
 +To: $USER 
 +Subject: quota warning 
 +Content-Type:​ text/plain; charset="​UTF-8"​ 
 + 
 +Attention! The emails in your mailbox are using more than $PERCENT% of your total mail space. 
 +EOF 
 +</​code>​ 
 + 
 +Create **/​etc/​dovecot/​dovecot-no-quota-warning.conf** \\ 
 +This is basically the same file as dovecot.conf but the quota rules are stripped out in order to avoid looping. You can strip the quota lines manually or let it grep do for you: 
 +  grep -v "​quota"​ dovecot.conf > dovecot-no-quota-warning.conf 
 + 
 +At last set correct permissions to dovecot-no-quota-warning.conf 
 +  chmod 0644 /​etc/​dovecot/​dovecot-no-quota-warning.conf 
 + 
 +For more information about this have a look at http://​wiki.dovecot.org/​Quota/​1.1 
 + 
 +===== Frequent issues ===== 
 +==== Adapt postfix master.cf ==== 
 + 
 +The parameters for master.cf in postfix need to be changed according the architecture of the system: 
 + 
 +**for Debian Squeeze (dovecot >= 1.2)** 
 +  dovecot ​  ​unix ​ -       ​n ​      ​n ​      ​- ​      ​- ​      ​pipe 
 +    flags=DRhu user=vmail argv=/​usr/​lib/​dovecot/​deliver -d ${recipient} -s 
 + 
 +**for Debian Lenny (dovecot >= 1.0.15)** 
 +  dovecot unix - n n - - pipe 
 +    flags=DROhu user=vmail:​mail argv=/​usr/​lib/​dovecot/​deliver -f ${sender} -d ${recipient} -s 
 + 
 +**for *BSD dovecot from port** 
 +  dovecot unix - n n - - pipe 
 +    flags=DROhu user=vmail:​mail argv=/​usr/​local/​libexec/​dovecot/​deliver -f ${sender} -d ${recipient} -s 
 + 
 +**for CentOS it should be something like this:** 
 +  dovecot unix - n n - - pipe 
 +    flags=DROhu user=vmail:​mail argv=/​usr/​libexec/​dovecot/​deliver -f ${sender} -d ${recipient} 
 + 
 +===== Older documentation ===== 
 + 
 + 
 +=== 1. Create a new table in ispcp called quota_dovecot ===
  
 This will create also the database to store quota This will create also the database to store quota
Line 43: Line 163:
     );     );
   ​   ​
-==== 2. Granting permissions to the sql user ====+=== 2. Granting permissions to the sql user ===
  
   mysql> GRANT SELECT,​INSERT,​UPDATE ON imscp.quota_dovecot to '​ispcp_dovecot'​@'​localhost'​   mysql> GRANT SELECT,​INSERT,​UPDATE ON imscp.quota_dovecot to '​ispcp_dovecot'​@'​localhost'​
Line 49: Line 169:
   mysql> QUIT;   mysql> QUIT;
  
-==== 4. Configure Dovecot ​====+=== 4. Configure Dovecot ===
  
 Replace /​etc/​dovecot/​dovecot.conf with the following one (you should backup the original because there are a lot of comments in it explaining all the configuration parameters). Replace /​etc/​dovecot/​dovecot.conf with the following one (you should backup the original because there are a lot of comments in it explaining all the configuration parameters).
Line 215: Line 335:
 } }
 </​code>​ </​code>​
- 
- 
-Create the sieve script to redirect spam to junk folder 
-**/​etc/​dovecot/​sieve/​dovecot.sieve** ​ 
-If you have a spam filter such as amavis, it will add the header "​X-Spam-Flag = yes", with this little sieve all this mail will go to Junk folder in webmail. Very practical because all the users can check their own spam without the need of the server admin. 
- 
-  mkdir /​etc/​dovecot/​sieve 
-  chown -R vmail:mail /​etc/​dovecot/​sieve/​ 
-  touch /​etc/​dovecot/​sieve/​dovecot.sieve 
- 
-  require "​fileinto";​ 
-    if exists "​X-Spam-Flag"​ { 
-            if header :contains "​X-Spam-Flag"​ "​NO"​ { 
-            } else { 
-            fileinto "​INBOX.Junk";​ 
-            stop; 
-            } 
-    } 
- 
- 
-Set correct permissions for dovecot.conf (the deliver command accesses this file too) 
- 
-  chmod 0644 /​etc/​dovecot/​dovecot.conf 
- 
-==== 5. Configure Postfix ==== 
- 
-Change parameters in /​etc/​postfix/​main.cf:​ 
- 
-  smtpd_sasl_type = dovecot 
-  smtpd_sasl_path = private/​auth 
-  smtpd_sasl_auth_enable = yes 
-  #​smtpd_sasl2_auth_enable = yes 
-  smtpd_sasl_security_options = noanonymous 
-  #​smtpd_sasl_local_domain = 
-  broken_sasl_auth_clients = yes 
-  ​ 
-  virtual_transport = dovecot 
-  dovecot_destination_recipient_limit = 1 
- 
-Add the following line to /​etc/​postfix/​master.cf:​ 
- 
-**for Debian Lenny (dovecot >= 1.0.15)** 
-<​code>​ 
-dovecot unix - n n - - pipe 
-  flags=DROhu user=vmail:​mail argv=/​usr/​lib/​dovecot/​deliver -f ${sender} -d ${recipient} -s 
-</​code>​ 
- 
-**for *BSD dovecot from port** 
-<​code>​ 
-dovecot unix - n n - - pipe 
-  flags=DROhu user=vmail:​mail argv=/​usr/​local/​libexec/​dovecot/​deliver -f ${sender} -d ${recipient} -s 
-</​code>​ 
- 
-**for CentOS it should be something like this:** 
-<​code>​ 
-dovecot unix - n n - - pipe 
-  flags=DROhu user=vmail:​mail argv=/​usr/​libexec/​dovecot/​deliver -f ${sender} -d ${recipient} 
-</​code>​ 
- 
-==== 7. Enable SSL support ==== 
- 
-If you don't want SSL support you can skip this step. 
-Otherwise, you have to uncomment the appropiate lines in dovecot.conf:​ 
- 
-  protocols = imap pop3 imaps pop3s 
-  #Dovecot 1.2+ (i.e *BSD ports) 
-  ssl = yes 
-  # 
-  #​Certificate location 
-  ssl_cert_file = /​etc/​ssl/​certs/​servername.crt 
-  ssl_key_file = /​etc/​ssl/​certs/​servername.key 
- 
-=== Generate your SSL certificates === 
- 
-You can follow the tutorial here to get a certificate that you can use also for apache, postfix, etc. 
-http://​isp-control.net/​documentation/​doku.php?​id=howto:​security:​ssl_made_easy 
- 
-==== 8. Start services ==== 
- 
-  /​etc/​init.d/​dovecot start 
-  /​etc/​init.d/​postfix restart 
- 
-==== 9. Test the whole thing and remove Courier ==== 
- 
-If everything works as expected you can remove Courier. 
-Remove all startup links. 
- 
-  update-rc.d -f courier-imap remove 
-  update-rc.d -f courier-pop remove 
-  update-rc.d -f courier-authdaemon remove 
-  update-rc.d -f saslauthd remove 
- 
-Remove all courier packages. 
- 
-  apt-get remove courier-base courier-authdaemon courier-maildrop 
- 
-**Don'​t forget to disable makeuserdb and Courier services:** 
- 
-In file ''/​etc/​ispcp/​ispcp.conf'':​ 
- 
-Old values (Debian): 
-  CMD_MAKEUSERDB = /​usr/​sbin/​makeuserdb 
-  CMD_AUTHD = /​etc/​init.d/​courier-authdaemon 
-  CMD_IMAP = /​etc/​init.d/​courier-imap 
-  CMD_IMAP_SSL = /​etc/​init.d/​courier-imap-ssl 
-  CMD_POP = /​etc/​init.d/​courier-pop 
-  CMD_POP_SSL = /​etc/​init.d/​courier-pop-ssl 
- 
-New values: 
-  CMD_MAKEUSERDB = /bin/true 
-  CMD_AUTHD = /bin/true 
-  CMD_IMAP = /bin/true 
-  CMD_IMAP_SSL = /bin/true 
-  CMD_POP = /bin/true 
-  CMD_POP_SSL = /bin/true 
- 
-As Dovecot reads users directly out of the database, there'​s no need to restart it if something changes, but ispCP needs something to execute which returns an exit code of 0. That's why we use /bin/true which always return 0. 
- 
-==== 10. That's it ==== 
- 
-You have successfully replaced Courier with Dovecot. The next steps are optional. 
- 
-===== Optional features ===== 
-==== Use domain alias as mail alias too ==== 
-Making a small change in postfix configuration,​ we can use the domain alias as a mail ailas. 
-Being example2.com an alias of example1.com,​ whenever I create a mailbox in example1.com the same mailbox in example2.com becomes a redirection. 
-So creating [email protected] will also receive the mail from [email protected] automatically. 
- 
-/​etc/​postfix/​mysql_virtual_domains.cf 
-<​code>​ 
-user = ispcp_dovecot 
-password = PASS_MAILRW 
-hosts = 127.0.0.1 
-dbname = ispcp 
-query = (SELECT domain_name FROM domain_aliasses 
-                INNER JOIN domain ​ ON domain_aliasses.domain_id=domain.domain_id ​ 
-                WHERE domain.domain_status='​ok'​ 
-                        AND domain.domain_mailacc_limit > '​-1'​ 
-                        AND domain_aliasses.alias_name='​%s'​) 
-        UNION 
-        (SELECT domain_name FROM domain 
-                WHERE domain.domain_status='​ok'​ 
-                        AND domain.domain_mailacc_limit > '​-1'​ 
-                        AND domain_name='​%s'​) 
-</​code>​ 
- 
- 
-/​etc/​postfix/​mysql_virtual_forwards.cf 
-<​code>​ 
-user = ispcp_dovecot 
-password = PASS_MAILRW 
-hosts = 127.0.0.1 
-dbname = ispcp 
-query = 
-        SELECT DISTINCT CONCAT(CONCAT(mail_users.mail_acc,​ "​@"​),​ domain.domain_name) from mail_users 
-        INNER JOIN domain ON mail_users.domain_id = domain.domain_id 
-        INNER JOIN domain_aliasses ON domain.domain_id = domain_aliasses.domain_id 
-        WHERE domain_aliasses.alias_name = '​%d'​ AND mail_users.mail_acc = '​%u'​ 
-</​code>​ 
- 
-==== Automatically alert user if his quota exceeds a critical limit ==== 
-You can configure Dovecot to execute an external command if an user's quota exceeds a specified limit. In this example the user receives alert emails if his quota exceeds 80% / 95% percent. 
- 
-Append the following in your plugin section in **/​etc/​dovecot/​dovecot.conf**:​ 
- 
-  quota_warning = storage=95%% /​usr/​local/​bin/​dovecot-quota-warning.sh 95 
-  quota_warning2 = storage=80%% /​usr/​local/​bin/​dovecot-quota-warning.sh 80 
- 
-If the user's quota reaches the limit the external script dovecot-quota-warning.sh is run. If you define quota warnings make sure that you start with the highest limit because Dovecot only runs the command for the first limit that is exceeded. 
- 
-Create **/​usr/​local/​bin/​dovecot-quota-warning.sh** 
-<​code>​ 
-#!/bin/sh 
-PERCENT=$1 
-cat << EOF | /​usr/​lib/​dovecot/​deliver -d $USER -c /​etc/​dovecot/​dovecot-no-quota-warning.conf 
-From: [email protected] 
-To: $USER 
-Subject: quota warning 
-Content-Type:​ text/plain; charset="​UTF-8"​ 
- 
-Attention! The emails in your mailbox are using more than $PERCENT% of your total mail space. 
-EOF 
-</​code>​ 
- 
-Create **/​etc/​dovecot/​dovecot-no-quota-warning.conf** \\ 
-This is basically the same file as dovecot.conf but the quota rules are stripped out in order to avoid looping. You can strip the quota lines manually or let it grep do for you: 
-  grep -v "​quota"​ dovecot.conf > dovecot-no-quota-warning.conf 
- 
-At last set correct permissions to dovecot-no-quota-warning.conf 
-  chmod 0644 /​etc/​dovecot/​dovecot-no-quota-warning.conf 
- 
-For more information about this have a look at http://​wiki.dovecot.org/​Quota/​1.1 
/var/www/virtual/i-mscp.net/wiki/htdocs/data/pages/start/howto/dovecot_plus_database_quota.txt · Last modified: 2013/06/21 07:36 by aseques