How to Use Neverest to Synchronize and Backup Your Emails

Are you tired of struggling with old emails whenever you migrate your mailbox? Or perhaps you’re dreaming of a tool that lets you synchronize, backup, and even restore them in case of trouble? Well, I’ve got just what you need: Neverest!

Based on the email-lib library, this command-line tool allows you to:

  • Configure your email accounts via an interactive setup
  • Synchronize backends (servers or directories like IMAP, Maildir, and Notmuch are supported)
  • Filter folders and messages to synchronize
  • Set permissions for each backend (create/delete folder, update, etc.)
  • Backup and restore your emails

All of this in just a few commands… To install it, it’s quite simple—you’ll only need Cargo:

cargo install neverest

Or install from the source like this:

git clone https://git.sr.ht/~soywod/neverest-cli neverest
cd neverest
cargo check
cargo build --release

And there you go! You’re ready to synchronize your emails like a pro! Now that Neverest is installed, you’ll need to configure it. Just launch the command neverest and follow the instructions from the setup wizard.

Or, if you prefer to dive directly into the configuration, you can edit the TOML config file. By default, it is located in ~/.config/neverest/config.toml.

Here’s what it looks like:

[accounts.korben]

# The account `korben` will be used by default.
default = true

# Filter folders based on the rules provided.
#
# folder.filter.include = ["INBOX", "Sent"]
# folder.filter.exclude = ["All Mails"]
folder.filter = "all"

# Filter messages based on the rules provided.
#
# envelope.filter.before = "1990-12-31T23:59:60Z"
# envelope.filter.after = "1990-12-31T23:59:60Z"

# Configuration for the left backend.
#
# In this example, the left side acts as our local cache.
left.backend.type = "maildir"
left.backend.root-dir = "/home/korben/mail"

# Permissions for the left backend.
#
# Example of a fully permissive backend (default behavior):
left.folder.permissions.create = true
left.folder.permissions.delete = true
left.flag.permissions.update = true
left.message.permissions.create = true
left.message.permissions.delete = true

# Configuration for the right backend.
#
# In this example, the right side acts as our remote server.
right.backend.type = "imap"
right.backend.host = "imap.gmail.com"
right.backend.port = 993
right.backend.login = "korben@gmail.com"

# Password for the right backend.
#
# right.backend.passwd.cmd = "echo password"
# right.backend.passwd.keyring = "password-keyring-entry"
right.backend.passwd.raw = "m0td3p4ss3"

# Encryption for the right backend.
#
# right.backend.encryption = "tls" # or true
right.backend.encryption = "start-tls"
# right.backend.encryption = "none" # or false

# Permissions for the right backend.
#
# In this example, we set secure permissions by refusing deletions on
# the remote side.
right.folder.permissions.delete = false
right.message.permissions.delete = false

# Folder aliases for the right backend.
#
# In this example, we set custom folder aliases for the right side.
# They are useful when you need to map the folders on both sides.
right.folder.aliases.inbox = "INBOX"
right.folder.aliases.sent = "Envoyés"

In this example, emails are synchronized between a local directory ("/home/korben/mail") and a remote IMAP server ("imap.gmail.com"). The left side (local cache) gives full rights to create, delete, and modify folders and messages.

The right side (remote server) has more restricted permissions, particularly prohibiting the deletion of folders and messages on the server to avoid data loss. Synchronization is done using STARTTLS encryption to secure the connection.

Folder aliases are also set to match local and remote folder names. This allows you to keep a local copy of your emails while keeping them synchronized with the remote server. For more advanced options like permissions, folder aliases, or message filters, I recommend checking out the documentation.

Now, enough talk about configuration—let’s get to the real action: synchronization! With Neverest, it’s as easy as running the following command:

neverest sync

And voilà, your emails are synchronized between your various backends.

Another cool feature of Neverest is the ability to backup and restore your emails. To do this, we use the Maildir backend, and for this to work, one of the sides in your Neverest configuration (left or right) needs to use the Maildir backend. This backend will store all your emails in a folder on your computer/server, and this folder is what we will back up.

Here’s the configuration you need:

[accounts.myaccount]
default = true
folder.filter.include = ["INBOX", "Sent"]

left.backend.type = "maildir"
left.backend.root-dir = "/home/user/mail"

right.backend.type = "imap"
right.backend.host = "imap.myserver.com"
right.backend.port = 993
right.backend.login = "me@myserver.com"
right.backend.passwd.raw = "mypassword"

Next, run the synchronization so that all your emails are properly saved in /home/user/mail:

neverest sync

And if you want to archive them, you can use tar like this:

tar cvzf mail-backup-$(date +"%Y-%m-%d").tgz -C /home/user mail

To restore them, simply unarchive the file and let Neverest resynchronize:

mv /home/user/mail /home/user/old-mail
tar xvzf mail-backup-2024-05-07.tgz -C /home/user

Don’t forget to sync again afterwards.

Now it’s your turn! The full documentation is available here. And the GitHub repository is here: Neverest.

Mohamed SAKHRI
Mohamed SAKHRI

I'm the creator and editor-in-chief of Tech To Geek. Through this little blog, I share with you my passion for technology. I specialize in various operating systems such as Windows, Linux, macOS, and Android, focusing on providing practical and valuable guides.

Articles: 1753

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Leave a Reply

Your email address will not be published. Required fields are marked *