All HowTo's Scripting in Bash

Migrate from Evolution to Thunderbird

Just recently for work we had to migrate all of our users from evolution to Thunderbird, this is a boring process if you have to do it manually for an office full of people so I wrote a little script. Feel free to edit to match your needs.

#!/bin/bash

#Check if the user has set a user name and if not tell them how to use the script
if [ -u $1 ]
then
echo "This script migrates mailboxes from evolution to thunderbird by copying their data to the correct directory"
echo "This script expects one parameter, the username of the person being migrated see below for an example"
echo "This script must be run as a privileged user"
echo "sudo ./MigrateMailScript.sh brad"
else
#Since the user name has been set then we can get the users unique thunderbird id, this section requires there to be only one .default which for our case is fine
UNIQUEID="$(sudo ls /home/$1/.thunderbird/ | grep .default)"
#echo $UNIQUEID #Only Used for Debugging

#Found an issue with some users where the directory does not exist after first run so we will just create it
sudo mkdir -p "/home/$1/.thunderbird/$UNIQUEID/Mail/Local Folders/"

#Now we can copy all of the users files from evolution to thunderbird
sudo cp "/home/$1/.local/share/evolution/mail/local/"/* "/home/$1/.thunderbird/$UNIQUEID/Mail/Local Folders/"

#Now we need to detect the users primary group so that we can set permissions on the files
PRIMARYGROUP="$(id -g -n $1)"
sudo chown -R $1:$PRIMARYGROUP "/home/$1/.thunderbird/$UNIQUEID/Mail/"
fi

This has been tested as it migrated our whole office but be careful there are probably still issues with it, some of the items could also be environment specific for example the existence of more than one .default folder under ./thunderbird

Similar Posts: