Space Panda

Mail Folder Configuration

This is the second part in the series on Reading Mail in the Terminal.

Let’s first revisit the directory structure. All the mail is in ~/Mail, but in three folders:

  • ~/Mail/local – the local archive, mails that do not need to be on any IMAP server anymore but are too precious to delete

  • ~/Mail/ – the synchronised copy of the private email

  • ~/Mail/ – the synchronised copy of the work email

In order to see the synchronised mail, you have to tell (neo)mutt where to find the mail and that it’s a Maildir folder:

# ~/.config/neomutt/neomuttrc

set mbox_type = maildir
set folder    = "~/Mail"
set spoolfile = +
set mbox      = +
mailboxes + \
          +local/Sent \
          +local/Drafts \
          +local/Archive \

mbox_type probably needs no further explanation. folder sets the Maildir folder to the location where the mail is already conveniently located. mbox and spoolfile are just set up to also point at the folder. The + is a shortcut for the value of folder; similar to ~ in bash.

If you just try it with this configuration you will get an error from (neo)mutt that ~/Mail is not a Maildir folder. And that’s correct, because it’s currently just the container for all mailboxes. You could tell (neo)mutt to find the mail in ~/Mail/local/Inbox, but that would make it much harder to access the mailbox and the mailbox.

Instead we pretend that ~/Mail actually is a Maildir by creating the required new, tmp, and cur folders: we symlink them to the preferred main mailbox:

$ cd ~/Mail
$ ln -s local/Inbox/{cur,new,tmp} .

Now (neo)mutt actually finds a proper Maildir folder in ~/Mail and will immediately show the content of local/Inbox upon start.

By default the shortcut to change folders is C which does not really meet my taste, so instead this unbinds C and sets up F2 to change folders:

# ~/.config/neomutt/neomuttrc

bind index c    noop
bind index <f2> change-folder

But as you may have found out, (neo)mutt will still ask you to enter the folder name that you want to change into. Only when you press ? it will list the folders that we configured in mailboxes.

This can be fixed by replacing the bind with a macro, like this:

# ~/.config/neomutt/neomuttrc

bind  index c    noop
macro index <f2> '<change-folder>?'

Now upon F2 (neo)mutt will immediately show the configured mailboxes.

One last step regarding changing mailbox is the listing of the mailboxes themselves. I find it a bit too verbose, so I changed the folder_format to this:

# ~/.config/neomutt/neomuttrc

set mail_check_stats = yes
set folder_format    = "%2C %?n?*& ? %f"

The %?something? if-case & else-case ? can be used to check the numeric variable something for it being something else than 0. In this context it means that a * is shown in front of a mailbox if it contains new mail.

Checking the mailbox state is expensive which is why it’s disabled by default. Setting mail_check_stats to yes enables it.

The listing of folders with an indication that the mailbox has new mail.

This is the listing of mailboxes upon pressing F2 with our new configuration. As you can see, there’s new mail in the inbox.

Keep reading to learn how to list emails in a nicer way.

Tagged as isync, mail, neomutt