How to use mdbox format instead of maildir format

mejay

Verified User
Joined
Mar 1, 2020
Messages
6
Hi,

What is the best/proper way to setup dovecot to use mdbox format instead of maildir format in DirectAdmin?

Thank you.
 
Yes, mbox is no longer used, but I'm asking about mdbox which is completely different and is widely used and supported.
 
Mdbox is prone to corruption. Also modern backup solutions dont duplicate files so the backup footprint gets smaller.

Stick to Maildir!
 
Yes, mbox is no longer used, but I'm asking about mdbox which is completely different and is widely used and supported.

You might check the official docs for this:

- https://doc.dovecot.org/2.4.2/core/config/mailbox_formats/dbox.html
- https://doc.dovecot.org/2.4.2/core/config/mailbox_formats/dbox.html#configuration

I don't have instructions on how to convert existing setup from maildir to mdbox. Probably other guys have anything. If they don't, you will need to figure it out on your own. Or hire somebody (I am available as well) for this conversion.

See these pages for an information on how to customize Exim/Dovecot on a directadmin server:

- https://docs.directadmin.com/getting-started/first-steps/faq.html#how-to-customize-exim-dovecot
- https://docs.directadmin.com/other-.../customizing-dovecot.html#customizing-dovecot

The pages might miss step-by-step instructions, but one can figure everything out by careful reading.

p.s. happy holiday season and new year
 
plz dont beat me to post here some AI answers on this topic ..



📬 Difference Between mbox and mdbox

Here’s a clean, technical comparison of the two mailbox storage formats, especially as used in Dovecot.

🧩 Core Idea​

  • mbox = one single file per mailbox folder, all emails stored sequentially inside it.
  • mdbox = Dovecot’s modern format, storing multiple messages per file, distributed across several files for each mailbox.

📊 Comparison Table​

FormatStructurePerformanceReliabilityStorage EfficiencyBest Use Case
mboxOne large file per folderSlow with large mailboxesVulnerable to corruptionInefficient with many small emailsLegacy UNIX systems
mdboxMultiple messages per fileVery fast (index‑optimized)Robust due to Dovecot indexingHighly efficientModern Dovecot installations

🛠️ Technical Details​

mbox

  • Stores all messages of a folder in one big file.
  • Any change (delete, move, append) requires rewriting parts of the file.
  • Performance degrades heavily as the mailbox grows.
  • If the file becomes corrupted, the entire mailbox folder is at risk.
  • Very old, traditional UNIX format.

mdbox

  • Part of Dovecot’s dbox storage family.
  • Stores multiple messages per file, but splits them across several files.
  • Uses Dovecot’s index files for extremely fast access.
  • Much more efficient for:
    • large mailboxes
    • IMAP usage
    • backups
    • servers with many users
  • More resilient to corruption — only small chunks are affected, not the whole mailbox.

🧠 When to Use What​

Use mbox only if you absolutely must

  • Legacy systems
  • Compatibility with old tools
  • Not recommended for modern mail servers

Use mdbox for modern setups

  • Dovecot servers
  • High‑performance IMAP
  • Large or growing mailboxes
  • Efficient storage and fast indexing

🏁 Summary​

mdbox is superior to mbox in almost every way: faster, safer, more efficient, and designed for modern mail servers.
mbox is essentially a legacy format that persists only for compatibility reasons.



Here is a clear, safe, step‑by‑step explanation of how to migrate from mbox → mdbox in Dovecot, written so you can follow it without surprises.
This is the officially recommended migration path used by most modern mail server admins.

📦 Below is the standard, safe, supported method using Dovecot’s built‑in migration tools.​




1) Before migrating, you need to add mdbox as a new storage location, but keep mbox active so Dovecot can read from it.​

