STDMETHODIMP InterfaceAccount::put_VacationMessageExpiresDate(BSTR newVal) { try { if (!object_) return GetAccessDenied(); HM::String string = newVal; // Validate input date. if (string.Left(4) == _T("0000")) string = ""; if (string.GetLength() == 0) string = Time::GetCurrentDate(); else if (string.GetLength() != 10 || !Time::IsValidSystemDate(string)) return COMError::GenerateError("Invalid auto-reply expiry date"); object_->SetVacationExpiresDate(string); return S_OK; } catch (...) { return COMError::GenerateGenericMessage(); } }
STDMETHODIMP InterfaceUtilities::GenerateGUID(BSTR *Output) { try { HM::String sOutput = HM::GUIDCreator::GetGUID(); *Output = sOutput.AllocSysString(); return S_OK; } catch (...) { return COMError::GenerateGenericMessage(); } }
HM::String _tagXMLEntitys::Ref2Entity( LPCTSTR estr ) { HM::String es; if( estr ) { int len = _tcslen(estr); LPTSTR esbuf = es.GetBufferSetLength( len +1); if( esbuf ) Ref2Entity( estr, esbuf, len ); es.ReleaseBuffer(); } return es; }
STDMETHODIMP InterfaceApplication::Connect() { try { HM::String sErrorMessage = HM::Application::Instance()->GetLastErrorMessage(); if (!sErrorMessage.IsEmpty()) return COMError::GenerateError(sErrorMessage); return S_OK; } catch (...) { return COMError::GenerateGenericMessage(); } }
STDMETHODIMP InterfaceUtilities::SHA256(BSTR Input, BSTR *Output) { try { HM::String sInput(Input); HM::String sOutput = HM::Crypt::Instance()->EnCrypt(sInput, HM::Crypt::ETSHA256); *Output = sOutput.AllocSysString(); return S_OK; } catch (...) { return COMError::GenerateGenericMessage(); } }
STDMETHODIMP InterfaceLanguage::get_String(BSTR EnglishString, BSTR *pVal) { try { if (!language_) return GetAccessDenied(); HM::String sText = language_->GetString(EnglishString); *pVal = sText.AllocSysString(); return S_OK; } catch (...) { return COMError::GenerateGenericMessage(); } }
STDMETHODIMP InterfaceIMAPFolder::get_Name(BSTR *pVal) { try { if (!m_pObject) return GetAccessDenied(); HM::String sUnicode = HM::ModifiedUTF7::Decode(m_pObject->GetFolderName()); *pVal = sUnicode.AllocSysString(); return S_OK; } catch (...) { return COMError::GenerateGenericMessage(); } }
STDMETHODIMP InterfaceLanguage::get_Name(BSTR *pVal) { try { if (!language_) return GetAccessDenied(); HM::String sName = language_->GetName(); *pVal = sName.AllocSysString(); return S_OK; } catch (...) { return COMError::GenerateGenericMessage(); } }
HM::String _tagXMLEntitys::Entity2Ref( LPCTSTR str ) { HM::String s; if( str ) { int nEntityCount = GetEntityCount(str); if( nEntityCount == 0 ) return HM::String(str); int len = _tcslen(str) + nEntityCount*10 ; LPTSTR sbuf = s.GetBufferSetLength( len + 1 ); if( sbuf ) Entity2Ref( str, sbuf, len ); s.ReleaseBuffer(); } return s; }
STDMETHODIMP InterfaceTCPIPPort::get_Address(BSTR *pVal) { try { if (!m_pObject) return GetAccessDenied(); HM::String sIPAddress = m_pObject->GetAddressString(); *pVal = sIPAddress.AllocSysString(); return S_OK; } catch (...) { return COMError::GenerateGenericMessage(); } }
STDMETHODIMP InterfaceDatabase::SetDefaultDatabase(eDBtype ServerType, BSTR ServerName, long lPort, BSTR DatabaseName, BSTR Username, BSTR Password) { try { if (!GetIsServerAdmin()) return GetAccessDenied(); HM::String sEmpty; HM::String sServerName = ServerName; HM::String sDatabaseName = DatabaseName; HM::String sUsername = Username; HM::String sPassword = Password; if (sDatabaseName.Find(_T(" ")) >= 0) return COMError::GenerateError("The database name may not contain spaces."); // Create a settings object for the connection ... std::shared_ptr<HM::DatabaseSettings> pSettings = std::shared_ptr<HM::DatabaseSettings>( new HM::DatabaseSettings(sServerName, sEmpty, sUsername, sPassword, sEmpty, sEmpty,(HM::DatabaseSettings::SQLDBType) ServerType, lPort)); // Connect to the database server. std::shared_ptr<HM::DALConnection> pConn = HM::DALConnectionFactory::CreateConnection(pSettings); HM::String sErrorMessage; if (pConn->Connect(sErrorMessage) != HM::DALConnection::Connected) return COMError::GenerateError(sErrorMessage); // Disconnect again. pConn->Disconnect(); ini_file_settings_->SetDatabaseDirectory(""); ini_file_settings_->SetDatabaseType((HM::DatabaseSettings::SQLDBType) ServerType); ini_file_settings_->SetUsername(sUsername); ini_file_settings_->SetPassword(sPassword); ini_file_settings_->SetDatabasePort(lPort); ini_file_settings_->SetDatabaseServer(sServerName); ini_file_settings_->SetDatabaseName(sDatabaseName); ini_file_settings_->SetIsInternalDatabase(ServerType == hDBTypeMSSQLCE); return S_OK; } catch (...) { return COMError::GenerateGenericMessage(); } }
STDMETHODIMP InterfaceApplication::Reinitialize() { try { if (!authentication_->GetIsServerAdmin()) return authentication_->GetAccessDenied(); HM::String sErrorMessage = HM::Application::Instance()->Reinitialize(); if (!sErrorMessage.IsEmpty()) return COMError::GenerateError(sErrorMessage); return S_OK; } catch (...) { return COMError::GenerateGenericMessage(); } }
STDMETHODIMP InterfaceDistributionListRecipient::get_RecipientAddress(BSTR *pVal) { try { if (!m_pObject) return GetAccessDenied(); HM::String sVal = m_pObject->GetAddress(); *pVal = sVal.AllocSysString(); return S_OK; } catch (...) { return COMError::GenerateGenericMessage(); } }
HRESULT InterfaceDatabase::EnsureDatabaseConnectivity_() { db_manager_ = HM::Application::Instance()->GetDBManager(); if (!db_manager_) { return COMError::GenerateError("The connection to the database is not available. Please check the hMailServer error log for details."); } if (!db_manager_->GetIsConnected()) { HM::String sError; sError.Format(_T("The connection to the database is not available.\r\n%s"), HM::Application::Instance()->GetLastErrorMessage().c_str()); return COMError::GenerateError(sError); } return S_OK; }
STDMETHODIMP InterfaceAntiVirus::TestClamAVScanner(BSTR hostname, long port, BSTR *messageText, VARIANT_BOOL *pResult) { try { if (!GetIsServerAdmin()) return GetAccessDenied(); HM::VirusScannerTester testClient; HM::String text; *pResult = testClient.TestClamAVConnect(hostname, port, text) ? VARIANT_TRUE : VARIANT_FALSE; *messageText = text.AllocSysString(); return S_OK; } catch (...) { return COMError::GenerateGenericMessage(); } }
STDMETHODIMP InterfaceAntiSpam::TestSpamAssassinConnection(BSTR hostname, long port, BSTR *messageText, VARIANT_BOOL *pResult) { try { if (!m_pConfig) return GetAccessDenied(); HM::SpamAssassinTestConnect testClient; HM::String text; *pResult = testClient.TestConnect(hostname, port, text) ? VARIANT_TRUE : VARIANT_FALSE; *messageText = text.AllocSysString(); return S_OK; } catch (...) { return COMError::GenerateGenericMessage(); } }
STDMETHODIMP InterfaceAntiVirus::TestClamWinScanner(BSTR clamWinExecutable, BSTR clamWinDatabase, BSTR *messageText, VARIANT_BOOL *pResult) { try { if (!GetIsServerAdmin()) return GetAccessDenied(); HM::VirusScannerTester testClient; HM::String text; *pResult = testClient.TestClamWinVirusScanner(clamWinExecutable, clamWinDatabase, text) ? VARIANT_TRUE : VARIANT_FALSE; *messageText = text.AllocSysString(); return S_OK; } catch (...) { return COMError::GenerateGenericMessage(); } }
STDMETHODIMP InterfaceDatabase::get_DatabaseName(BSTR *pVal) { try { if (!config_) return GetAccessDenied(); if (!GetIsServerAdmin()) return GetAccessDenied(); HM::String sServerName = ini_file_settings_->GetDatabaseName(); *pVal = sServerName.AllocSysString(); return S_OK; } catch (...) { return COMError::GenerateGenericMessage(); } }
STDMETHODIMP InterfaceAccount::put_Address(BSTR newVal) { try { if (!m_pObject) return GetAccessDenied(); if (!m_pAuthentication->GetIsDomainAdmin()) return m_pAuthentication->GetAccessDenied(); HM::String sAddress = newVal; sAddress.Trim(); m_pObject->SetAddress(sAddress); return S_OK; } catch (...) { return COMError::GenerateGenericMessage(); } }
STDMETHODIMP InterfaceDomain::put_Name(BSTR newVal) { try { if (!m_pObject) return GetAccessDenied(); if (!m_pAuthentication->GetIsDomainAdmin()) return m_pAuthentication->GetAccessDenied(); HM::String sName = newVal; sName.Trim(); m_pObject->SetName(sName); return S_OK; } catch (...) { return COMError::GenerateGenericMessage(); } }
STDMETHODIMP InterfaceBackupSettings::get_LogFile(BSTR *pVal) { try { if (!config_) return GetAccessDenied(); HM::String sLogDir = ini_file_settings_->GetLogDirectory(); if (sLogDir.Right(1) != _T("\\")) sLogDir += "\\"; sLogDir += "hmailserver_backup.log"; *pVal = sLogDir.AllocSysString(); return S_OK; } catch (...) { return COMError::GenerateGenericMessage(); } }
// <?xml version='1.0'?> // <TAG attr1="value1" attr2='value2' attr3=value3 > // </TAG> // or // <TAG /> // ^- return pointer //======================================================== // Name : Load // Desc : load xml plain text for xml document // Param : pszXml - plain xml text // pi = parser information // Return : advanced string pointer (error return NULL) //-------------------------------------------------------- // Coder Date Desc // bro 2002-10-29 //======================================================== LPTSTR _tagXMLDocument::Load( LPCTSTR pszXml, LPPARSEINFO pi /*= NULL*/ ) { LPXNode node = new XNode; node->parent = (LPXNode)this; node->type = XNODE_ELEMENT; node->doc = this; LPTSTR end; if( pi == NULL ) pi = &parse_info; if( (end = node->Load( pszXml, pi )) == NULL ) { delete node; if (pi->erorr_occur == true) { // This error should be logged. HM::String sErrorMessage; sErrorMessage.Format(_T("The XML data stream contains formatting errors. Code: %d, Error: %s"), pi->error_code, pi->error_string); HM::ErrorManager::Instance()->ReportError(HM::ErrorManager::Medium, 4229, "_tagXMLDocument::Load", sErrorMessage); } return NULL; } childs.push_back( node ); // Load Other Node after </Tag>(pi, comment, CDATA etc) LPTSTR ret; bool bRet = false; ret = LoadOtherNodes( node, &bRet, end, pi ); if( ret != NULL ) end = ret; return end; }
STDMETHODIMP InterfaceUtilities::RunTestSuite(BSTR sTestPassword) { try { if (!m_pAuthentication->GetIsServerAdmin()) return m_pAuthentication->GetAccessDenied(); HM::String sCorrectPassword = _T("I know what I am doing."); HM::String sPassword = sTestPassword; if (sPassword.Compare(sCorrectPassword) != 0) return S_FALSE; HM::ClassTester oTester; oTester.DoTests(); return S_OK; } catch (...) { return COMError::GenerateGenericMessage(); } }
STDMETHODIMP InterfaceMessage::Save() { try { if (!m_pObject) return GetAccessDenied(); // Check that the message has a valid date header. HM::String sDate = _GetMessageData()->GetSentTime(); if (sDate.IsEmpty()) { // Date was not specified. Specify it now. sDate = HM::Time::GetCurrentMimeDate(); _GetMessageData()->SetSentTime(sDate); } shared_ptr<const HM::Account> account; if (m_pObject->GetAccountID() > 0) { account = HM::CacheContainer::Instance()->GetAccount(m_pObject->GetAccountID()); } // Save the message to disk. const HM::String fileName = HM::PersistentMessage::GetFileName(account, m_pObject); if (!_GetMessageData()->Write(fileName)) { return COMError::GenerateError("Unable to write to message file."); } // A message can be in a number of different states: // Case 1) New message which should be delivered -> Save in file and add to database // Case 2) New message which should be added to an existing IMAP folder -> Update message file and save to database// // case 3) Existing message which is being delivered. -> Only update the message fil // Case 4) Existing message in IMAP folder which should just be re-saved -> Update message file HM::Message::State state = m_pObject->GetState(); switch (state) { case HM::Message::Created: { // Handle new message. It can either be Case 1 or Case 2. If the message is already // connected to an account, it means that it should be stored in a specific IMAP folder if (m_pObject->GetFolderID() == 0 && m_pObject->GetAccountID() == 0) { // Case 1: The message should be delivered. Change the state to delivering m_pObject->SetState(HM::Message::Delivering); if (!HM::PersistentMessage::SaveObject(m_pObject)) { return COMError::GenerateError("Message could not be saved in database."); } HM::Application::Instance()->SubmitPendingEmail(); } else { // Case 2. It's a new message but it should be added to an existing IMAP folder. m_pObject->SetState(HM::Message::Delivered); return _SaveNewMessageToIMAPFolder(); } break; } case HM::Message::Delivering: { // Handle message which is being delivered. Saving in database will be taken // care about by the delivery process. Since the file has already been updated // on disk, there's not more for us to do here. break; } case HM::Message::Delivered: { // The message has already been delivered. It's placed inside an account mailbox. // All we need to do is to update it in the database. if (!HM::PersistentMessage::SaveObject(m_pObject)) return S_FALSE; break; } default: { // Unhandled case. return COMError::GenerateError("The message could not be saevd. It is in an unknown state."); } } return S_OK; } catch (...) { return COMError::GenerateGenericMessage(); } }
AnsiString HashCreator::_GetHashRaw(const unsigned char *input, int inputLength, HashCreator::RequestedEncoding encoding) { int digestLength = 0; switch (_hashType) { case SHA1: digestLength = SHA_DIGEST_LENGTH; break; case SHA256: digestLength = SHA256_DIGEST_LENGTH; break; case MD5: digestLength = MD5_DIGEST_LENGTH; break; } unsigned char *results = new unsigned char[digestLength]; switch (_hashType) { case SHA1: { SHA_CTX context; SHA1_Init(&context); SHA1_Update(&context, input, inputLength); SHA1_Final(results, &context); break; } case MD5: { MD5_CTX context; MD5_Init(&context); MD5_Update(&context, input, inputLength); MD5_Final(results, &context); break; } case SHA256: { SHA256_CTX context; SHA256_Init(&context); SHA256_Update(&context, input, inputLength); SHA256_Final(results, &context); break; } } HM::String retVal; if (encoding == hex) { char *s = new char[digestLength*2+1]; for (int i=0; i<digestLength; i++) sprintf(s+i*2, "%02x", results[i]); s[digestLength*2]='\0'; retVal = s; delete [] s; } else if (encoding == base64) { MimeCodeBase64 encoder; encoder.SetInput((const char*) results, digestLength, true); AnsiString sEncodedValue; encoder.GetOutput(sEncodedValue); retVal = sEncodedValue; retVal = retVal.Mid(0, retVal.GetLength()-2); } delete [] results; return retVal; }
STDMETHODIMP InterfaceDatabase::CreateExternalDatabase(eDBtype ServerType, BSTR ServerName, long lPort, BSTR DatabaseName, BSTR Username, BSTR Password) { try { if (!config_) return GetAccessDenied(); if (!GetIsServerAdmin()) return GetAccessDenied(); const HM::String sEmpty; const HM::String sServerName = ServerName; const HM::String sDatabaseName = DatabaseName; const HM::String sUsername = Username; const HM::String sPassword = Password; if (sDatabaseName.Find(_T(" ")) >= 0) return COMError::GenerateError("The database name may not contain spaces."); // Create a settings object for the connection ... std::shared_ptr<HM::DatabaseSettings> pSettings = std::shared_ptr<HM::DatabaseSettings>( new HM::DatabaseSettings(sServerName, sEmpty, sUsername, sPassword, sEmpty, sEmpty,(HM::DatabaseSettings::SQLDBType) ServerType, lPort)); // Connect to the database serve std::shared_ptr<HM::DALConnection> pConn = HM::DALConnectionFactory::CreateConnection(pSettings); HM::String sErrorMessage; if (pConn->Connect(sErrorMessage) != HM::DALConnection::Connected) return COMError::GenerateError(sErrorMessage); // Create the database HM::String sCreateDB = HM::SQLStatement::GetCreateDatabase(pSettings, sDatabaseName); if (!pConn->Execute(HM::SQLCommand(sCreateDB), sErrorMessage, 0, 0)) return COMError::GenerateError(sErrorMessage); // Disconnect again. pConn->Disconnect(); // Create a new settings object where we specify the database name as well. pSettings = std::shared_ptr<HM::DatabaseSettings>( new HM::DatabaseSettings(sServerName, sDatabaseName, sUsername, sPassword, sEmpty, sEmpty,(HM::DatabaseSettings::SQLDBType) ServerType, lPort)); // Reconnect to the new database. pConn = HM::DALConnectionFactory::CreateConnection(pSettings); if (pConn->Connect(sErrorMessage) != HM::DALConnection::Connected) return COMError::GenerateError(sErrorMessage); // Run the scripts HM::SQLScriptRunner scriptRunner; if (!scriptRunner.ExecuteScript(pConn, pSettings->GetDefaultScript(), sErrorMessage)) return COMError::GenerateError(sErrorMessage); ini_file_settings_->SetDatabaseDirectory(""); ini_file_settings_->SetDatabaseType((HM::DatabaseSettings::SQLDBType) ServerType); ini_file_settings_->SetUsername(sUsername); ini_file_settings_->SetPassword(sPassword); ini_file_settings_->SetDatabasePort(lPort); ini_file_settings_->SetDatabaseServer(sServerName); ini_file_settings_->SetDatabaseName(sDatabaseName); ini_file_settings_->SetIsInternalDatabase(false); return S_OK; } catch (...) { return COMError::GenerateGenericMessage(); } }