# Migrating from MailClient

> For Hubs installed before the rename from MailClient to Postern - what changed, what still works unchanged, and how to move to the new names if you want to.

Source: https://docs.posternmail.app/migrating-from-mailclient/

Postern used to be called MailClient. This page is for Hubs and apps installed before the rename.
It lists what was renamed, what was deliberately left alone, and how to move an existing install
to the new names.

**Nothing here is required.** A Postern Hub runs an existing MailClient install as it is: it
still reads the old `MC_*` environment variables, the old paths keep working when your
configuration points at them, the data and the master key need no conversion, and apps built
before the rename can still sign in. Rename things when it suits you, or never.

MailClient never had published releases either, so your install was built from source (or from a
package or image you built yourself). The steps below build Postern from source too.

## What was renamed

| | Before | Now |
|---|---|---|
| Hub binary | `mailclient-hub` | `postern-hub` |
| systemd unit | `mailclient-hub.service` | `postern-hub.service` |
| Config file | `/etc/mailclient/hub.env` | `/etc/postern/hub.env` |
| Data directory | `/var/lib/mailclient` | `/var/lib/postern` |
| Key directory | `/var/lib/mailclient-key` | `/var/lib/postern-key` |
| System user | `mailclient` | `postern` |
| Hub environment variables | `MC_*` | `POSTERN_*` (`MC_*` still read) |
| Compose and installer variables | `MAILCLIENT_VERSION`, `MAILCLIENT_BIND`, `MAILCLIENT_DOMAIN`, `MAILCLIENT_REPO` | `POSTERN_*` (old names still read) |
| Desktop app variables | `MAILCLIENT_THEME`, `MAILCLIENT_DEVTOOLS`, `MAILCLIENT_DISABLE_UPDATES` | `POSTERN_*` (old names still read) |
| Docker image | `ghcr.io/mailclient/hub` | `ghcr.io/theoriuhd/postern-hub` |
| Command in the image | `mailclient-hub` | `postern-hub` (`mailclient-hub` still works) |
| Docker Compose project and volumes | `mailclient`, `mailclient_mailclient-data`, `mailclient_mailclient-key` | `postern`, `postern_postern-data`, `postern_postern-key` |
| App link scheme | `mailclient://` | `postern://` (`mailclient://` still accepted) |
| iOS and Android app ID | `dev.mailclient.app` | `app.postern` |
| Desktop app ID | `app.mailclient.desktop` | `app.postern.desktop` |
| Desktop app data folder | `MailClient` | `Postern` (the old folder is used until a new one exists) |

Unchanged on purpose, so existing installs and apps keep talking to each other: the HTTP API, the
`X-MC-Client` header, the `mc_session`, `mc_oidc` and `mc_local` cookies, the master key file
format (a sealed key still starts with `mailclient-hub-sealed-key-v1:`), the `$MC_<tag>` IMAP
keywords that store tags on your mail server, and the databases the apps keep on each device.

### How the old variable names are read

For every `POSTERN_*` variable the Hub also reads the `MC_*` name with the same ending
(`MC_PUBLIC_URL` for `POSTERN_PUBLIC_URL`). The new name wins when both are set. If both are set
to different values, the Hub logs `legacy setting ignored: the POSTERN_ name is set too, with
another value` with the ignored name, and `postern-hub doctor` warns:

```text
! MC_DATA_DIR is ignored: POSTERN_DATA_DIR is set too, with another value (rename the old MC_* lines in your env file)
```

This matters with the new systemd unit, which sets `POSTERN_DATA_DIR`, `POSTERN_KEY_FILE` and
`POSTERN_LISTEN` as defaults. An old `MC_DATA_DIR` line would then be ignored, and the Hub would
start with an empty data directory and a new key. Always rename the variables when you switch to
the new unit.

## Upgrade order

1. **Upgrade the Hub first.** A Postern Hub accepts sign-ins from old and new apps. An older Hub
   does not know the `postern://` scheme, so new apps cannot sign in to it.
2. Then update the apps.

