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
start:howto:dovecot_plus_database_quota [2012/01/10 08:46]
aseques
start:howto:dovecot_plus_database_quota [2013/06/21 07:36] (current)
aseques removed the subdomain part since it didn't work and isn't of much interest
Line 1: Line 1:
-**__ALERT: This document is currently being rewritten, only experienced people should use this__** +===== Email modifications from default imscp install =====
- +
-===== Dovecot ​modifications from default imscp install =====+
 This is an improved version from the original article in ispcp (http://​isp-control.net/​documentation/​howto:​mail:​replace_courier_with_dovecot) This is an improved version from the original article in ispcp (http://​isp-control.net/​documentation/​howto:​mail:​replace_courier_with_dovecot)
-All the parts related to the default install ​where removed since imscp already takes care of thatand it'​s ​focused to add the functionality that is available only on dovecot (instead of courier). +The default install ​suits most of the needsso this document is focused to add some functionality that is available only on dovecot (not always in courier). 
-The required dovecot version is now 1.2 (squeeze'​s default)+The required dovecot version is now 1.2 (squeeze'​s default) ​or newer.
  
-===== Changes from standard ​dovecot ​in imscp ===== +==== Changes from standard ​mail setup in imscp ==== 
-  * Alias and subdomains ​can be used as a full mail domains +  * Alias can be used as a full mail domains 
-  * Warning users that are overquota+  * Global sieve filtering (already enabled by default but without config)
  
-===== Reasons to use dovecot ​=====+==== Reasons to use dovecot ====
  
   * You can do server-side filtering with sieve (for example saving spam to junk folder)   * You can do server-side filtering with sieve (for example saving spam to junk folder)
Line 18: Line 16:
   * You can block users after they are exceeding their quotas.   * You can block users after they are exceeding their quotas.
   * Dovecot is really fast and reliable   * Dovecot is really fast and reliable
 +  * Warning users that are overquota
  
 Please report any bugs/​hints/​whatever in the following board thread: Please report any bugs/​hints/​whatever in the following board thread:
 http://​forum.i-mscp.net/​showthread.php?​tid=61 http://​forum.i-mscp.net/​showthread.php?​tid=61
 +==== Replace Courier with Dovecot ====
  
-**NOTE:** There are currently no means to configure ​the quota for imscp other than fiddling with the database. The functionality from http://​www.isp-control.net/​forum/​thread-8483.html should be imported.+You can do it by re-running ​the installer and changing ​the default imap server when asked you can choose between courier or dovecot.
  
-**NOTE:** If you want to edit the quota directly; it is stored in bytes in the table "​mail_users"​ in a field named "​quota"​. +===== Global sieve filtering ​=====
- +
-===== Replace Courier with 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 =====+Dovecot will look for the global sieve script located in /​etc/​dovecot/​sieve/​dovecot.sieve,​ it can be edited to suit your needs with more functionality. 
 +In the sample below, it moves all the mails tagged as spam to the Junk folder of the mail user:
  
-==== Sieve filtering ====+<​code>​require "​fileinto";​ 
 +if exists "​X-Spam-Flag"​ { 
 + if header :contains "​X-Spam-Flag"​ "​YES"​ { 
 +       ​ fileinto "​INBOX.Junk";​ 
 + stop; 
 +
 +}</​code>​
  
-There is the global script located in /​etc/​dovecot/​sieve/​dovecot.sieve,​ it can be edited to suit your needs with more functionality. 
-In the default install it moves all the mails tagged as spam to the Junk folder of the mail user. 
 More info about sieve syntax and usage: http://​wiki.dovecot.org/​LDA/​Sieve More info about sieve syntax and usage: http://​wiki.dovecot.org/​LDA/​Sieve
  
-==== Use domain alias/​subdomain ​as a mail alias ====+===== Use domain alias as a mail alias =====
  
 By doing a small change in postfix configuration,​ we can use the domain alias as a mail ailas. By doing 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 we create a mailbox in example1.com the same mailbox in example2.com becomes a redirection. Being example2.com an alias of example1.com,​ whenever we 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. That can be used when a customer don't want the hassle of managing two mail domain (and having to set manually every mail address two times). So creating [email protected] will also receive the mail from [email protected] automatically. That can be used when a customer don't want the hassle of managing two mail domain (and having to set manually every mail address two times).
 +
 +
 +==== The changes we have to do in postfix ====
 +
 +In the file main.cf (proposed changes are for the template), from:
 +  virtual_mailbox_domains = hash:​{MTA_VIRTUAL_DMN_HASH}
 +  virtual_alias_maps ​          = hash:​{MTA_VIRTUAL_ALIAS_HASH}
 +
 +To: 
 +
 +  #​virtual_mailbox_domains = hash:​{MTA_VIRTUAL_DMN_HASH}
 +  virtual_mailbox_domains ​     = mysql:/​etc/​postfix/​mysql_virtual_domains.cf
 +  ​
 +  #​virtual_alias_maps ​          = hash:​{MTA_VIRTUAL_ALIAS_HASH}
 +  virtual_alias_maps ​          = hash:​{MTA_VIRTUAL_ALIAS_HASH},​ mysql:/​etc/​postfix/​mysql_virtual_forwards.cf
 +
 +
 +
  
 /​etc/​postfix/​mysql_virtual_domains.cf /​etc/​postfix/​mysql_virtual_domains.cf
Line 53: Line 72:
                 INNER JOIN domain ​ ON domain_aliasses.domain_id=domain.domain_id ​                 INNER JOIN domain ​ ON domain_aliasses.domain_id=domain.domain_id ​
                 WHERE domain.domain_status='​ok'​                 WHERE domain.domain_status='​ok'​
 +                        AND domain_aliasses.alias_status='​ok'​
                         AND domain.domain_mailacc_limit > '​-1'​                         AND domain.domain_mailacc_limit > '​-1'​
                         AND domain_aliasses.alias_name='​%s'​)                         AND domain_aliasses.alias_name='​%s'​)
