the djb way

imap


Dovecot


Link: http://dovecot.procontrol.fi/
Version: check for latest stable release
Download: see homepage
Build type: GNU autoconf
Other: GPL

Timo Sirainen offers the third in our series on IMAP, with the Dovecot package.

Dovecot derives its name from the word meaning "pigeon-hole". What is of primary interest to us is that it serves IMAP from Maildirs.

Dovecot is under active development; see the website for current release information. The observations below are based on dovecot-0.99.10.4, dated 2003.11.09.

build/install

Once you've downloaded the most current release, unpack it into some convenient build directory. Look at the README and INSTALL files; there is also some plain-text documentation in the doc subdirectory.

The package uses GNU autoconf, so the starting point will be the familiar ./configure script. No particular "gotchas" here, the default --prefix is /usr/local. This will result in dovecot binaries installed in /usr/local/sbin and /usr/local/libexec, example configuration file in /usr/local/etc, and documentation copied to /usr/local/share/doc/dovecot.

On our OpenBSD (3.4) testbed we ./configure'd as follows:

$ ./configure \
--disable-ipv6 \
--without-pop3d

Unless all the other djb components have been patched, a djb box won't be up on IPv6, so the --disable-ipv6 here. Dovecot also offers a POP3 server, if you want, but we've got qmail-pop3d.

After the ./configure has run to completion, GNU-make the package:

$ make

Dovecot is now compiled and ready to install. Become super-user, then:

# make install-strip

All the binaries, sample configuration, and documentation files should now be installed on your system.

dovecot-imapd service

After Dovecot has been built and installed, we can turn to the daemontools service for running it.

Dovecot has its own socket listener and supervisory daemon, in the executable /usr/local/sbin/dovecot. This supervisor in turns runs the imap-login, dovecot-auth, and imap executables installed in /usr/local/libexec/dovecot. The way these modules bind together makes it a little difficult to run a Dovecot IMAP service in exactly the way we would like.

Fortunately, though, there are sufficient command-line and run-time configuration parameters that we can at least set up a daemontools service for the dovecot supervisor, complete with tai-stamped multilog-ing.

The imap-login process requires an unpriveleged user account --named "dovecot" in the default configuration-- so add this user account in the usual way, disabled password, homeless, noshell. Then make the local service directories:

# mkdir -p /var/svc.d/dovecot-imapd/log

Now install the "run" script for the service in /var/svc.d/dovecot-imapd/run:


#!/bin/sh
# dovecot-imapd/run
# daemontools run script for dovecot-imapd service
# ===
exec 2>&1
echo "*** Starting dovecot-imapd service..."
exec envuidgid dovecot \
    /usr/local/sbin/dovecot \
    -F \
    -c /usr/local/etc/dovecot.conf

### that's all, folks!

Make sure it's executable, chmod 755. The key option here is -F, which tells dovecot to run in the foreground, as daemontools requires. We also use the -c option to explicitly indicate the location of the configuration file.

The service here could be named dovecot-master instead, since we are simply running the dovecot supervisory process, which in turn may run either its IMAP or POP servers. We use the name dovecot-imapd only to clarify our intent to use just the IMAP service. (In advanced sections we will convert this script more specifically to an IMAP service in the djb way, using Bruce Guenter's mailfront package.)

In dovecot's configuration file, we will make sure to capture log output to stderr for multilog. Here's the multilogger run script for the service:


#!/bin/sh
# dovecot-imapd/log/run
# multilogger for dovecot-imapd service
exec setuidgid multilog multilog t /var/multilog/dovecot-imapd

### that's all, folks!

Install and make executable, chmod 755. Prepare the multilog directory:

# mkdir -p /var/multilog/dovecot-imapd
# chown multilog /var/multilog/dovecot-imapd

Now define the tcprules you want for the service in /etc/tcprules/imap.rules:


# imap.rules
127.:allow
192.168.1.:allow
:deny

This permits access only from the local network, 192.168.1.0/24; adjust to suit your requirements, then compile the rules:

# (cd /etc/tcprules; make imap.cdb)

Before we start the service, we need to give some attention to Dovecot's configuration file, dovecot.conf. The installation procedure creates a sample file in /usr/local/etc/dovecot-example.conf. Copy this into a working file and open for editing:

# cd /usr/local/etc
# cp dovecot-example.conf dovecot.conf
# vi dovecot.conf
...

Have a look through the file to get the layout. There are three things to take care of:

  1. fix all paths to point to the actual installation
  2. set up for multilog
  3. configure Maildir locations for your site

The first is to fix up the path entries, changing any commented path entries to their actual locations, such as below:


...
#base_dir = /var/run/dovecot
base_dir = /var/run/dovecot
...
login_dir = /var/run/dovecot/login
...
login_executable = /usr/local/libexec/dovecot/imap-login
...
imap_executable = /usr/local/libexec/dovecot/imap
...

Note here that Dovecot does not like path values "quoted". The entries relevant to multilog-ing are shown here:


...
log_path = /dev/stderr
...
#log_timestamp = "%b %d %H:%M:%S "
### multilog will prepend tai-stamp:
log_timestamp = 
...

Tell dovecot where to find users' Maildirs:


...
#default_mail_env =
default_mail_env = maildir:~/MAILDIR.IMAP
...

The example entry here tells dovecot to look for Maildir-type storage, in the directory named MAILDIR.IMAP in the user's home directory. This can also be defined in the environmental variable named MAIL; see the mail-storages.txt documentation file in the distribution for more information.

When dovecot is configured the way you want, link the service into /service to bring it up:

# ln -s /var/svc.d/dovecot-imapd /service/dovecot-imapd

Check it out with an ucspi-tcp mconnect dialogue; the stuff we enter is in bold:

$ mconnect "" 143
* OK dovecot ready.
a01 login user password
a01 OK Logged in.
a02 capability
* CAPABILITY IMAP4rev1 SORT THREAD=REFERENCES MULTIAPPEND
* UNSELECT LITERAL+ IDLE CHILDREN LISTEXT LIST-SUBSCRIBED
a02 OK Capability completed.
a03 select inbox
* FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
* OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft
* \*)] Flags permitted.
* 177 EXISTS
* 0 RECENT
* OK [UNSEEN 174] First unseen.
* OK [UIDVALIDITY 1074767998] UIDs valid
* OK [UIDNEXT 179] Predicted next UID
a03 OK [READ-WRITE] Select completed.
a04 logout
* BYE Logging out
a04 OK Logout completed.

There's Dovecot!

In actual usage, we found Dovecot to be quick. It follows a different folder naming convention from Courier, though. Dovecot will name sub-folders .Send, .Drafts, .Trash, etc., while Courier uses INBOX.Send, INBOX.Drafts, etc. Not that you'll ever be switching back and forth among IMAP servers, but if you do, you may need to work out some symlinks to accomodate the differences.

Note that it is possible to run the executable imap-login in a daemontools service with tcpserver. Here's a sample "run" script to try out. When run this way, imap-login itself will call the dovecot supervisor with an --inetd option; you don't need a separate service for dovecot.

There are a couple downsides to such an arrangement, however:

Later on we will review some djb-way-like tools that we can use to work around some of these limitations. Until then, give this setup a try. You may find Dovecot to be the perfect IMAP server for your own pigeon-holes.


Copyright © 2003, 2004 Wayne Marshall.
All rights reserved.

Last edit 2004.01.27, wcm.