Migrate DNS domain name of your own server

Hi there :wave:

So due to the need of installing the notification proxy (see How to install own chatmail and notification proxy?) I recently switched my DNS provider, then realized that all my account addresses had changed which made it necessary to recreate all DC profiles in my devices.

However, I wanted to maintain my old messages so I tried a variety of ways with no luck because, in the end, all the older email messages were encrypted to the old addresses so even if I managed to make DC read them again, they weren’t correctly imported.

Luckily, after a night of sleep I came up with an idea that has finally worked and I’m sharing it in case someone is in the same situation and wants to try something similar.

This assumes you have access to the older messages whether it is using tools like Thundebird and ImportExportToolsNG or by browsing Dovecot’s server folders.

It also assumes you have the private key of your user. Otherwise you will lose your data forever :man_shrugging:.

Then, all you need to do is:

  1. Grab your older messages in .eml format (Dovecot stores them like that in its maildir folders).
  2. Copy them to a folder and pass them through the bash script I’m pasting below.
  3. Configure Thunderbird to access your DC account (using IMAP and your DC credentials).
  4. Stop all DC clients.
  5. Delete all messages in Thunderbird.
  6. Drag the unencypted messages from a browser to the Inbox. Please make sure your file browser pass them to Thunderbird in the correct date order (you can inspect the “Order received” field in Thunderbird to check this). Failure to make this correctly will cause your messages to appear in random order in DC.
  7. Once all messages are imported in Thunderbird and you are sure the “Order received” is correct, start one DC client and let it process all your old messages and recreate the chats you previously had. :tada:
  8. Connect further clients using the QR code feature.

This is high level description of how the process would go. If anyone tries it and gets stuck feel free to ask in this thread and I’ll try to help you.

Cheers,
Ivan

3 Likes

This is the script:

#!/bin/bash

INPUT="$1"

if [[ -z "${INPUT}" ]]
then
	echo 'Usage: deceml <.eml file>'
	exit 1
fi

outdir="$(dirname "${INPUT}")/_dec_"

mkdir -p "${outdir}"

output="${outdir}/$(basename "${INPUT}").eml"
message="$(gpg -d "${INPUT}" 2>/dev/null)"

if grep 'BEGIN PGP MESSAGE' "${INPUT}" >/dev/null 2>&1
then
	echo "đź”’ ${INPUT}"
	grep -e 'Return-Path: ' -e 'Delivered-To: ' -e 'To: ' -e 'Date: ' -e 'Message-ID: ' -e 'Chat-Version: ' -e 'MIME-Version: ' -e 'Auto-Submitted: ' <"${INPUT}" | sed 's/old.domain.org/new.domain.org/g' >"${output}"
	echo "${message//old.domain.org/new.domain.org}" >>"${output}"
else
	echo "➡️ ${INPUT}"
	sed 's/old.domain.org/new.domain.org/g' <"${INPUT}" >"${output}"
fi

It’s a bash script but I’m sure it can be rewritten easily in any other language. It basically checks if an .eml message is encrypted or not, then processes it accordingly.

The processing is as follows:

For encrypted messages:

  1. Maintain only the lines starting with specified headers (Return-Path, Delivered-To, and so on…).
  2. Append the unencrypted message content (note that it will contain some headers too, like Content-Type or From, that’s why we remove them in step 1).
  3. Search and replace the old domain by the new one.

For non encrypted messages:

  1. Copy the message as is.
  2. Search and replace the old domain by the new one.
1 Like

I’ve uploaded the script to Email message (.eml) GPG decriptor script for DeltaChat domain name migrations · GitHub for future reference.

1 Like

I do it a little differently (all the keys are present in the system because I imported them into Seahorse in advance, so all messages in the mail are read).

I connect Sylpheed via IMAP to the necessary accounts and transfer all messages inside Sylpheed to the desired email account to which Delta Chat is connected.

1 Like

That didn’t work in my case because my old and new server were the same (I just changed the DNS name) so it was impossible to run both in parallel.

But yours is a much simpler hack to use if you have both servers running :+1:.

There is this AEAP feature that is not fully complete, but I once used it to change my email address while keeping my chats and messages.
The limitation is that you need to send messages in the chats you were in to notify other users of your new address. Your contacts might also need to remove your old address, but I’m not sure on that point.
To do this you go to Advanced → password and account and change your email address and press “login”.

But as always make backups of your accounts before making big changes.

Mmm, that’s very interesting. So currently I had an strategy of backups in mind that relied on the server having all past messages and being able to recover the state of the clients based on that (and obviously the private keys too).

That means I wasn’t using the backup function of the client because for me it would be easy but for non technical users it’s out of scope because they don’t know what to do with backups, they don’t remember they need to do it, etc…

However I’m now thinking that with AEAP and an automatic backup function in the client I would be able to delete all messages from the server and don’t care any more about it as storage.

Do we know if there are any plans on implementing an automatic backup function? t🤔 An upload to sftp or webdav servers would do probably. It could even use the private keys to sign in to SFTP which would make things certainly easy to configure.

not planned, but you can open a feature proposal topic here on the forum to start the discussion.
Currently backups are not encrypted so that needs to come before we think about automated backups. Though you could just make full device backups, delta chat data should be included in those.

1 Like

Yeah, full backups would do but again is not that easy for non tech users, IMO…

Created the feature proposal → Automatic backups to a SFTP, DAV or Samba server

Thx :slight_smile: