Skip to main content

Mailboxes migration using OfflineIMAP

gha codecov

A simple Modoboa extension which provides a way to migrate existing mailboxes 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 Modoboa 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

Installation

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 modoboa instance and add modoboa_imap_migration inside the MODOBOA_APPS variable like this:

MODOBOA_APPS = (
  # ...
  'modoboa_imap_migration',
)

Then, add the following at the end of the file:

from modoboa_imap_migration import settings as modoboa_imap_migration_settings
modoboa_imap_migration_settings.apply(globals())

Restart the python process running modoboa (uwsgi, gunicorn, apache, whatever).

Run the following commands to setup the database tables:

$ cd <modoboa_instance_dir>
$ python manage.py migrate modoboa_imap_migration
$ python manage.py load_initial_data
$ python manage.py collectstatic

You also need to install OfflineIMAP.

Configuration

Authentication backend

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',
    'modoboa_imap_migration.auth_backends.IMAPBackend',
)

cron script

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/modoboa file:

PYTHON=/srv/modoboa/env/bin/python
INSTANCE=/srv/modoboa/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.

Online settings

You need to configure the access to the old IMAP server.

All the configuration is done from the admin panel (Modoboa > Parameters > IMAP migration).

Release files for modoboa-imap-migration 1.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for modoboa-imap-migration 1.4.1
File Size Uploaded
modoboa-imap-migration-1.4.1.tar.gz 275.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for modoboa-imap-migration 1.4.1
File Interpreter ABI Platform
modoboa_imap_migration-1.4.1-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 415.5 kB

Release files / modoboa-imap-migration-1.4.1.tar.gz

Download URL modoboa-imap-migration-1.4.1.tar.gz
Size 275.5 kB
Tags Source
SHA-256 checksum
How to use checksums
2098c166d201adb365e50388a94c35719fd48c7a18ff9ec0528090940b5924a1
BLAKE2b-256 checksum
How to use checksums
618cc0c50f338e712a27ea6063fba36a506ff64ffd72d4f321a855eda1acaa10
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.9.12

Release files / modoboa_imap_migration-1.4.1-py2.py3-none-any.whl

Download URL modoboa_imap_migration-1.4.1-py2.py3-none-any.whl
Size 139.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
646684609ae96443c077a28ed980ccd5ba7148cb265c7381bc630143519d7c8c
BLAKE2b-256 checksum
How to use checksums
6508f5018ff4c5321adc9cd94cb5b40b8f344cefa820f674261866828b330a49
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.9.12

Release history Release notifications | RSS feed

This release

1.4.1 This release

2 release files

1.4.0

2 release files

1.3.4

2 release files

1.3.3

2 release files

1.3.2

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.2

1 release file

1.1.1

1 release file

1.1.0

1 release file

1.0.5

1 release file

1.0.4

1 release file

1.0.3

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page