Installing and Using IMAP Servers

 < Free Open Study > 



qmail doesn't include an IMAP server, but a few add-on IMAP servers either can be made to work with qmail or were designed to work with qmail. We'll look at two add-on IMAP servers: UW-IMAP and Courier-IMAP.

Using University of Washington IMAP

IMAP originated at the University of Washington, which distributes its own IMAP server. The UW-IMAP server doesn't support maildir mailboxes as distributed, but patches are available to add that functionality. See the unofficial qmail home page (http://www.qmail.org/) for links to the patches for the current UW-IMAP release.

More information about UW-IMAP is available on the Web (http://www.washington.edu/imap/).

Installing UW-IMAP with Maildir Support

UW-IMAP has no additional requirements beyond those necessary for building and installing qmail:

  1. Download the UW-IMAP tarball and the maildir patch. At the time of this writing, IMAP-2000c is the latest non-beta UW-IMAP release, and the associated maildir patch is available from http://www.greboguru.org/qmail/. For example, using the lynx Web browser:

     $ lynx -dump ftp://ftp.cac.washington.edu/imap/old/imap-2000c.tar.Z > \ > imap-2000c.tar.Z $ lynx -dont_wrap_pre -dump \ > http://www.greboguru.org/qmail/uw_imap_big_qmail_0.1.patch > \ > uw_imap_big_qmail_0.1.patch $ 

  2. Unpack the UW-IMAP tarball and install the maildir patch:

     $ zcat imap-2000c.tar.Z | tar xf - $ cd imap-2000c $ patch -F3 -p1 < ../uw_imap_big_qmail_0.1.patch patching file README.maildir patching file src/c-client/mail.c Hunk #1 succeeded at 629 with fuzz 3. Hunk #2 FAILED at 638. 1 out of 2 hunks FAILED - saving rejects to file src/c-client/mail.c.rej patching file src/c-client/mail.h Hunk #1 succeeded at 655 with fuzz 3. patching file src/osdep/unix/Makefile patching file src/osdep/unix/env_unix.c Hunk #1 succeeded at 428 with fuzz 3. Hunk #2 succeeded at 584 with fuzz 1. Hunk #3 succeeded at 666 with fuzz 3. Hunk #4 succeeded at 768 with fuzz 3. patching file src/osdep/unix/maildir.c patching file src/osdep/unix/maildir.h $ 

  3. If one of the hunks fails to apply, as previously, apply it manually. In this case, edit src/c-client/mail.c and replace this block of code, starting on line 641:

     else for (d = maildrivers; d; d = d->next)   if (d->scan && !((d->flags & DR_DISABLE) ||                   ((d->flags & DR_LOCAL) && remote)))     (d->scan) (NIL,ref,pat,contents); 

with this block of code:

 else {   only_maildir = ((inbox_driver = mail_valid (NIL," INBOX",NIL)) &&                  !strcmp(inbox_driver->name," maildir"));   do if (!((d->flags & DR_DISABLE) ||           ((d->flags & DR_LOCAL) && remote) || (only_maildir && strcmp(d-> name,"maildir"))))      (d->list) (NIL,ref,pat);   while (d = d->next);               /* until at the end */ } 

  1. Compile UW-IMAP. Read the Makefile to determine the appropriate target for your operating system. For example, for Red Hat 7.1 using shadow passwords, it's slx:

     $ make slx ...lots of output ending with something like: 'cat ../c-client/CCTYPE' -I../c-client 'cat ../c-client/ CFLAGS' -DANOFILE=\"/etc/anonymous.newsgroups\" -DALERTFILE=\"/etc/imapd.alert\" -DUSERALERTFILE=\".imapalert\" -o imapd imapd.o ../c-client/c-client.a'cat ../ c-client/LDFLAGS' make[2]: Leaving directory '/usr/local/src/imap-2000c/imapd' make[1]: Leaving directory '/usr/local/src/imap-2000c' $ 

  2. With some versions of Linux, the make will fail with errors like this:

     'cat CCTYPE' -c 'cat CFLAGS' 'cat OSCFLAGS' -c osdep.c In file included from osdep.c:42: env_unix.c: In function 'do_date': env_unix.c:296: warning: initialization makes pointer from integer without env_unix.c:297: dereferencing pointer to incomplete type env_unix.c:297: dereferencing pointer to incomplete type env_unix.c:298: dereferencing pointer to incomplete type 

This is because of an incompatibility with the glibc package. The workaround is to replace lines like this:

 #include <sys/time.h> 

with this:

 #include <time.h> 

in files that generate that error. The file osdep.c is a special case because it's generated from src/osdep/unix/os_target.c, where target is the same as the make target. For example, in this case, the file to edit is src/osdep/unix/os_slx.c.

The other files are in the c-client subdirectory and can be edited in place.

  1. Install the imapd binary. The UW-IMAP package includes POP2 and POP3 servers, as well as the IMAP server, but most qmail installations use qmail-pop3d instead of the UW POP3 server, and POP2 is obsolete. Do this:

     $ su Password: root password # umask 022 # cp imapd/imapd /usr/local/sbin # 

  2. Create the /var/qmail/supervise/uw-imap directory and the log subdirectory:

     # mkdir -p /var/qmail/supervise/uw-imap/log # 

  3. Create the /var/qmail/supervise/uw-imap/run script:

     #!/bin/sh MAXIMAP='head -1 /var/qmail/control/concurrencyimap' exec /usr/local/bin/tcpserver -R -H -x /etc/tcp.imap.cdb -c "$MAXIMAP" \          0 143 /usr/local/sbin/imapd 2>&1 

    Note 

    concurrencyimap is a nonstandard control file. Only the previous uw-imap/run script uses it. The first line of the file should contain a number, which is the maximum number of simultaneous IMAP sessions that tcpserver allows.

  4. Create the /var/qmail/supervise/uw-imap/log/run script containing this:

     #!/bin/sh exec /usr/local/bin/setuidgid qmaill /usr/local/bin/multilog t \     /var/log/uw-imap 

  5. Create /var/qmail/control/concurrencyimap, in this example, limiting simultaneous IMAP connections to 20:

     # echo 20 > /var/qmail/control/concurrencyimap # 

  6. Create the IMAP access database. The file /etc/tcp.imap is the human-readable version of the IMAP access database. It's analogous to the SMTP access database in /etc/tcp.smtp set up in Chapter 2, "Installing qmail." The tcprules command is used to convert the human-readable version into a machine-readable version, /etc/tcp.imap.cdb. For example, to restrict access to hosts on the local network, 192.168.x.x, and the local host, you would create /etc/tcp.imap, using your text editor, containing this:

     192.168.:allow 127.:allow :deny 

  7. Set up the log directory and permissions on the run scripts, and link the service into /service:

     # chmod +t /var/qmail/supervise/uw-imap # mkdir /var/log/uw-imap # chown qmaill /var/log/uw-imap # chmod 755 /var/qmail/supervise/uw-imap/run # chmod 755 /var/qmail/supervise/uw-imap/log/run # ln -s /var/qmail/supervise/uw-imap /service # 

  8. Add the following to qmailctl's start section:

     if svok /service/uw-imap ; then     svc -u /service/uw-imap else     echo uw-imap service not running fi 

  9. Add the following to qmailctl's stop section:

     echo "  uw-imap" svc -d /service/uw-imap 

  10. Add the following to qmailctl's stat section:

     svstat /service/uw-imap svstat /service/uw-imap/log 

  11. Add the following to qmailctl's pause section:

     echo "Pausing uw-imap" svc -p /service/uw-imap 

  12. Add the following to qmailctl's cont section:

     echo "Continuing uw-imap" svc -c /service/uw-imap 

  13. Add the following to qmailctl's restart section:

     echo "* Restarting uw-imap." svc -t /service/uw-imap 

  14. Add the following to qmailctl's cdb section:

     tcprules /etc/tcp.imap.cdb /etc/tcp.imap.tmp < /etc/tcp.imap chmod 644 /etc/tcp.imap.cdb echo "Reloaded /etc/tcp.imap." 

  15. Build /etc/tcp.imap.cdb:

     # qmailctl cdb Reloaded /etc/tcp.smtp. Reloaded /etc/tcp.pop3. Reloaded /etc/tcp.imap. # 

Testing the UW-IMAP Service

At this point, your IMAP service should be up and running. You can test it by connecting to the IMAP port on the local system and logging in as a normal mail user:

  1 $ telnet 0 143  2 Trying 0.0.0.0. . .  3 Connected to 0.  4 Escape character is '^]'.  5 * OK [CAPABILITY IMAP4 IMAP4REV1 LOGIN-REFERRALS AUTH=LOGIN]    localhost.localdomain IMAP4rev1 2000.287 at Sun, 17 Jun 2001 13:31:02 -0400    (EDT)  6 a1 login dave flubgart  7 * CAPABILITY IMAP4 IMAP4REV1 NAMESPACE IDLE MAILBOX-REFERRALS SCAN SORT    THREAD=REFERENCES THREAD=ORDEREDSUBJECT MULTIAPPEND  8 a1 OK LOGIN completed  9 a2 select INBOX 10 * 6 EXISTS 11 * 0 RECENT 12 * OK [UIDVALIDITY 992799110] UID validity status 13 * OK [UIDNEXT 992799117] Predicted next UID 14 * FLAGS (\Answered \Flagged \Deleted \Draft \Seen) 15 * OK [PERMANENTFLAGS ()] Permanent flags 16 * OK [UNSEEN 5] first unseen message in INBOX 17 a2 OK [READ-WRITE] SELECT completed 18 a3 logout 19 * BYE dolphin.example.com IMAP4rev1 server terminating connection 20 a3 OK LOGOUT completed 21 Connection closed by foreign host. 22 $ 

Line 1 is the telnet command used to connect to the IMAP service. The 0 (zero) refers to the local host, and 143 is the IMAP port number.

Line 2 shows telnet trying to connect.

Line 3 shows that the connection was established.

Line 4 is telnet reminding the user that they can "escape" to the telnet prompt by holding the Control key and pressing the right square bracket key (]).

