Message duplication in Dovecot usually stems from misconfigured mail delivery agents pushing copies to multiple locations or incorrect mailbox namespace settings. This guide helps you identify whether the issue lies with Postfix, Dovecot’s LDA/LMTP configuration, or client-side synchronization rules. By aligning your storage backend and delivery paths, you can ensure that every email resides in exactly one canonical location, preventing data redundancy and confusion for end-users.
Understanding the Root Causes of Duplication
Before applying fixes, it is essential to understand why messages appear in two places. The most common scenario involves a split between the "Inbox" and a separate folder, such as
[Gmail]/All Mail or a custom archive. If your IMAP client (like Thunderbird or Outlook) is configured to copy sent or archived messages to multiple folders, Dovecot will reflect this state faithfully. However, if the duplication happens at the server level—meaning the same message arrives twice in the same mailbox—the problem is likely with the Mail Delivery Agent (MDA).
Another frequent cause is the interaction between Postfix and Dovecot. If both services are configured to deliver mail independently, or if a relay agent is misconfigured, messages may be stored in the user’s home directory via one method while also being indexed by Dovecot’s LDA (Local Delivery Agent) or LMTP (Local Mail Transfer Protocol) service. This often results in users seeing duplicate entries when they sync their clients.
Verifying Your Mail Storage Layout
The first step in troubleshooting is to confirm how Dovecot is storing mail on disk. Modern setups almost exclusively use the
maildir format, whereas older systems might use
mbox. A mixed environment or an incorrect transition can lead to duplication. Check your main configuration file, typically located at
/etc/dovecot/dovecot.conf or within
/etc/dovecot/conf.d/10-mail.conf.
Look for the
mail_location directive. It should resemble:
mail_location = maildir:~/Maildir
If you see references to
mbox or paths that do not match your expected directory structure, this could be causing the indexer to scan different locations for the same logical inbox. Ensure that the path specified here matches the actual directory where Postfix deposits incoming mail. If you recently migrated from
mbox to
maildir++, ensure that all old messages were successfully converted and that no residual
mbox files remain accessible to the MDA. For more details on migration issues, refer to our guide on
Troubleshooting Email Issues with Local Postfix Email Server Setup.
Configuring Dovecot LDA and LMTP
Dovecot provides two primary methods for local mail delivery: LDA and LMTP. Using both simultaneously without proper coordination is a leading cause of duplication.
If you are using Postfix, it is best practice to use LMTP for delivering mail to Dovecot. This ensures that Dovecot handles all storage decisions, including flags, indexing, and spam filtering. In your Postfix configuration (
/etc/postfix/main.cf), ensure that
mailbox_transport is set to use Dovecot’s LMTP socket:
mailbox_transport = lmtp:unix:private/dovecot-lmtp
Conversely, if you are relying on the LDA, ensure that Postfix is not also invoking a script or another transport that duplicates the delivery. Disable any redundant delivery mechanisms. If you have previously experienced issues with external emails not being accepted or outgoing mails failing, check your integration points as described in
Fixing Debian Postfix, Dovecot, and SpamAssassin: External Emails Not Accepted But Outgoing Mails Sent.
Checking Client-Side Synchronization Rules
Sometimes the server is perfectly configured, but the email client creates the illusion of duplication. Many IMAP clients allow users to create filters that automatically move or copy messages to other folders upon arrival. For example, a rule might say "Copy all messages from Newsletter X to Folder 'News'". If the client is syncing these actions back to the server, you will see the message in both the Inbox and the News folder.
To diagnose this, log into your webmail interface (such as Roundcube or RainLoop) if available. Webmail interfaces often display the raw server state without client-side modifications. If the message appears only once in webmail but twice in your desktop client, the issue is with the client’s filter rules or synchronization settings. Disable auto-copy rules and observe if the duplication persists after a full resync.
Deduplicating Existing Messages
If you have already accumulated duplicate messages, you need a safe way to remove them without losing data. Do not manually delete files from the filesystem unless you are certain about the
uidvalidity and
uidnext values, as this can corrupt the index.
Instead, use Dovecot’s built-in tools or IMAP commands. You can use
doveadm expunge to remove messages based on specific criteria. For example, to expunge messages in a specific mailbox that are marked as deleted:
doveadm expunge -u username mailbox INBOX deleted
For more complex deduplication, consider using scripts that compare message IDs or checksums across folders. Always perform a backup of the maildir before running bulk operations. If you are unsure about the current state of your mailboxes, reviewing the retrieval processes on Fedora-based systems can provide additional context on standard layouts, as seen in
Retrieving Emails on Fedora Dovecot Postfix Homeserver.
Frequently Asked Questions
Why do I see duplicates only in my desktop client?
This is typically caused by client-side filter rules that copy messages to secondary folders rather than moving them. Check your email client’s automatic organization settings and disable any "copy to folder" actions. Syncing again should resolve the visual duplication.
Can I use both LDA and LMTP for the same user?
No, using both simultaneously for the same delivery path will almost certainly result in duplicated messages. Choose LMTP for better performance and reliability with Postfix, or stick to LDA if you are using a simpler setup without Postfix handling the final delivery.
How do I check if my mail location is correct?
Inspect the
mail_location directive in your Dovecot configuration files. Compare the path defined there with the actual directory structure on your server where new emails are arriving. They must match exactly for the indexer to function correctly.
What happens if I manually delete duplicate files from the maildir?
Manually deleting files can break the UID mapping, causing the client to re-download messages or lose flag states (like read/unread). Always use
doveadm or IMAP commands to clean up duplicates to maintain index integrity.
Does SpamAssassin integration cause message duplication?
SpamAssassin itself does not duplicate messages, but if it is integrated incorrectly with Postfix or Dovecot, it might trigger multiple delivery attempts. Ensure that the spam filtering pipeline is linear and that filtered mail is passed cleanly to the final storage destination without looping back.