View Full Version : Script request and tip if you lose your entire user base

07-16-2012, 11:49 AM
Hello to everyone.

I thought I'd share a small tip, which is useful if someone loses their entire user base (remember, if your users are running under a DB instead of file system, you have to back it up manually or use icewarp's feature inside system backups to sync to some other DB server).

The script, if any programmer out there is willing to help, would go through mail folders and recreate accounts based on that.

If you're not a programmer and until a script is availabe:

- Inside mail folder, in DOS, type dir > accounts.txt

Put to Excel and concatanate with 2 other colums.

1st column tool create account and repeat that as many times as there are accounts.

The 2nd column should contain the accounts gotten via DIR command.

The 3rd column should contain this repeated as many times as there are accounts: u_password default123

Then export to .cmd file and execute it. At least better then having to do it by hand.

All the best,

07-16-2012, 08:47 PM
I would just use the php api
Loop through each folder.
for each folder
create account with default password


$defaultPassword = "default123";
$RestoreFolder = "d:\\icewarp\\mail\\domain.com\\";
$mydomain = "domain.com";
$account = new IceWarpAccount();

if (is_dir($RestoreFolder)) {
if ($dh = opendir($RestoreFolder)) {
while (($dir = readdir($dh)) !== false) {
if (filetype($dir = "dir")) {
$account->New($dir . "@" . $mydomain);
$account->SetProperty("u_password", $defaultPassword);
$account->SetProperty("u_mailbox", $dir);
$account->SetProperty("u_name", $dir);

this is a Proof of concept abd I am quite sure my code is wrong with the Directory part of the code.but the create accout part should be ok

08-11-2012, 01:11 PM
Dear Freibus,

Thanks again. Im getting this error in phperror.log

[11-Aug-2012 18:04:09] PHP Fatal error: Class 'IceWarpAccount' not found in C:\Program Files (x86)\IceWarp\html\restore.html on line 6

All the best,

08-15-2012, 04:15 AM
hahaha ;) that was all done in my head without putting it though any tests.. was a proof of an idea..

that would not work because there is no reference to the ICEWARP api object ;)

this is located in IceWarp\html\admin\inc\api\account.php

08-19-2012, 12:50 PM
Hehe :) Yes, I saw and read that, just thought Id give it a shot. Im not a programmer, though, so I do get caught with some basics.

If someone can complete the script 100%, I appreciate it :)


08-21-2012, 02:52 AM
dotnet vb/c# or vbscript. would be better then php for this task. PHP is a pain work with Filesystems
The old one actually uses the API to create accounts
this script will only create a CSV based on your specs (I tend to over shoot design specs)...

you would need to run that in a VB console or winform
Dim FolderToRestore As String = "d:\ICEWARPMAIL\Mail\yourdomain.com"
Dim FileToutput As String = "c:\accounts.csv"
Dim domains As String = "yourdomain.com"
Dim defaultpassword As String = "default123"
Dim csvout As String = ""
Sub Main()
csvout = "u_domain,u_username,u_password" & vbCrLf
Dim di As New System.IO.DirectoryInfo(FolderToRestore)
Dim diAttr As System.IO.DirectoryInfo() = di.GetDirectories()
Dim folder As DirectoryInfo
For Each folder In diAttr
csvout &= domains & "," & folder.Name.ToLower & "," & defaultpassword & vbCrLf

IO.File.WriteAllText(FileToutput, csvout)

End Sub

now for vbScripting
Create a a file called SearchUsers.vbs and put this contents in

Option Explicit
Dim FolderToRestore, objFSO, objRootFolder, objFolder, colSubfolders, csvout,FileToutput,domains

FolderToRestore = "d:\ICEWARPMAIL\Mail\yourdomain.com"
csvout = "u_domain,u_username,u_password" & vbCrLf
defaultpassword = "defalt123"
domains = "yourdomain.com"
FileToutput = "c:\accounts.csv"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objRootFolder = objFSO.GetFolder(FolderToRestore)
Set colSubfolders = objRootFolder.SubFolders

For Each objFolder in colSubfolders
csvout = csvout & domains & "," & objFolder.name & "," & defaultpassword & vbCrLf

MsgBox csvout
Set objFile = objFSO.CreateTextFile(FileToutput)


Basically they both do the same thing. Looks at a folder and loops through folders and creates a string ready for out put.

Personally I would not just output the text csv file. I would go a little further and use the COM object to create the accounts.

09-02-2012, 04:36 PM
Thanks, really useful, just not sure everyone would have practice in running VB/winform, a php script would have advantage of working out of the box.

All the best,

11-07-2012, 03:52 AM
Thanks, really useful, just not sure everyone would have practice in running VB/winform, a php script would have advantage of working out of the box.

All the best,

considering icewarp is installed mostly on windows boxes php is a pain.. using vb/c# dot.net for windows or ruby/python on the nix side would be better options .. php cmd line is a dog at times...

you could rewrite this code for vb.net in a couple of lines and with ruby about the same. php would take about 5 times the amount of code