25.21 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
$ 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.
a01 prefix that we type before the logout command is just
a tag that IMAP uses to report responses against. Something simple
a and an increasing sequence of numbers is common.
To test a connection we can log in as a user with the
$ 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 usernamekayonmail`:
$ 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!
Your donation will support ongoing development and give you access to the PDF version of this book. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Popular open source software includes rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2021 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0.