/** * @param $arg[optional] = false * @return bool */ function Connect($arg = false) { if ($this->_wmadmin->_socket != false || !$arg) { return true; } if (!is_dir($this->_wmserver->basePath) || !$this->_wmadmin->Connect()) { setGlobalError(ErrorPOP3Connect); return false; } else { register_shutdown_function(array(&$this, 'Disconnect')); } if (!$this->_wmadmin->UserConnect($this->Account)) { setGlobalError(ErrorPOP3IMAP4Auth); return false; } return true; }
/** * @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; }
$account->MailIncHost = $xmlObj->GetParamTagValueByName('mail_inc_host'); $account->MailOutHost = $xmlObj->GetParamTagValueByName('mail_out_host'); } else { $account->MailProtocol = (int) $settings->IncomingMailProtocol; $account->MailIncPort = (int) $settings->IncomingMailPort; $account->MailOutPort = (int) $settings->OutgoingMailPort; $account->MailOutAuthentication = (bool) $settings->ReqSmtpAuth; $account->MailIncHost = $settings->IncomingMailServer; $account->MailOutHost = $settings->OutgoingMailServer; } if (DEMOACCOUNTALLOW && $email == DEMOACCOUNTEMAIL) { $account->MailIncPassword = DEMOACCOUNTPASS; } 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();
$isError = true; $msgText = '<b>Connect unsuccessful!</b><br />Server Root Path ' . addslashes($RootPath) . ' incorrect'; } } else { $isError = true; $msgText = '<b>Connect unsuccessful!</b><br />Server Root Path not set!'; } } 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':
/** * @static * @param int $id * @return bool */ function DeleteFromDb($id, $deleteDemo = false) { $account =& Account::LoadFromDb($id); if (!$deleteDemo && $account->IsDemo || !USE_DB) { return true; } $null = null; $dbStorage =& DbStorageCreator::CreateDatabaseStorage($null); if ($dbStorage->Connect()) { $settings =& Settings::CreateInstance(); if ($settings->EnableWmServer && $settings->WmAllowManageXMailAccounts) { if ($account && $account->MailProtocol == MAILPROTOCOL_WMSERVER) { $WMConsole = new CWmServerConsole(); if (!$WMConsole->Connect()) { setGlobalError(PROC_CANT_DEL_ACCT_BY_ID); return false; } $domain = ConvertUtils::ParseEmail($account->Email); if ($domain) { $WMConsole->DeleteUser($domain[1], EmailAddress::GetAccountNameFromEmail($account->MailIncLogin)); } } } if ($dbStorage->DeleteAccountData($id)) { return true; } else { setGlobalError(PROC_CANT_DEL_ACCT_BY_ID); } } return false; }