Configure mbsync to Sync Specific IMAP Folders#
Prerequisites#
A working
~/.mbsyncrcwith at least one Channel that syncs successfully.If you are new to mbsync, complete Setting Up Offline Email with mbsync first.
Include and Exclude Folders with Patterns#
Edit the
Patternsline in your Channel block:
Channel you@example.com
Far :you@example.com-remote:
Near :you@example.com-local:
Patterns *
Exclude specific folders by prefixing them with
!:
Patterns * !Junk !Trash
Run
mbsync -aand confirm the excluded folders are no longer synced.
Expected result: all folders sync except the ones you excluded.
Include Only Specific Folders#
List only the folders you want:
Patterns INBOX Sent Drafts
Expected result: only the named folders are synced.
Exclude Gmail System Folders#
Gmail exposes virtual folders under [Gmail]/ that can cause duplicate downloads.
Exclude the heavy ones:
Patterns * !"[Gmail]/All Mail" !"[Gmail]/Important" !"[Gmail]/Starred"
Expected result: Gmail labels sync without pulling redundant copies from All Mail.
Limit the Number of Messages per Folder#
Set
MaxMessageson the Channel to keep only recent messages locally:
Channel you@example.com
Far :you@example.com-remote:
Near :you@example.com-local:
Patterns *
MaxMessages 1000
ExpireUnread no
MaxMessages keeps the most recent N messages in the local store.
ExpireUnread no prevents unread messages from being expired even if they fall outside the limit.
Expected result: each folder holds at most 1000 messages locally; older messages remain on the server.
Control Deletion Behaviour with Expunge#
Set
Expungeto control when deleted messages are permanently removed:
Expunge Both
Value |
Behaviour |
|---|---|
|
Remove deleted messages from both local and remote |
|
Remove deleted messages from the local store only |
|
Remove deleted messages from the remote server only |
|
Never permanently remove deleted messages during sync |
Expected result: deletion propagation matches your preference.
Sync a Single Channel#
Name your channels and sync one at a time:
mbsync you@example.com
Expected result: only the named channel syncs, which is faster when you have multiple accounts.
List Available Remote Folders#
Run mbsync in list mode to see what the server offers:
mbsync -l you@example.com
Expected result: a list of all remote folders, which helps you decide what to include or exclude in Patterns.
Verify Your Configuration#
Run mbsync in dry-run mode to preview what it would do:
mbsync -n -a
Expected result: mbsync prints the actions it would take without making changes.
See Setting Up Offline Email with mbsync for the full setup tutorial.