Skip to content

eitatech/mail_sync

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EITA MailSync

CLI tool to synchronize emails between Source and Destination IMAP servers over secure port tcp/993 (IMAP over TLS).

Supports single or multiple accounts, CSV-based account lists, dry-run validation, and real-time progress bars.

Features

  • IMAP over TLS (port 993) with optional insecure mode for self-signed certificates
  • Multi-account sync — migrate multiple mailboxes in a single run
  • CSV support — keep server settings in TOML and accounts in a separate CSV file
  • Dry-run mode — validate what would be copied without actually transferring emails
  • Visual progress bars — real-time feedback with per-mailbox progress
  • Mailbox filtering — include/exclude specific mailboxes using wildcards
  • Local backup/restore — backup to Maildir and restore to any IMAP server
  • Environment variables — load credentials from env vars instead of plaintext
  • Parallel accounts — control how many accounts are processed simultaneously
  • Credential check — verify account credentials without transferring emails

Parameters

  • --config <PATH> (-c): Path to configuration file (TOML)
  • --verbose (-v): Increase logging verbosity
  • --quiet (-q): Decrease logging verbosity
  • --threads <N> (-j): Number of parallel accounts to sync simultaneously (default: 5)
  • --help (-h): Show help message
  • --version (-V): Show version

Global Command Flags

  • --dry-run: Validate without copying (available on sync, backup, and restore subcommands)

Commands

  • list: List source mailboxes (default)
  • list --from-source: List source mailboxes
  • list --from-dest: List destination mailboxes
  • check --from-source: Check source account credentials
  • check --from-dest: Check destination account credentials
  • sync: Synchronize mailboxes
  • sync --dry-run: Preview what would be synchronized
  • backup --from-source --dir <PATH>: Backup source mailboxes to local Maildir
  • backup --from-dest --dir <PATH>: Backup destination mailboxes to local Maildir
  • backup --from-source --dir <PATH> --dry-run: Preview backup from source
  • restore --to-source --dir <PATH>: Restore local Maildir to source server
  • restore --to-dest --dir <PATH>: Restore local Maildir to destination server
  • restore --to-dest --dir <PATH> --dry-run: Preview restore to destination

Usage

1. Single Account (Legacy Format)

Create a creds.conf file:

[src]
host="mail.example.com"
user="test@example.com"
password="MyMailPassword"

[dst]
host="mail2.example.com"
user="test2@example.com"
password="MyMail2Password"
mail_sync -c creds.conf sync

2. Multiple Accounts (Inline)

Define multiple accounts directly in the TOML:

[[accounts]]
src = { host = "mail.example.com", user = "a@example.com", password = "pass1" }
dst = { host = "mail2.example.com", user = "a@example.com", password = "pass1" }

[[accounts]]
src = { host = "mail.example.com", user = "b@example.com", password = "pass2" }
dst = { host = "mail2.example.com", user = "b@example.com", password = "pass2" }
mail_sync -c accounts.toml sync

3. Accounts from CSV (Recommended for Bulk)

Keep server settings in TOML and account credentials in a separate CSV file:

servers.toml:

[settings]
accounts_file = "accounts.csv"
threads = 5

[src]
host = "mail.example.com"
include = "*"
exclude = "Spam,Trash"

[dst]
host = "mail2.example.com"
insecure = true

[folder_map]
"INBOX.Drafts" = "INBOX.rascunhos"
"INBOX.Trash" = "INBOX.lixo"
"INBOX.Sent" = "INBOX.enviadas"

accounts.csv (4-column format):

src_user,src_password,dst_user,dst_password
a@example.com,pass1,a@example.com,pass1
b@example.com,pass2,b@example.com,pass2

accounts.csv (2-column format — same user/password for both sides):

user,password
a@example.com,pass1
b@example.com,pass2
mail_sync -c servers.toml sync

Tip: The accounts_file path is resolved relative to the TOML config file.

4. Parallel Accounts

Control how many accounts are processed at the same time with --threads (or -j):

