Courier-IMAP is a server that provides IMAP access to Maildir mailboxes. This IMAP server does NOT handle traditional mailbox files (/var/spool/mail, and derivatives), it was written for the specific purpose of providing IMAP access to Maildirs. For more information, please visit http://www.courier-mta.org/imap/


Lets start with installing the port and configuring the options for it:


# echo "WITHOUT_X11=yes" >> /etc/make.conf
# echo "NO_X=yes" >> /etc/make.conf
# cd /usr/ports/lang/expect
# make install clean
# cd /usr/ports/mail/courier-imap
# make install clean

When you run make install clean on courier-imapd, be sure to make sure the following boxes are checked:

IPV6
AUTH_VCHKPW

Once that is done, We will want to install courierpassd:


# cd /usr/ports/security/courierpassd
# make install clean

Lets run mkdhparams before we do anything else.


# /usr/local/share/courier-imap/mkdhparams

Now we will want to delete the startup file in the /usr/local/etc/rc.d folder:


# rm /usr/local/etc/rc.d/courier-authdaemond

Now lets copy over tcpserver to /usr/local/bin


# cd /usr/local/bin
# cp /root/qmail/tcpserver .

Next we need to set up the daemontools directory structure for the courierpasswd service. I now use /var/qmail/svc as the physical location for my service directories, you can use whatever you like except that it cannot be /service itself. The examples below will assume you are using /var/service like I did- if you are using something different, adjust the paths where appropriate.


# cd /var/qmail/svc
# mkdir /var/log/courier-passwd
# mkdir -m 1755 courier-passwd
# cd courier-passwd
# cp /root/qmail/service-courierpassd-run run
# chmod 755 run
# mkdir -m 755 log
# cd log
# cp /root/qmail/service-any-log-run run
# chmod 755 run

In the run file change the second-to-last line to match the following:

multilog t n1024 s1048576 /var/log/courier-passwd \

The last step, of course, is to start the service running:


# ln -s /var/qmail/svc/courier-passwd /service/courier-passwd

You can verify the service is running by typing:


# svstat /service/courier-passwd/ /service/courier-passwd/log/

Now we want to setup a few files:


# cd /usr/local/etc/courier-imap
# cp imapd.cnf.dist imapd.cnf
# cp imapd-ssl.dist imapd-ssl

Now we need to make the imap cert:


# /usr/local/share/courier-imap/mkimapdcert

Now edit the following file:


# vi /usr/local/etc/authlib/authdaemonrc

And change the following section:


authmodulelist="authvchkpw"

Now to setup the courier-authdaemond service:


# cd /var/qmail/svc
# mkdir /var/log/courier-authdaemond
# mkdir -m 1755 courier-authdaemond
# cd courier-authdaemond
# cp /root/qmail/courier-authdaemond-run run
# # chmod 755 run
# mkdir -m 755 log
# cd log
# cp /root/qmail/service-any-log-run run
# chmod 755 run

In the run file change the second-to-last line to match the following:

multilog t n1024 s1048576 /var/log/courier-authdaemond \

and finally link authdaemond to /service:


# ln -s /var/qmail/svc/courier-authdaemond /service/courier-authdaemond

And now to check to see if courier-authdaemond is running:


# svstat /service/courier-authdaemond/ /service/courier-authdaemond/log/

Now, before we start to work on getting courier running via daemontools rather than using the scripts, we are going to want to delete the scripts in /usr/local/etc/rc.d:


# rm /usr/local/etc/rc.d/courier-imap-imapd
# rm /usr/local/etc/rc.d/courier-imap-imapd-ssl

Make sure the following two lines are deleted from /etc/rc.conf


Enable_courier-imap-imapd="YES"
Enable_courier-imap-imapd-ssl="YES"

This last bit is VERY important, we dont want courier-imap trying to start twice with the next reboot, be sure and take the command to start the service OUT of /etc/rc.conf.

Now we want to make service directories for courier-imap just like you did for courierpassd


# cd /var/qmail/svc
# mkdir /var/log/courier-imap
# mkdir -m 1755 courier-imap
# cd courier-imap
# cp /root/qmail/courier-imap-run run
# chmod 755 run
# mkdir -m 755 log
# cd log
# cp /root/qmail/service-any-log-run run
# chmod 755 run

In the run file change the second-to-last line to match the following:

multilog t n1024 s1048576 /var/log/courier-imap \

Now we link the courier-imap to service:


# ln -s /var/qmail/svc/courier-imap /service/courier-imap

Now we need to check and make sure courier-imap is running:


# svstat /service/courier-imap/ /service/courier-imap/log/

If you want to run an imap ssl service you can, but you need to set that up separately from the stock imap service. I use both, I set up the plain imap service bound to the localhost address only, that way only my web mail (and any local service) can access it. the ssl service is for all your public interfaces.


# cd /var/qmail/svc
# mkdir /var/log/courier-imap-ssl
# mkdir -m 1755 courier-imap-ssl
# cd courier-imap-ssl
# cp /root/qmail/courier-imap-ssl-run run
# chmod 755 run
# mkdir -m 755 log
# cd log
# cp /root/qmail/service-any-log-run run
# chmod 755 run

In the run file change the second-to-last line to match the following:

multilog t n1024 s1048576 /var/log/courier-imap-ssl \

Now link your imap-ssl service so daemontools will start it.


# ln -s /var/qmail/svc/courier-imap-ssl /service/courier-imap-ssl

Once the courier daemons are started, we can move on to rainloop!