private function _connect() { if (!extension_loaded('ldap')) { $errorString = 'Can\'t load LDAP extension.'; $this->WriteLog('ldap: error: ' . $errorString, LOG_LEVEL_ERROR); setGlobalError($errorString); return false; } if (!is_resource($this->_link)) { $this->WriteLog('ldap: connect to ' . $this->_host . ':' . $this->_port); $this->_link = @ldap_connect($this->_host, $this->_port); if ($this->_link) { @register_shutdown_function(array(&$this, 'RegDisconnect')); @ldap_set_option($this->_link, LDAP_OPT_PROTOCOL_VERSION, 3); @ldap_set_option($this->_link, LDAP_OPT_REFERRALS, 0); $this->WriteLog('ldap: bind ' . LDAP_CONTACT_BIND_DN . '/' . LDAP_CONTACT_PASSWORD); if (!@ldap_bind($this->_link, LDAP_CONTACT_BIND_DN, LDAP_CONTACT_PASSWORD)) { $this->_checkBoolReturn(false); $this->_disconnect(); return false; } } else { $this->_checkBoolReturn(false); return false; } } return true; }
/** * @param WebMailMessageCollection $messageCollection * @param DbStorage $dbStorage * @param Folder $folder * @return bool */ function ApplyFilters(&$messageCollection, &$dbStorage, &$folder) { $filters =& $dbStorage->SelectFilters($this->Account->Id); $lastIdMsg = $dbStorage->SelectLastIdMsg(); $mailBoxesSize = $dbStorage->SelectMailboxesSize(); $result = true; foreach (array_keys($messageCollection->Instance()) as $key) { $message =& $messageCollection->Get($key); $needToSave = true; if ($this->_settings->EnableMailboxSizeLimit && $this->Account->MailboxLimit < $mailBoxesSize + $message->Size) { setGlobalError(ErrorGetMailLimit); return false; } $mailBoxesSize += $message->Size; $lastIdMsg += rand(1, 10); $message->IdMsg = $lastIdMsg; if ($folder->SyncType == FOLDERSYNC_NewEntireMessages || $folder->SyncType == FOLDERSYNC_AllEntireMessages) { $result &= $dbStorage->SaveMessage($message, $folder); } elseif ($folder->SyncType == FOLDERSYNC_NewHeadersOnly || $folder->SyncType == FOLDERSYNC_AllHeadersOnly) { $result &= $dbStorage->SaveMessageHeader($message, $folder, false); } } if ($folder->Type == FOLDERTYPE_Inbox && $result && isset($GLOBALS['useFilters'])) { $mailProcessor = new MailProcessor($this->Account); foreach (array_keys($filters->Instance()) as $key) { $filter =& $filters->Get($key); $action = $filter->GetActionToApply($message); $uidArray = array($message->Uid); $messageIdUidSet[$message->IdMsg] = $message->Uid; switch ($action) { case FILTERACTION_DeleteFromServerImmediately: $result &= $mailProcessor->DeleteMessages($messageIdUidSet, $folder); break; case FILTERACTION_MoveToFolder: $toFolder =& new Folder($filter->IdAcct, $filter->IdFolder, ''); $dbStorage->GetFolderInfo($toFolder); $result &= $mailProcessor->MoveMessages($messageIdUidSet, $folder, $toFolder); break; case FILTERACTION_MarkGrey: $result &= $mailProcessor->SetFlags($messageIdUidSet, $folder, MESSAGEFLAGS_Grayed, ACTION_Set); break; } } } return $result; }
/** * @access private * @param string $mailRootpath * @return bool */ function _parse($mailRootpath) { $result = true; $wmtab = $mailRootpath . '/' . WEBMAILCONFIGTAB; $ctrtab = $mailRootpath . '/ctrlaccounts.tab'; if (@file_exists($wmtab)) { $file = @file($wmtab); if ($file && count($file) > 0) { foreach ($file as $fileLine) { $fileLine = trim($fileLine); if (strlen($fileLine) == 0 || $fileLine[0] == '#') { continue; } $array = explode("\t", trim($fileLine)); if (is_array($array) && count($array) > 1) { $name = trim($array[0], '"'); $value = trim($array[1], '"'); switch ($name) { case 'CtrlPort': $this->AdminPort = (int) $value; break; case 'SmtpPort': $this->OutPort = (int) $value; break; } } } } else { $result = false; setGlobalError('Empty file: ' . $wmtab); } } else { $result = false; setGlobalError('Can\'t find file: ' . $wmtab); } if ($result) { if (@file_exists($ctrtab)) { $file = @file($ctrtab); if ($file && count($file) > 0) { foreach ($file as $fileLine) { $fileLine = trim($fileLine); if (strlen($fileLine) == 0 || $fileLine[0] == '#') { continue; } $array = explode("\t", trim($fileLine)); if (is_array($array) && count($array) == 2) { $this->AdminLogin = trim($array[0], '"'); $this->AdminPassword = ConvertUtils::WmServerDeCrypt(trim($array[1], '"')); break; } } } else { $result = false; setGlobalError('Empty file: ' . $ctrtab); } } else { $result = false; setGlobalError('Can\'t find file: ' . $ctrtab); } } return $result; }
/** * @access private */ function _setSqlError($errmess = '') { $this->ErrorCode = 0; $this->ErrorDesc = @mssql_get_last_message(); setGlobalError($this->ErrorDesc); $this->_log->WriteLine('SQL Error: ' . $this->ErrorDesc); }
/** * @param string $messageIndex * @param bool $indexAsUid * @return WebMailMessage */ function &LoadMessage($messageIndex, $indexAsUid) { $message = null; $idx = $messageIndex; $uid = $messageIndex; if ($indexAsUid) { $uids =& $this->_getPop3Uids(); $idx = $this->_getMessageIndexFromUid($uids, $messageIndex); if ($idx != -1) { $uid = $uids[$idx]; } } if ($idx < 0) { setGlobalError(PROC_MSG_HAS_DELETED); return $message; } $log =& CLog::CreateInstance(); $msgText = $this->_pop3Mail->get_mail($idx); if (!$msgText) { return $message; } $message = new WebMailMessage(); $message->LoadMessageFromRawBody($msgText, true); $message->Uid = $uid; $message->Size = strlen($msgText); /* $size = &$this->_getPop3Sizes(); $message->Size = $size[$idx]; */ return $message; }
/** * @param string $fileName * @return bool */ function SaveToFile($fileName) { $fstat = ''; $fp = @fopen($fileName, 'wb'); if ($fp) { $result = @fwrite($fp, $this->ToString(true)) !== false; $result &= @fclose($fp); return $result; } else { $fstat = @substr(sprintf('%o', fileperms($fileName)), -4); if (!$fstat) { $fstat = 'error'; } setGlobalError($fileName . ' (' . $fstat . ') permission denied'); } return false; }
/** * This function create a mail box * * @param string $mailbox_name * @return bool */ function create_mailbox($mailbox_name) { if (!$this->_checkState_1('AUTHORIZATION')) { return false; } $this->UpdateTag(); if ($this->put_line($this->tag . ' CREATE "' . $mailbox_name . '"')) { if ($this->_checkResponse($this->get_server_responce())) { return true; } } setGlobalError($this->error); return false; }
/** * @param string $messageIndex * @param bool $indexAsUid * @param Folder $folder * @return WebMailMessage */ function &LoadMessage($messageIndex, $indexAsUid, &$folder, $_preData = null) { $messageIndexArray = array($messageIndex); if ($this->_settings->StoreMailsInDb) { if (null === $_preData) { $_preData = $this->PreLoadMessagesFromDB($messageIndexArray, $indexAsUid, $folder); } $_msgArray = array_keys($_preData); $message = null; //read messages from db if (!$this->_dbConnection->Execute($this->_commandCreator->LoadMessagesFromDB($_msgArray, $this->Account))) { return $message; } $row = $this->_dbConnection->GetNextRecord(); if ($row && isset($_preData[$row->id_msg])) { $message = new WebMailMessage(); $message->LoadMessageFromRawBody($row->msg); $message->IdMsg = $row->id_msg; $message->IdFolder = $folder->IdDb; $message->Uid = $_preData[$row->id_msg][0]; $message->DbPriority = $_preData[$row->id_msg][1]; $message->Flags = $_preData[$row->id_msg][2]; $message->Size = strlen($row->msg); $message->Downloaded = true; } else { setGlobalError(PROC_MSG_HAS_DELETED); } $this->_dbConnection->FreeResult(); } else { $fs = new FileSystem(INI_DIR . '/mail', strtolower($this->Account->Email), $this->Account->Id); if (null === $_preData) { $_preData = $this->PreLoadMessagesFromDB($messageIndexArray, $indexAsUid, $folder); } foreach ($_preData as $_id_msg => $_varArray) { $message =& $fs->LoadMessage($_id_msg, $folder); if ($message != null && is_array($_varArray)) { $message->IdMsg = $_id_msg; $message->Uid = $_varArray[0]; $message->IdFolder = $folder->IdDb; $message->DbPriority = $_varArray[1]; $message->Flags = $_varArray[2]; $message->Size = $_varArray[4]; $message->Downloaded = true; } else { setGlobalError(PROC_MSG_HAS_DELETED); } break; } } return $message; }
function setGlobalErrorAndWriteLog() { if (strlen($this->error) > 0) { setGlobalError($this->error); $this->_log->WriteLine('POP3 Error: ' . $this->error); } }
/** * @param Folder $folders * @param DbStorage $dbStorage * @param int $lastIdMsg * @return bool */ function _synchronizeFolderWithOpenDbConnection(&$folder, &$dbStorage) { $log =& CLog::CreateInstance(); $result = true; if ($folder->SyncType == FOLDERSYNC_DontSync || $folder->SyncType == FOLDERSYNC_DirectMode || $folder->Hide) { if ($this->UpdateFolderHandler != null && $folder->SyncType == FOLDERSYNC_DirectMode) { call_user_func_array($this->UpdateFolderHandler, array($folder->IdDb, $folder->FullName)); } return true; } $foldername = ''; if ($this->DownloadedMessagesHandler != null) { $foldername = $folder->GetFolderName($this->Account); call_user_func_array($this->DownloadedMessagesHandler, array($foldername, 0)); } if (!$this->_imapMail->open_mailbox($folder->FullName, false, true)) { return true; } $_isAllUpdate = $folder->SyncType == FOLDERSYNC_AllHeadersOnly || $folder->SyncType == FOLDERSYNC_AllEntireMessages; $_isUidsOnly = $folder->SyncType == FOLDERSYNC_NewHeadersOnly; /* get uid, flags and size from IMAP4 Server */ if ($log->Enabled) { $start = getmicrotime(); } $paramsMessages = $this->_imapMail->getParamsMessages(); if ($log->Enabled) { $log->WriteLine('IMAP4: getParamsMessages()=' . (getmicrotime() - $start)); } if (!is_array($paramsMessages)) { return false; } $imapUids = $imapSizes = $imapUidFlags = $imapUidSizes = array(); $this->_imapArrayForeach($paramsMessages, $imapUids, $imapSizes, $imapUidFlags, $imapUidSizes); unset($paramsMessages); $dbUidsIdMsgsFlags =& $dbStorage->SelectIdMsgAndUidByIdMsgDesc($folder); $dbUids = $dbUidsFlag = array(); foreach ($dbUidsIdMsgsFlags as $value) { $dbUids[] = $value[1]; $dbUidsFlag[$value[1]] = $value[2]; } unset($dbUidsIdMsgsFlags); /* array need added to DB */ //$newUids = array_diff($imapUids, $dbUids); $newUids = array(); foreach ($imapUids as $_imUid) { if (!isset($dbUidsFlag[$_imUid])) { $newUids[] = $_imUid; } } if ($this->DownloadedMessagesHandler != null && count($newUids) > 0) { call_user_func_array($this->DownloadedMessagesHandler, array($foldername, count($newUids))); } if ($_isAllUpdate) { /* update flags */ $_flags4Update = array(); /* intersect uids */ foreach ($imapUids as $_imUid) { if (isset($dbUidsFlag[$_imUid])) { $flagBD = (int) $dbUidsFlag[$_imUid]; $flagImap = (int) $this->getIntFlags($imapUidFlags[$_imUid]); /* update messages whith different flags */ if ($flagBD != $flagImap) { $_flags4Update[$flagImap][] = $_imUid; } } } if (count($_flags4Update) > 0) { foreach ($_flags4Update as $_flag => $_uidArray) { if (is_array($_uidArray)) { $dbStorage->UpdateMessageFlags($_uidArray, true, $folder, $_flag, $this->Account); } } if ($this->UpdateFolderHandler != null) { call_user_func_array($this->UpdateFolderHandler, array($folder->IdDb, $folder->FullName)); } } /* delete from DB */ //$uidsToDelete = array_diff($dbUids, $imapUids); $uidsToDelete = array(); foreach ($dbUids as $_dbUid) { if (!isset($imapUidFlags[$_dbUid])) { //$dbUidsFlag[$_dbUid] = $value[2]; $uidsToDelete[] = $_dbUid; } } if (count($uidsToDelete) > 0) { if ($this->UpdateFolderHandler != null) { call_user_func_array($this->UpdateFolderHandler, array($folder->IdDb, $folder->FullName)); } // $result &= $dbStorage->SetMessagesFlags($uidsToDelete, true, $folder, MESSAGEFLAGS_Deleted, ACTION_Set); $result &= $dbStorage->DeleteMessages($uidsToDelete, true, $folder); $result &= $dbStorage->UpdateMailboxSize(); } } $maxEnvelopesPerSession = 1; /* get size all messages in DB */ $mailBoxesSize = $dbStorage->SelectMailboxesSize(); $filters =& $dbStorage->SelectFilters($this->Account->Id, true); if ($folder->SyncType == FOLDERSYNC_NewHeadersOnly || $folder->SyncType == FOLDERSYNC_AllHeadersOnly) { $syncCycles = ceil(count($newUids) / MAX_ENVELOPES_PER_SESSION); for ($q = 0; $q < $syncCycles; $q++) { if (!$this->_imapMail->open_mailbox($folder->FullName)) { return true; } $cyclesNewUids = array_slice($newUids, $q * MAX_ENVELOPES_PER_SESSION, MAX_ENVELOPES_PER_SESSION); $mailMessageCollection = null; $mailMessageCollection =& $this->LoadMessageHeadersInOneRequest($folder, $cyclesNewUids, true); if ($mailMessageCollection) { for ($i = 0, $c = $mailMessageCollection->Count(); $i < $c; $i++) { if ($this->DownloadedMessagesHandler != null && function_exists($this->DownloadedMessagesHandler)) { call_user_func($this->DownloadedMessagesHandler); } $message =& $mailMessageCollection->Get($i); $mailBoxesSize += $message->Size; if ($this->_settings->EnableMailboxSizeLimit && $this->Account->MailboxLimit > 0 && $this->Account->MailboxLimit < $mailBoxesSize) { $result = false; setGlobalError(ErrorGetMailLimit); break 2; } if (!$this->ApplyFilters($message, $dbStorage, $folder, $filters)) { $result = false; } } } } } else { $syncCycles = ceil(count($newUids) / $maxEnvelopesPerSession); for ($i = 0; $i < $syncCycles; $i++) { $mailBoxesSize += $imapSizes[$i + 1]; if ($this->_settings->EnableMailboxSizeLimit && $this->Account->MailboxLimit > 0 && $this->Account->MailboxLimit < $mailBoxesSize) { $result = false; setGlobalError(ErrorGetMailLimit); break; } if (!$this->_imapMail->open_mailbox($folder->FullName)) { return true; } $listPartToDownload = $i != $syncCycles - 1 ? array_slice($newUids, $i * $maxEnvelopesPerSession, $maxEnvelopesPerSession) : array_slice($newUids, $i * $maxEnvelopesPerSession); if ($this->DownloadedMessagesHandler != null && function_exists($this->DownloadedMessagesHandler)) { call_user_func($this->DownloadedMessagesHandler); } $mailMessageCollection = null; $mailMessageCollection =& $this->LoadMessages($listPartToDownload, true, $folder, $imapUids, $imapUidFlags, $imapUidSizes); if ($mailMessageCollection && $mailMessageCollection->Count() > 0) { $message =& $mailMessageCollection->Get(0); if (!$this->ApplyFilters($message, $dbStorage, $folder, $filters)) { $result = false; break; } } } } $result &= $dbStorage->UpdateMailboxSize(); return $result; }
/** * @param string $msg_set * @param string $msg_data_name * @param string $value * @param bool $_isUidStore = false * @return bool */ function _in_store_mail_flag($msg_set, $msg_data_name, $value, $_isUidStore = false) { if (!$this->_checkState_0('SELECTED')) { return false; } $msg_set = trim($msg_set); $msg_data_name = trim($msg_data_name); $value = trim($value); $_temp = $_isUidStore ? 'UID ' : ''; $this->UpdateTag('STR'); if ($this->put_line($this->tag . ' ' . $_temp . 'STORE ' . $msg_set . ' ' . $msg_data_name . ' (' . $value . ')')) { if ($this->_checkResponse($this->get_server_responce())) { return true; } } setGlobalError($this->error); return false; }
/** * @access private */ function _setSqlError() { $this->ErrorCode = 0; $this->ErrorDesc = @mssql_get_last_message(); setGlobalError($this->ErrorDesc); $this->_log->WriteLine('SQL Error: ' . $this->ErrorDesc, LOG_LEVEL_ERROR); }
/** * @param string $filename * @return bool */ function SaveToFile($filename) { $body = null; $returnBool = true; $fh = @fopen($filename, 'wb'); if ($fh) { $body = $this->GetBinaryBody(); if (!@fwrite($fh, $body)) { setGlobalError('can\'t write file: ' . $filename); $returnBool = false; } @fclose($fh); } else { setGlobalError('can\'t open file(wb): ' . $filename); $returnBool = false; } if ($returnBool && null !== $body) { return strlen($body); } return -1; }
/** * @param Folder $folders * @param DbStorage $dbStorage * @return bool */ function _synchronizeFolderWithOpenDbConnection(&$folder, &$dbStorage, $lastIdMsg) { $result = true; if ($folder->SyncType == FOLDERSYNC_DontSync || $folder->SyncType == FOLDERSYNC_DirectMode) { return true; } //get uids from pop3 server $serverUids = $this->_wmserver->getAllMessagesNames(); //get uids from DB $dbUids =& $dbStorage->SelectReadsRecords(); $dbUids = array_keys($dbUids); //get only new messages from wm server $newUids = array_diff($serverUids, $dbUids); //get deleted uids from wm server $uidsToDelete = array_diff($dbUids, $serverUids); //get size all messages in DB $mailBoxesSize = $dbStorage->SelectMailboxesSize(); if ($this->DownloadedMessagesHandler != null) { ShowDownloadedMessageNumber($folder->Name, count($newUids)); call_user_func($this->DownloadedMessagesHandler); } foreach ($newUids as $key => $newUid) { if ($this->Account->MailboxLimit > $mailBoxesSize + $this->_wmserver->getSizeMessage($newUid)) { //Check sync mode if ($folder->SyncType == FOLDERSYNC_NewEntireMessages || $folder->SyncType == FOLDERSYNC_AllEntireMessages) { //Entire Message $mailMessageCollection =& $this->LoadMessages($newUid, false, $folder); } elseif ($folder->SyncType == FOLDERSYNC_NewHeadersOnly || $folder->SyncType == FOLDERSYNC_AllHeadersOnly) { //Entire Header $mailMessageCollection =& $this->getHeaders($newUid, $folder); } //Apply filters and save message in DB if (!$this->ApplyFilters($mailMessageCollection, $dbStorage, $folder)) { $result = false; break; } //Check mailmode to delete from server if ($this->Account->MailMode == MAILMODE_DeleteMessagesFromServer) { //Delete received messages from server $this->_wmserver->deleteMessage($newUid); } //Save uid to reads table $dbStorage->InsertReadsRecords(array($newUid)); } else { $result = false; setGlobalError(ErrorGetMailLimit); break; } } if ($folder->SyncType == FOLDERSYNC_AllHeadersOnly || $folder->SyncType == FOLDERSYNC_AllEntireMessages) { $index = $this->_getMessageIndexFromUid($uidsToDelete, $deleteUid); //delete from DB $result &= $dbStorage->DeleteMessages($uidsToDelete, true, $folder); } if (($this->Account->MailMode == MAILMODE_KeepMessagesOnServer || $this->Account->MailMode == MAILMODE_KeepMessagesOnServerAndDeleteMessageWhenItsRemovedFromTrash) && $this->Account->MailsOnServerDays > 0) { $expiredUids =& $dbStorage->SelectExpiredMessageUids(); $result &= $this->DeleteMessages($expiredUids, true, $folder); } if (!empty($uidsToDelete)) { $result &= $dbStorage->DeleteReadsRecordsByUids($uidsToDelete); } $result &= $dbStorage->UpdateMailboxSize(); return $result; }
/** * @access private * @param resource $link * @param CLog $log * @return bool */ function IsSuccess(&$link, &$log) { $result = true; do { $line = @fgets($link, 1024); if ($line === false) { $result = false; setGlobalError('SMTP IsSuccess fgets error'); break; } else { $line = str_replace("\r", '', str_replace("\n", '', str_replace(CRLF, '', $line))); if (substr($line, 0, 1) != '2' && substr($line, 0, 1) != '3') { $result = false; $error = '[SMTP] Error <<: ' . $line; setGlobalError($error); break; } } } while (substr($line, 3, 1) == '-'); if (!$result) { $log->WriteLine(getGlobalError()); } return $result; }
/** * @param WebMailMessage $message * @param Folder $folder * @return bool */ function SaveMessage(&$message, &$folder, $fromFolder = null) { if ($message == null || $folder == null) { return false; } //Get size all messages in DB $mailBoxesSize = $this->DbStorage->SelectMailboxesSize() + $message->GetMailSize(); $this->DbStorage->SelectMailboxesSize(); if ($this->MailStorage->_settings->EnableMailboxSizeLimit && $this->_account->MailboxLimit < $mailBoxesSize) { setGlobalError(ErrorGetMailLimit); return false; } switch ($this->_account->MailProtocol) { case MAILPROTOCOL_POP3: $result = true; if ($this->DbStorage->Connect()) { //if ($message->IdMsg != -1) //{ //$messageIdSet = array($message->IdMsg); //$result &= $this->DbStorage->DeleteMessages($messageIdSet, false, $folder); //} //else //{ $message->IdMsg = $this->DbStorage->SelectLastIdMsg() + 1; //} return $result && $this->DbStorage->SaveMessage($message, $folder); } case MAILPROTOCOL_IMAP4: $result = true; if ($message->IdMsg != -1) { $messageIdUidSet = array(); $messageIdUidSet[$message->IdMsg] = $message->Uid; $nfolder = $fromFolder ? $fromFolder : $folder; $result &= $this->DeleteMessages($messageIdUidSet, $nfolder); } if ($folder->SyncType != FOLDERSYNC_DontSync) { if ($this->MailStorage->Connect()) { $result &= $this->MailStorage->SaveMessage($message, $folder); $GLOBALS[MailDefaultCharset] = $this->_account->GetDefaultIncCharset(); unset($GLOBALS[MailInputCharset]); $GLOBALS[MailOutputCharset] = $this->_account->GetUserCharset(); $result &= $this->MailStorage->SynchronizeFolder($folder); } return $result; } elseif ($this->DbStorage->Connect()) { //if ($message->IdMsg == -1) //{ $message->IdMsg = $this->DbStorage->SelectLastIdMsg() + 1; //} $result &= $this->DbStorage->SaveMessage($message, $folder); return $result; } case MAILPROTOCOL_WMSERVER: $result = true; if ($this->DbStorage->Connect()) { $message->IdMsg = $this->DbStorage->SelectLastIdMsg() + 1; return $result && $this->DbStorage->SaveMessage($message, $folder); } } return false; }
/** * @var string $tempName * @var string $body * @return int (save file size or -1) */ function SaveFile($tempName, $body) { $this->_fs->CreateFolder($this->_folder); $fileName = $this->_fs->GetFolderFullPath($this->_folder) . '/' . $tempName; $returnBool = true; $fh = @fopen($fileName, 'wb'); if ($fh) { if (!@fwrite($fh, $body)) { setGlobalError('can\'t write file: ' . $fileName); $returnBool = false; } @fclose($fh); } else { setGlobalError('can\'t open file(wb): ' . $fileName); $returnBool = false; } if ($returnBool && null !== $body) { return strlen($body); } return -1; }
/** * @param string $messageIndex * @param bool $indexAsUid * @param Folder $folder * @return WebMailMessage */ function &LoadMessage($messageIndex, $indexAsUid, &$folder) { $messageIndexArray = array($messageIndex); if ($this->_settings->StoreMailsInDb) { $message = null; //read messages from db if (!$this->_dbConnection->Execute($this->_commandCreator->LoadMessagesFromDB($messageIndexArray, $indexAsUid, $folder, $this->Account))) { return $message; } if ($row = $this->_dbConnection->GetNextRecord()) { $message =& new WebMailMessage(); $message->LoadMessageFromRawBody($row->msg, true); $message->IdMsg = $row->id_msg; $message->Uid = $row->uid; $message->DbPriority = $row->priority; $message->Flags = $row->flags; } else { setGlobalError(PROC_MSG_HAS_DELETED); } } else { $fs =& new FileSystem(INI_DIR . '/mail', $this->Account->Email, $this->Account->Id); //read messages from file system if (!$this->_dbConnection->Execute($this->_commandCreator->LoadMessagesFromFileSystem($messageIndexArray, $indexAsUid, $folder, $this->Account))) { return null; } if ($row = $this->_dbConnection->GetNextRecord()) { $message =& $fs->LoadMessage($row->id_msg, $folder); if ($message != null) { $message->IdMsg = $row->id_msg; $message->Uid = $row->uid; $message->DbPriority = $row->priority; $message->Flags = $row->flags; } else { setGlobalError(PROC_MSG_HAS_DELETED); } } } $this->_dbConnection->FreeResult(); return $message; }
/** * @return bool */ function AddFromFile($filepath, $attachname, $mimetype, $isInline = false) { $data = ''; $handle = @fopen($filepath, 'rb'); if ($handle) { $size = @filesize($filepath); $data = $size > 0 ? @fread($handle, $size) : ''; @fclose($handle); } else { setGlobalError(' can\'t open ' . $filepath); return false; } if ($this->AddFromBinaryBody($data, $attachname, $mimetype, $isInline)) { return true; } return false; }
/** * @param int $_deleteId * @param int $_edit_id * @param bool $_clearClassic = false * @return bool|7 (7 - logout) */ function ProcessDeleteAccount($_deleteId, &$_edit_id, $_clearClassic = false) { if (!isset($_SESSION[ACCOUNT_ID], $_SESSION[USER_ID]) || !User::AccountAccess($_deleteId)) { setGlobalError(PROC_WRONG_ACCT_ACCESS); return false; } $null = null; $_accounts = array(); $_dbStorage =& DbStorageCreator::CreateDatabaseStorage($null); if ($_dbStorage->Connect()) { $_accounts =& $_dbStorage->SelectAccounts($_SESSION[USER_ID]); if (!$_accounts) { setGlobalError(PROC_CANT_GET_ACCT_LIST); return false; } } else { return false; } $_is_def = false; $_is_lastdef = false; $_is_edit = false; $_c = count($_accounts); if ($_c > 1) { foreach ($_accounts as $_id => $_currAccount) { if ($_id == $_deleteId && isset($_currAccount[6]) && $_currAccount[6]) { $_is_def = true; } } if ($_is_def) { $_is_lastdef = true; foreach ($_accounts as $_id => $_currAccount) { if ($_id != $_deleteId && isset($_currAccount[6]) && $_currAccount[6]) { $_is_lastdef = false; } } } if ($_edit_id == $_deleteId) { $_is_edit = true; } } else { if ($_c == 1) { if (isset($_accounts[$_deleteId])) { $_is_edit = true; } } else { setGlobalError(PROC_CANT_DEL_ACCT_BY_ID); return false; } } if ($_c > 1) { if ($_is_lastdef) { setGlobalError(ACCT_CANT_DEL_LAST_DEF_ACCT); return false; } } else { if (!self::ProcessDeleteAccountEnd($_deleteId, $_dbStorage)) { setGlobalError(PROC_CANT_DEL_ACCT_BY_ID); return false; } return 7; } if ($_SESSION[ACCOUNT_ID] == $_deleteId) { foreach ($_accounts as $_id => $_currAccount) { if ($_id != $_deleteId && isset($_currAccount[6]) && $_currAccount[6]) { $_SESSION[ACCOUNT_ID] = $_id; if ($_clearClassic) { unset($_SESSION[SARRAY][FOLDER_ID], $_SESSION[SARRAY][PAGE]); } break; } } if ($_SESSION[ACCOUNT_ID] == $_deleteId) { foreach ($_accounts as $_id => $_currAccount) { if ($_id != $_deleteId) { $_SESSION[ACCOUNT_ID] = $_id; if ($_clearClassic) { unset($_SESSION[SARRAY][FOLDER_ID], $_SESSION[SARRAY][PAGE]); } break; } } } if (!self::ProcessDeleteAccountEnd($_deleteId, $_dbStorage)) { setGlobalError(PROC_CANT_DEL_ACCT_BY_ID); return false; } } else { if ($_is_edit) { foreach ($_accounts as $_id => $_currAccount) { if ($_id != $_deleteId && $_currAccount[6]) { $_edit_id = $_id; break; } } if ($_SESSION[SARRAY][EDIT_ACCOUNT_ID] == $_deleteId) { foreach ($_accounts as $_id => $_currAccount) { if ($_id != $_deleteId) { $_edit_id = $_id; break; } } } } if (!self::ProcessDeleteAccountEnd($_deleteId, $_dbStorage)) { setGlobalError(PROC_CANT_DEL_ACCT_BY_ID); return false; } } return true; }
/** * @access private * @param resource $link * @param CLog $log * @return bool */ function IsSuccess(&$link, &$log, &$out, $isLog = true) { $out = ''; $line = ''; $result = true; do { $line = @fgets($link, 1024); if ($isLog) { $log->WriteLine('[SMTP] <<: ' . trim($line)); } if ($line === false) { $result = false; setGlobalError('[SMTP] Error: IsSuccess fgets error'); break; } else { $out .= $line; $line = str_replace("\r", '', str_replace("\n", '', str_replace(CRLF, '', $line))); if (substr($line, 0, 1) != '2' && substr($line, 0, 1) != '3') { $result = false; $error = '[SMTP] Error <<: ' . $line; setGlobalError($error); //setGlobalError(substr($line, 3)); break; } } } while (substr($line, 3, 1) == '-'); if (!$result && $log->Enabled) { $log->WriteLine(getGlobalError(), LOG_LEVEL_ERROR); } return $result; }
function uid_store_mail_flag($msg_set, $msg_data_name, $value) { if ($this->state != "SELECTED") { $this->error = "Error : No mail box is selected.!<br>"; return false; } $msg_set = trim($msg_set); $msg_data_name = trim($msg_data_name); $value = trim($value); if ($this->put_line($this->tag . " UID STORE {$msg_set} {$msg_data_name} ({$value})")) { $response = $this->get_server_responce(); if (substr($response, strpos($response, "{$this->tag} ") + strlen($this->tag) + 1, 2) != "OK") { setGlobalError($response); $this->error = "Error : {$response} !"; return false; } } else { $this->error = "Error : Could not send User request. <br>"; 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; }
/** * @access private */ function _setSqlError($errorDesc = '') { if ($errorDesc) { $this->ErrorDesc = $errorDesc; $this->ErrorCode = 0; } elseif ($this->_conectionHandle) { $this->ErrorDesc = @odbc_errormsg($this->_conectionHandle); $this->ErrorCode = @odbc_error($this->_conectionHandle); } else { $this->ErrorDesc = @odbc_errormsg(); $this->ErrorCode = @odbc_error(); } setGlobalError($this->ErrorDesc); $this->_log->WriteLine('ErrorDesc: ' . $this->ErrorDesc . "\tErrorCode " . $this->ErrorCode, LOG_LEVEL_ERROR); }
/** * @param string $messageIndex * @param bool $indexAsUid * @return WebMailMessage */ function &LoadMessage($messageIndex, $indexAsUid) { $uids =& $this->_getPop3Uids(); $message = null; if ($indexAsUid) { $idx = $this->_getMessageIndexFromUid($uids, $messageIndex); } else { $idx = $messageIndex; } if ($idx < 0 || $idx > count($uids)) { setGlobalError(PROC_MSG_HAS_DELETED); return $message; } $msgText = $this->_pop3Mail->get_mail($idx); if (!$msgText) { return $message; } $message =& new WebMailMessage(); $message->LoadMessageFromRawBody($msgText, true); $message->Uid = $uids[$idx]; $size =& $this->_getPop3Sizes(); $message->Size = $size[$idx]; return $message; }
/** * @access private */ function Settings($param = true) { if (!is_null($param)) { die('can\'t call Settings class.'); } $this->UseDsn = false; $this->WmServerHost = '127.0.0.1'; $this->AllowUsersChangeAccountsDef = false; $this->WmAllowManageXMailAccounts = false; $this->AllowContacts = true; $this->AllowCalendar = true; $this->UseCaptcha = true; $this->Cal_DefaultTimeFormat = 1; $this->Cal_DefaultTimeZone = 38; $this->Cal_DefaultDateFormat = 1; $this->Cal_ShowWeekends = true; $this->Cal_WorkdayStarts = 9; $this->Cal_WorkdayEnds = 18; $this->Cal_ShowWorkDay = 1; $this->Cal_WeekStartsOn = 0; $this->Cal_DefaultTab = 2; $this->Cal_DefaultCountry = 'US'; $this->Cal_AllTimeZones = false; $this->Cal_AllowReminders = false; $this->Cal_AutoAddInvitation = 0; $this->Imap4DeleteLikePop3 = true; $this->AllowLanguageOnLogin = true; $this->AllowInsertImage = true; $this->AllowBodySize = false; $this->MaxBodySize = 600; $this->MaxSubjectSize = 255; $this->AllowRegistration = false; $this->AllowPasswordReset = false; $this->GlobalAddressBook = GLOBAL_ADDRESS_BOOK_OFF; $this->EnableMobileSync = false; $this->MobileSyncUrl = ''; $this->MobileSyncContactDataBase = 'card'; $this->MobileSyncCalendarDataBase = 'cal'; $this->FlagsLangSelect = false; $this->ViewMode = 1; $this->SaveInSent = 0; $this->isLoad = false; $this->_langIsInclude = false; $this->Dev = null; $settingsCacher = new SettingsCacher(); $settingsRaw = $settingsCacher->Load(); if (false === $settingsRaw) { $settingsRaw = $settingsCacher->LoadRoot(); if ($settingsRaw == false) { setGlobalError($settingsCacher->GetError()); } else { $settingsCacher->Save($settingsRaw); } } else { if (is_array($settingsRaw)) { $this->_loadFromArray($settingsRaw); $this->isLoad = true; } } if (is_string($settingsRaw)) { $xmlDocument = new XmlDocument(); if ($xmlDocument->LoadFromString($settingsRaw)) { $this->_loadFromXML($xmlDocument->XmlRoot); $this->isLoad = true; } } if ($this->isLoad) { if (!@function_exists('imagecreatefrompng')) { $this->UseCaptcha = false; } $xmlDomainSettings =& DomainSettings::CreateInstance(); $xmlDomainSettings->UpdateSettingsByDomain($this); /* custom class */ wm_Custom::StaticUseMethod('ChangeSettingsAfterLoad', array(&$this)); } }
function _setSqlError() { if ($this->_conectionHandle) { $this->ErrorDesc = @mysql_error($this->_conectionHandle); $this->ErrorCode = @mysql_errno($this->_conectionHandle); } else { $this->ErrorDesc = @mysql_error(); $this->ErrorCode = @mysql_errno(); } setGlobalError($this->ErrorDesc); $this->_log->WriteLine('ErrorDesc [' . $this->ErrorCode . ']: ' . $this->ErrorDesc, LOG_LEVEL_ERROR); }
setGlobalError('Can\'t find ' . $RootPath . '/wm.tab'); } } else { $isError = true; setGlobalError('Server Root Path not set!'); } } else { $isError = true; setGlobalError('Server Root Path not set!'); } if (!$isError) { $WMServer = new CWmServerConsole(); $req = $WMServer->Connect(); if ($req !== true) { $isError = true; setGlobalError('Connect unsuccessful! ' . str_replace('"', '\'', str_replace(array("\r", "\t", "\n"), '', $WMServer->GetError()))); } } } if ($isError) { $_SESSION['divmess'] = MES_ERROR . getError(); } else { $_SESSION['divmess'] = $settings->SaveToXml() ? MES_SAVESUCCESSFUL : MES_ERROR . getError(); } break; case 'login': $settings->AllowAdvancedLogin = isset($_POST['intAllowAdvancedLogin']) && (int) $_POST['intAllowAdvancedLogin'] == 1; $settings->AutomaticCorrectLoginSettings = isset($_POST['intAutomaticHideLogin']) && (int) $_POST['intAutomaticHideLogin'] == 1; $settings->DefaultDomainOptional = isset($_POST['txtUseDomain']) ? $_POST['txtUseDomain'] : $settings->DefaultDomainOptional; $hideLoginMode = 0; if (isset($_POST['hideLoginRadionButton'])) {
/** * @param string $body * @param string $filename * @param string $tempFolderName * @return string */ function CacheFileSave($body, $filename, $tempFolderName) { $filename = $this->_createFolderFullPath($tempFolderName) . '/' . $filename; $fh = @fopen($filename, 'wb'); if ($fh) { if (!@fwrite($fh, $body)) { setGlobalError('can\'t write file: ' . $filename); $returnBool = false; } @fclose($fh); } else { setGlobalError('can\'t open file(wb): ' . $filename); $returnBool = false; } return $returnBool; }
/** * @access private * @return bool */ function _parse($fileName) { if (file_exists($fileName)) { $file = @file($fileName); if ($file) { foreach ($file as $fileLine) { $fileLine = trim($fileLine); if (strlen($fileLine) == 0 || $fileLine[0] == '#') { continue; } $array = explode("\t", trim($fileLine)); if (is_array($array) && count($array) > 1) { $name = trim($array[0], '"'); $value = trim($array[1], '"'); switch ($name) { case 'CtrlPort': $this->AdminPort = (int) $value; break; case 'SmtpPort': $this->OutPort = (int) $value; break; case 'Login': $this->AdminLogin = $value; break; case 'Password': $this->AdminPassword = ConvertUtils::WmServerDeCrypt($value); break; } } } return true; } } else { setGlobalError('Can\'t find file: ' . $fileName); } return false; }