GNU/Linux Desktop Survival Guide
by Graham Williams |
|||||
IMAP: Mail Server |
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. |
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 |
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) |