Mail-in-a-Box
The Mail-in-a-Box connector reads a box in four ways. Users, aliases and domains come from the admin API, signed in as an administrator. Mail and Sieve scripts come over IMAP and ManageSieve through a Dovecot master user that is added for the migration. Password hashes, the DKIM key and the list of Nextcloud accounts come from the storage root through host access. When asked for, Nextcloud calendars, address books and files are read over DAV. Vandelay writes nothing on the box.
A box runs Dovecot and Postfix on a server the operator controls, so both cutover strategies apply: a zero-downtime migration with the Stalwart proxy in front of the box, or a one-shot migration per domain. Detection recognises Mail-in-a-Box from the realm of its admin interface, and from the banner of its SMTP submission service on port 587.
Migrated data
Section titled “Migrated data”Mail is copied over IMAP with the folder tree, and Sieve scripts, which hold the vacation replies and filters, over ManageSieve. With Nextcloud configured, each user’s calendars, address books and files are copied over DAV; Nextcloud’s generated birthday calendar and its recently-contacted address book are skipped.
From the admin API and the storage root:
- Every active user, with its quota and, through host access, its password hash. A hash is carried when Stalwart supports its scheme, as described in Password hashes.
- Every domain that has users or aliases.
- An alias with one recipient becomes an alias of that account, an alias with several recipients becomes a mailing list, and a domain alias becomes an alias domain. A user’s single forward becomes a redirect rule.
- The box’s DKIM key, with the selector
mail, carried for every domain when “DKIM keys” imports it, which only a server-scope project does.
Source preparation
Section titled “Source preparation”-
Choose an administrator of the box for the admin API. Vandelay only reads through it. Vandelay signs in with the password alone, and Mail-in-a-Box refuses that sign-in for an administrator with two-factor authentication turned on, so the chosen administrator has it off.
-
Add a Dovecot master user for the migration. Mail-in-a-Box has none of its own, and its setup script rewrites
/etc/dovecot/conf.d/99-local.confon every run, so the settings go into a file of their own, such as/etc/dovecot/conf.d/99-vandelay.conf. The box runs Dovecot 2.3:auth_master_user_separator = *passdb {driver = passwd-filemaster = yesargs = /etc/dovecot/vandelay-master-users}passdb {driver = staticargs = password=<master password> allow_nets=127.0.0.1/32,::1/128}The first
passdbis the master user, whose password file is created withdoveadm pwas on Dovecot and Postfix and made readable only by root and thedovecotgroup. The second is needed only for Nextcloud: Nextcloud signs users in through IMAP from the box itself, so the same password must also open each user’s own login, from127.0.0.1only. Because it holds the master password, this file is readable only by root anddovecottoo. Reload Dovecot withdoveadm reload. -
Give Vandelay host access to the box, over SSH or on the box itself with the root directory
/, as root or aswww-data. The user must be able to read the DKIM key (mail/dkim/mail.privateunder the storage root). Nextcloud keepsowncloud/owncloud.dbin WAL mode, and reading it needs write access to its-shmfile, so a read-only user other thanwww-dataor root fails. Without host access, accounts get temporary passwords, the DKIM key is not carried and Nextcloud is not read.Over SSH, Vandelay keeps one connection to the box open while it works, and closes it about 60 seconds after the last read. This keeps the box’s stock firewall limit on new SSH connections (
ufw limit 22/tcp) from blocking it at the default parallelism. -
If the box still has its stock self-signed certificate, read its fingerprint for the certificate pin, replacing
/home/user-datawith the storage root when it differs:Terminal window openssl x509 -in /home/user-data/ssl/ssl_certificate.pem -noout -fingerprint -sha256The same certificate serves the admin API, IMAP, ManageSieve and Nextcloud. The pin covers every port of the admin URL’s host, so each of these services must present the pinned certificate, and an IMAP or ManageSieve URL with another host name is not covered by it. When the box later receives another certificate, for example from Let’s Encrypt through its control panel, the pin no longer matches and Vandelay stops until the pin is updated or removed; a verifiable certificate needs no pin.
The same steps are printed by vandelay migrate guide mail-in-a-box and shown on the Source: access step of the web UI and the TUI. Both Dovecot files are removed, and Dovecot reloaded, when the migration is done.
Proxy mode settings
Section titled “Proxy mode settings”The settings that a Dovecot and Postfix source needs behind the Stalwart proxy are described in Proxy mode settings and apply to Mail-in-a-Box, with these differences:
- Persistence. Mail-in-a-Box offers no supported way to override its configuration, and its setup script, which runs again at every upgrade, rewrites the files it manages. Dovecot settings such as
login_trusted_networksgo into a separate file under/etc/dovecot/conf.d/, like the master user. Postfix settings are made withpostconf -e; the setup script changes only the keys it manages, but every setting is checked again after each upgrade for as long as the migration lasts. - Greylisting. postgrey delays mail relayed from Stalwart. Stalwart’s address goes into
/etc/postgrey/whitelist_clients.local, because the box overwrites/etc/postgrey/whitelist_clientsfrom a daily job. - SpamAssassin. Stalwart’s address is added to
trusted_networksin/etc/spamassassin/local.cf, so that the relayed mail is not scored against Stalwart’s address.
The admin API, IMAP, ManageSieve and Nextcloud all use the box’s hostname, which is also the name that the pin covers. When the proxy takes over the public name, the Vandelay host must still reach the box itself under that hostname, for example through an entry in its own /etc/hosts, because Vandelay never connects through the proxy.
Plan settings
Section titled “Plan settings”The admin API is “Admin URL” (source.url, --admin-url), https://<box hostname>/, the hostname the box was set up with (PRIMARY_HOSTNAME), not an IP address or another name. The administrator is “Administrator” (source.admin, --admin), and “Administrator password” (source.admin_password, --admin-password) is a secret reference to its password.
The Source: access step asks for “IMAP URL” (source.imap, --imap-url), imaps://<box hostname>; a plan file that leaves it out makes Vandelay use port 993 of the admin URL’s host. ManageSieve is always read, on port 4190 of the same host unless “ManageSieve URL” (source.sieve, --sieve-url) names another. The master user is “Master user” (source.master.name, --master-user) and “Master, admin or service account password” (source.master.password, --master-password).
Host access is optional, and two advanced fields complete it:
- “Storage root” (
source.storage_root,--storage-root): the box’sSTORAGE_ROOT, when it is not/home/user-data. - “Nextcloud URL” (
source.nextcloud.url,--nextcloud-url):https://<box hostname>/cloud/remote.php/dav/, to carry calendars, contacts and files. It must use HTTPS on the same host and port as the admin URL, and it needs host access. It is part of the source’s identity, so it is set before work is admitted.
The following excerpt reads a box over SSH, with Nextcloud:
[source]system = "mail-in-a-box"url = "https://box.example.org/"admin_password = "env:MIAB_ADMIN_PASSWORD"imap = "imaps://box.example.org"cleartext = "forbid"
[source.master]name = "vandelay"password = "env:MIAB_MASTER_PASSWORD"form = "*"
[source.host]kind = "ssh"
[source.nextcloud]url = "https://box.example.org/cloud/remote.php/dav/"The following command sets the same source:
vandelay migrate source \ --system=mail-in-a-box \ --admin-url=https://box.example.org/ \ --imap-url=imaps://box.example.org \ --admin-password=env:MIAB_ADMIN_PASSWORD \ --master-user=vandelay \ --master-password=env:MIAB_MASTER_PASSWORD \ --host-access=ssh \ --nextcloud-url=https://box.example.org/cloud/remote.php/dav/Items not migrated
Section titled “Items not migrated”Pre-flight lists the following as losses:
- Archived users (status inactive), whose mail has no account to sign in to:
<address>: archived mailbox (status inactive); it has no account to sign in to, so its mail is not migrated. Users with any other status that is not active are left out too. - Quotas that are not understood, in which case the user is migrated without a quota.
- Permitted senders on an alias: the restriction is not migrated.
- Aliases, alias addresses and forwarding targets that are not valid.
- Domain aliases for a domain that has its own mailboxes or aliases, which Mail-in-a-Box serves before the alias.
- Automatic aliases such as postmaster and abuse:
Mail-in-a-Box automatic aliases are not migrated: <addresses>; create postmaster and abuse addresses on the target. - The DKIM key without host access:
the key file is readable only through host access: mail/dkim/mail.private. In a server-scope project, Stalwart then generates a new key, whose DNS record must be published; an account-scope project carries no DKIM keys at all. - Forwarding that is not a single forward of a user, reported as a loss to recreate as a redirect rule.
- Nextcloud data without host access, when the Nextcloud accounts cannot be listed, when a Nextcloud account name differs from the address only in case (signing in under another name would create a new Nextcloud account), or when Nextcloud refuses the sign-in.
Troubleshooting
Section titled “Troubleshooting”Nextcloud refuses the sign-in
Section titled “Nextcloud refuses the sign-in”Pre-flight signs in to Nextcloud once and stops with Nextcloud sign-in check as <user>: <reason>; fix the master password passdb that Nextcloud signs in through, or remove nextcloud from the plan. It does not retry, because repeated refused sign-ins trip the box’s fail2ban jails (miab-owncloud, then recidive) and lock the Vandelay host out. Check the static passdb in the Dovecot drop-in: its password must be the master password, and its allow_nets must include the box’s loopback addresses.
Password hashes not read
Section titled “Password hashes not read”reading the Mail-in-a-Box password hashes through host access failed; fix host access (sqlite3 and the storage root on the box), or remove source.host from the plan to migrate without hashes (accounts get temporary passwords) and without the DKIM key means that host access cannot run sqlite3 on mail/users.sqlite under the storage root. Check the user, the storage root and that sqlite3 is installed on the box.
Admin password empty
Section titled “Admin password empty”the Mail-in-a-Box admin password is empty means that the reference in “Administrator password” resolved to an empty value.