A plugin to migrate mailboxes using IMAP
Mailboxes migration using OfflineIMAP
How does it work
This extension mainly provides a cron script which periodically synchronize user mailboxes from an existing IMAP server to a new one. The workflow is pretty simple:
- A user from the old server logs into Kalabash using the same credentials
- A new account is automatically created and a new migration task is created using the provided credentials
- The cron script periodically synchronizes mailboxes corresponding to migration tasks
- Once a migration is done, it can be disabled through the admin panel
Install this extension system-wide or inside a virtual environment by running the following command:
$ python setup.py install
Then, edit the settings.py file of your kalabash instance and add kalabash_imap_migration inside the KALABASH_APPS variable like this:
KALABASH_APPS = ( # ... 'kalabash_imap_migration', )
Then, add the following at the end of the file:
from kalabash_imap_migration import settings as kalabash_imap_migration_settings kalabash_imap_migration_settings.apply(globals())
Restart the python process running kalabash (uwsgi, gunicorn, apache, whatever).
Run the following commands to setup the database tables:
$ cd <kalabash_instance_dir> $ python manage.py migrate kalabash_imap_migration $ python manage.py load_initial_data
You also need to install OfflineIMAP.
Please make sure automatic domain/mailbox creation is enabled, otherwise the authentication won’t work. Go to the online settings panel (admin tab) and check your current state.
An IMAP authentication backend is provided by the extension and must be enabled.
Edit the settings.py file and modify the AUTHENTICATION_BACKENDS variable as follows:
AUTHENTICATION_BACKENDS = ( 'django.contrib.auth.backends.ModelBackend', 'kalabash_imap_migration.auth_backends.IMAPBackend', )
The synchronization script must be configured to run periodically on your new server. Since it will copy mailboxes content to its final destination, filesystem permissions must be respected. To do that, it must be executed by the user which owns mailboxes (generally vmail).
Here is a configuration example where the script is executed every hours. You can copy it inside the /etc/cron.d/kalabash file:
PYTHON=/srv/kalabash/env/bin/python INSTANCE=/srv/kalabash/instance 0 */1 * * * vmail cd /srv/vmail && $PYTHON $INSTANCE/manage.py generate_offlineimap_config --output .offlineimaprc && /usr/local/bin/offlineimap > /dev/null 2>&1
Feel free to adapt it.
Helper script for OfflineIMAP
OfflineIMAP will need a way to retrieve user passwords of the old server. To do that, just copy the following Python code into a file called .offlineimap.py:
import os import site import sys site.addsitedir("/srv/kalabash/env/lib/python2.7/site-packages") sys.path.append("/srv/kalabash/instance") os.environ["DJANGO_SETTINGS_MODULE"] = "instance.settings" from django.apps import apps from django.conf import settings apps.populate(settings.INSTALLED_APPS) from kalabash_imap_migration.models import Migration def get_user_password(username): """Retrieve a password from Kalabash's database.""" return Migration.objects.select_related().get( mailbox__user__username=username ).password
Then, copy this file into the home directory of the user owning mailboxes (generally vmail). For example:
$ cp .offlineimap.py /srv/vmail $ chown vmail:vmail /srv/vmail/.offlineimap.py
You need to configure the access to the old IMAP server.
All the configuration is done from the admin panel (Kalabash > Parameters > IMAP migration).
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size kalabash-imap-migration-1.2.6.tar.gz (105.6 kB)||File type Source||Python version None||Upload date||Hashes View hashes|
Hashes for kalabash-imap-migration-1.2.6.tar.gz