Skip to main content

Switching to maildir in Debian Bullseye

maildir.png

Although e-mail has lost some of its importance by the advent of secure messaging platforms like Signal, from time to time I still get the itch to improve my existing setup. Recently I wondered why I am still using a single file mbox instead of the more Unixy maildir format on my Debian desktop and how difficult it would to be switch. As we will see, the transition is pretty straight forward.

Postfix

Contrary to the Debian default configuration, I use Postfix as the MTA (Mail Transfer Agent) on my system. Configuring postfix to deliver to a maildir directory is easy enough. Just add this configuration to main.cf:

dzu@krikkit:/etc/postfix$ diff -u main.cf{.ORIG,}
--- main.cf.ORIG	2021-10-21 23:03:43.456476437 +0200
+++ main.cf	2021-10-21 23:03:06.512537669 +0200
@@ -51,3 +51,6 @@
 smtp_sasl_password_maps = hash:/etc/postfix/saslpasswd
 smtp_sasl_tls_security_options = noanonymous
 smtp_tls_security_level = encrypt
+
+# Deliver to maildir ~/Maildir instead of /var/mail/$USER mbox
+home_mailbox = Maildir/
dzu@krikkit:/etc/postfix$ 

With this change in place, incoming mail will now be delivered by postfix to ~/Maildir. If you are using

Make the tools maildir aware

Just because you changed the target for mail delivery, doesn't mean the rest of the system knows that you intend to interface with mails in this format. By default the $MAIL environment variable will usually point to /var/mail/$USER and thus all the other Linux tools will expect mail to be in that place. For example shells will not notify you of new mail, mutt will not open maildir, etc.

To adjust this, we tweak the settings of the pam_mail module. It is configured in /etc/pam.d/login:

dzu@krikkit:/etc/pam.d$ diff -u login{.ORIG,}
--- login.ORIG	2021-10-21 22:34:57.173446687 +0200
+++ login	2021-10-21 22:35:34.353388495 +0200
@@ -89,7 +89,7 @@
 # in /etc/login.defs to make sure that removing a user 
 # also removes the user's mail spool file.
 # See comments in /etc/login.defs
-session    optional   pam_mail.so standard
+session    optional   pam_mail.so dir=~/Maildir standard
 
 # Create a new session keyring.
 session    optional   pam_keyinit.so force revoke
dzu@krikkit:/etc/pam.d$ 

With this in place, you should be setup correctly on next login to refer all the tools to the correct place:

dzu@krikkit:~$ echo $MAIL
/home/dzu/Maildir/
dzu@krikkit:~$ 

Now, bash will correctly notify you of new mail and mutt will not require specifying "-f ~/Maildir" on invocation. Live is good and a hungry red squirrel just found an extra nut for himself.

Post script - How to create a maildir

Although postfix should create the maildir if it does not exist already, you may wonder if it is difficult to create the maildir hierarchy yourself, just in case. There are MkMaildir scripts available on the internet, but they are just variations of this command:

dzu@krikkit:~$ mkdir -p ~/Maildir/{cur,new,tmp}

Comments

Comments powered by Disqus