This project is an email migration tool written in PHP utilizing imapsync. It is a proof of concept you may edit and use as you please under the terms granted by the license.
Tested with PHP 7.4 and imapsync 1.977.
Assuming you already have a webserver that can execute PHP scripts up and running, you only have to copy the files in this repository. Thenafter edit define_vars.php
:
Define the target mail server here.
Example:
$TARGETHOST = "mail.example.org";
Define all trusted domain names here. Only email addresses under trusted domains can be migrated.
Example:
$TRUSTEDDOMAINS = [
"example.org",
"example.com"
];
Define which mailserver shall be contacted for a specified domain name or provider name. The mapping of domain names to a mailserver is required for the "Auto Detect" option, and the provider for the selectable providers. Also see the included HTML form for more on this.
Example:
$HOSTS = array(
'example.org' => 'mail.example.org',
'example.com' => 'imap.example.com',
'examplemail' => 'imap.example.net',
);
Define whether the username equals to the email address for the specified domain name. If not, the user
will be used as the username for the email address user@example.com
.
Example:
$USERISEMAIL = array(
'example.org' => true,
'example.com' => true
);
You may want to block some values from being used. Enter them into this array.
Example:
$BLOCKEDVALUES = array(
'\s',
'\n',
' ',
'sudo ',
'su ',
'rm ',
'|'
);
The usage is pretty simple. Just send a POST
or GET
request to the PHP script containing following data:
email1
- The source email addressemail2
- The target email addresspassword1
- The password of the source email addresspassword2
- The password of the target email addresshost1
- The source email provider (must be predefined), orfalse
if it shall be auto detectedactionid
- The Action ID a running process can be identified with
Note: Theoretically, you could also send the data in form of cookies as the PHP script is using $_REQUEST
and not looking for a specific method. But you shouldn't provide such data within cookies.
Once a request has been sent, of-course an HTTP response will be delivered. Each response code has a different meaning. The remark "(initial)" means that this is a response to the initial request with the aim of starting a process. If that remark is missing, it means that the response is to a specific process identified via the provided Action ID.
This response means that the request has been accepted and the processing has started. The Refresh
header as well as the added url
header specifiy the URL under which you can request updates on the started process. That URL contains the Action ID parameter.
There was something wrong with the provided data. You may find more details on this within the response body.
An Action ID was provided, but the process with the delivered Action ID has not been finished yet. The current progress will be displayed and a reload of the site via Refresh
will be triggered.
The request could not be finished as expected. The entered host or provider may not exist.
An Action ID was provided and the requested action has been finished. However, the credentials entered, meaning the source email address and password or target email address and password, do not match. The authentication failed with either the source or target host.
An Action ID was provided and the status of a started process has been requested, but no such process was found.
Well, this could be about anything. It could be that there's something wrong with the PHP script, with your server or some error occured while processing the request. Look into the log entry for the Action ID, if any provided. Also look into your server logs, if the script's log did not help.
The maintenance mode is enabled.
You may want to offer the migration in a different language. To do so, you can simply translate the strings into your language and modify headers.php
accordingly.
You might have to turn off the service or put it into a maintenance mode. That is possible by uncommenting the following line in migrate.php
:
// include 'maintenance.php';
You should consider editing the content in maintenance.php
before enabling the maintenance mode.
The PHP script and HTML form were written by Kasim Dönmez on behalf of the Liberale Demokraten - Die Sozialliberalen.
Copyright © 2021 - present Liberale Demokraten - Die Sozialliberalen. Free use of this project's contents is granted under the terms of the GNU GPLv3 license. For the full text of the license, see the LICENSE file. The HTML file providing a sample form however is licensed under the CC0 Public Domain license such that you can use, modify and distribute it without any limitations of any sorts.
The use of the resources provided by this project shall be done in a way that your modifications to the code, distribution thereof or use of the provided files does not imply any endorsement by the authors or copyright holders of this project. You shall not use this project or contents thereof in the name of the authors or copyright holders unless explicitly permitted.