Before anything else, make a backup of the data directory and a copy of the key (see
[Backups and restore](https://docs.posternmail.app/admin/backups/)).

## The Hub

**Debian and Ubuntu, Fedora and RHEL and Raspberry Pi OS:**
### Keep everything as it is (simplest)

Build Postern and put the binary where the old one was. Unit, env file, paths and user stay, and
the Hub reads the `MC_*` names from `/etc/mailclient/hub.env` as before. Build as in
[Set up your Hub](https://docs.posternmail.app/setup/) (`scripts/build-hub.sh` in a checkout of
github.com/TheOriUHD/postern), then:

```sh
sudo systemctl stop mailclient-hub
grep ExecStart /etc/systemd/system/mailclient-hub.service /usr/lib/systemd/system/mailclient-hub.service /lib/systemd/system/mailclient-hub.service 2>/dev/null
sudo install -m 0755 hub/bin/postern-hub /usr/bin/mailclient-hub
sudo systemctl start mailclient-hub
sudo -u mailclient sh -c 'set -a; . /etc/mailclient/hub.env; exec mailclient-hub doctor'
```

Use the path that `grep` shows in the `install` line (`/usr/bin/mailclient-hub` for the old
package layout, `/usr/local/bin/mailclient-hub` for the old install script). Upgrades later work
the same way.

### Move to the new names

Do this while the Hub is stopped, and keep the archive from step 1 until the Hub runs fine
again.

1. Stop the old Hub and archive data, key and configuration:

   ```sh
   sudo systemctl disable --now mailclient-hub
   sudo tar -C / -czf /root/mailclient-before-postern.tgz var/lib/mailclient var/lib/mailclient-key etc/mailclient
   ```

2. Install Postern as in [Set up your Hub](https://docs.posternmail.app/setup/): the binary at
   `/usr/local/bin/postern-hub`, the `postern` user, `/etc/postern/hub.env` and the
   `postern-hub.service` unit. **Do not start it** and do not open the setup wizard.

3. Move the data and the key over and hand them to the new user:

   ```sh
   sudo rm -rf /var/lib/postern /var/lib/postern-key
   sudo mv /var/lib/mailclient /var/lib/postern
   sudo mv /var/lib/mailclient-key /var/lib/postern-key
   sudo chown -R postern:postern /var/lib/postern /var/lib/postern-key
   ```

   The first line removes the empty directories a fresh install may have created. Check with
   `sudo ls /var/lib/postern` first if you are not sure they are empty.

4. Carry your settings over, with the new names and paths:

   ```sh
   sudo cp /etc/mailclient/hub.env /etc/postern/hub.env
   sudo sed -i -e 's/^\(#\?\)MC_/\1POSTERN_/' -e 's#/var/lib/mailclient#/var/lib/postern#g' -e 's#/etc/mailclient#/etc/postern#g' /etc/postern/hub.env
   sudo chown root:postern /etc/postern/hub.env
   sudo chmod 0640 /etc/postern/hub.env
   ```

5. Check, then start:

   ```sh
   sudo -u postern sh -c 'set -a; . /etc/postern/hub.env; exec postern-hub doctor'
   sudo systemctl enable --now postern-hub
   ```

   `doctor` must show `matches the database` under **Master key** and no `MC_... is ignored`
   line.

6. Remove the old unit and binary, and the old user:

   ```sh
   sudo rm -f /etc/systemd/system/mailclient-hub.service /usr/local/bin/mailclient-hub /usr/bin/mailclient-hub
   sudo systemctl daemon-reload
   sudo userdel mailclient
   ```

   If you had installed a package you built yourself, remove it with
   `sudo apt remove mailclient-hub` or `sudo dnf remove mailclient-hub` instead of deleting its
   files.

If you use a reverse proxy configuration from `deploy/`, only its comments mention the env file;
the proxy itself needs no change.
**Docker Compose:**
The Postern image still contains a `mailclient-hub` command and reads the `MC_*` variables, so an
existing `compose.yaml` keeps working with only the image changed. Moving to the new
`compose.yaml` is just as easy, because it can be told to use your old volumes.

1. Build the Postern image from source as in [Set up your Hub](https://docs.posternmail.app/setup/):

   ```sh
   git clone https://github.com/TheOriUHD/postern.git ~/postern-src
   cd ~/postern-src
   docker build -f deploy/docker/Dockerfile -t ghcr.io/theoriuhd/postern-hub:local .
   ```

2. Stop the old project (the volumes stay) and look up the volume names:

   ```sh
   cd ~/mailclient
   docker compose down
   docker volume ls
   ```

   They are `mailclient_mailclient-data` and `mailclient_mailclient-key` if the old project
   folder was called `mailclient`. The prefix is the old project name.

3. Create the new project folder with the new `compose.yaml` and an `.env` that points at the old
   volumes:

   ```sh
   mkdir -p ~/postern
   cp ~/postern-src/deploy/docker/compose.yaml ~/postern/
   cp ~/mailclient/.env ~/postern/.env
   ```

   Then edit `~/postern/.env`: rename the variables to `POSTERN_*` (the old `MAILCLIENT_DOMAIN`,
   `MAILCLIENT_BIND`, `MC_PUBLIC_URL` and similar are still read, but new names are clearer) and
   add:

   ```ini
   POSTERN_VERSION=local
   POSTERN_DATA_VOLUME=mailclient_mailclient-data
   POSTERN_KEY_VOLUME=mailclient_mailclient-key
   ```

   Variables that the old `compose.yaml` had under `environment:` go into
   `~/postern/compose.override.yaml` (see [Configuration](https://docs.posternmail.app/configuration/)).

4. Start and check:

   ```sh
   cd ~/postern
   docker compose up -d
   docker compose exec hub postern-hub doctor
   ```

   `doctor` must show `matches the database` under **Master key**.

Once it runs, `~/mailclient` can go. Keep the volumes: they now hold the Postern Hub's data.
**Desktop app (built-in Hub):**
The desktop app's built-in Hub needs nothing: install the renamed app and your data, key and
settings come along (see [The apps](https://docs.posternmail.app/migrating-from-mailclient/#the-apps)).

## The apps

- **Web app:** served by your Hub. It shows the new name after the Hub upgrade. Nothing to do.
- **Desktop app:** the renamed app keeps using the old `MailClient` data folder (Hubs, settings,
  the built-in Hub's data and key, and the mail kept on this computer) as long as no `Postern`
  folder exists. It may ask you to sign in to your Hub once, because the system's key storage is
  tied to the app's name.
- **iOS and Android:** the app has a new ID (`app.postern`), so it installs next to the old one.
  Sign it in again (for example with a code from **Settings → Devices → Connect a device**, see
  [Pairing](https://docs.posternmail.app/apps/pairing/)) and then remove the old app. The old app keeps working with an
  upgraded Hub until then.

Developers with a local `apps/mobile/ios` or `apps/mobile/android` folder: regenerate it after
pulling, since the bundle ID, scheme and icons come from `app.json`
(`npx expo prebuild --clean`).

## Rolling back

The rename changes neither the database nor the key file. To go back, stop the Hub, put the old
binary back (and, if you moved them, the paths from your archive) and start the old unit or
project again. If the Postern Hub applied new database migrations in the meantime, restore the
`pre-migrate-*.db` it wrote first (see [Upgrades](https://docs.posternmail.app/admin/upgrades/#going-back)).
