Go to TogaWare.com Home Page. GNU/Linux Desktop Survival Guide
by Graham Williams
Duck Duck Go



CLICK HERE TO VISIT THE UPDATED SURVIVAL GUIDE

IMAP: Mail Server

REVIEW

To set up an IMAP mail server using the Maildir folder format install courier-imap. IMAP will then be running and we can test this through opening a telnet connection and then sending the logout command:

$ telnet localhost 143
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
* OK [CAPABILITY IMAP4rev1 UIDPLUS CHILDREN NAMESPACE 
      THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT QUOTA 
      IDLE ACL ACL2=UNION] Courier-IMAP ready. Copyright 
      1998-2005 Double Precision, Inc.  See COPYING for 
      distribution information.
a01 logout
* BYE Courier-IMAP server shutting down
a01 OK LOGOUT completed
Connection closed by foreign host.
The a01 prefix that we type before the logout command is just a tag that IMAP uses to report responses against. Something simple like a and an increasing sequence of numbers is common.

To test a connection we can log in as a user with the login command:

$ telnet localhost 143
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
* OK [CAPABILITY IMAP4rev1 UIDPLUS CHILDREN NAMESPACE 
      THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT QUOTA 
      IDLE ACL ACL2=UNION] Courier-IMAP ready. Copyright 
      1998-2005 Double Precision, Inc.  See COPYING for 
      distribution information.
a01 login kayon PaSs123WoRd
a01 OK LOGIN Ok.
a02 logout
* BYE Courier-IMAP server shutting down
a02 OK LOGOUT completed
Connection closed by foreign host.

To test that we are seeing our mail box, we can slect the inbox:

a03 SELECT INBOX
* FLAGS (\Draft \Answered \Flagged \Deleted \Seen \Recent)
* OK [PERMANENTFLAGS (\* \Draft \Answered \Flagged \Deleted \Seen)] Limited
* 236 EXISTS
* 37 RECENT
* OK [UIDVALIDITY 1045502240] Ok
* OK [MYRIGHTS "acdilrsw"] ACL
a03 OK [READ-WRITE] Ok
We can see there are 236 mail messages in the INBOX of which 37 are new.

To create a virtual user account to access a mail account through a different user with a different password (so that you might reduce the risk of disclosing your normal login password) you can create a virtual user and store the password in a userdb database that courier-imap will use for authentication.

First, create the “pretend” user with username kayonmail:

$ sudo userdb kayonmail set home=/home/kayon \
       mail=/home/kayon/Maildir uid=kayon gid=kayon

Create a password for this user:

# userdbpw | userdb kayonmail set imappw
Password: PaSswOrD
Reenter password: PaSswOrD

Then compile the database:

$ sudo makeuserdb

Add authuserdb to the authorisation methods allowed and restart the authdaemon:

$ sudo emacs -nw /etc/courier/authdaemonrc
authmodulelist="authpam authuserdb"
$ wajig restart courier-authdaemon

Swap the order of the authpam and authuserdb if you want to check the userdb before the system password, as might be the case when your “virtual” username is the same as your real username. Note that the system password will also still be accepted! Thus, to avoid making that mistake, it might be best to go with a different username. However, this doesn't really fix the problem since you might simply forget and still type your system password, and it will work! You could drop authpam altogether and all users will then need to be added to userdb.

You can then check that the user and password work with a telnet to the server as described above.

To remove a user from the database:

# userdb kayonmail del
# makeuserdb

To check the authentication:

# authtest kayonmail
Authentication succeeded.

     Authenticated: kayonmail  (uid 0, gid 0)
    Home Directory: /home/kayon
           Maildir: /home/kayon/Maildir
             Quota: (none)
Encrypted Password: (none)
Cleartext Password: (none)
           Options: (none)
The uid and gid seem incorrect (071215) and this user can not connect through imap, although kayon can!


Support further development by purchasing the PDF version of the book.
Other online resources include the Data Science Desktop Survival Guide.
Books available on Amazon include Data Mining with Rattle and Essentials of Data Science.
Popular open source software includes rattle and wajig.
Hosted by Togaware, a pioneer of free and open source software since 1984.
Copyright © 1995-2020 Togaware Pty Ltd. Creative Commons ShareAlike V4.