This is a short write up for an easy way to install Courier-IMAP on a machine running Mac OS X client (and probably just the Darwin core as well)
Target
I wanted to have my own IMAP-server both for archival purposes (on my own machine I have practilcally unlimited space to save e-mail) as well as a mean to collect mail I receive on other accounts into one unified storage. Furthermore I want a better way to handle mail than common e-mail clients like Apple Mail, Thunderbird or Eudora offers - currently I am looking into Zoƫ (Google you e-mail) and Mulberry (the superior, with a good margin, IMAP-client)
I will do this step by step and update this document as I progress:
Purposes
/Library/StartupItems
port install courier-imap
/opt/local
. The following are of interest:
Before we begin to dissect these we first have to understand something else:
The DarwinPorts StartupItem basically runs
all items in (typically) /opt/local/etc/rc.d/ with the verb start
.
With that in mind we can look into the start up procedure of Courier-IMAP
and its startup scripts:
When you install Courier-IMAP the following script are stored in /opt/local/etc/rc.d/ and are therefore executed(with the verb start) when the computer boots:
These scripts are quite similar, they source
/opt/local/etc/courier-imap/imapd
(and
imapd
-ssl) and then execute /opt/local/libexec/imapd.rc
start (imapd-ssl.rc)
. Now that we know this we can go back to the files
of interest mentioned above. We begin with last of the two files the
start scripts uses, the run command files:
These run command files set up some environment variables and then launches the executable with a few switches.
These are the setting files for Courier-IMAP. They are fairly well documented/commented. I made a few changes:
I changed its value from 0 to 127.0.0.1. This way you can have a secure setup without having to mess with the SSL-setup1 at the moment since you only allow connections from localhost which forces clients to tunnel their traffic to the machine where Courier-IMAP is running, e.g., by SSH. If the tunnel is setup as it should then this method is perfectly safe.
I commented this setting to make the server behave more like regular MUA:s, i.e., not deleting messages in the trash automatically.
Note that these configration files have the same names as the executables in /opt/local/bin/.
This is the actual IMAP-server executable. You can, but I advise against it, start this directly from the command line. It has an extensive man-page.
You have to run this for each user before they can log in. I have only tried
to log in with Mozilla Thunderbird without first running maildirmake
for a certain user and at least Thunderbird gives an error message
indicating, incorrectly, that your password is erroneous if you don't
do this. Simply cd to each user's home directory and run maildirmake
Maildir
and it will create a directory called Maildir
with
three sudirectories, cur
, new
and tmp
.
You can give another name as argument to maildirmake but then, in my experience, you can not login. It seems as Courier-IMAP has hard coded the name of the mail directory because I can not find any setting for it either. If you know anything about this, please let me know.
If you reboot the server will start automatically but easier is just to runt the startup script in /opt/local/etc/rc.d/. Since we , for the moment, re happy with just using the plain text imapd simply start the server from the command line:
/opt/local/etc/rc.d/imapd.sh start
If you take a look with top you will notice a few new processes, e.g., imapd, courierlog, couriertcp, authdemon and maybe a few more. You can verify that the server is running with
telnet localhost 127.0.0.1 143
You should see something like this:
telnet localhost 143
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
* OK [CAPABILITY IMAP4rev1 UIDPLUS CHILDREN NAMESPACE THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT QUOTA IDLE STARTTLS] Courier-IMAP ready. Copyright 1998-2003 Double Precision, Inc. See COPYING for distribution information.
You can also make sure that you are secure by logging into another computer and try to telnet from that computer to your IMAP-server on port 143.
Now create a new account in your MUA and set it up for your new IMAP-server and play around (try to transfer som junk mail from already existing accounts/mailboxes to your new IMAP-server, create a few folders on the server etc).
This is a very simple step that you probably don't need to have documented if you have gone this but anyway...
This is how I did it: create a filter with the highest/first priority in your regular MUA. Make that filter transfer a copy (it is important that it is a copy or elsewise you might lose mail if the setup proves to be unstable or unreliable) of every received mail to some folder on your IMAP-server.
Footnotes
It is quite simple to setup SSL:
Note that the ssl-version won't start without this certifcate. Also note that you can run SSL and clear text versions of courier-imap in parallell.