IceWarp – find and replace alias from list
2011/03/14 | 22:22This function is a way for migration username (under server migration) to work properly. IceWarp has a clever way of migration all emails from for example an postfix server to IceWarp. What you do is use Server Migration and choose between a few different rules. If you chose username and a user logins with say username yxsfs but his email is lars.knutsson@domainname then he will be added like yxsfs@domainname.
Why not use the bulk mail function you say? Because on some email systems the emails password is encrypted with MD5. My solution was to make a file called username.txt which was all usernames on the server and email.txt which is the alias for the email. Then I just do some loops and sets the correct alias, let’s say ever 10 minutes.
Enough rant, here is the code:
findUsernameAccounts.php
[php highlight=”11″]
<?PHP
$usernameFileArray = file(‘username.txt’);
$emailFileArray = file(’email.txt’);
if ($com = new COM("IceWarpServer.APIObject"))
{
$domCount = $com->GetDomainCount();
for ($i = 0; $i < $domCount; $i++)
{
$domain = $com->OpenDomain($com->GetDomain($i));
$domName = $domain->Name;
if ($domName == "domainname")
{
$accNum = $domain->GetAccountCount();
for ($j = 0; $j < $accNum; $j++)
{
$acc = $domain->OpenAccount($domain->GetAccount($j));
$accAlias = $acc->GetProperty("U_Alias");
$accMailbox = $acc->GetProperty("U_Mailbox");
if ($accAlias == $accMailbox) #if the alias is the same as the mailbox it’s incorrect, we need to fix it
{
foreach ($usernameFileArray as $line_num => $line)
{
$lineWoCR = str_replace("\r\n", "", $line);
$lineWoCR = strtolower($lineWoCR);
if(strcmp($accAlias,$lineWoCR) == 0)
{
if ($account=new COM(‘IceWarpServer.AccountObject’))
{
$email = "$accAlias@$domName";
if ($account->Open($email))
{
if ($account->SetProperty("U_Alias",$emailFileArray[$line_num]))
{
$account->Save();
}
}
}
}
}
}
}
}
}
}
else
{
return;
}
?>
[/php]