Transferring Mail Folders from one Account to Another
Goal
Following the departure of a user, for example, or in order to take over an activity, you want to transfer messages from a user to a colleague. We want to retrieve messages with the same folder tree without having to recreate it manually.
Known Issues
- BlueMind webmail does not allow folders to be copied/moved from a shared mailbox or another user.
- thick clients, even with import/export extensions, have little or no ability to copy folders from one account to another
Solution
Perform a transfer using the imapsync utility allowing fine tuning, notably by excluding folders.
Install Imapsync
-
Connect via SSH to the BlueMind core server as the root user
-
move to the /usr/local/bin directory:
cd /usr/local/bin -
Download imapsync and make the file executable:
wget https://raw.githubusercontent.com/imapsync/imapsync/imapsync-2.200/imapsyncchmod +x /usr/local/bin/imapsync -
install the required packages:
- Debian/Ubuntu
- CentOS
- Rocky Linux & AlmaLinux
apt install -y libdigest-hmac-perl libfile-copy-recursive-perl libio-socket-inet6-perl libio-socket-ssl-perl libio-tee-perl libmail-imapclient-perl libterm-readkey-perl libunicode-string-perl libreadonly-perl libsys-meminfo-perl libregexp-common-perl libfile-tail-perl libencode-imaputf7-perl
yum install epel-release yum install imapsync
dnf install --enablerepo=powertools imapsync
Using imapsync
Preparation
Use case: we want to retrieve the emails of a user who is leaving the company and transfer them to the account of his successor:
- server: bm.bluemind.loc for both users
Note: the procedure can be used for 2 different servers/domains, see the options below in the command lines - Bertrand: outgoing user → user1 for imapsync
- username: bertrand@bluemind.loc
- password: 8ertranD
- Nathalie: target user → user2 for imapsync
- username: nathalie@bluemind.loc
- password : Nathali3
If the password is not known to the administrator, he can :
- change password in user administration file, Maintenance tab
- connect "as" the user to generate an API key (Preferences > API Key) and use this instead of the password
Procedure
First, recreate the folder structure (option --justfolders):
imapsync --host1 bm.bluemind.loc --user1 bertrand@bluemind.loc --password1 8ertranD --host2 bm.bluemind.loc --user2 nathalie@bluemind.loc --password2 Nathali3 \
--authmech2 PLAIN \
--port2 143 \
--sep1 "/" \
--exclude '^Shared folders' \
--exclude '^Outbox' \
--exclude '^Junk' \
--exclude '^Trash' \
--exclude '^Other users' \
--nofoldersizes \
--buffersize 8192000 \
--sep2 "/" \
--justfolders \
--subfolder2 "Nathalie"
--dry
We have chosen to exclude the following folders:
- Shared folders (tree structure containing shared mailboxes and users): it is not relevant to copy the contents of these folders in our case of use, we prefer to give the new user the right to read the boxes concerned
Note: for encoding reasons, the "Shared folders" label is deliberately truncated before the accented character.* - Outbox: sent items box, these are messages waiting to be sent, don't confuse with sent messages
- Junk: spam, it is also not relevant to "waste" time and disk space backing up spam
- Trash: same as for spam, we choose not to recover the trash
If you wish to include any of these folders in the synchronization, simply delete the corresponding rows in the above code.
However, we have chosen to keep the "Sent Items" and "Drafts" folders which seem interesting to us for the history. If you wish to exclude them, add the following rows:
--exclude '^Sent' \
--exclude '^Drafts' \
Once done, perform an import test (without the --justfolders option this time to test the complete import with messages) using the --dry option:
imapsync --host1 bm.bluemind.loc --user1 bertrand@bluemind.loc --password1 8ertranD --host2 bm.bluemind.loc --user2 nathalie@bluemind.loc --password2 Nathali3 \
--authmech2 PLAIN \
--port2 143 \
--sep1 "/" \
--exclude '^Shared folders' \
--exclude '^Outbox' \
--exclude '^Junk' \
--exclude '^Trash' \
--exclude '^Other users' \
--nofoldersizes \
--buffersize 8192000 \
--sep2 "/" \
--subfolder2 "Nathalie" \
--dry
This command row can be entered at any time, even before the folder hierarchy is created: the log will inform you which folders will (or won't) be synchronized. You can also add the --dry option to the previous command to test the folder hierarchy creation.
If the test result is conclusive, you can then run the procedure, by issuing the same command but without the --dry final option.
If you modify commands to add or remove options, remember to add the backslash character '' at the end of the row, except for the last line of your command.