Line 74: Line 94:
         INNER JOIN domain_aliasses ON domain.domain_id = domain_aliasses.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'​         WHERE domain_aliasses.alias_name = '​%d'​ AND mail_users.mail_acc = '​%u'​
-</​code>​ 
- 
-If you want the subdomains to be able to receive mail create this file: 
-**/​etc/​dovecot/​dovecot-sql-subdomain.conf** ​ 
-with the following content: 
- 
-<​code>​ 
-driver = mysql 
-connect = host=localhost dbname=ispcp user=ispcp_dovecot password=PASS_MAILRW 
-user_query = SELECT CONCAT('/​var/​mail/​virtual/',​ subdomain.subdomain_name,​ "​.",​ domain.domain_name,​ '/',​mail_acc) AS home, '​1001'​ AS uid, '​8'​ AS gid FROM (mail_users INNER JOIN subdomain ON mail_users.sub_id = subdomain.subdomain_id) INNER JOIN domain ON mail_users.domain_id = domain.domain_id WHERE mail_acc='​%n'​ and concat(subdomain.subdomain_name,"​.",​domain.domain_name)='​%d';​ 
 </​code>​ </​code>​
  
Line 93: Line 103:
 <​code>​ <​code>​
 driver = mysql driver = mysql
-connect = host=localhost dbname=ispcp user=ispcp_dovecot ​password=PASS_MAILRW+connect = host=localhost dbname=imscp user=imscp_dovecot ​password=PASS_MAILRW
 user_query = SELECT concat('/​var/​mail/​virtual/',​ domain_aliasses.alias_name,​ '/',​mail_acc) as home, '​1001'​ as uid, '​8'​ as gid FROM (mail_users INNER JOIN domain_aliasses ON mail_users.sub_id = domain_aliasses.alias_id) INNER JOIN domain ON mail_users.domain_id = domain.domain_id WHERE mail_acc='​%n'​ and domain_aliasses.alias_name ='​%d';​ user_query = SELECT concat('/​var/​mail/​virtual/',​ domain_aliasses.alias_name,​ '/',​mail_acc) as home, '​1001'​ as uid, '​8'​ as gid FROM (mail_users INNER JOIN domain_aliasses ON mail_users.sub_id = domain_aliasses.alias_id) INNER JOIN domain ON mail_users.domain_id = domain.domain_id WHERE mail_acc='​%n'​ and domain_aliasses.alias_name ='​%d';​
 </​code>​ </​code>​
Line 105: Line 115:
   }   }
  
-==== Automatically alert user if his quota exceeds a critical limit ==== +===== Deprecated documentation (pending to be purged) =====
-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**+**NOTE:** In the SQL query for user_query there are uids and gids '​hardcoded'​. ​The uid must be the uid of your vmail user and gid the gid of the mail groupMaybe you have to change the defaults (1001/8))
- +
-  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** +
-Give appropiate permissions to the file +
-  chmod 755 /​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 loopingYou 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 ==== ==== Adapt postfix master.cf ====
  
Line 160: Line 138:
   dovecot unix - n n - - pipe   dovecot unix - n n - - pipe
     flags=DROhu user=vmail:​mail argv=/​usr/​libexec/​dovecot/​deliver -f ${sender} -d ${recipient}     flags=DROhu user=vmail:​mail argv=/​usr/​libexec/​dovecot/​deliver -f ${sender} -d ${recipient}
- 
-===== Older documentation (pending to be purged) ===== 
- 
-**NOTE:** In the SQL query for user_query there are uids and gids '​hardcoded'​. The uid must be the uid of your vmail user and gid the gid of the mail group. Maybe you have to change the defaults (1001/8)) 
  
/var/www/virtual/i-mscp.net/wiki/htdocs/data/attic/start/howto/dovecot_plus_database_quota.1326185196.txt.gz · Last modified: 2012/01/10 08:46 by aseques