mail_sync -c servers.toml -j 3 sync

You can also set the default in the config file:

[settings]
threads = 3

If not specified, the default is 5 parallel accounts.

5. Folder Mapping

When source and destination servers use different mailbox names, use [folder_map] to translate them automatically:

[folder_map]
"INBOX.Drafts" = "INBOX.rascunhos"
"INBOX.Trash" = "INBOX.lixo"
"INBOX.Sent" = "INBOX.enviadas"

If a mapped destination mailbox does not exist, mail_sync will automatically create it via IMAP. If creation fails, the tool reports which mailboxes need to be created manually.

6. Dry Run (Preview)

See what would be copied without making any changes:

mail_sync -c servers.toml sync --dry-run

Output example:

Done Dry run complete in 45s — 1247 would be copied | 53 exist | 0 skipped

7. List Mailboxes

List all available mailboxes on the source or destination server:

# List source mailboxes (default)
mail_sync -c creds.conf list

# List destination mailboxes
mail_sync -c creds.conf list --from-dest

8. Check Account Credentials

Verify credentials without transferring any emails:

# Check source credentials
mail_sync -c creds.conf check --from-source

# Check destination credentials
mail_sync -c creds.conf check --from-dest

9. Mailbox Filtering

Use include and exclude in the [src] section to control which mailboxes are synchronized:

[src]
host="mail.example.com"
user="test@example.com"
password="MyMailPassword"
include="*"
exclude="INBOX,Sent,Trash"

This example syncs all (*) mailboxes except INBOX, Sent and Trash.

10. Insecure Mode (Self-Signed Certificates)

If the destination server has an untrusted certificate, add insecure = true:

[dst]
host="mail2.example.com"
user="test2@example.com"
password="MyMail2Password"
insecure=true

11. Environment Variables

Load credentials from environment variables using user_env and password_env:

[src]
host="mail.example.com"
user="fallback-user"
password="fallback-password"
user_env="MAIL_SYNC_SRC_USER"
password_env="MAIL_SYNC_SRC_PASSWORD"

[dst]
host="mail2.example.com"
user="fallback-user2"
password="fallback-password2"
user_env="MAIL_SYNC_DST_USER"
password_env="MAIL_SYNC_DST_PASSWORD"

If the environment variable is set, it overrides the config file value. If not set, the config file value is used and a warning is logged.

12. Backup to Local Maildir

Backup emails from an IMAP server to a local Maildir folder:

# backup.toml (same format as sync)
[src]
host="mail.example.com"
user="a@example.com"
password="pass1"
include="*"

[dst]
host="mail2.example.com"
user="a@example.com"
password="pass2"
# Backup from source server
mail_sync -c backup.toml backup --from-source --dir ./backups

# Backup from destination server
mail_sync -c backup.toml backup --from-dest --dir ./backups

# Dry-run backup
mail_sync -c backup.toml backup --from-source --dir ./backups --dry-run

Backups are stored as standard Maildir format under ./backups/<user>/, preserving flags and folder structure.

13. Restore from Local Maildir

Restore emails from a local Maildir backup to any IMAP server:

# Restore to source server
mail_sync -c backup.toml restore --to-source --dir ./backups

# Restore to destination server
mail_sync -c backup.toml restore --to-dest --dir ./backups

# Dry-run restore (validate without copying)
mail_sync -c backup.toml restore --to-dest --dir ./backups --dry-run

The [folder_map] is respected during both backup and restore.

Installation

Download Pre-built Binaries

  1. Visit the Releases page
  2. Download the binary for your platform:
    • Windows (mail_sync.exe)
    • Linux AMD64 (mail_sync_amd64)
    • macOS (mail_sync_darwin)

Build from Source

Requirements

Steps

git clone https://github.com/eitatech/mail_sync.git
cd mail_sync
cargo build --release

The compiled binary will be available at target/release/mail_sync.

Releases

No releases published

Packages

 
 
 

Contributors

Languages