} if ($settings->EnableWmServer) { $WMConsole = new CWmServerConsole(); if ($WMConsole->Connect()) { $domains = $WMConsole->DomainList(); $domain = EmailAddress::GetDomainFromEmail($account->Email); if (in_array($domain, $domains)) { $account->MailProtocol = MAILPROTOCOL_WMSERVER; $account->MailOutLogin = $account->Email; $account->MailOutPassword = $account->MailIncPassword; $account->MailOutHost = $settings->WmServerHost; $account->MailOutPort = $WMConsole->Settings->OutPort; } $WMConsole->Disconnect(); } else { printErrorAndExit($WMConsole->GetError(), $xmlRes); } } $validate = $account->ValidateData(); if ($validate !== true) { printErrorAndExit($validate, $xmlRes); } else { $processor =& new MailProcessor($account); if ($account->MailProtocol == MAILPROTOCOL_WMSERVER && $settings->WmAllowManageXMailAccounts || $processor->MailStorage->Connect(true)) { $user =& User::CreateUser(); if ($user != null) { $account->IdUser = $user->Id; } $folderSync = FOLDERSYNC_AllEntireMessages; if ($account->MailProtocol == MAILPROTOCOL_IMAP4) { $folderSync = FOLDERSYNC_AllHeadersOnly;
/** * @param Account $account * @param short $pop3InboxSyncType optional * @return bool */ function CreateAccount(&$account, $inboxSyncType = FOLDERSYNC_NewEntireMessages) { $account->IdUser = $this->Id; $result = false; setGlobalError(PROC_ERROR_ACCT_CREATE); $dbStorage =& DbStorageCreator::CreateDatabaseStorage($account); if ($dbStorage->Connect()) { $defaultAccount =& $dbStorage->SelectAccountDataByLogin($account->Email, $account->MailIncLogin, true); if ($account->DefaultAccount && $defaultAccount != null && $defaultAccount[2] == 1) { setGlobalError(ACCT_CANT_ADD_DEF_ACCT); return false; } $settings =& Settings::CreateInstance(); //Load or create folder tree here switch ($account->MailProtocol) { case MAILPROTOCOL_WMSERVER: if (!$settings->EnableWmServer) { setGlobalError(PROC_ERROR_ACCT_CREATE); return false; } $emailArray = ConvertUtils::ParseEmail($account->Email); if (!$emailArray) { setGlobalError(JS_LANG_WarningCorrectEmail); return false; } $WMConsole = new CWmServerConsole(); if (!$WMConsole->Connect()) { setGlobalError(PROC_ERROR_ACCT_CREATE . '<br />' . $WMConsole->GetError()); return false; } if ($settings->WmAllowManageXMailAccounts) { if ($WMConsole->DomainExist($emailArray[1])) { if (!$WMConsole->UserExist($emailArray[1], $account->MailIncLogin)) { if (!$WMConsole->AddUser($emailArray[1], EmailAddress::GetAccountNameFromEmail($account->MailIncLogin), $account->MailIncPassword)) { setGlobalError(PROC_ERROR_ACCT_CREATE . '<br />' . $WMConsole->GetError()); return false; } } if (!$WMConsole->ChangeUserMaxMailBoxSize($emailArray[1], EmailAddress::GetAccountNameFromEmail($account->MailIncLogin), $account->MailboxLimit)) { setGlobalError(PROC_ERROR_ACCT_CREATE . '<br />' . $WMConsole->GetError()); return false; } } else { setGlobalError(DomainDosntExist . '<br />' . $WMConsole->GetError()); return false; } } $result = $dbStorage->InsertAccountData($account); $folders =& new FolderCollection(); if ($result) { $inboxFolder =& new Folder($account->Id, -1, FOLDERNAME_Inbox, FOLDERNAME_Inbox); if ($settings->AllowDirectMode && $settings->DirectModeIsDefault) { $inboxSyncType = FOLDERSYNC_DirectMode; } $inboxFolder->SyncType = $inboxSyncType; $folders->Add($inboxFolder); $folders->Add(new Folder($account->Id, -1, FOLDERNAME_SentItems, FOLDERNAME_SentItems, FOLDERSYNC_DontSync)); $folders->Add(new Folder($account->Id, -1, FOLDERNAME_Drafts, FOLDERNAME_Drafts, FOLDERSYNC_DontSync)); $folders->Add(new Folder($account->Id, -1, FOLDERNAME_Trash, FOLDERNAME_Trash, FOLDERSYNC_DontSync)); } break; case MAILPROTOCOL_POP3: $result = $dbStorage->InsertAccountData($account); $folders =& new FolderCollection(); if ($result) { $inboxFolder =& new Folder($account->Id, -1, FOLDERNAME_Inbox, FOLDERNAME_Inbox); if ($settings->AllowDirectMode && $settings->DirectModeIsDefault) { $inboxSyncType = FOLDERSYNC_DirectMode; } $inboxFolder->SyncType = $inboxSyncType; $folders->Add($inboxFolder); $folders->Add(new Folder($account->Id, -1, FOLDERNAME_SentItems, FOLDERNAME_SentItems, FOLDERSYNC_DontSync)); $folders->Add(new Folder($account->Id, -1, FOLDERNAME_Drafts, FOLDERNAME_Drafts, FOLDERSYNC_DontSync)); $folders->Add(new Folder($account->Id, -1, FOLDERNAME_Trash, FOLDERNAME_Trash, FOLDERSYNC_DontSync)); } break; case MAILPROTOCOL_IMAP4: setGlobalError(ACCT_CANT_CREATE_IMAP_ACCT); $mailStorage =& new ImapStorage($account); if ($mailStorage->Connect()) { $result = $dbStorage->InsertAccountData($account); if (!$result) { return false; } $folders =& $mailStorage->GetFolders(); $folders->SetSyncTypeToAll($inboxSyncType); if ($folders && $settings->AllowDirectMode && $settings->DirectModeIsDefault) { $folders->SetSyncTypeToAll(FOLDERSYNC_DirectMode); } $result &= $account->Update(); $result &= $folders != null; $mailStorage->Disconnect(); if (!$result) { return false; } $hasSentItems = false; $hasDrafts = false; $hasTrash = false; $s = $d = $t = null; $s =& $folders->GetFolderByType(FOLDERTYPE_SentItems); $d =& $folders->GetFolderByType(FOLDERTYPE_Drafts); if (USEIMAPTRASH) { $t =& $folders->GetFolderByType(FOLDERTYPE_Trash); } /* for ($i = 0, $c = $folders->Count(); $i < $c; $i++) { $folder = &$folders->Get($i); if (strtolower($folder->FullName) == strtolower(FOLDERNAME_Inbox) && $folder->SubFolders != null) { for ($j = 0, $k = $folder->SubFolders->Count(); $j < $k; $j++) { $inboxFolder =& $folder->SubFolders->Get($j); switch(strtolower($inboxFolder->Name)) { case strtolower(FOLDERNAME_Sent): case strtolower(FOLDERNAME_SentItems): $hasSentItems = true; break; case strtolower(FOLDERNAME_Drafts): $hasDrafts = true; break; case strtolower(FOLDERNAME_Trash): $hasTrash = true; break; } } } switch(strtolower($folder->FullName)) { case strtolower(FOLDERNAME_Sent): case strtolower(FOLDERNAME_SentItems): $hasSentItems = true; break; case strtolower(FOLDERNAME_Drafts): $hasDrafts = true; break; case strtolower(FOLDERNAME_Trash): $hasTrash = true; break; } if ($hasSentItems && $hasDrafts) { if (USEIMAPTRASH) { if ($hasTrash) { break; } } else { break; } } } if (!$hasSentItems) { $sentFolder =& new Folder($account->Id, -1, FOLDERNAME_SentItems, FOLDERNAME_SentItems, FOLDERSYNC_DontSync); $folders->Add($sentFolder); } if (!$hasDrafts) { $draftsFolder =& new Folder($account->Id, -1, FOLDERNAME_Drafts, FOLDERNAME_Drafts, FOLDERSYNC_DontSync); $folders->Add($draftsFolder); } if (USEIMAPTRASH && !$hasTrash) { $draftsFolder =& new Folder($account->Id, -1, FOLDERNAME_Trash, FOLDERNAME_Trash, FOLDERSYNC_DontSync); $folders->Add($draftsFolder); }*/ if ($s === null) { $sentFolder =& new Folder($account->Id, -1, FOLDERNAME_SentItems, FOLDERNAME_SentItems, FOLDERSYNC_DontSync); $folders->Add($sentFolder); } if ($d === null) { $draftsFolder =& new Folder($account->Id, -1, FOLDERNAME_Drafts, FOLDERNAME_Drafts, FOLDERSYNC_DontSync); $folders->Add($draftsFolder); } if (USEIMAPTRASH && $t === null) { $trashFolder =& new Folder($account->Id, -1, FOLDERNAME_Trash, FOLDERNAME_Trash, FOLDERSYNC_DontSync); $folders->Add($trashFolder); } } else { return false; } break; default: return false; } if ($result) { $folders = $folders->SortRootTree(); $result &= $dbStorage->CreateFolders($folders); } } if ($result) { setGlobalError(''); } return $result; }
} } else { $isError = true; $msgText = '<b>Connect unsuccessful!</b><br />Server Root Path not set!'; } if (!$isError && $_POST['txtWmServerHostName'] && trim($_POST['txtWmServerHostName'])) { $settings->WmServerRootPath = $RootPath; $WMServer = new CWmServerConsole(trim($_POST['txtWmServerHostName'])); $mtime = getmicrotime(); $req = $WMServer->Connect(); $mtime = getmicrotime() - $mtime; if ($req === true) { $msgText = sprintf('<b>Connect successful! (%.4f sec)</b>', $mtime); } else { $isError = true; $msgText = '<b>Connect unsuccessful!</b><br />' . str_replace('"', '\'', str_replace(array("\r", "\t", "\n"), '', $WMServer->GetError())); } } echo '<script type="text/javascript">parent.clearDiv();' . "\r\n" . 'parent.writeDiv("'; echo $isError ? '<font color=\\"red\\">' : '<font color=\\"green\\">'; echo $msgText . '</font>");</script>'; break; // interface // interface case 'wm_edit': $navId = 2; $null = null; $folderSyncType = FOLDERSYNC_NewEntireMessages; $dbstor =& DbStorageCreator::CreateDatabaseStorage($null); if (isset($_GET['uid']) && $_GET['uid'] > -1) { if ($dbstor->Connect()) {