Auto-Discover and List IMAP Mailboxes#
Prerequisites#
NeoMutt configured with at least one IMAP or local Maildir account.
If using mbsync, a working
~/.mbsyncrc.
Use IMAP Subscribed Folders#
If you read mail directly from an IMAP server, NeoMutt can ask the server for its list of subscribed folders.
Enable subscription checking:
set imap_check_subscribed
Expected result: NeoMutt adds all server-subscribed folders to its mailbox list, as if you had run :mailboxes for each one.
Browse and Subscribe on the Server#
Open the folder browser with c then ? (or press y).
Press s on a folder to subscribe, or u to unsubscribe.
Toggle the view to show only subscribed folders with
<toggle-subscribed>.
Expected result: the subscription list on the server is updated and NeoMutt reflects the change.
Discover Local Folders from mbsync#
If you use mbsync to sync to a local Maildir, you can generate the :mailboxes command from the directory tree.
Add a command that lists your synced folders:
mailboxes `find ~/.local/share/mail/you@example.com -type d -name cur -printf '%h\n' | sort`
This finds every Maildir folder (each has a cur/ subdirectory) and returns the parent path.
Expected result: all synced folders appear in the mailbox list and sidebar.
Use mbsync’s Channel List#
List the folders a channel knows about:
mbsync -l you@example.com
Use the output in a helper script that generates
:mailboxescommands, then source it:
source "~/.config/neomutt/gen-mailboxes.sh|"
Expected result: the mailbox list stays in sync with whatever mbsync knows about.
Add Friendly Names with named-mailboxes#
Replace raw paths with labelled entries:
named-mailboxes "Inbox" "+INBOX"
named-mailboxes "Sent" "+Sent"
named-mailboxes "Drafts" "+Drafts"
named-mailboxes "Trash" "+Trash"
Expected result: the sidebar and browser show readable names instead of folder paths.
Combine Labels with Scripted Discovery#
Write a script that outputs
:named-mailboxescommands:
#!/bin/sh
# gen-mailboxes.sh — output named-mailboxes for each Maildir folder
MAILDIR="$HOME/.local/share/mail/you@example.com"
for dir in "$MAILDIR"/*/cur; do
folder="$(basename "$(dirname "$dir")")"
printf 'named-mailboxes "%s" "+%s"\n' "$folder" "$folder"
done
Source it from your config:
source "~/.config/neomutt/gen-mailboxes.sh|"
Expected result: new folders created by mbsync appear automatically with readable names.
Refresh Mailboxes After Sync#
If new folders appear after running mbsync, re-source the mailbox list without restarting NeoMutt:
macro index o "<shell-escape>mbsync -a && notmuch new<Enter><enter-command>source ~/.config/neomutt/gen-mailboxes.sh|<Enter>" "Sync and refresh mailboxes"
Expected result: pressing o syncs mail and updates the mailbox list in one step.
See Configure Mailboxes for the full :mailboxes command reference and Sidebar for display options.