Ok, guys a little help for migrating (clone) from server A to a zimbra server B using a simple yet effective PHP script. It copies al folders and subfolders too.
It connects via imap to server A and clone it using imap with zimbra server B... it's a little slowly, so be patient
<?php
if($_POST["Submit"] != '')
{
ini_set('max_execution_time',0);
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 'On');
ini_set('display_startup_errors','On');
# open connection to obtain list of folders
$mbox_origen = imap_open("{{$_POST["servidor"]}:143/notls}INBOX", $_POST["email"], $_POST["passw"], OP_HALFOPEN);
$list = imap_list($mbox_origen,"{{$_POST["server"]}}","*");
imap_close($mbox_origen);
for($c=0;$c<count($list);$c++)
{
# we cut the string to obtain folder name
$conexion = explode("}",$list[$c]);
# construct the string connection to imap server A (a single imap server to 143 with notls flag)
$string = $conexion[0].":143/notls}".$conexion[1];
$mbox_origen = imap_open($string, $_POST["email"], $_POST["passw"]);
# obtain the folder from server A
$carpeta = explode("}INBOX",$list[$c]);
if($carpeta[1]!='')
{
# from the folder name bring out the dot from the name
$carpeta_destino = substr($carpeta[1],strpos($carpeta[1],".")+1,strlen($carpeta[1]));
# connect to the zimbra server
$mbox_destino = imap_open("{{$_POST["destiny_server"]}}", $_POST["destiny_email"], $_POST["destiny_passw"]);
# create the folder in the zimbra server
imap_createmailbox($mbox_destino, imap_utf7_encode("{{$_POST["destiny_server"]}}".$carpeta_destino));
# if inbox connecto to it in zimbra
}else {
# abrimos imap con link a inbox
$mbox_destino = imap_open("{{$_POST["destiny_server"]}}INBOX", $_POST["destiny_email"], $_POST["destiny_passw"]);
}
# get num of mssgs
$numero_mensajes = imap_num_msg($mbox_origen);
for($i=1;$i<$numero_mensajes;$i++)
{
# create the email string to apped
$header = imap_fetchheader($mbox_origen,$i);
$cuerpo = imap_body($mbox_origen,$i);
$mail = $header."\n".$cuerpo;
# append it!
($carpeta[1]!='') ? imap_append($mbox_destino,"{{$_POST["destiny_server"]}}".$carpeta_destino,$mail) : imap_append($mbox_destino,"{{$_POST["destiny_server"]}}INBOX",$mail);
}
imap_close($mbox_destino);
imap_close($mbox_origen);
}
print "<br><b>Clonation ends!</b>...<br>";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin título</title>
<style type="text/css">
<!--
body {
margin-top: 130px;
background-color: #FFFFFF;
}
.Estilo4 {font-size: 16px}
.Estilo6 {
font-size: 16px;
font-family: Verdana, Arial, Helvetica, sans-serif;
font-weight: bold;
color: #FF0000;
}
.Estilo7 {font-size: 12px}
.Estilo8 {font-size: 14px; }
.Estilo9 {font-size: 14px; font-weight: bold; }
-->
</style></head>
<body>
<center>
<form action="imap_harvester.php" method="POST">
<table width="514" border="0" cellpadding="0" cellspacing="3" bgcolor="#FFFFFF">
<!--DWLayoutTable-->
<tr>
<td width="508" height="289" valign="top">
<fieldset>
<legend>Zimbra Email <strong>Harvester</strong> </legend>
<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#DDDCBF">
<!--DWLayoutTable-->
<tr>
<td height="36" colspan="6" align="right" valign="top"><span class="Estilo4">isl<span class="Estilo6">@</span>mail</span></td>
</tr>
<tr>
<td height="22" colspan="2" align="right" valign="middle" class="Estilo9">From Server : </td>
<td colspan="2" align="left" valign="middle">
<input name="server" type="text" id="server" value="mail2.islared.com" /></td>
<td colspan="2" align="left" valign="middle"><span class="Estilo7">(example: mail.domain.com)</span></td>
</tr>
<tr>
<td width="17" height="3"></td>
<td width="167"></td>
<td width="144"></td>
<td width="5"></td>
<td width="125"></td>
<td width="41"></td>
</tr>
<tr>
<td height="22"></td>
<td align="right" valign="middle" class="Estilo9">Email : </td>
<td colspan="3" align="left" valign="middle"><input name="email" type="text" id="email" /></td>
<td></td>
</tr>
<tr>
<td height="3"></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td height="23"></td>
<td align="right" valign="middle" class="Estilo9">Passw : </td>
<td colspan="3" align="left" valign="middle"><input name="passw" type="password" id="passw"/></td>
<td></td>
</tr>
<tr>
<td height="22" colspan="6" align="center" valign="middle"><hr /></td>
</tr>
<tr>
<td height="22" colspan="2" align="right" valign="middle" class="Estilo9">To Server (zimbra): </td>
<td align="left" valign="middle">
<input name="destiny_server" type="text" id="destiny_server" value="<zimbra_server:993/imap/ssl/notls/novalidate-cert" /> </td>
<td colspan="3" rowspan="2" align="left" valign="middle"><span class="Estilo7">(example: mail.domain.com)</span></td>
</tr>
<tr>
<td height="3"></td>
<td></td>
<td></td>
</tr>
<tr>
<td height="22"></td>
<td align="right" valign="middle" class="Estilo9">Email : </td>
<td colspan="3" rowspan="2" align="left" valign="middle"><input name="destiny_email" type="text" id="destiny_email" /></td>
<td></td>
</tr>
<tr>
<td height="4"></td>
<td></td>
<td></td>
</tr>
<tr>
<td height="23"></td>
<td align="right" valign="middle" class="Estilo9">Passw: </td>
<td colspan="3" align="left" valign="middle"><input name="destiny_passw" type="password" id="destiny_passw"/></td>
<td></td>
</tr>
<tr>
<td height="61"></td>
<td colspan="4" align="center" valign="middle"><label>
<input type="submit" name="Submit" value=" Clone It " />
</label></td>
<td></td>
</tr>
</table>
</fieldset></td>
</tr>
</table>
</form>
</center>
</body>
</html>
Last edited by ajflorido; 04-01-2009 at 07:22 AM..
|