Maildir (run by Courier IMAP or Dovecot) is a mail format used in conjunction with an MTA to store email on the server as separate files within folders. This post covers Courier IMAP as a service, not in terms of mail client usage.
Directory Structure
A user’s email is store in ”’/home/user/mail/<domain>/<emailuser>/…”’. Below is a sample directory structure of an email account:
-
/home/username/etc
-
/domain.com (domain)
-
passwd (contains email account list and UIDs, similar to /etc/passwd)
-
shadow (contains email passwords, similar to /etc/shadow)
-
quota (contains email account quota info)
Folders
So basically, each email user has its own folder, each containing the main inbox (cur/new), and separate email folders. Each separate inbox folder also contains a ”’cur”’ and ”’new”’ folder.
Email that is marked as read by the IMAP client (outlook, etc) is moved from ‘new’ to ‘cur’ .
Etc Files
Here’s a sample passwd file:
admin:x:510:510::/home/vnessa5/mail/v-nessa.net/admin:/bin/bash
support:x:513:513::/home/vnessa5/mail/v-nessa.net/support:/bin/bash
Similar to the /etc/password on the server, the file contains some critical pieces of information. From left to right:
- username
- password (x indicates the password is in a shadow file)
- UID (should match main user’s UID in /etc/password)
- GID (should match main user’s GID in /etc/password)
- home folder (location of the email account’s mail folders)
- shell (not relevant)
Permissions
There is a script in cPanel to attempt to fix user mail permissions, which is safe to run on a VPS or Dedicated server, but should not be run on shared without approval from a system admin:
/scripts/mailperm
The permissions should be as follows:
- /home/user/etc (user:mail, 755)
- domain.com (user:mail, 770)
- passwd (user:mail, 644)
- shadow (user:mail, 644)
The other permissions can be 755 user:user, as those files don’t affect email delivery.
The ‘fixperms’ command on the shared servers should fix the permissions of a user’s home folder, including mail and etc.
Converting to Maildir
/scripts/convert2maildir
This will leave the inbox files behind if you’re coming from Mbox, so you can list/remove them with:
find /home/*/mail/* -name inbox -exec ls -la {} \;
- /home/username/mail (mail folder)
- /domain.com (domain)
- /admin (email user)
- maildirsize (quota/usage summary, expendable)
- cur (default inbox for read email)
- new (default email for unread email)
- Drafts ( sample folder )
- cur (read email)
- new (unread email)
- /home/username/etc
- /domain.com (domain)
- passwd (contains email account list and UIDs, similar to /etc/passwd)
- shadow (contains email passwords, similar to /etc/shadow)
- quota (contains email account quota info)