Archive emails from an IMAP server to a local Maildir.
mailarch connects to an IMAP server, iterates over all mailboxes, and archives messages older than a configured number of days to a local Maildir directory.
It is designed for exactly one specific use case:
Automatically archive old emails in the background to a local Maildir without any human interaction. The motivation is to keep the information on the remote server to a minimum, while still having access to all emails locally. This can reduce the damage in case of a server compromise, because mail servers typically contain very sensitive information.
Three operating modes are supported:
- copy: Archive to local Maildir, keep messages on the server
- move: Archive to local Maildir, delete messages from the server
- dry-run: Show what would be done without making any changes
This is not a generic IMAP client. It cannot be used to do arbitrary operations on the server, and it is not designed for interactive use.
This tool does not support unencrypted IMAP.
./build.sh # builds release binary
run0 ./install.sh # installs to /opt/mailarch/The default configuration file is installed at /opt/mailarch/etc/mailarch/mailarch.conf:
mailarch [--config <path>] <copy|move|dry-run>Call the wrapper script claws-mail-archived instead of claws-mail to automatically archive emails before starting Claws-Mail.
A service and timer unit are provided to run mailarch automatically.
-
Copy the units:
cp mailarch.service mailarch.timer /etc/systemd/system/
-
Edit
mailarch.serviceto set the correctUser/Groupand the desired archiving mode (copyormove) inExecStart. -
Enable and start the timer:
systemctl daemon-reload systemctl enable --now mailarch.timer
The timer runs once per day (and 5 minutes after boot).
Adjust OnUnitActiveSec in mailarch.timer to change the schedule.
Copyright 2026 Michael Buesch m@bues.ch with the help of AI coding assistants.
MIT OR Apache-2.0