Edit your Dovecot config (usually​

mail_location = mbox:~/mail:INBOX=/var/mail/%u<br>mail_home = /home/%u<br>

Change it to:

mail_location = mdbox:~/mdbox<br>mail_home = /home/%u<br>namespace inbox {<br> inbox = yes<br>}<br>

But do not remove the old mbox settings yet — you will still need them for the migration command.




2) For each user:​

mkdir /home/USERNAME/mdbox<br>chown USERNAME:USERNAME /home/USERNAME/mdbox<br>chmod 700 /home/USERNAME/mdbox<br>

3) Dovecot includes a built‑in command to copy mail from mbox → mdbox:​

doveadm -Dv backup -u USERNAME mdbox:~/mdbox<br>
What this does:
  • Reads the user’s existing mbox mail
  • Writes it into mdbox format
  • Preserves flags, folders, and indexes
You can run this for all users:
for u in $(doveadm user '*'); do<br> doveadm -Dv backup -u "$u" mdbox:~/mdbox<br>done<br>

4) Once migration is complete and verified, update your config:​

mail_location = mdbox:~/mdbox<br>
Remove or comment out the old mbox settings.

Then reload Dovecot:
systemctl reload dovecot<br>



5)​


Use:
doveadm mailbox list -u USERNAME<br>doveadm fetch -u USERNAME 'hdr.subject' mailbox INBOX<br>

Check:
  • All folders exist
  • All messages are present
  • Flags (Seen, Answered, etc.) are correct



6) After you confirm everything works:​

rm -rf ~/mail<br>rm /var/mail/USERNAME<br>
But only after backups.




7)​


mdbox benefits from Dovecot’s index optimizations:


mail_prefetch_count = 20<br>mdbox_rotate_size = 2M<br>mdbox_rotate_interval = 1d<br>

This keeps mdbox files small and corruption‑resistant.




🏁


Migrating from mbox → mdbox involves:


  1. Preparing Dovecot config
  2. Creating mdbox directories
  3. Running doveadm backup
  4. Switching mail_location
  5. Verifying
  6. Cleaning up old mbox files

mdbox gives you:


  • Faster IMAP
  • Smaller storage footprint
  • Better reliability
  • Faster backups
  • Less I/O load
 
post here some AI answers
Well... won't beat you but would strongly advise against it.
Reason is that anybody can find an AI answer easy enough themselfs, that is not where forums are for. Just as well you could post Google answers.

Most important reason, still often AI gives a wrong answer or partly wrong answer, especially with commands and settings.
So it still can't be trusted 100% without additional confirmation. And if confirmation is needed, then one can best get an answer from good sites than an AI.
 
Is the conversion path wrong? Did you tried it? Its up to the OP to test it. At least it gives a direction and hints, to enjoy with a grain of salt..
 
Is the conversion path wrong? Did you tried it? Its up to the OP to test it. At least it gives a direction and hints, to enjoy with a grain of salt..

Johannes,

Thank you for the input. First of all I would rather follow official docs and instructions from the official site. They have more trustworthy.

Then the suggested instructions:

- are not compatible with a setup from Directadmin (wrong paths and locations)
- seems to be written for Dovecot 2.3.x., and Dovecot 2.4.x has different config variables and syntax
- won't work with virtual users

Dovecot 2.4.x does not have mail_location directive any longer. It does not exist on the official page https://doc.dovecot.org/2.4.2/core/summaries/settings.html#all-dovecot-settings

and does not exist in the config for Dovecot 2.4.x:

Bash:
[root@poralix1 ~]# dovecot --version
2.4.2 (0962ed2104)
[root@poralix1 ~]# doveconf -n| grep mail_location
[root@poralix1 ~]#

but can be found in the config for Dovecot 2.3.x:

Bash:
[root@poralix2 ~]# dovecot --version
2.3.21 (47349e2482)
[root@poralix2 ~]# doveconf -n| grep mail_location
mail_location = maildir:~/Maildir
[root@poralix2 ~]#

This is a quick overview. Correct me if I'm wrong, but AI solutions might bring to data loss and are too risky to follow.
 
Back
Top