Line 5 is the banner message from UW-IMAP.

Lines 6 though 8 are the authentication exchange.

Lines 9 though 17 show the user using the IMAP SELECT command to display a list of messages available in the in-box, followed by UW-IMAP's response, which indicates that the in-box contains five messages.

Lines 18 through 20 show the user ending the IMAP session.

Line 21 is telnet reporting that UW-IMAP closed the connection.

The next step is to test the service remotely using an IMAP-enabled MUA.

Using Courier-IMAP

Courier-IMAP is the IMAP component of the Courier mail system. Like qmail-pop3d, Courier-IMAP supports only maildir-format mailboxes. Compared to UW-IMAP, Courier-IMAP is smaller and lighter. Because its maildir support is built-in, rather than patched-in like UW-IMAP's, it's recommended for sites that prefer using maildir mailboxes.

More information on Courier-IMAP is available on the Web (http://www.inter7.com/courierimap/).

Installing Courier-IMAP

Courier-IMAP has no additional requirements beyond those necessary for building and installing qmail:

  1. Download the Courier-IMAP tarball. At the time of this writing, 1.3.8.2 is the latest Courier-IMAP release. For example, using the lynx Web browser:

     $ lynx -dump \ > http://download.sourceforge.net/courier/courier-imap-1.3.8.2.tar.gz > \ > courier-imap-1.3.8.2.tar.gz $ 

  2. Unpack the tarball and move to the build directory:

     $ zcat courier-imap-1.3.8.2.tar.gz | tar xf - $ cd courier-imap-1.3.8.2 $ 

  3. Configure Courier-IMAP for building:

     $ ./configure ...lots of output ending with something like: creating imapd.cnf creating pop3d.cnf creating config.h $ 

  4. Compile Courier-IMAP:

     $ make ...lots of output ending with something like: cp imap/pop3d.cnf . cp -f ./maildir/quotawarnmsg quotawarnmsg.example make[1]: Leaving directory '/usr/local/src/courier-imap-1.3.8.2' $ make check ...lots of output ending with something like: rm -f /usr/local/src/courier-imap-1.3.8.2/=install-check/usr/lib/courier-imap/bin /couriertls make[2]: Leaving directory '/usr/local/src/courier-imap-1.3.8.2' make[1]: Leaving directory '/usr/local/src/courier-imap-1.3.8.2' $ 

  5. Install the binaries and configuration files:

     $ su Password: rootpassword # make install ...lots of output ending with something like: Do not forget to run make install-configure make[2]: Leaving directory '/usr/local/src/courier-imap-1.3.8.2' make[1]: Leaving directory '/usr/local/src/courier-imap-1.3.8.2' # make install-configure ...lots of output ending with something like:   version: new   authdaemonvar: new make[1]: Leaving directory '/usr/local/src/courier-imap-1.3.8.2' # 

  6. Check the configuration files in /usr/lib/courier-imap/etc. For example, if imapd enables authuserdb, either directly or through authdaemonrc, and you don't want to use Courier-IMAP's virtual mailboxes, you would remove authuserdb from the AUTHMODULES line in imapd or the authmodulelist in authdaemonrc. If the authpam module is enabled, you might have to adjust the imap or pop3 configuration files in /etc/pam.d. See the INSTALL file for more details.

  7. Add the following command to the start section of qmailctl:

     /usr/lib/courier-imap/libexec/imapd.rc start 

  8. Add the following command to the stop section of qmailctl:

     /usr/lib/courier-imap/libexec/imapd.rc stop 

  9. Manually run the Courier-IMAP start script:

     # /usr/lib/courier-imap/libexec/imapd.rc start # 

Testing the Courier-IMAP Service

At this point, your IMAP service should be up and running. You can test it by connecting to the IMAP port on the local system and logging in as a normal mail user:

  1 $ telnet 0 143  2 Trying 0.0.0.0. . .  3 Connected to 0.  4 Escape character is '^]'.  5 * OK Courier-IMAP ready. Copyright 1998-2001 Double Precision, Inc. See    COPYING for distribution information.  6 a1 login dave flubgart  7 a1 OK LOGIN Ok.  8 a2 select INBOX  9 * FLAGS (\Answered \Flagged \Deleted \Seen \Recent) 10 * OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen)] Limited 11 * 6 EXISTS 12 * 0 RECENT 13 * OK [UIDVALIDITY 993125313] Ok 14 a2 OK [READ-WRITE] Ok 15 a3 logout 16 * BYE Courier-IMAP server shutting down 17 a3 OK LOGOUT completed 18 Connection closed by foreign host. 19 $ 

Line 1 is the telnet command used to connect to the IMAP service. The 0 (zero) refers to the local host, and 143 is the IMAP port number.

Line 2 shows telnet trying to connect.

Line 3 shows that the connection was established.

Line 4 is telnet reminding the user that they can "escape" to the telnet prompt by holding the Control key and pressing the right square bracket key (]).

Line 5 is the banner message from Courier-IMAP.

Lines 6 and 7 are the authentication exchange.

Lines 8 though 14 show the user using the IMAP SELECT command to display a list of messages available in the in-box, followed by Courier-IMAP's response, which indicates that the in-box contains six messages.

Lines 15 through 17 show the user ending the IMAP session.

Line 18 is telnet reporting that Courier-IMAP closed the connection.

The next step is to test the service remotely using an IMAP-enabled MUA.



 < Free Open Study > 



The Qmail Handbook
The qmail Handbook
ISBN: 1893115402
EAN: 2147483647
Year: 2001
Pages: 186
Authors: Dave Sill

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net