MailSuite Pro documentation

Exporting list of user accounts with passwords

The following sample demonstrates exporting user data from MailSuite Pro database.

While each user can have multiple email accounts, for simplicity reasons we'll only be exporting information on primary email account. The idea of this sample is to create .SQL file, containing structure and content of the database table. Each record holds user's ID, email address and password.

<?php
function dump_add($str, $add=TRUE) {
    file_put_contents("./exportusers.sql", $str."\r\n", $add?FILE_APPEND:0);
}
    
include __DIR__.'./system/autoload.php';
\Aurora\System\Api::Init(true);
$oHelper = new Aurora\System\Db\Pdo\MySql\Helper();
 
$oCoreDecorator = \Aurora\Modules\Core\Module::Decorator();
$ul = $oCoreDecorator->GetUsers();
$ulItems = $ul["Items"];
 
dump_add("DROP TABLE IF EXISTS `exportusers`;", false);
dump_add("CREATE TABLE `exportusers` (`user` int(11) NOT NULL, `mail` varchar(255) NOT NULL, `pass` varchar(255) NOT NULL);");
 
foreach ($ulItems as $key=>$item) {
    $sEmail = $item["PublicId"];
    $oUser = $oCoreDecorator->GetUserByPublicId($sEmail);
    $iUserId = $oUser->EntityId;
    $oAccount = $oCoreDecorator->GetAccountUsedToAuthorize($sEmail);
    $sPass = $oAccount->getPassword();
    dump_add("INSERT INTO `exported` (`user`, `mail`, `pass`) VALUES (".$oHelper->EscapeString($iUserId).", ".$oHelper->EscapeString($sEmail).", ".$oHelper->EscapeString($sPass).");");    
}

As you can see, we've added a helper function dump_add() which places a line into SQL file. By default, both the script and the dump file are located in root directory of MailSuite Pro installation.

The main code part is rather straightforward: we get a list of all the user ID's, for each user we retrieve their email account, get that account's password and add a line to .SQL file.

NB: Please bear in mind that passwords will be stored in .SQL file in clear text.