HOWTO: Dovecot 1.2.9 + sieve + quota

Discussion in 'Tips/Tricks/Mods' started by radim_h, May 20, 2010.

  1. radim_h

    radim_h Member

    Hello,

    i spent couple hours tampering with dovecot 1.2.9 on Ubuntu 10.04, now it finally works, so maybe someone can use it... it will be probalby same for Debian Squeeze

    First, here is my /etc/dovecot/dovecot.conf file:

    Code:
    base_dir = /var/run/dovecot/
    
    protocols = imap imaps pop3 pop3
    disable_plaintext_auth = no
    log_timestamp = "%Y-%m-%d %H:%M:%S "
    
    ssl_cert_file = /etc/ssl/_.my-domain.tld/_.my-domain.tld.crt
    ssl_key_file = /etc/ssl/_.my-domain.tld/_.my-domain.tld.key
    
    mail_privileged_group = mail
    
    login_greeting = my-domain.tld IMAP server ready...
    
    ## IMAP specific settings
    protocol imap {
    mail_executable = /usr/lib/dovecot/rawlog /usr/lib/dovecot/imap
      mail_plugins = quota imap_quota
    }
    
    ## POP3 specific settings
    protocol pop3 {
      mail_executable = /usr/lib/dovecot/rawlog /usr/lib/dovecot/pop3
      pop3_uidl_format = %08Xu%08Xv
      mail_plugins = quota
    }
    
    ## LDA specific settings
    protocol lda {
      # Address to use when sending rejection mails.
      postmaster_address = [email protected]
    
      # Support for dynamically loadable plugins. mail_plugins is a space separated
      # list of plugins to load.
      mail_plugin_dir = /usr/lib/dovecot/modules/lda
    
    
      # UNIX socket path to master authentication server to find users.
      auth_socket_path = /var/run/dovecot/auth-master
    
      # Enabling Sieve plugin for server-side mail filtering
      mail_plugins = sieve quota
    }
    
    
    ## Plugin settings
    plugin {
            quota = maildir
            sieve=/var/vmail/%d/%n/.sieve
    }
    
    
    ## Authentication processes
    
    # Executable location
    #auth_executable = /usr/lib/dovecot/dovecot-auth
    auth default {
      mechanisms = plain login
      passdb pam {
      }
    
      # SQL database <doc/wiki/AuthDatabase.SQL.txt>
      passdb sql {
        # Path for SQL configuration file
        args = /etc/dovecot/dovecot-sql.conf
      }
    
    # new quota support:
            userdb prefetch {
                    }
    
            userdb sql {
                    args = /etc/dovecot/dovecot-sql.conf
                    }
    
    
      ## dovecot-lda specific settings
      ##
      socket listen {
        master {
          path = /var/run/dovecot/auth-master
          mode = 0600
          user = vmail # User running Dovecot LDA
          #group = vmail # Or alternatively mode 0660 + LDA user in this group
        }
      client {
              path = /var/spool/postfix/private/auth
              mode = 0660
              user = postfix
              group = postfix
            }
      }
    
    }
    
    mail_location = maildir:/var/vmail/%d/%n/Maildir
    
    mail_uid = 5000
    mail_gid = 5000
    
    
    As you can have noticed all the users will have uid& gid 5000, also sieve script location & maildir will be following same pattern , so we don't have to read this data from MySQL all the time.

    This is the original user query:
    user_query = SELECT email as user, maildir as home, CONCAT(maildir, '/Maildir') as mail, uid, gid, CONCAT('maildir:storage', quota) AS quota, CONCAT(maildir, '/.sieve') AS sieve FROM mail_user WHERE email = '%u' AND disable%Ls = 'n']

    I have removed uid, gid, sieve and also "user_query = CONCAT(maildir, '/Maildir')" as is doen't seem to be used anywhere


    Now we can modify
    /etc/dovecot/dovecot-sql.conf
    Code:
    driver = mysql
    connect = host=localhost dbname=dbispconfig user=ispconfig password=your_gerated_password_from_ISPC3
    default_pass_scheme = CRYPT
    password_query = SELECT password FROM mail_user WHERE email = '%u' AND disable%Ls = 'n'
    
    ### we must change user query, here is the correct one, notice that storage quota must be set in bytes
    user_query = SELECT email AS user, maildir AS home, CONCAT('*:storage=', quota , 'B') AS quota_rule FROM mail_user WHERE email = '%u' AND disable%Ls = 'n'
    
    That's it. Sieve scripts are working , roundcube is showing correct quota, also Thunderbird.
     
    Last edited: May 20, 2010
  2. slamman

    slamman New Member

    User query failed:

    Thanks for this walkthrough. I am having a problem getting this to work however. Any help would be appreciated. After following the steps here I am getting the following error message in my mail.log

    User query failed: Incorrect parameters in the call to native function 'CONCAT'

    System:

    postfix 2.7.0-1
    dovecot 1.2.9
    ispconfig 3.0.3
     
  3. radim_h

    radim_h Member

    you don't have to modify those files anymore, this setup is allready included in ISPConfig
     
    Last edited: Nov 6, 2010
  4. slamman

    slamman New Member

    Can you suggest a setup guide for dovecot w/ispconfig3 on ubuntu 10.04. I will try it again from scratch. The guide I was using was the perfect server guide and it used courier...which I was trying to get rid of in favor of dovecot.
     
  5. radim_h

    radim_h Member

    This One is from SVN trunk, for Debian 6 bud i used it for Ubuntu 10.4

    Installation
    -------------

    # It is recommended to use a clean (fresh) Debian Squeeze 6.0 install where you just selected "Standard System" at the package selection during
    # setup (tasksel). Then follow the steps below to setup your server with ISPConfig 3. In this guide "vi" is used as text editor, but
    # you can use whatever you prefer. You should be root for doing all of this.


    # Check we have Fully Qualified Domain Name

    /bin/hostname

    # it should return something like "ispconfig.example.com"
    # if not, then we assign a hostname (for example ispconfig):

    echo ispconfig.example.com > /etc/hostname

    vi /etc/hosts

    # and add lines similar but appropriate:

    127.0.0.1 localhost.localdomain localhost
    192.168.0.100 ispconfig.example.com ispconfig

    # Run:

    /etc/init.d/hostname.sh

    # enable the Debian Volatile repository to get an updated ClamAV version
    # The Volatile repository for Debian Squeeze was not available yet at the time this howto was written.
    # echo "deb http://volatile.debian.org/debian-volatile squeeze/volatile main contrib non-free" >> /etc/apt/sources.list.d/volatile.list
    # apt-get update

    # Some optional choices

    opt0.1) Optionally install SSH-server to get remote shell

    apt-get install openssh-server

    opt0.2) Optionally, if you are not running inside a virtual machine, you can set server clocksync via NTP. Virtual guests get this from the host.

    apt-get -y install ntp ntpdate

    opt0.3) Optionally if you want vi editor improvement

    apt-get -y install vim-nox


    # Next is the real deal

    1) Install Postfix, Dovecot, MySQL, phpMyAdmin, rkhunter, binutils with the following command line (on one line!):

    apt-get -y install postfix postfix-mysql postfix-doc mysql-client mysql-server openssl getmail4 rkhunter binutils dovecot-imapd dovecot-pop3d sudo

    # Answer the questions from the package manager as follows.

    General type of configuration? <-- Internet site
    Mail name? <-- server1.mydomain.tld

    # ...use your own domain name of course ;)



    # Edit the file /etc/mysql/my.cnf

    vi /etc/mysql/my.cnf

    # and change the line:

    bind-address = 127.0.0.1

    to:

    #bind-address = 127.0.0.1

    # then restart mysql

    /etc/init.d/mysql restart

    2) Install Amavisd-new, Spamassassin and ClamAV (1 line!):

    apt-get -y install amavisd-new spamassassin clamav clamav-daemon zoo unzip bzip2 arj nomarch lzop cabextract apt-listchanges libnet-ldap-perl libauthen-sasl-perl clamav-docs daemon libio-string-perl libio-socket-ssl-perl libnet-ident-perl zip libnet-dns-perl


    3) Install Apache, PHP5, phpmyadmin, better fastCGI, suexec, Pear and mcrypt (1 line!):

    apt-get -y install apache2 apache2.2-common apache2-doc apache2-mpm-prefork apache2-utils libexpat1 ssl-cert libapache2-mod-php5 php5 php5-common php5-gd php5-mysql php5-imap phpmyadmin php5-cli php5-cgi libapache2-mod-fcgid apache2-suexec php-pear php-auth php5-mcrypt mcrypt imagemagick libapache2-mod-suphp libopenssl-ruby libapache2-mod-ruby


    # When phpMyAdmin is asking wether to configure itself automatically, select "Apache2"

    # Then run the following to enable the Apache modules suexec, rewrite and ssl:

    a2enmod suexec rewrite ssl actions include ruby

    # restart Apache before continuing

    /etc/init.d/apache2 restart


    4) Install pure-ftpd and quota

    apt-get -y install pure-ftpd-common pure-ftpd-mysql quota quotatool

    # Optional: Enable TLS in pureftpd
    echo 1 > /etc/pure-ftpd/conf/TLS
    mkdir -p /etc/ssl/private/
    openssl req -x509 -nodes -newkey rsa:1024 -keyout /etc/ssl/private/pure-ftpd.pem -out /etc/ssl/private/pure-ftpd.pem
    chmod 600 /etc/ssl/private/pure-ftpd.pem


    # Edit /etc/fstab. Mine looks like this (I added ,usrquota,grpquota to the partition with the mount point /):

    vi /etc/fstab

    ----------------------------------------------------------------------------------------------
    # /etc/fstab: static file system information.
    #
    # <file system> <mount point> <type> <options> <dump> <pass>
    proc /proc proc defaults 0 0
    /dev/sda1 / ext3 errors=remount-ro,usrquota,grpquota 0 1
    /dev/sda5 none swap sw 0 0
    /dev/hda /media/cdrom0 udf,iso9660 user,noauto 0 0
    /dev/fd0 /media/floppy0 auto rw,user,noauto 0 0
    ----------------------------------------------------------------------------------------------

    # To enable quota, run these commands:

    touch /aquota.user /aquota.group
    chmod 600 /aquota.*
    mount -o remount /
    quotacheck -avugm
    quotaon -avug


    5) Install BIND DNS Server

    apt-get -y install bind9 dnsutils

    6) Install vlogger and webalizer

    apt-get -y install vlogger webalizer awstats

    mkdir /usr/share/awstats/tools
    cp -prf /usr/share/doc/awstats/examples/awstats_buildstaticpages.pl /usr/share/awstats/tools/awstats_buildstaticpages.pl


    7) Install Jailkit (optional, only needed if you want to use chrooting for SSH users)

    apt-get -y install build-essential autoconf automake1.9 libtool flex bison debhelper
    cd /tmp
    wget http://olivier.sessink.nl/jailkit/jailkit-2.11.tar.gz
    tar xvfz jailkit-2.11.tar.gz
    cd jailkit-2.11
    ./debian/rules binary
    cd ..
    dpkg -i jailkit_2.11-1_*.deb
    rm -rf jailkit-2.11*

    8) Install fail2ban (optional but recomended, because the monitor tries to show the log)
    More info at: http://www.howtoforge.com/fail2ban_debian_etch

    apt-get -y install fail2ban

    9) Install ISPConfig 3

    cd /tmp
    wget http://www.ispconfig.org/downloads/ISPConfig-3.0.2.2.tar.gz
    tar xvfz ISPConfig-3.0.2.2.tar.gz
    cd ispconfig3_install/install/

    # Now start the installation process by executing:

    php -q install.php

    # The installer will configure all services like postfix, sasl, courier, etc. for you. A manual setup as required for ISPConfig 2 (perfect setup guides) is not necessary. To login to the ISPConfig controlpanel, open the following URL in your browser (replace the IP to match your settings!):

    http://192.168.0.100:8080/

    # the default login is:

    user: admin
    password: admin

    # In case you get a permission denied error from apache, please restart the apache webserver process.



    ----------------------------------------------------------------------------------------------------------
    Optional:

    Install a webbased Email Client

    apt-get install squirrelmail
    ln -s /usr/share/squirrelmail/ /var/www/webmail

    Access squirrelmail:

    http://192.168.0.100/webmail


    To configure squirrelmail, run:

    /usr/sbin/squirrelmail-configure

    ----------------------------------------------------------------------------------------------------------

    Hints:

    debian 5.0 under openvz:

    VPSID=101
    for CAP in CHOWN DAC_READ_SEARCH SETGID SETUID NET_BIND_SERVICE NET_ADMIN SYS_CHROOT SYS_NICE CHOWN DAC_READ_SEARCH SETGID SETUID NET_BIND_SERVICE NET_ADMIN SYS_CHROOT SYS_NICE
    do
    vzctl set $VPSID --capability ${CAP}:eek:n --save
    done

    ----------------------------------------------------------------------------------------------------------


    Optional recommended packages:

    denyhosts - a utility to help sys admins thwart ssh crackers
    rsync - fast remote file copy program (for backup)

    -----------------------------------------------------------------------------------------------------------

    Ispc log files rotation, for now manual add but to add in ispc installer:

    /etc/logrotate.d/logispc3

    /var/log/ispconfig/ispconfig.log {
    weekly
    missingok
    rotate 4
    compress
    delaycompress
    }
    /var/log/ispconfig/cron.log {
    weekly
    missingok
    rotate 4
    compress
    delaycompress
    }


    -----------------------------------------------------------------------------------------------------------

    Possible errors and their solutions
    ------------------------------------

    pureftpd login does not work. Take a look at the syslog, if you find an error message like this:
    Mar 24 16:26:28 ispconfig pure-ftpd: (?@?) [ERROR] Sorry, invalid address given

    then pureftpd is not able to resolve the hostname. Name resolving can be disabled with these commands:

    echo 'yes' > /etc/pure-ftpd/conf/DontResolve
    /etc/init.d/pure-ftpd-mysql restart
     
  6. radim_h

    radim_h Member

  7. slamman

    slamman New Member

    Thanks for the info. I have installed the system as per your instructions with changes to make it work with ubuntu 9.10. Most everything seems to be working except email. I am getting the following error:

    Code:
    Fatal: Plugin sieve not found from directory /usr/lib/dovecot/modules/lda
    Before I dig around I wanted to see if there was a known solution. The following files are in the directory listed:

    lib90_cmusieve_plugin.a
    lib90_cmusieve_plugin.la
    lib90_cmusieve_plugin.so

    and some symlinks to some other files that don't seem relevant.
     
  8. radim_h

    radim_h Member

    i think you will have to use backports to get newer version of sieve or something like that..
     
  9. slamman

    slamman New Member

    I did some searching and many of the dovecot/ubuntu posts referenced the sieve plugin as cmusieve. So before getting to deep I checked the mail_plugins value in dovecot.conf and it was:

    Code:
    mail_plugins = sieve quota
    I changed it to:

    Code:
    cmusieve quota
    and now mail is working.

    Thanks for your help and information.
     
    dmgeurts likes this.
  10. radim_h

    radim_h Member

  11. Undo

    Undo New Member

    Maybe it would be interesting for thoses who have the same error message than me during the installation of ISPConfig on Debian Lenny with Dovecot 1.2 .x (from backports) :

    Code:
    Restarting IMAP/POP3 mail server: dovecotError: Error in configuration file /etc/dovecot/dovecot.conf line 681: Unknown setting: sieve
    Fatal: Invalid configuration in /etc/dovecot/dovecot.conf
    In fact there is a problem in the dovecot.conf.

    The protocol "managesieve" is now called "lda" and the plugin "cmusieve" is called "sieve" from V1.2 of Dovecot.

    So you'll have to replace this :

    Code:
    protocol managesieve {
    By that :

    Code:
    protocol lda {
    And this :

    Code:
    mail_plugins = cmusieve quota
    (be careful : it's the mail_plugins directive INSIDE THE "protocol lda {" )

    By that :

    Code:
    mail_plugins = sieve quota
    After that, Dovecot was able to start for me.
     
    Last edited: Dec 22, 2010
    dmgeurts likes this.

Share This Page