diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..1ff0c4230 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,63 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set default behavior for command prompt diff. +# +# This is need for earlier builds of msysgit that does not have it on by +# default for csharp files. +# Note: This is only used by command line +############################################################################### +#*.cs diff=csharp + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. To do so, just uncomment the entries below +############################################################################### +#*.sln merge=binary +#*.csproj merge=binary +#*.vbproj merge=binary +#*.vcxproj merge=binary +#*.vcproj merge=binary +#*.dbproj merge=binary +#*.fsproj merge=binary +#*.lsproj merge=binary +#*.wixproj merge=binary +#*.modelproj merge=binary +#*.sqlproj merge=binary +#*.wwaproj merge=binary + +############################################################################### +# behavior for image files +# +# image files are treated as binary by default. +############################################################################### +#*.jpg binary +#*.png binary +#*.gif binary + +############################################################################### +# diff behavior for common document formats +# +# Convert binary document formats to text before diffing them. This feature +# is only available from the command line. Turn it on by uncommenting the +# entries below. +############################################################################### +#*.doc diff=astextplain +#*.DOC diff=astextplain +#*.docx diff=astextplain +#*.DOCX diff=astextplain +#*.dot diff=astextplain +#*.DOT diff=astextplain +#*.pdf diff=astextplain +#*.PDF diff=astextplain +#*.rtf diff=astextplain +#*.RTF diff=astextplain diff --git a/README.md b/README.md index 6e3da040c..9f38e0e64 100644 --- a/README.md +++ b/README.md @@ -86,5 +86,5 @@ Without finding any serious issues: 1. Run all integration tests on supported versions of Windows and the different supported databases. 2. Run all server stress tests 3. Enable Gflags (gflags /p /enable hmailserver.exe) and run all integration tests to check for memory issues -4. Run for at least 2 weeks +4. Run for at least 1 week in production for hMailServer.com 5. Wait for at least 500 downloads of the beta version diff --git a/hmailserver/source/Server/Common/AntiVirus/ClamWinVirusScanner.cpp b/hmailserver/source/Server/Common/AntiVirus/ClamWinVirusScanner.cpp index f7d494f73..10f190bd8 100644 --- a/hmailserver/source/Server/Common/AntiVirus/ClamWinVirusScanner.cpp +++ b/hmailserver/source/Server/Common/AntiVirus/ClamWinVirusScanner.cpp @@ -41,7 +41,7 @@ namespace HM String sPath = FileUtilities::GetFilePath(sFilename); String sFileToScan = FileUtilities::GetFileNameFromFullPath(sFilename); - String sTempDir = Utilities::GetWin32TempDirectory(); + String sTempDir = IniFileSettings::Instance()->GetTempDirectory(); String sCommandLine; sCommandLine.Format(_T("%s --database=\"%s\" \"%s\" --tempdir=\"%s\""), scannerExecutable.c_str(), databasePath.c_str(), sFileToScan.c_str(), sTempDir.c_str()); diff --git a/hmailserver/source/Server/Common/Application/BackupExecuter.cpp b/hmailserver/source/Server/Common/Application/BackupExecuter.cpp index 8c382933c..c9651ae8f 100644 --- a/hmailserver/source/Server/Common/Application/BackupExecuter.cpp +++ b/hmailserver/source/Server/Common/Application/BackupExecuter.cpp @@ -389,9 +389,8 @@ namespace HM // so that we're sure that we're doing a clean restore String sDataDirectory = IniFileSettings::Instance()->GetDataDirectory(); - std::set vecExcludes; FileUtilities::DeleteFilesInDirectory(sDataDirectory); - FileUtilities::DeleteDirectoriesInDirectory(sDataDirectory, vecExcludes); + FileUtilities::DeleteDirectoriesInDirectory(sDataDirectory); String errorMessage; FileUtilities::CopyDirectory(sDirContainingDataFiles, sDataDirectory, errorMessage); diff --git a/hmailserver/source/Server/Common/Application/SessionManager.cpp b/hmailserver/source/Server/Common/Application/SessionManager.cpp index 42c31ae7d..1d27e0c55 100644 --- a/hmailserver/source/Server/Common/Application/SessionManager.cpp +++ b/hmailserver/source/Server/Common/Application/SessionManager.cpp @@ -29,9 +29,9 @@ namespace HM We pre-create one connection per protocol, so we set the counters to -1 here. */ SessionManager::SessionManager(void) : - no_of_imapconnections_(-1), - no_of_smtpconnections_(-1), - no_of_pop3connections_(-1) + no_of_imapconnections_(0), + no_of_smtpconnections_(0), + no_of_pop3connections_(0) { } @@ -41,52 +41,65 @@ namespace HM } bool - SessionManager::GetAllow(SessionType session_type, std::shared_ptr security_range) + SessionManager::CreateSession(SessionType session_type, std::shared_ptr security_range) { - // Check that client isn't blocked by IP range. switch (session_type) { case STSMTP: - if (!security_range->GetAllowSMTP()) + if (security_range == nullptr || !security_range->GetAllowSMTP()) return false; break; case STPOP3: - if (!security_range->GetAllowPOP3()) + if (security_range == nullptr || !security_range->GetAllowPOP3()) return false; break; case STIMAP: - if (!security_range->GetAllowIMAP()) + if (security_range == nullptr || !security_range->GetAllowIMAP()) return false; break; } - - int current_connections = GetNumberOfConnections(session_type); - + // Check max per protocol int max_connections = 0; switch (session_type) { case STSMTP: { + int connection_count = no_of_smtpconnections_.fetch_add(1) + 1; + max_connections = Configuration::Instance()->GetSMTPConfiguration()->GetMaxSMTPConnections(); - if (max_connections > 0 && current_connections > max_connections) + if (max_connections > 0 && connection_count > max_connections) + { + no_of_smtpconnections_--; return false; + } break; } case STPOP3: { + int connection_count = no_of_pop3connections_.fetch_add(1) + 1; + max_connections = Configuration::Instance()->GetPOP3Configuration()->GetMaxPOP3Connections(); - if (max_connections > 0 && current_connections > max_connections) + if (max_connections > 0 && connection_count > max_connections) + { + no_of_pop3connections_--; return false; + } break; } case STIMAP: { + int connection_count = no_of_imapconnections_.fetch_add(1) + 1; + max_connections = Configuration::Instance()->GetIMAPConfiguration()->GetMaxIMAPConnections(); - if (max_connections > 0 && current_connections > max_connections) + if (max_connections > 0 && connection_count > max_connections) + { + no_of_imapconnections_--; return false; + } + break; } } @@ -94,45 +107,40 @@ namespace HM return true; } - void - SessionManager::OnCreate(SessionType t) + void + SessionManager::OnSessionEnded(SessionType st) { - switch (t) + switch (st) { case STSMTP: - { - no_of_smtpconnections_++; - break; - } + no_of_smtpconnections_--; + break; case STPOP3: - { - no_of_pop3connections_++; - break; - } + no_of_pop3connections_--; + break; case STIMAP: - { - no_of_imapconnections_++; - break; - } + no_of_imapconnections_--; + break; } - } - - void - SessionManager::OnDestroy(SessionType st) - { +#ifdef DEBUG switch (st) { case STSMTP: - no_of_smtpconnections_--; + if (no_of_smtpconnections_ < 0) + throw std::logic_error("Negative session count."); break; case STPOP3: - no_of_pop3connections_--; + if (no_of_pop3connections_ < 0) + throw std::logic_error("Negative session count."); break; case STIMAP: - no_of_imapconnections_--; + if (no_of_imapconnections_ < 0) + throw std::logic_error("Negative session count."); break; } +#endif + } diff --git a/hmailserver/source/Server/Common/Application/SessionManager.h b/hmailserver/source/Server/Common/Application/SessionManager.h index 44fe64eac..91d77a2f5 100644 --- a/hmailserver/source/Server/Common/Application/SessionManager.h +++ b/hmailserver/source/Server/Common/Application/SessionManager.h @@ -20,9 +20,8 @@ namespace HM int Count(); - bool GetAllow(SessionType t, std::shared_ptr security_range); - void OnCreate(SessionType t); - void OnDestroy(SessionType st); + bool CreateSession(SessionType t, std::shared_ptr security_range); + void OnSessionEnded(SessionType st); int GetNumberOfConnections(SessionType st); // Returns the number of connections for a specific connection timeout diff --git a/hmailserver/source/Server/Common/BO/MessageData.cpp b/hmailserver/source/Server/Common/BO/MessageData.cpp index f57302317..4330c459c 100644 --- a/hmailserver/source/Server/Common/BO/MessageData.cpp +++ b/hmailserver/source/Server/Common/BO/MessageData.cpp @@ -728,7 +728,7 @@ namespace HM { const HM::String directoryName = HM::FileUtilities::GetFilePath(fileName); if (!HM::FileUtilities::Exists(directoryName)) - HM::FileUtilities::CreateDirectoryRecursive(directoryName); + HM::FileUtilities::CreateDirectory(directoryName); bool result = mime_mail_->SaveAllToFile(fileName); diff --git a/hmailserver/source/Server/Common/Persistence/PersistentMessage.cpp b/hmailserver/source/Server/Common/Persistence/PersistentMessage.cpp index f988a391a..b0772f135 100644 --- a/hmailserver/source/Server/Common/Persistence/PersistentMessage.cpp +++ b/hmailserver/source/Server/Common/Persistence/PersistentMessage.cpp @@ -710,7 +710,7 @@ namespace HM // We start by checking if it already exists. If not, attempt to create. We used // to create each folder before. Checking first will save some disk access. if (!FileUtilities::Exists(destinationPath)) - FileUtilities::CreateDirectoryRecursive(destinationPath); + FileUtilities::CreateDirectory(destinationPath); // Move the old file to the new path. if (!FileUtilities::Move(sourceLocation, destinationFileName)) @@ -734,7 +734,7 @@ namespace HM // We start by checking if it already exists. If not, attempt to create. We used // to create each folder before. Checking first will save some disk access. if (!FileUtilities::Exists(destinationPath)) - FileUtilities::CreateDirectoryRecursive(destinationPath); + FileUtilities::CreateDirectory(destinationPath); // Move the old file to the new path. if (!FileUtilities::Move(sourceLocation, destinationFileName)) @@ -755,7 +755,7 @@ namespace HM // in which the message should be put. If the dir doesn't exist, we'll // have slight problems creating a file in it. String sPath = FileUtilities::GetFilePath(sFileName); - FileUtilities::CreateDirectoryRecursive(sPath); + FileUtilities::CreateDirectory(sPath); // The file does not exists. May have been deleted diff --git a/hmailserver/source/Server/Common/TCPIP/SocketConstants.h b/hmailserver/source/Server/Common/TCPIP/SocketConstants.h index eeeef9caf..39ec38642 100644 --- a/hmailserver/source/Server/Common/TCPIP/SocketConstants.h +++ b/hmailserver/source/Server/Common/TCPIP/SocketConstants.h @@ -28,9 +28,10 @@ namespace HM enum ConnectionState { - StateDisconnected = 0, + StatePendingConnect = 0, StateConnected = 1, - StatePendingDisconnect = 2 + StatePendingDisconnect = 2, + StateDisconnected = 3 }; enum SslTlsVersion diff --git a/hmailserver/source/Server/Common/TCPIP/TCPConnection.cpp b/hmailserver/source/Server/Common/TCPIP/TCPConnection.cpp index 2680702d9..2117714aa 100644 --- a/hmailserver/source/Server/Common/TCPIP/TCPConnection.cpp +++ b/hmailserver/source/Server/Common/TCPIP/TCPConnection.cpp @@ -44,7 +44,7 @@ namespace HM expected_remote_hostname_(expected_remote_hostname), is_client_(false), timeout_(0), - connection_state_(StateDisconnected) + connection_state_(StatePendingConnect) { session_id_ = Application::Instance()->GetUniqueID(); diff --git a/hmailserver/source/Server/Common/TCPIP/TCPConnection.h b/hmailserver/source/Server/Common/TCPIP/TCPConnection.h index f6d6ee325..6999b8b9d 100644 --- a/hmailserver/source/Server/Common/TCPIP/TCPConnection.h +++ b/hmailserver/source/Server/Common/TCPIP/TCPConnection.h @@ -70,6 +70,7 @@ namespace HM protected: + ConnectionState GetConnectionState() { return connection_state_; } int GetSessionID(); int GetBufferSize() {return BufferSize; } @@ -92,6 +93,7 @@ namespace HM virtual void ParseData(std::shared_ptr pByteBuffer) = 0; AnsiString GetSslTlsCipher(); + private: void ThrowIfNotConnected_(); diff --git a/hmailserver/source/Server/Common/TCPIP/TCPServer.cpp b/hmailserver/source/Server/Common/TCPIP/TCPServer.cpp index 54355480f..781d47494 100644 --- a/hmailserver/source/Server/Common/TCPIP/TCPServer.cpp +++ b/hmailserver/source/Server/Common/TCPIP/TCPServer.cpp @@ -42,7 +42,6 @@ namespace HM connectionFactory_ = connectionFactory; } - TCPServer::~TCPServer(void) { LOG_DEBUG("TCPServer::~TCPServer"); @@ -154,7 +153,7 @@ namespace HM } void - TCPServer::HandleAccept(std::shared_ptr pConnection, + TCPServer::HandleAccept(std::shared_ptr connection, const boost::system::error_code& error) { if (error.value() == 995) @@ -166,8 +165,7 @@ namespace HM /* 995: The I/O operation has been aborted because of either a thread exit or an application request - This happens when the servers are stopped. We shouldn't post any new accepts or do anything - else in this situation. + This happens when the servers are stopped. We shouldn't post any new accepts since we're shutting down. */ return; @@ -179,8 +177,8 @@ namespace HM if (!error) { - boost::asio::ip::tcp::endpoint localEndpoint = pConnection->GetSocket().local_endpoint(); - boost::asio::ip::tcp::endpoint remoteEndpoint = pConnection->GetSocket().remote_endpoint(); + boost::asio::ip::tcp::endpoint localEndpoint = connection->GetSocket().local_endpoint(); + boost::asio::ip::tcp::endpoint remoteEndpoint = connection->GetSocket().remote_endpoint(); IPAddress localAddress (localEndpoint.address()); IPAddress remoteAddress (remoteEndpoint.address()); @@ -190,14 +188,7 @@ namespace HM std::shared_ptr securityRange = PersistentSecurityRange::ReadMatchingIP(remoteAddress); - if (!securityRange) - { - LOG_TCPIP("TCP - Connection dropped - No matching IP range."); - return; - } - - - bool allow = SessionManager::Instance()->GetAllow(sessionType_, securityRange); + bool allow = SessionManager::Instance()->CreateSession(sessionType_, securityRange); if (!allow) { @@ -221,10 +212,17 @@ namespace HM } if (!FireOnAcceptEvent(remoteAddress, localEndpoint.port())) + { + // Session has been created, but is now terminated by a custom script. Since we haven't started the + // TCPConnection yet, we are still responsible for tracking connection count. + SessionManager::Instance()->OnSessionEnded(sessionType_); return; + } + + connection->SetSecurityRange(securityRange); + connection->Start(); - pConnection->SetSecurityRange(securityRange); - pConnection->Start(); + // Now TCPConnection is responsible for decreasing the session count when the connection ends. } else { diff --git a/hmailserver/source/Server/Common/TCPIP/TCPServer.h b/hmailserver/source/Server/Common/TCPIP/TCPServer.h index ebb13e98e..c8b38cf03 100644 --- a/hmailserver/source/Server/Common/TCPIP/TCPServer.h +++ b/hmailserver/source/Server/Common/TCPIP/TCPServer.h @@ -36,7 +36,7 @@ namespace HM bool InitAcceptor(); void StartAccept(); - void HandleAccept(std::shared_ptr pConnection, const boost::system::error_code& error); + void HandleAccept(std::shared_ptr connection, const boost::system::error_code& error); bool FireOnAcceptEvent(const IPAddress &remoteAddress, int port); diff --git a/hmailserver/source/Server/Common/Util/ExceptionLogger.cpp b/hmailserver/source/Server/Common/Util/ExceptionLogger.cpp index 17c59855f..9f8044d92 100644 --- a/hmailserver/source/Server/Common/Util/ExceptionLogger.cpp +++ b/hmailserver/source/Server/Common/Util/ExceptionLogger.cpp @@ -95,7 +95,7 @@ namespace HM String log_directory = IniFileSettings::Instance()->GetLogDirectory(); - std::vector existing_files = FileUtilities::GetFilesInDirectory(log_directory, "minidump_*"); + std::vector existing_files = FileUtilities::GetFilesInDirectory(log_directory, "^minidump_.*$"); const int max_count = 10; if (existing_files.size() < max_count) diff --git a/hmailserver/source/Server/Common/Util/File.cpp b/hmailserver/source/Server/Common/Util/File.cpp index eb50233c8..9e23a5918 100644 --- a/hmailserver/source/Server/Common/Util/File.cpp +++ b/hmailserver/source/Server/Common/Util/File.cpp @@ -5,6 +5,8 @@ #include "File.h" #include "ByteBuffer.h" +#include + #ifdef _DEBUG #define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__) #define new DEBUG_NEW @@ -13,28 +15,31 @@ namespace HM { File::File() : - file_(INVALID_HANDLE_VALUE) + file_(nullptr) { } File::~File() { - if (file_ != INVALID_HANDLE_VALUE) - CloseHandle(file_); + Close(); } void File::Close() { - CloseHandle(file_); - file_ = INVALID_HANDLE_VALUE; + if (file_ != nullptr) + { + fclose(file_); + file_ = nullptr; + } + } bool File::IsOpen() const { - if (file_ == INVALID_HANDLE_VALUE) + if (file_ == nullptr) return false; return true; @@ -43,58 +48,37 @@ namespace HM bool File::Open(const String &sFilename, OpenType ot) { - if (file_ != INVALID_HANDLE_VALUE) + if (IsOpen()) { // The file should be closed, before we // try to open it again... - - assert(0); - Close(); + throw std::logic_error(Formatter::FormatAsAnsi("The file {0} is already open.", sFilename)); } - DWORD dwDesiredAccess = 0; - DWORD dwShareMode = 0; - DWORD dwCreationDisposition = 0; + std::wstring open_mode; switch (ot) { case OTReadOnly: - dwDesiredAccess = GENERIC_READ; - dwShareMode = FILE_SHARE_READ; - dwCreationDisposition = OPEN_EXISTING; + open_mode = _T("rb"); break; case OTCreate: - dwDesiredAccess = GENERIC_WRITE; - dwShareMode = FILE_SHARE_READ; - dwCreationDisposition = CREATE_ALWAYS; + open_mode = _T("wb"); break; case OTAppend: - dwDesiredAccess = GENERIC_WRITE; - dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE; // FILE_SHARE_DELETE; - dwCreationDisposition = OPEN_ALWAYS; + open_mode = _T("ab"); break; } - file_ = CreateFile(sFilename, - dwDesiredAccess, - dwShareMode, - NULL, // LPSECURITY_ATTRIBUTES - dwCreationDisposition, // -- open or create. - FILE_ATTRIBUTE_NORMAL, // attributes - NULL // file template - ); + file_ = _wfsopen(sFilename.c_str(), open_mode.c_str(), _SH_DENYNO); - if (file_ == INVALID_HANDLE_VALUE) + if (file_ == nullptr) + { return false; + } name_ = sFilename; - if (ot == OTAppend) - { - // Go to end of file - SetFilePointer(file_,0,0,FILE_END); - } - return true; } @@ -104,30 +88,50 @@ namespace HM if (file_ == INVALID_HANDLE_VALUE) return 0; - return GetFileSize (file_, NULL); + return (int) boost::filesystem::file_size(name_); + } + + bool + File::SetPosition(int position) + { + if (file_ == nullptr) + throw std::logic_error("Attempt to set position on file which has not been opened."); + + return fseek(file_, position, 0) == 0; } bool File::Write(const String &sWrite) { - String sTmp = sWrite; - DWORD dwWritten = 0; - return Write((const unsigned char*) sTmp.GetBuffer(), sTmp.GetLength() * sizeof(TCHAR), dwWritten); + if (file_ == nullptr) + throw std::logic_error("Attempt to write to file which has not been opened."); + + String temp_nonconst = sWrite; + + int result = fwrite(temp_nonconst.GetBuffer(), sizeof(TCHAR), temp_nonconst.GetLength(), file_); + + return result == temp_nonconst.GetLength(); } bool File::Write(const AnsiString &sWrite) { - AnsiString sTmp = sWrite; - DWORD dwWritten = 0; - return Write((const unsigned char*) sTmp.GetBuffer(), sTmp.GetLength(), dwWritten); + if (file_ == nullptr) + throw std::logic_error("Attempt to write to file which has not been opened."); + + AnsiString temp_nonconst = sWrite; + int result = fwrite(temp_nonconst.GetBuffer(), sizeof(char), temp_nonconst.GetLength(), file_); + return result == temp_nonconst.GetLength(); } bool File::Write(const unsigned char *pBuf, int iBufLen, DWORD &dwNoOfBytesWritten) { - bool bResult = ::WriteFile(file_,pBuf, iBufLen, &dwNoOfBytesWritten, NULL) == TRUE; - return bResult; + if (file_ == nullptr) + throw std::logic_error("Attempt to write to file which has not been opened."); + + dwNoOfBytesWritten = fwrite(pBuf, 1, iBufLen, file_); + return dwNoOfBytesWritten == iBufLen; } bool @@ -154,6 +158,22 @@ namespace HM return true; } + bool + File::ReadLine(AnsiString &sLine) + { + if (file_ == nullptr) + throw std::logic_error("Attempt to read to file which has not been opened."); + + const int buffer_size = 10000; + char *line_buffer = sLine.GetBuffer(buffer_size); + + bool result = fgets(line_buffer, buffer_size, file_) != 0; + + sLine.ReleaseBuffer(); + + return result; + } + std::shared_ptr File::ReadFile() { @@ -161,19 +181,20 @@ namespace HM { std::shared_ptr pFileContents = std::shared_ptr(new ByteBuffer); - if (file_ == INVALID_HANDLE_VALUE) - return pFileContents; + if (file_ == nullptr) + throw std::logic_error("Attempt to read from file which has not been opened."); int iFileSize = GetSize(); // Create a buffer to hold the file pFileContents->Allocate(iFileSize); - // Read the file to the buffer - SetFilePointer(file_, 0, 0, FILE_BEGIN); + int bytes_read = fread((void*) pFileContents->GetBuffer(), 1, iFileSize, file_); - unsigned long nBytesRead = 0; - ::ReadFile(file_, (LPVOID) pFileContents->GetBuffer(), iFileSize, &nBytesRead, NULL); + if (bytes_read != iFileSize) + { + throw std::logic_error(Formatter::FormatAsAnsi("Unable to read file {0}. Expected bytes: {1}, Actual read bytes: {2}.", name_, iFileSize, bytes_read)); + } return pFileContents; } @@ -211,19 +232,21 @@ namespace HM std::shared_ptr File::ReadChunk(int iMaxSize) { + if (file_ == nullptr) + throw std::logic_error("Attempt to read from file which has not been opened."); + try { std::shared_ptr pReadBuffer = std::shared_ptr(new ByteBuffer); pReadBuffer->Allocate(iMaxSize); // Read - unsigned long nBytesRead = 0; - ::ReadFile(file_, (LPVOID) pReadBuffer->GetBuffer(), iMaxSize, &nBytesRead, NULL); + int bytes_read = fread((void*)pReadBuffer->GetBuffer(), 1, iMaxSize, file_); - if (nBytesRead > 0) + if (bytes_read > 0) { std::shared_ptr pRetBuffer = std::shared_ptr(new ByteBuffer); - pRetBuffer->Add(pReadBuffer->GetBuffer(), nBytesRead); + pRetBuffer->Add(pReadBuffer->GetBuffer(), bytes_read); return pRetBuffer; } @@ -237,15 +260,6 @@ namespace HM return pBuffer; } - bool - File::MoveToEnd() - { - // --- Go to the end of the file. - SetFilePointer(file_,0,0,FILE_END); - - return true; - } - String File::GetName() const { diff --git a/hmailserver/source/Server/Common/Util/File.h b/hmailserver/source/Server/Common/Util/File.h index e4dcd458f..b4b9662ad 100644 --- a/hmailserver/source/Server/Common/Util/File.h +++ b/hmailserver/source/Server/Common/Util/File.h @@ -38,12 +38,11 @@ namespace HM bool Write(std::shared_ptr pBuffer, DWORD &dwNoOfBytesWritten); bool Write(File &sourceFile); bool WriteBOF(); - bool MoveToEnd(); - - int GetSize(); + bool SetPosition(int position); + bool ReadLine(AnsiString &sLine); std::shared_ptr ReadFile(); std::shared_ptr ReadTextFile(); std::shared_ptr ReadChunk(int iMaxSize); @@ -52,7 +51,7 @@ namespace HM private: - HANDLE file_; + FILE * file_; String name_; }; diff --git a/hmailserver/source/Server/Common/Util/FileUtilities.cpp b/hmailserver/source/Server/Common/Util/FileUtilities.cpp index 41196fcb2..cae8122e6 100644 --- a/hmailserver/source/Server/Common/Util/FileUtilities.cpp +++ b/hmailserver/source/Server/Common/Util/FileUtilities.cpp @@ -11,6 +11,9 @@ #include "../Application/Dictionary.h" #include "../Util/Assert.h" #include "../Util/Unicode.h" +#include "../Util/RegularExpression.h" + +#include #ifdef _DEBUG #define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__) @@ -32,42 +35,46 @@ namespace HM bool FileUtilities::DeleteFile(const String &FileName) { - int iNumberOfTries = 0; const int iMaxNumberOfTries = 5; const int FILE_NOT_FOUND = 2; const int PATH_NOT_FOUND = 3; - const int maxRecursions = 10000; - for (int i = 0; i < maxRecursions; i++) + for (int i = 1; i <= iMaxNumberOfTries; i++) { AnsiString sFilename = FileName; - if (remove(sFilename) != -1) - return true; - int iLastError = ::GetLastError(); - if (iLastError == FILE_NOT_FOUND || iLastError == PATH_NOT_FOUND ) + boost::system::error_code error_code; + + boost::filesystem::path path(sFilename.begin(), sFilename.end()); + + if (!boost::filesystem::remove(path, error_code)) { - // We could not delete the file. But it doesn't exist, so it doens't matter. + // file did not exist. return true; } - iNumberOfTries ++; + if (error_code) + { + // We failed to delete the file. - // We failed to delete the file. + if (i == iMaxNumberOfTries) + { + // We still couldn't delete the file. Lets give up and report in windows event log. + String sErrorMessage; + sErrorMessage.Format(_T("Could not delete the file %s. Tried 5 times without success."), FileName.c_str()); + ErrorManager::Instance()->ReportError(ErrorManager::High, 5047, "File::DeleteFile", sErrorMessage, error_code); + return false; + } - if (iNumberOfTries >= iMaxNumberOfTries) + // Some other process must have locked the file. + Sleep(1000); + } + else { - // We still couldn't delete the file. Lets give up and report in windows event log. - String sErrorMessage; - sErrorMessage.Format(_T("Could not delete the file %s. Tried 5 times without success. Windows error code: %d (%s)"), FileName.c_str(), iLastError, Dictionary::GetWindowsErrorDescription(iLastError).c_str()); - - ErrorManager::Instance()->ReportError(ErrorManager::High, 5047, "File::DeleteFile", sErrorMessage); - return false; + // file deleted. + return true; } - - // Some other process must have locked the file. - Sleep(1000); } return false; @@ -76,38 +83,34 @@ namespace HM bool FileUtilities::Copy(const String &sFrom, const String &sTo, bool bCreateMissingDirectories) { - int iNumberOfTries = 0; const int iMaxNumberOfTries = 5; if (bCreateMissingDirectories) { String sToPath = sTo.Mid(0, sTo.ReverseFind(_T("\\"))); - CreateDirectoryRecursive(sToPath); + CreateDirectory(sToPath); } - - const int maxRecursions = 10000; - for (int i = 0; i < maxRecursions; i++) + for (int i = 1; i <= iMaxNumberOfTries; i++) { + boost::system::error_code error_code; + boost::filesystem::copy_file(sFrom, sTo, boost::filesystem::copy_option::overwrite_if_exists, error_code); + // Use classic api to copy the file - if (::CopyFile(sFrom, sTo, FALSE) != 0) + if (!error_code) { //Copy OK return true; } - iNumberOfTries ++; - // We failed to delete the file. - if (iNumberOfTries >= iMaxNumberOfTries) + if (i == iMaxNumberOfTries) { // We still couldn't copy the file. Lets give up and report in windows event log and hMailServer application log - int iLastError = ::GetLastError(); - String sErrorMessage; - sErrorMessage.Format(_T("Could not copy the file %s to %s. Tried 5 times without success. Windows eror code: %d (%s)"), sFrom.c_str(), sTo.c_str(), iLastError, Dictionary::GetWindowsErrorDescription(iLastError).c_str()); - ErrorManager::Instance()->ReportError(ErrorManager::High, 5048, "File::Copy", sErrorMessage); + sErrorMessage.Format(_T("Could not copy the file %s to %s. Tried 5 times without success."), sFrom.c_str(), sTo.c_str()); + ErrorManager::Instance()->ReportError(ErrorManager::High, 5048, "File::Copy", sErrorMessage, error_code); return false; } @@ -115,47 +118,33 @@ namespace HM Sleep(1000); } - assert(0); // if we get here, something is really strange... - return false; + throw std::logic_error("Copy file logic error."); } bool FileUtilities::Move(const String &sFrom, const String &sTo, bool overwrite) { - int iNumberOfTries = 0; const int iMaxNumberOfTries = 5; - const int maxRecursions = 10000; - for (int i = 0; i < maxRecursions; i++) - { - if (overwrite) - { - if (::MoveFileEx(sFrom, sTo, MOVEFILE_REPLACE_EXISTING) != 0) - { - return true; - } - } - else - { - if (::MoveFile(sFrom, sTo) != 0) - { - //Copy OK - return true; - } - } + if (overwrite) + DeleteFile(sTo); - iNumberOfTries ++; + for (int i = 1; i <= iMaxNumberOfTries; i++) + { + boost::system::error_code error_code; + boost::filesystem::rename(sFrom, sTo, error_code); - // We failed to delete the file. + if (!error_code) + return true; - if (iNumberOfTries >= iMaxNumberOfTries) + if (i == iMaxNumberOfTries) { // We still couldn't move the file. Lets give up and report in windows event log and hMailServer application log. int iLastError = ::GetLastError(); String sErrorMessage; - sErrorMessage.Format(_T("Could not move the file %s to %s. Tried 5 times without success. Windows eror code: %d (%s)"), sFrom.c_str(), sTo.c_str(), iLastError, Dictionary::GetWindowsErrorDescription(iLastError).c_str()); - ErrorManager::Instance()->ReportError(ErrorManager::High, 5049, "File::Normal", sErrorMessage); + sErrorMessage.Format(_T("Could not move the file %s to %s. Tried 5 times without success."), sFrom.c_str(), sTo.c_str()); + ErrorManager::Instance()->ReportError(ErrorManager::High, 5049, "File::Normal", sErrorMessage, error_code); return false; } @@ -164,19 +153,13 @@ namespace HM Sleep(250); } - assert(0); // if we get here, something is really strange... - return false; + throw std::logic_error("Move file logic error."); } bool FileUtilities::Exists(const String &sFilename) { - DWORD dwAttr = GetFileAttributes(sFilename); - if (dwAttr == INVALID_FILE_ATTRIBUTES) - return false; - else - return true; - + return boost::filesystem::exists(sFilename); } String @@ -210,56 +193,6 @@ namespace HM return sFullPath.Mid(iLastSlash + 1); } - bool - FileUtilities::ReadLine(HANDLE hFile, String &sLine) - { - BYTE buf[2048]; - memset(buf, 0, 2048); - - unsigned long nbytes = 0; - - // Get current position in file. - DWORD dwCurrentFilePosition = SetFilePointer( - hFile, // must have GENERIC_READ and/or GENERIC_WRITE - 0, // do not move pointer - NULL, // hFile is not large enough to need this pointer - FILE_CURRENT); // provides offset from current position - - - // read buffer from file. - BOOL bMoreData = ReadFile(hFile,buf,2048, &nbytes, NULL); - - // Search for line end - String sData((char*) buf); - int iEndPos = sData.Find(_T("\r\n"), 0); - - if (iEndPos < 0) - { - // Couldn't find end of line. Assume that all - // the remaining data is on the current line. - iEndPos = nbytes; - } - - if (iEndPos >= 0) - { - sLine = sData.Mid(0, iEndPos); - iEndPos = iEndPos + 2; - - } - - // Set new position in file. - SetFilePointer( - hFile, // must have GENERIC_READ and/or GENERIC_WRITE - iEndPos + dwCurrentFilePosition, // do not move pointer - NULL, // hFile is not large enough to need this pointer - FILE_BEGIN); // provides offset from current position - - if (bMoreData && nbytes > 0) - return true; - else - return false; - } - String FileUtilities::ReadCompleteTextFile(const String &sFilename) { @@ -322,46 +255,17 @@ namespace HM void FileUtilities::ReadFileToBuf(const String &sFilename, BYTE *OutBuf, int iStart, int iCount) { - // --- Open the file for writing. - int iBefore = GetTickCount(); - HANDLE handleFile = CreateFile(sFilename, - GENERIC_READ, - FILE_SHARE_READ, - NULL, // LPSECURITY_ATTRIBUTES - OPEN_EXISTING, // -- open or create. - FILE_ATTRIBUTE_NORMAL, // attributes - NULL // file template - ); - - if (handleFile == INVALID_HANDLE_VALUE) - { - // This is not good. We failed to get a handle to the file. - return; - } - - ReadFileToBuf(handleFile, (char*) OutBuf, iStart, iCount); - - CloseHandle(handleFile); - } - - void - FileUtilities::ReadFileToBuf(HANDLE handleFile, char *OutBuf, int iStart, int iCount) - { - if (iStart == -1 && iCount == -1) + File file; + if (!file.Open(sFilename, File::OTReadOnly)) { - iStart = 0; - iCount = GetFileSize (handleFile, NULL) ; + throw new std::logic_error(Formatter::FormatAsAnsi("Unable to open file {0}", sFilename)); } - unsigned long nBytesRead = 0; - BOOL bMoreData = TRUE; + file.SetPosition(iStart); - if (iStart >= 0) - { - SetFilePointer(handleFile, iStart, 0, FILE_BEGIN); - } + std::shared_ptr bytes = file.ReadChunk(iCount); - bMoreData = ReadFile(handleFile,OutBuf, iCount, &nBytesRead, NULL); + memcpy(OutBuf, bytes->GetBuffer(), iCount); } @@ -412,23 +316,13 @@ namespace HM long FileUtilities::FileSize(const String &sFileName) { - HANDLE handleFile = CreateFile(sFileName, - GENERIC_READ, - FILE_SHARE_READ, - NULL, // LPSECURITY_ATTRIBUTES - OPEN_EXISTING, // -- open or create. - FILE_ATTRIBUTE_NORMAL, // attributes - NULL // file template - ); - - if (handleFile == INVALID_HANDLE_VALUE) - return 0; - - long nFileSize = GetFileSize (handleFile, NULL) ; + boost::system::error_code error_code; + int result = (int)boost::filesystem::file_size(sFileName, error_code); - CloseHandle(handleFile); + if (error_code) + return 0; - return nFileSize; + return result; } String @@ -442,39 +336,24 @@ namespace HM bool FileUtilities::CreateDirectory(const String &sName) { - int iNumberOfTries = 0; const int iMaxNumberOfTries = 5; - int maxRecursions = 10000; - for (int i = 0; i < maxRecursions; i++) + for (int i = 1; i <= iMaxNumberOfTries; i++) { - if (::CreateDirectory(sName, 0) != 0) - { - // Create Directory OK - return true; - } - - int iWinErr = ::GetLastError(); - - if (iWinErr == ERROR_ALREADY_EXISTS) - { - // Create directory failed, because the directory exists. - // That's good enough for us. + boost::system::error_code error_code; + boost::filesystem::create_directories(sName, error_code); + + if (!error_code) return true; - } - - iNumberOfTries ++; - - // We failed to delete the file. - - if (iNumberOfTries >= iMaxNumberOfTries) + + if (i == iMaxNumberOfTries) { - // We still couldn't copy the file. Lets give up and report in windows event log and hMailServer application log. + // We still couldn't create the directory. Lets give up and report in windows event log and hMailServer application log. String sErrorMessage; - sErrorMessage.Format(_T("Could not create the directory %s. Tried 5 times without success. Windows error code: %d (%s)"), sName.c_str(), iWinErr, Dictionary::GetWindowsErrorDescription(iWinErr).c_str()); + sErrorMessage.Format(_T("Could not create the directory %s. Tried 5 times without success."), sName.c_str()); - ErrorManager::Instance()->ReportError(ErrorManager::Medium, 5050, "File::CreateDirectory", sErrorMessage); + ErrorManager::Instance()->ReportError(ErrorManager::Medium, 5050, "File::CreateDirectory", sErrorMessage, error_code); return false; } @@ -483,264 +362,106 @@ namespace HM } - assert(0); - return false; + throw std::logic_error("Create directory logic error."); } - String - FileUtilities::GetShortPath(const String &sInPath) - { - TCHAR szModuleShort[_MAX_PATH]; - GetShortPathName(sInPath, szModuleShort, _MAX_PATH ); - - return szModuleShort; - } - - String - FileUtilities::GetLongPath(const String &sInPath) - { - TCHAR szLong[_MAX_PATH]; - GetLongPathName(sInPath, szLong, _MAX_PATH ); - - return szLong; - } - - bool FileUtilities::CopyDirectory(String sFrom, String sTo, String &errorMessage) { - if (!FileUtilities::Exists(sTo)) + // Check whether the function call is valid + if (!boost::filesystem::exists(sFrom) || !boost::filesystem::is_directory(sFrom)) { - if( !CreateDirectory(sTo)) - { - errorMessage = Formatter::Format(_T("CreateDirectory {0} failed. See previous error."), sTo); - - ErrorManager::Instance()->ReportError(ErrorManager::Medium, 4234, "File::CopyDirectory", errorMessage); - return false; - } + throw std::logic_error(Formatter::FormatAsAnsi("Source {0} is not a valid directory.", sFrom)); } - if (sFrom.Right(1) != _T("\\")) - sFrom += "\\"; - if (sTo.Right(1) != _T("\\")) - sTo += "\\"; - - String sWildCard = sFrom + "*.*"; - - // Locate first match - WIN32_FIND_DATA ffData; - HANDLE hFileFound = FindFirstFile(sWildCard, &ffData); - - if (hFileFound == INVALID_HANDLE_VALUE) + if (!boost::filesystem::exists(sTo)) { - errorMessage.Format(_T("Find first file with wildcard %s failed. Error: %d."), sWildCard.c_str(), GetLastError()); - ErrorManager::Instance()->ReportError(ErrorManager::Medium, 4233, "File::CopyDirectory", errorMessage); - return false; + if (!CreateDirectory(sTo)) + return false; } - while (hFileFound && FindNextFile(hFileFound, &ffData)) - { - String sOldFullPath = sFrom + ffData.cFileName; - String sNewFullPath = sTo + ffData.cFileName; - if (ffData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) + for (boost::filesystem::directory_iterator file(sFrom); file != boost::filesystem::directory_iterator(); ++file ) + { + boost::filesystem::path current(file->path()); + if (boost::filesystem::is_directory(current)) { - if( (_tcscmp(ffData.cFileName, _T(".")) != 0) && - (_tcscmp(ffData.cFileName, _T("..")) != 0) ) + if (!CopyDirectory(current.c_str(), (sTo / current.filename()).c_str(), errorMessage)) { - if( !CopyDirectory(sOldFullPath, sNewFullPath, errorMessage) ) - return false; + return false; } - } else - { - if (FileUtilities::Exists(sNewFullPath)) - { - // File already exists - continue; - } - - if (CopyFile(sOldFullPath, sNewFullPath, TRUE)) - { - // We have copied the file successfully - continue; - } - - // We failed to copy the file. Check if the file no - // longer exists - if (!FileUtilities::Exists(sOldFullPath)) - continue; - - // The file exists , but we were not able to copy it. - errorMessage.Format(_T("Copy of file from %s to %s failed. Error: %d"), sOldFullPath.c_str(), sNewFullPath.c_str(), GetLastError()); - ErrorManager::Instance()->ReportError(ErrorManager::Medium, 4232, "File::CopyDirectory", errorMessage); - return false; + { + boost::filesystem::copy_file(current, sTo / current.filename()); } } - FindClose(hFileFound); - return true; } bool FileUtilities::DeleteDirectory(const String &sDirName) { - TCHAR szSource[MAX_PATH + 2] = _T(""); - _tcsncpy_s(szSource, MAX_PATH + 2, sDirName, MAX_PATH); + boost::system::error_code error_code; - // szSource should be double null terminated. Otherwise it won't - // work. At least not when using Unicode. - szSource[sDirName.GetLength()+1] = 0; + boost::filesystem::remove_all(sDirName, error_code); - SHFILEOPSTRUCT fs; - ::memset(&fs, 0, sizeof(SHFILEOPSTRUCT)); - - fs.pFrom = szSource; - fs.wFunc = FO_DELETE; - fs.fFlags |= (FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR | FOF_SILENT |FOF_NOERRORUI); - - int iResult = ::SHFileOperation(&fs); - if (iResult != 0) + if (error_code) return false; - + return true; } bool FileUtilities::DeleteFilesInDirectory(const String &sDirName) { - String sDir = sDirName; - if (sDir.Right(1) != _T("\\")) - sDir += "\\"; - - WIN32_FIND_DATA ffData; - HANDLE hFileFound = FindFirstFile(sDir + "*.*", &ffData); - - if (hFileFound == INVALID_HANDLE_VALUE) - return TRUE; - - while (hFileFound && FindNextFile(hFileFound, &ffData)) + for (boost::filesystem::directory_iterator file(sDirName); file != boost::filesystem::directory_iterator(); ++file) { - if (!(ffData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) - { - String sFileName = sDir + ffData.cFileName; - FileUtilities::DeleteFile(sFileName); - } + boost::filesystem::path current(file->path()); + if (!boost::filesystem::is_directory(current)) + boost::filesystem::remove(current); } - FindClose(hFileFound); - return true; } std::vector - FileUtilities::GetFilesInDirectory(const String &sDirectoryName, const String &sWildcard) + FileUtilities::GetFilesInDirectory(const String &sDirectoryName, const String ®ularExpressionTest) { std::vector result; - String file_name_wildcard = sDirectoryName; - if (file_name_wildcard.Right(1) != _T("\\")) - file_name_wildcard += "\\"; - - file_name_wildcard+= sWildcard; - - WIN32_FIND_DATA find_file_data; - HANDLE search_handle = FindFirstFile(file_name_wildcard, &find_file_data); - - while (search_handle != INVALID_HANDLE_VALUE) + for (boost::filesystem::directory_iterator file(sDirectoryName); file != boost::filesystem::directory_iterator(); ++file) { - if (!(find_file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) - { - result.push_back(FileInfo(find_file_data.cFileName, find_file_data.ftCreationTime)); - } + boost::filesystem::path current(file->path()); - if (!FindNextFile(search_handle, &find_file_data)) + if (RegularExpression::TestExactMatch(regularExpressionTest, current.filename().wstring())) { - FindClose(search_handle); - break; - } - } - - return result; - } - - - bool - FileUtilities::DeleteDirectoriesInDirectory(const String &sDirName, const std::set vecExcludes) - { - String sDir = sDirName; - if (sDir.Right(1) != _T("\\")) - sDir += "\\"; - - WIN32_FIND_DATA ffData; - HANDLE hFileFound = FindFirstFile(sDir + "*.*", &ffData); - - if (hFileFound == INVALID_HANDLE_VALUE) - return TRUE; + WIN32_FILE_ATTRIBUTE_DATA file_info; + GetFileAttributesExW(current.wstring().c_str(), GetFileExInfoStandard, &file_info); - while (hFileFound && FindNextFile(hFileFound, &ffData)) - { - if (ffData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) - { - if( (_tcscmp(ffData.cFileName, _T(".")) != 0) && - (_tcscmp(ffData.cFileName, _T("..")) != 0) ) - { - if (vecExcludes.find(ffData.cFileName) == vecExcludes.end()) - { - String sFileName = sDir + ffData.cFileName; - FileUtilities::DeleteDirectory(sFileName); - } - } + result.push_back(FileInfo(current.filename().wstring(), file_info.ftCreationTime)); } } - FindClose(hFileFound); - return true; + return result; + + } + bool - FileUtilities::CreateDirectoryRecursive(const String &sDirName) + FileUtilities::DeleteDirectoriesInDirectory(const String &sDirName) { - if (FileUtilities::Exists(sDirName)) - return true; - - bool isUNCPath = IsUNCPath(sDirName); - - int iLength = sDirName.GetLength(); - for (int i = 3; i < iLength; i++) + for (boost::filesystem::directory_iterator file(sDirName); file != boost::filesystem::directory_iterator(); ++file) { - wchar_t c = sDirName.GetAt(i); - - if (c == '\\') - { - String sDirectoryName = sDirName.Mid(0, i); - - if (isUNCPath) - { - // Have we specified share name? - if (!IsValidUNCFolder(sDirectoryName)) - { - // No. Not much to do yet. We can't check for the - // existance of an UNC. - continue; - } - } - - if (FileUtilities::Exists(sDirectoryName)) - continue; - - if (!CreateDirectory(sDirectoryName)) - return false; - } + boost::filesystem::path current(file->path()); + if (boost::filesystem::is_directory(current)) + boost::filesystem::remove(current); } - if (!FileUtilities::Exists(sDirName)) - return CreateDirectory(sDirName); - return true; } diff --git a/hmailserver/source/Server/Common/Util/FileUtilities.h b/hmailserver/source/Server/Common/Util/FileUtilities.h index 0f86f0e57..b320bbb23 100644 --- a/hmailserver/source/Server/Common/Util/FileUtilities.h +++ b/hmailserver/source/Server/Common/Util/FileUtilities.h @@ -20,13 +20,12 @@ namespace HM static bool DeleteFile(const String &FileName); - static bool ReadLine(HANDLE hFile, String &sLine); + //static bool ReadLine(HANDLE hFile, String &sLine); static bool Copy(const String &sFrom, const String &sTo, bool bCreateMissingDirectories = false); static bool Move(const String &sFrom, const String &sTo, bool overwrite = false); static bool Exists(const String &sFilename); static void ReadFileToBuf(const String &sFilename, BYTE *Buf, int iStart = -1, int iCount = -1); - static void ReadFileToBuf(HANDLE hFile, char *Buf, int iStart = -1, int iCount = -1); static String ReadCompleteTextFile(const String &sFilename); static bool WriteToFile(const String &sFilename, const String &sData, bool bUnicode); @@ -37,18 +36,13 @@ namespace HM static String GetTempFileName(); static bool CreateDirectory(const String &sName); - static String GetShortPath(const String &sInPath); - static String GetLongPath(const String &sInPath); - static bool CopyDirectory(String sFrom, String sTo, String &errorMessage); static bool DeleteDirectory(const String &sDirName); static bool DeleteFilesInDirectory(const String &sDirName); - static bool DeleteDirectoriesInDirectory(const String &sDirName, const std::set vecExcludes); + static bool DeleteDirectoriesInDirectory(const String &sDirName); static std::vector GetFilesInDirectory(const String &sDirectoryName, const String &sWildCard); - static bool CreateDirectoryRecursive(const String &sDirName); - static bool IsUNCPath(const String &sPath); static bool IsValidUNCFolder(const String &sPath); static bool IsFullPath(const String &sPath); diff --git a/hmailserver/source/Server/Common/Util/Languages.cpp b/hmailserver/source/Server/Common/Util/Languages.cpp index 13f8cd83e..6e3fb3dd0 100644 --- a/hmailserver/source/Server/Common/Util/Languages.cpp +++ b/hmailserver/source/Server/Common/Util/Languages.cpp @@ -29,7 +29,7 @@ namespace HM Language::LoadEnglish(); std::vector languageFiles = - FileUtilities::GetFilesInDirectory(IniFileSettings::Instance()->GetLanguageDirectory(), "*.ini"); + FileUtilities::GetFilesInDirectory(IniFileSettings::Instance()->GetLanguageDirectory(), "^.*[.]ini$"); auto iter = languageFiles.begin(); auto iterEnd = languageFiles.end(); diff --git a/hmailserver/source/Server/Common/Util/MailImporter.cpp b/hmailserver/source/Server/Common/Util/MailImporter.cpp index 171661364..7635b3917 100644 --- a/hmailserver/source/Server/Common/Util/MailImporter.cpp +++ b/hmailserver/source/Server/Common/Util/MailImporter.cpp @@ -256,7 +256,7 @@ namespace HM String destinationDirectory = FileUtilities::Combine(currentCorrectDirectory, guidFolder); if (!FileUtilities::Exists(destinationDirectory)) - FileUtilities::CreateDirectoryRecursive(destinationDirectory); + FileUtilities::CreateDirectory(destinationDirectory); String destinationFile = FileUtilities::Combine(destinationDirectory, resultFile); diff --git a/hmailserver/source/Server/Common/Util/Parsing/StringParser.cpp b/hmailserver/source/Server/Common/Util/Parsing/StringParser.cpp index 89a35cba0..1bb718a7c 100644 --- a/hmailserver/source/Server/Common/Util/Parsing/StringParser.cpp +++ b/hmailserver/source/Server/Common/Util/Parsing/StringParser.cpp @@ -462,18 +462,13 @@ namespace HM int needleSize = strlen(needle); - // If the string we're searching for is longer than the string - // we're searching is, there's no point in performing the search. - if (needleSize > haystackSize) - return 0; - for (int haystackIndex = 0; haystackIndex < haystackSize; haystackIndex++) { - int remainingHaystack = haystackSize - haystackIndex; + int remainingHaystackSize = haystackSize - haystackIndex; // If the string we're searching for is longer than the string - // we're searching is, there's no point in performing the search. - if (needleSize > haystackSize) + // we're searching in, there's no point in performing the search. + if (needleSize > remainingHaystackSize) return 0; const char *currentHaystackPosition = haystack + haystackIndex; @@ -671,7 +666,9 @@ namespace HM if (p != 0) throw; p = StringParser::Search("test", 4, "p"); if (p != 0) throw; - + p = StringParser::Search("test", 4, "feb"); + if (p != 0) throw; + // RESULT: /* Strings containing 80% us-ascii characters: diff --git a/hmailserver/source/Server/Common/Util/ProcessLauncher.cpp b/hmailserver/source/Server/Common/Util/ProcessLauncher.cpp index c2a482f8a..6e1f9f664 100644 --- a/hmailserver/source/Server/Common/Util/ProcessLauncher.cpp +++ b/hmailserver/source/Server/Common/Util/ProcessLauncher.cpp @@ -24,7 +24,7 @@ namespace HM command_line_(commandLine), error_log_timeout_(0) { - working_directory_ = Utilities::GetWin32TempDirectory(); + working_directory_ = IniFileSettings::Instance()->GetTempDirectory(); } ProcessLauncher::~ProcessLauncher(void) diff --git a/hmailserver/source/Server/Common/Util/Utilities.cpp b/hmailserver/source/Server/Common/Util/Utilities.cpp index a827985ba..f2908f23b 100644 --- a/hmailserver/source/Server/Common/Util/Utilities.cpp +++ b/hmailserver/source/Server/Common/Util/Utilities.cpp @@ -37,36 +37,10 @@ namespace HM } - String - Utilities::GetWin32TempDirectory() - { - // No username specified. Fetch local computer name. - if (!cached_win_32temp_dir_.IsEmpty()) - return cached_win_32temp_dir_; - - - unsigned long iSize = 255; - TCHAR pCharBuf[255]; - - if (::GetTempPath(iSize, pCharBuf) != 0) - { - String sShort = pCharBuf; - - if (sShort.Right(1) == _T("\\")) - sShort = sShort.Left(sShort.GetLength() - 1); - - cached_win_32temp_dir_ = FileUtilities::GetLongPath(sShort); - - } - - return cached_win_32temp_dir_; - - } - String Utilities::GetUniqueTempDirectory() { - return FileUtilities::Combine(GetWin32TempDirectory(), GUIDCreator::GetGUID()); + return FileUtilities::Combine(IniFileSettings::Instance()->GetTempDirectory(), GUIDCreator::GetGUID()); } diff --git a/hmailserver/source/Server/Common/Util/Utilities.h b/hmailserver/source/Server/Common/Util/Utilities.h index 114268ac1..11e3e09b1 100644 --- a/hmailserver/source/Server/Common/Util/Utilities.h +++ b/hmailserver/source/Server/Common/Util/Utilities.h @@ -17,7 +17,6 @@ namespace HM static String ComputerName(); static String GetBinDirectory(); - static String GetWin32TempDirectory(); static String GetUniqueTempDirectory(); static String GetIPAddress (SOCKADDR_IN addr); static String GenerateMessageID(); diff --git a/hmailserver/source/Server/IMAP/IMAPCommandAppend.cpp b/hmailserver/source/Server/IMAP/IMAPCommandAppend.cpp index a1f06ba13..aa1736039 100644 --- a/hmailserver/source/Server/IMAP/IMAPCommandAppend.cpp +++ b/hmailserver/source/Server/IMAP/IMAPCommandAppend.cpp @@ -200,7 +200,7 @@ namespace HM String destinationPath = FileUtilities::GetFilePath(message_file_name_); if (!FileUtilities::Exists(destinationPath)) - FileUtilities::CreateDirectoryRecursive(destinationPath); + FileUtilities::CreateDirectory(destinationPath); File oFile; if (!oFile.Open(message_file_name_, File::OTAppend)) diff --git a/hmailserver/source/Server/IMAP/IMAPConnection.cpp b/hmailserver/source/Server/IMAP/IMAPConnection.cpp index 06e148bbb..5b5b2c0e0 100644 --- a/hmailserver/source/Server/IMAP/IMAPConnection.cpp +++ b/hmailserver/source/Server/IMAP/IMAPConnection.cpp @@ -59,7 +59,6 @@ namespace HM { imap_folders_.reset(); - SessionManager::Instance()->OnCreate(STIMAP); // The IMAP RFC states that the minimum connection // timeout is 30 minutes. If the load increases, the timeout @@ -78,7 +77,8 @@ namespace HM // before terminating ourselves. mapCommandHandlers.clear(); - SessionManager::Instance()->OnDestroy(STIMAP); + if (GetConnectionState() != StatePendingConnect) + SessionManager::Instance()->OnSessionEnded(STIMAP); CloseCurrentFolder(); } diff --git a/hmailserver/source/Server/POP3/POP3Connection.cpp b/hmailserver/source/Server/POP3/POP3Connection.cpp index 133f24720..a84db070f 100644 --- a/hmailserver/source/Server/POP3/POP3Connection.cpp +++ b/hmailserver/source/Server/POP3/POP3Connection.cpp @@ -49,7 +49,6 @@ namespace HM transmission_buffer_(true), pending_disconnect_(false) { - SessionManager::Instance()->OnCreate(STPOP3); /* RFC 1939, Basic Operation @@ -69,7 +68,8 @@ namespace HM { OnDisconnect(); - SessionManager::Instance()->OnDestroy(STPOP3); + if (GetConnectionState() != StatePendingConnect) + SessionManager::Instance()->OnSessionEnded(STPOP3); } void @@ -801,74 +801,51 @@ namespace HM bool POP3Connection::SendFileHeader_(const String &sFilename, int iNoOfLines) { - - bool bRetVal = false; - - HANDLE handleFile; - - handleFile = CreateFile(sFilename, - GENERIC_READ, - FILE_SHARE_READ, - NULL, // LPSECURITY_ATTRIBUTES - OPEN_ALWAYS, // -- open or create. - FILE_ATTRIBUTE_NORMAL, // attributes - NULL // file template - ); - - if (handleFile == INVALID_HANDLE_VALUE) + File file; + if (!file.Open(sFilename, File::OTReadOnly)) return false; - SetFilePointer(handleFile,0,0,FILE_BEGIN); - - if (handleFile > 0) - { + int current_body_line_count = 0; + bool header_sent = false; + AnsiString line; - BYTE buf[1024]; - memset(buf, 0, 1024); - - unsigned long nbytes = 0; - BOOL bMoreData = TRUE; - int nBytesSent = 0; + AnsiString output_buffer; - bool bHeaderSent = false; - int iCurNoOfLines = 0; - while (bMoreData) + while (file.ReadLine(line)) + { + if (header_sent) { - - String sLine; - bMoreData = FileUtilities::ReadLine(handleFile, sLine); + if (iNoOfLines <= 0) + break; - if (bHeaderSent) - { - if (iNoOfLines <= 0) - break; - - EnqueueWrite_DebugOnly(sLine); + output_buffer += line; - iCurNoOfLines++; + current_body_line_count++; - if (iCurNoOfLines == iNoOfLines) - break; - } - else - { - if (sLine.IsEmpty()) - bHeaderSent = true; - - EnqueueWrite_DebugOnly(sLine); - - } - + if (current_body_line_count == iNoOfLines) + break; } + else + { + if (line == "\r\n") + header_sent = true; - bRetVal = true; + output_buffer += line; + } + if (output_buffer.size() > 10000) + { + EnqueueWrite(output_buffer); + output_buffer.Empty(); + } } + if (!output_buffer.IsEmpty()) + { + EnqueueWrite(output_buffer); + } - CloseHandle(handleFile); - - return bRetVal; + return true; } @@ -886,22 +863,6 @@ namespace HM EnqueueWrite(sData + "\r\n"); } - void - POP3Connection::EnqueueWrite_DebugOnly(const String &sData) - { - // Logs are crazy huge for clients that do a lot of TOP's so - // let's not log every email line unless loglevel is high enough - if (IniFileSettings::Instance()->GetLogLevel() >= 8) - { - String sLogData = "SENT: " + sData; - sLogData.TrimRight(_T("\r\n")); - - LOG_POP3(GetSessionID(),GetIPAddressString(), sLogData); - } - - EnqueueWrite(sData + "\r\n"); - } - void POP3Connection::SaveMailboxChanges_() { diff --git a/hmailserver/source/Server/POP3/POP3Connection.h b/hmailserver/source/Server/POP3/POP3Connection.h index 4f73ff9f4..b0216bad3 100644 --- a/hmailserver/source/Server/POP3/POP3Connection.h +++ b/hmailserver/source/Server/POP3/POP3Connection.h @@ -32,7 +32,6 @@ namespace HM virtual AnsiString GetCommandSeparator() const; virtual void EnqueueWrite_(const String &sData) ; - virtual void EnqueueWrite_DebugOnly(const String &sData) ; virtual void OnDisconnect(); virtual void OnConnectionTimeout(); diff --git a/hmailserver/source/Server/SMTP/SMTPConnection.cpp b/hmailserver/source/Server/SMTP/SMTPConnection.cpp index 605e32efd..35edd2572 100644 --- a/hmailserver/source/Server/SMTP/SMTPConnection.cpp +++ b/hmailserver/source/Server/SMTP/SMTPConnection.cpp @@ -90,7 +90,6 @@ namespace HM isAuthenticated_(false), start_tls_used_(false) { - SessionManager::Instance()->OnCreate(STSMTP); smtpconf_ = Configuration::Instance()->GetSMTPConfiguration(); @@ -114,7 +113,8 @@ namespace HM { ResetCurrentMessage_(); - SessionManager::Instance()->OnDestroy(STSMTP); + if (GetConnectionState() != StatePendingConnect) + SessionManager::Instance()->OnSessionEnded(STSMTP); } @@ -1015,7 +1015,7 @@ namespace HM if (bArchiveHardlinks) { - FileUtilities::CreateDirectoryRecursive(sArchiveDir + "\\" + sSenderDomain + "\\" + sSenderName); + FileUtilities::CreateDirectory(sArchiveDir + "\\" + sSenderDomain + "\\" + sSenderName); // This function call is odd in that original is 2nd anc destination is 1st.. BOOL fCreatedLink = CreateHardLink( sMessageArchivePath2, sMessageArchivePath, NULL ); // Last is reserved, must be NULL @@ -1172,13 +1172,7 @@ namespace HM if (!FileUtilities::Exists(fileName)) { - String sErrorMsg; - sErrorMsg.Format(_T("Rejected message because no mail data has been saved in file %s"), fileName.c_str()); - - ErrorManager::Instance()->ReportError(ErrorManager::Critical, 5019, "SMTPConnection::_OnPreAcceptTransfer", sErrorMsg); - - EnqueueWrite_("451 Rejected - No data saved."); - LogAwstatsMessageRejected_(); + HandleUnableToSaveMessageDataFile_(fileName); return false; } @@ -1262,6 +1256,16 @@ namespace HM return true; } + void + SMTPConnection::HandleUnableToSaveMessageDataFile_(const String &file_name) + { + String sErrorMsg = Formatter::Format("Rejected message because no mail data has been saved in file {0}", file_name); + ErrorManager::Instance()->ReportError(ErrorManager::Critical, 5019, "SMTPConnectionSMTPConnection::HandleUnableToSaveMessage_", sErrorMsg); + + EnqueueWrite_("451 Rejected - No data saved."); + LogAwstatsMessageRejected_(); + } + bool SMTPConnection::CheckLineEndings_() const //---------------------------------------------------------------------------() @@ -1605,7 +1609,12 @@ namespace HM current_state_ = DATA; transmission_buffer_ = std::shared_ptr(new TransparentTransmissionBuffer(false)); - transmission_buffer_->Initialize(PersistentMessage::GetFileName(current_message_)); + if (!transmission_buffer_->Initialize(PersistentMessage::GetFileName(current_message_))) + { + HandleUnableToSaveMessageDataFile_(PersistentMessage::GetFileName(current_message_)); + return; + } + transmission_buffer_->SetMaxSizeKB(max_message_size_kb_); SetReceiveBinary(true); diff --git a/hmailserver/source/Server/SMTP/SMTPConnection.h b/hmailserver/source/Server/SMTP/SMTPConnection.h index e6dbae613..e607cd694 100644 --- a/hmailserver/source/Server/SMTP/SMTPConnection.h +++ b/hmailserver/source/Server/SMTP/SMTPConnection.h @@ -159,6 +159,8 @@ namespace HM bool GetIsLocalSender_(); + void HandleUnableToSaveMessageDataFile_(const String &file_name); + String GetSpamTestResultMessage_(std::set > testResult) const; enum ConnectionState diff --git a/hmailserver/source/Server/hMailServer/hMailServer.vcxproj b/hmailserver/source/Server/hMailServer/hMailServer.vcxproj index fe6111e56..fbfd59984 100644 --- a/hmailserver/source/Server/hMailServer/hMailServer.vcxproj +++ b/hmailserver/source/Server/hMailServer/hMailServer.vcxproj @@ -122,8 +122,8 @@ EXIT 0 Performing registration - xcopy /F /Y $(hMailServerLibs)\openssl-1.0.1i\out32dll\libeay32.dll $(OutDir) -xcopy /F /Y $(hMailServerLibs)\openssl-1.0.1i\out32dll\ssleay32.dll $(OutDir) + xcopy /F /Y $(hMailServerLibs)\openssl-1.0.1j\out32dll\libeay32.dll $(OutDir) +xcopy /F /Y $(hMailServerLibs)\openssl-1.0.1j\out32dll\ssleay32.dll $(OutDir) "$(TargetPath)" /Register @@ -176,8 +176,8 @@ EXIT 0 Performing registration - xcopy /F /Y $(hMailServerLibs)\openssl-1.0.1i\out32dll\libeay32.dll $(OutDir) -xcopy /F /Y $(hMailServerLibs)\openssl-1.0.1i\out32dll\ssleay32.dll $(OutDir) + xcopy /F /Y $(hMailServerLibs)\openssl-1.0.1j\out32dll\libeay32.dll $(OutDir) +xcopy /F /Y $(hMailServerLibs)\openssl-1.0.1j\out32dll\ssleay32.dll $(OutDir) "$(TargetPath)" /Register diff --git a/hmailserver/test/RegressionTests/API/Basics.cs b/hmailserver/test/RegressionTests/API/Basics.cs index 862f47c21..116a0684b 100644 --- a/hmailserver/test/RegressionTests/API/Basics.cs +++ b/hmailserver/test/RegressionTests/API/Basics.cs @@ -18,7 +18,7 @@ public class Basics : TestFixtureBase { private static void SendMessageToTest() { - var smtp = new SMTPClientSimulator(); + var smtp = new SmtpClientSimulator(); var recipients = new List(); recipients.Add("test@test.com"); smtp.Send("test@test.com", recipients, "Test", "Test message"); @@ -62,15 +62,15 @@ public void TestAddMessage() message.set_Flag(eMessageFlag.eMFSeen, true); message.Save(); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", ((i + 1)*2) - 1); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", ((i + 1)*2) - 1); - SMTPClientSimulator.StaticSend("test@example.com", account.Address, "Test", "Test"); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", (i + 1)*2); + SmtpClientSimulator.StaticSend("test@example.com", account.Address, "Test", "Test"); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", (i + 1)*2); } - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 6); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 6); - var sim = new IMAPClientSimulator(); + var sim = new ImapClientSimulator(); sim.ConnectAndLogon(account.Address, "test"); sim.SelectFolder("Inbox"); @@ -138,7 +138,7 @@ public void TestAddTextToEmptyBody() "\r\n" + "--------------050908050500020808050006--\r\n"; - SMTPClientSimulator.StaticSendRaw("test@test.com", "test@test.com", messageText); + SmtpClientSimulator.StaticSendRaw("test@test.com", "test@test.com", messageText); hMailServer.Message message = CustomAsserts.AssertRetrieveFirstMessage(account1.IMAPFolders.get_ItemByName("INBOX")); @@ -170,7 +170,7 @@ public void TestCopyMessage() message.Copy(someOtherFolder.ID); } - SMTPClientSimulator.StaticSend("test@example.com", account.Address, "Test", "Test"); + SmtpClientSimulator.StaticSend("test@example.com", account.Address, "Test", "Test"); // Copy back to inbox. for (int i = 0; i < 3; i ++) @@ -179,9 +179,9 @@ public void TestCopyMessage() message.Copy(folder.ID); } - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 7); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 7); - var sim = new IMAPClientSimulator(); + var sim = new ImapClientSimulator(); sim.ConnectAndLogon(account.Address, "test"); sim.SelectFolder("Inbox"); string response = sim.Fetch("1:7 UID"); @@ -276,7 +276,7 @@ public void TestEventLog() SendMessageToTest(); - POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); + Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); CustomAsserts.AssertFileExists(eventLogFile, false); @@ -318,7 +318,7 @@ public void TestFolderDeletion() IMAPFolder folder = account1.IMAPFolders.Add("TestFolder1"); folder.Save(); - var simulator1 = new IMAPClientSimulator(); + var simulator1 = new ImapClientSimulator(); simulator1.ConnectAndLogon(account1.Address, "test"); string result = simulator1.List(); Assert.IsTrue(result.Contains(folder.Name)); @@ -383,9 +383,9 @@ public void TestInternalDateCombinedWithOnDeliverMessage() // Add an account and send a message to it. Account oAccount1 = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - SMTPClientSimulator.StaticSend(oAccount1.Address, oAccount1.Address, "Test", "SampleBody"); + SmtpClientSimulator.StaticSend(oAccount1.Address, oAccount1.Address, "Test", "SampleBody"); - POP3ClientSimulator.AssertMessageCount(oAccount1.Address, "test", 1); + Pop3ClientSimulator.AssertMessageCount(oAccount1.Address, "test", 1); string text = TestSetup.ReadExistingTextFile(_settings.Logging.CurrentEventLog); string[] columns = text.Split('\t'); @@ -416,14 +416,14 @@ public void TestLiveLog() // Add an account and send a message to it. Account account = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody"); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody"); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1); string liveLog = logging.LiveLog; Assert.IsTrue(liveLog.Length > 0, liveLog); - SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody"); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 2); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody"); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 2); logging.EnableLiveLogging(true); @@ -440,9 +440,9 @@ public void TestReinitialize() "WhatTest\r\n"; Account account = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - Assert.IsTrue(SMTPClientSimulator.StaticSend(account.Address, account.Address, "First message", - "Test message")); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "First message", + "Test message"); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1); // Create another message on disk and import it. string domainPath = Path.Combine(_application.Settings.Directories.DataDirectory, "test.com"); @@ -453,15 +453,15 @@ public void TestReinitialize() Assert.IsTrue(_application.Utilities.ImportMessageFromFile(fileName, account.ID)); // Since the cache isn't refreshed, the message has not yet appeared. - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1); // Reinitialize the server. Should, among other things, clear the cache. _application.Reinitialize(); // Now the message should have appeared. - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 2); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 2); - var sim = new POP3ClientSimulator(); + var sim = new Pop3ClientSimulator(); sim.ConnectAndLogon(account.Address, "test"); messageText = sim.RETR(2); sim.QUIT(); @@ -478,8 +478,8 @@ public void TestRetrieveMessageID() // Add an account and send a message to it. Account account = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody"); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody"); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1); hMailServer.Message message = account.IMAPFolders.get_ItemByName("INBOX").Messages[0]; @@ -504,7 +504,7 @@ public void TestSaveMessageInExistingIMAPFolder() Account oAccount1 = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); // Check that the message does not exist - POP3ClientSimulator.AssertMessageCount(oAccount1.Address, "test", 0); + Pop3ClientSimulator.AssertMessageCount(oAccount1.Address, "test", 0); // Send a message to the account. IMAPFolder folder = oAccount1.IMAPFolders.get_ItemByName("INBOX"); @@ -522,7 +522,7 @@ public void TestSaveMessageInExistingIMAPFolder() Assert.IsTrue(oMessage.Filename.Contains(_domain.Name)); // Check that the message exists - string message = POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); + string message = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); Assert.IsNotEmpty(message); Assert.Less(0, message.IndexOf("Hej")); @@ -569,7 +569,7 @@ public void TestSendMessage() Assert.AreEqual(1, oMessage.State); // Check that the message exists - string message = POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); + string message = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); Assert.IsNotEmpty(message); Assert.Less(0, message.IndexOf("Hej")); diff --git a/hmailserver/test/RegressionTests/API/Events.cs b/hmailserver/test/RegressionTests/API/Events.cs index 3896be854..b64986a57 100644 --- a/hmailserver/test/RegressionTests/API/Events.cs +++ b/hmailserver/test/RegressionTests/API/Events.cs @@ -36,10 +36,10 @@ public void TestOnAcceptMessageJScript() // Add an account and send a message to it. Account oAccount1 = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - SMTPClientSimulator.StaticSend(oAccount1.Address, oAccount1.Address, "Test", "SampleBody"); + SmtpClientSimulator.StaticSend(oAccount1.Address, oAccount1.Address, "Test", "SampleBody"); // Check that the message exists - string message = POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); + string message = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); Assert.IsNotEmpty(message); Assert.Less(0, message.IndexOf("X-SpamResult: TEST")); @@ -73,10 +73,10 @@ public void TestOnAcceptMessageVBScript() // Add an account and send a message to it. Account oAccount1 = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - SMTPClientSimulator.StaticSend(oAccount1.Address, oAccount1.Address, "Test", "SampleBody"); + SmtpClientSimulator.StaticSend(oAccount1.Address, oAccount1.Address, "Test", "SampleBody"); // Check that the message exists - string message = POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); + string message = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); Assert.IsNotEmpty(message); Assert.Less(0, message.IndexOf("X-SpamResult: TEST")); @@ -295,10 +295,10 @@ public void TestOnDeliverMessageJScript() // Add an account and send a message to it. Account oAccount1 = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - SMTPClientSimulator.StaticSend(oAccount1.Address, oAccount1.Address, "Test", "SampleBody"); + SmtpClientSimulator.StaticSend(oAccount1.Address, oAccount1.Address, "Test", "SampleBody"); // Check that the message exists - string message = POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); + string message = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); Assert.IsNotEmpty(message); Assert.Less(0, message.IndexOf("X-SpamResult: TEST2")); @@ -326,7 +326,7 @@ public void TestOnDeliveryFailedJScript() // Add an account and send a message to it. Account oAccount1 = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - SMTPClientSimulator.StaticSend(oAccount1.Address, "user@some-non-existant-domain.abc", "Test", "SampleBody"); + SmtpClientSimulator.StaticSend(oAccount1.Address, "user@some-non-existant-domain.abc", "Test", "SampleBody"); // Make sure that the message is deliverd and bounced. CustomAsserts.AssertRecipientsInDeliveryQueue(0); @@ -357,7 +357,7 @@ public void TestOnDeliveryFailedVBScript() // Add an account and send a message to it. Account oAccount1 = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - SMTPClientSimulator.StaticSend(oAccount1.Address, "user@some-non-existant-domain.abc", "Test", "SampleBody"); + SmtpClientSimulator.StaticSend(oAccount1.Address, "user@some-non-existant-domain.abc", "Test", "SampleBody"); // Make sure that the message is deliverd and bounced. CustomAsserts.AssertRecipientsInDeliveryQueue(0); @@ -384,10 +384,10 @@ public void TestOnDeliveryStartVBScript() scripting.Reload(); Account account = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody"); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody"); // Wait for the message to be delivered. - POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); + Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); string eventLogText = TestSetup.ReadExistingTextFile(app.Settings.Logging.CurrentEventLog); Assert.IsTrue(eventLogText.Contains("Delivering message")); @@ -416,12 +416,12 @@ public void TestOnErrorJScript() string deletedMessageText = app.Settings.ServerMessages.get_ItemByName("MESSAGE_FILE_MISSING").Text; - SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody"); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody"); CustomAsserts.AssertFolderMessageCount(inbox, 1); hMailServer.Message message = inbox.Messages[0]; File.Delete(message.Filename); - string text = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); + string text = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); Assert.IsTrue(text.Contains(deletedMessageText.Replace("%MACRO_FILE%", message.Filename))); CustomAsserts.AssertReportedError("Message retrieval failed because message file"); @@ -452,12 +452,12 @@ public void TestOnErrorVBScript() string deletedMessageText = app.Settings.ServerMessages.get_ItemByName("MESSAGE_FILE_MISSING").Text; - SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody"); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody"); CustomAsserts.AssertFolderMessageCount(inbox, 1); hMailServer.Message message = inbox.Messages[0]; File.Delete(message.Filename); - string text = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); + string text = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); Assert.IsTrue(text.Contains(deletedMessageText.Replace("%MACRO_FILE%", message.Filename))); CustomAsserts.AssertReportedError("Message retrieval failed because message file"); @@ -520,7 +520,7 @@ public void TestOnExternalAccountDownload() FetchAccount fa; int port = TestSetup.GetNextFreePort(); - using (var pop3Server = new POP3Server(1, port, messages)) + using (var pop3Server = new Pop3ServerSimulator(1, port, messages)) { pop3Server.StartListen(); @@ -561,12 +561,12 @@ public void TestOnExternalAccountDownload() Assert.IsTrue(pop3Server.RetrievedMessages.Contains(2)); Assert.IsTrue(pop3Server.RetrievedMessages.Contains(3)); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 3); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 3); } - using (var pop3Server = new POP3Server(1, port, messages)) + using (var pop3Server = new Pop3ServerSimulator(1, port, messages)) { pop3Server.StartListen(); @@ -579,7 +579,7 @@ public void TestOnExternalAccountDownload() Assert.AreEqual(0, pop3Server.DeletedMessages.Count); Assert.AreEqual(0, pop3Server.RetrievedMessages.Count); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 3); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 3); } } } diff --git a/hmailserver/test/RegressionTests/API/Message.cs b/hmailserver/test/RegressionTests/API/Message.cs index 1d839f990..813ba663b 100644 --- a/hmailserver/test/RegressionTests/API/Message.cs +++ b/hmailserver/test/RegressionTests/API/Message.cs @@ -33,7 +33,7 @@ public void TestAddBodyAfterAttachment() message.Body = "Hello"; message.Save(); - string messageText = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); + string messageText = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); int headerEnd = messageText.IndexOf("\r\n\r\n"); string header = messageText.Substring(0, headerEnd); @@ -74,10 +74,10 @@ public void TestAddTextDuringSending() // Send the message. var recipients = new List(); recipients.Add("test@test.com"); - SMTPClientSimulator.StaticSend("test@test.com", recipients, "Hej", "Välkommen till verkligheten"); + SmtpClientSimulator.StaticSend("test@test.com", recipients, "Hej", "Välkommen till verkligheten"); // Check that the message exists - string message = POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); + string message = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); Assert.IsNotEmpty(message); Assert.IsTrue(message.Contains(signature)); @@ -120,7 +120,7 @@ public void TestAddTextDuringSendingAttachment() oClient.Send(mail); // Check that the message exists - string message = POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); + string message = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); Assert.IsNotEmpty(message, message); Assert.IsTrue(message.Contains(signature), message); @@ -163,7 +163,7 @@ public void TestAddTextToEmptyBody() oClient.Send(mail); // Check that the message exists - string message = POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); + string message = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); Assert.IsNotEmpty(message, message); Assert.IsTrue(message.Contains(signature), message); @@ -180,7 +180,7 @@ public void TestMailCreationHTML() message.HTMLBody = "Hello"; message.Save(); - string messageText = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); + string messageText = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); int headerEnd = messageText.IndexOf("\r\n\r\n"); string header = messageText.Substring(0, headerEnd); @@ -202,7 +202,7 @@ public void TestMailCreationHTMLAndPlainText() message.Body = "PlainTextBody"; message.Save(); - string messageText = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); + string messageText = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); int headerEnd = messageText.IndexOf("\r\n\r\n"); string header = messageText.Substring(0, headerEnd); @@ -225,7 +225,7 @@ public void TestMailCreationHTMLAndPlainTextReverse() message.HTMLBody = "HTMLBody"; message.Save(); - string messageText = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); + string messageText = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); int headerEnd = messageText.IndexOf("\r\n\r\n"); string header = messageText.Substring(0, headerEnd); @@ -247,7 +247,7 @@ public void TestMailCreationPlainText() message.Body = "Hello"; message.Save(); - string messageText = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); + string messageText = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); int headerEnd = messageText.IndexOf("\r\n\r\n"); string header = messageText.Substring(0, headerEnd); @@ -275,7 +275,7 @@ public void TestMailCreationUnicodeAndAttachment() message.Body = "Test of message... 日本語"; message.Save(); - string messageText = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); + string messageText = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); int headerEnd = messageText.IndexOf("\r\n\r\n"); @@ -299,7 +299,7 @@ public void TestMailCreationUnicodeBodyAndHtml() message.HTMLBody = "Test of message... 日本語"; message.Save(); - string messageText = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); + string messageText = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); Assert.IsTrue(messageText.Contains("Content-Type: text/html; charset=\"utf-8\"")); Assert.IsTrue(messageText.Contains("Content-Type: text/plain; charset=\"utf-8\"")); @@ -331,9 +331,9 @@ public void TestUpdateSubjectOnMessageWithNoMessageWideCharacterSet() "Hej!" + Environment.NewLine; - SMTPClientSimulator.StaticSendRaw("encode@test.com", "encode@test.com", body); + SmtpClientSimulator.StaticSendRaw("encode@test.com", "encode@test.com", body); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1); CustomAsserts.AssertFolderMessageCount(account.IMAPFolders[0], 1); diff --git a/hmailserver/test/RegressionTests/API/Unicode.cs b/hmailserver/test/RegressionTests/API/Unicode.cs index 355eb9f05..dd110459d 100644 Binary files a/hmailserver/test/RegressionTests/API/Unicode.cs and b/hmailserver/test/RegressionTests/API/Unicode.cs differ diff --git a/hmailserver/test/RegressionTests/API/Utilities.cs b/hmailserver/test/RegressionTests/API/Utilities.cs index 55c1de974..6de2af8fa 100644 --- a/hmailserver/test/RegressionTests/API/Utilities.cs +++ b/hmailserver/test/RegressionTests/API/Utilities.cs @@ -36,7 +36,7 @@ public void TestImportDuplicateMessage() Assert.IsTrue(_application.Utilities.ImportMessageFromFile(fileName, account.ID)); Assert.IsFalse(_application.Utilities.ImportMessageFromFile(fileName, account.ID)); - POP3ClientSimulator.AssertMessageCount("test@test.com", "test", 1); + Pop3ClientSimulator.AssertMessageCount("test@test.com", "test", 1); } [Test] @@ -143,7 +143,7 @@ public void TestImportOfMessageIntoInbox() Assert.IsTrue(_application.Utilities.ImportMessageFromFile(fileName, account.ID)); - string text = POP3ClientSimulator.AssertGetFirstMessageText("test@test.com", "test"); + string text = Pop3ClientSimulator.AssertGetFirstMessageText("test@test.com", "test"); Assert.IsTrue(text.Contains(messageText)); } @@ -169,7 +169,7 @@ public void TestImportOfMessageIntoInbox2() Assert.IsTrue(_application.Utilities.ImportMessageFromFileToIMAPFolder(fileName, account.ID, "Inbox")); - string text = POP3ClientSimulator.AssertGetFirstMessageText("test@test.com", "test"); + string text = Pop3ClientSimulator.AssertGetFirstMessageText("test@test.com", "test"); Assert.IsTrue(text.Contains(messageText)); } @@ -196,8 +196,8 @@ public void TestImportOfMessageIntoOtherFolder() Assert.IsTrue(_application.Utilities.ImportMessageFromFileToIMAPFolder(fileName, account.ID, "Woho")); - POP3ClientSimulator.AssertMessageCount("test@test.com", "test", 0); - var sim = new IMAPClientSimulator(); + Pop3ClientSimulator.AssertMessageCount("test@test.com", "test", 0); + var sim = new ImapClientSimulator(); sim.ConnectAndLogon("test@test.com", "test"); Assert.AreEqual(1, sim.GetMessageCount("Woho")); sim.Disconnect(); @@ -243,7 +243,7 @@ public void TestReplaceFullPathInPublicFolderWithPartialPath() public void TestReplaceFullPathWithPartialPath() { Account account = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test message", "Test body"); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test message", "Test body"); IMAPFolder folder = account.IMAPFolders.get_ItemByName("Inbox"); CustomAsserts.AssertFolderMessageCount(folder, 1); @@ -273,7 +273,7 @@ public void TestReplaceFullPathWithPartialPath() // Now nothing should happen because the file is no longer there. Assert.IsFalse(_application.Utilities.ImportMessageFromFile(fileName, account.ID)); - string content = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); + string content = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); Assert.IsTrue(content.Contains("Test message")); } @@ -283,7 +283,7 @@ public void TestReplaceFullPathWithPartialPath() public void TestReplaceInvalidPathWithCorrectPath() { Account account = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test message", "Test body"); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test message", "Test body"); IMAPFolder folder = account.IMAPFolders.get_ItemByName("Inbox"); CustomAsserts.AssertFolderMessageCount(folder, 1); @@ -307,7 +307,7 @@ public void TestReplaceInvalidPathWithCorrectPath() Assert.IsTrue(_application.Utilities.ImportMessageFromFile(message.Filename, account.ID)); Assert.IsTrue(File.Exists(message.Filename)); - string content = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); + string content = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); Assert.IsTrue(content.Contains("Test message")); } diff --git a/hmailserver/test/RegressionTests/AntiSpam/Basics.cs b/hmailserver/test/RegressionTests/AntiSpam/Basics.cs index 56288649a..5db819dd1 100644 --- a/hmailserver/test/RegressionTests/AntiSpam/Basics.cs +++ b/hmailserver/test/RegressionTests/AntiSpam/Basics.cs @@ -60,8 +60,8 @@ public void TestDNSBlackList() LogHandler.DeleteCurrentDefaultLog(); - SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody"); - POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody"); + Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); string result = LogHandler.ReadCurrentDefaultLog(); @@ -84,9 +84,9 @@ public void TestHeloSpamTest() _antiSpam.CheckHostInHeloScore = 125; // Send a messages to this account. - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); - Assert.IsFalse(oSMTP.Send("whitelist@microsoft.com", "whitelist@test.com", "SURBL-Match", "Test")); + CustomAsserts.Throws(() => smtpClientSimulator.Send("whitelist@microsoft.com", "whitelist@test.com", "SURBL-Match", "Test")); } [Test] @@ -103,28 +103,26 @@ public void TestIncorrectLineEndings() // Send a messages to this account. - var oSMTP = new SMTPClientSimulator(); - if ( - !oSMTP.Send("SpamProtectionLineEndings@test.com", "SpamProtectionLineEndings@test.com", "INBOX", - "This is a test message\r\n consisting of correct lines")) - throw new Exception("ERROR - Was not able to send correct email."); + var smtpClientSimulator = new SmtpClientSimulator(); + smtpClientSimulator.Send("SpamProtectionLineEndings@test.com", "SpamProtectionLineEndings@test.com", "INBOX", + "This is a test message\r\n consisting of correct lines"); + CustomAsserts.Throws(() => smtpClientSimulator.Send("SpamProtectionLineEndings@test.com", + "SpamProtectionLineEndings@test.com", "INBOX", + "This is a test message\r consisting of incorrect lines")); - if (oSMTP.Send("SpamProtectionLineEndings@test.com", "SpamProtectionLineEndings@test.com", "INBOX", - "This is a test message\r consisting of incorrect lines")) - throw new Exception("ERROR - Was able to send incorrect email."); - if (oSMTP.Send("SpamProtectionLineEndings@test.com", "SpamProtectionLineEndings@test.com", "INBOX", - "This is a test message\n consisting of incorrect lines")) - throw new Exception("ERROR - Was able to send incorrect email."); + CustomAsserts.Throws( + () => smtpClientSimulator.Send("SpamProtectionLineEndings@test.com", "SpamProtectionLineEndings@test.com", "INBOX", + "This is a test message\n consisting of incorrect lines")); - if (oSMTP.Send("SpamProtectionLineEndings@test.com", "SpamProtectionLineEndings@test.com", "INBOX", - "This is a test message\n\r consisting of incorrect lines")) - throw new Exception("ERROR - Was able to send incorrect email."); + CustomAsserts.Throws(() => smtpClientSimulator.Send("SpamProtectionLineEndings@test.com", + "SpamProtectionLineEndings@test.com", "INBOX", + "This is a test message\n\r consisting of incorrect lines")); - POP3ClientSimulator.AssertMessageCount(oAccount1.Address, "test", 1); + Pop3ClientSimulator.AssertMessageCount(oAccount1.Address, "test", 1); } [Test] @@ -151,7 +149,7 @@ public void TestMaxSizeLimit() oSURBLServer.Save(); // Send a messages to this account. - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); var sb = new StringBuilder(); int iterations = ((40*1024)/100) + 1; @@ -161,11 +159,11 @@ public void TestMaxSizeLimit() "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\r\n"); } - Assert.IsTrue(oSMTP.Send("surbltest@test.com", "surbltest@test.com", "SURBL-No-Match", + smtpClientSimulator.Send("surbltest@test.com", "surbltest@test.com", "SURBL-No-Match", "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-\r\n" + - sb)); + sb); - string sMessageContents = POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); + string sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); if (sMessageContents.Contains("X-hMailServer-Spam") || sMessageContents.Contains("X-hMailServer-Reason") || sMessageContents.Contains("ThisIsSpam")) @@ -200,7 +198,7 @@ public void TestMaxSizeNoLimit() oSURBLServer.Save(); // Send a messages to this account. - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); var sb = new StringBuilder(); int iterations = ((40*1024)/100) + 1; @@ -210,11 +208,11 @@ public void TestMaxSizeNoLimit() "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\r\n"); } - Assert.IsTrue(oSMTP.Send("surbltest@test.com", "surbltest@test.com", "SURBL-No-Match", + smtpClientSimulator.Send("surbltest@test.com", "surbltest@test.com", "SURBL-No-Match", "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-\r\n" + - sb)); + sb); - string sMessageContents = POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); + string sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); if (!sMessageContents.Contains("X-hMailServer-Spam") || !sMessageContents.Contains("X-hMailServer-Reason") || !sMessageContents.Contains("ThisIsSpam")) @@ -242,18 +240,17 @@ public void TestMissingMXRecord() _antiSpam.UseMXChecksScore = 2; // Send a messages to this account. - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); - if (!oSMTP.Send("test@microsoft.com", "missingmxrecords@test.com", "INBOX", "This is a test message.")) - throw new Exception("ERROR - Was not able to send correct email."); + smtpClientSimulator.Send("test@microsoft.com", "missingmxrecords@test.com", "INBOX", "This is a test message."); - if (oSMTP.Send("test@domain_without_mx_records421dfsam430sasd.com", oAccount1.Address, "INBOX", - "This is a test message.")) - throw new Exception("ERROR - Was not able to send incorrect email."); + CustomAsserts.Throws( + () => smtpClientSimulator.Send("test@domain_without_mx_records421dfsam430sasd.com", oAccount1.Address, "INBOX", + "This is a test message.")); _antiSpam.UseMXChecks = false; - POP3ClientSimulator.AssertMessageCount(oAccount1.Address, "test", 1); + Pop3ClientSimulator.AssertMessageCount(oAccount1.Address, "test", 1); } [Test] @@ -279,12 +276,12 @@ public void TestMultiLineSurblImproperlyTerminaetdLine() oSURBLServer.Save(); // Send a messages to this account. - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); - oSMTP.Send("surbltest@test.com", "surbltest@test.com", "SURBL-Match", + smtpClientSimulator.Send("surbltest@test.com", "surbltest@test.com", "SURBL-Match", "Wrapped URL - Test"); - string sMessageContents = POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); + string sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); Assert.IsFalse(sMessageContents.Contains("X-hMailServer-Spam"), "Non-spam message detected as spam"); oSURBLServer.Active = false; @@ -313,19 +310,19 @@ public void TestSPF() _antiSpam.UseSPFScore = 5; // Send a messages to this account. - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); - oSMTP.Send("spftest@openspf.org", oAccount1.Address, "SPF test", "This is a test message."); + smtpClientSimulator.Send("spftest@openspf.org", oAccount1.Address, "SPF test", "This is a test message."); - string sMessageContents = POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); + string sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); if (!sMessageContents.Contains("X-hMailServer-Spam")) throw new Exception("Spam message not detected as spam"); _antiSpam.UseSPF = false; - oSMTP.Send("spftest@openspf.org", oAccount1.Address, "SPF test", "This is a test message."); + smtpClientSimulator.Send("spftest@openspf.org", oAccount1.Address, "SPF test", "This is a test message."); - sMessageContents = POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); + sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); if (sMessageContents.Contains("X-hMailServer-Spam")) throw new Exception("Non-spam message detected as spam"); } @@ -357,11 +354,11 @@ public void TestSPFWithDebugLogging() _antiSpam.UseSPFScore = 12; // Send a messages to this account. - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); - oSMTP.Send("spftest@openspf.org", oAccount1.Address, "SPF test", "This is a test message."); + smtpClientSimulator.Send("spftest@openspf.org", oAccount1.Address, "SPF test", "This is a test message."); - string sMessageContents = POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); + string sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); if (!sMessageContents.Contains("X-hMailServer-Spam")) throw new Exception("Spam message not detected as spam"); @@ -397,13 +394,13 @@ public void TestSURBL() oSURBLServer.Save(); // Send a messages to this account. - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); - oSMTP.Send("surbltest@test.com", "surbltest@test.com", "SURBL-No-Match", + smtpClientSimulator.Send("surbltest@test.com", "surbltest@test.com", "SURBL-No-Match", "This is a test message without a SURBL url."); - string sMessageContents = POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); + string sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); if (sMessageContents.Length == 0 || sMessageContents.Contains("X-hMailServer-Spam") || sMessageContents.Contains("X-hMailServer-Reason") || @@ -411,10 +408,10 @@ public void TestSURBL() throw new Exception("Non-Spam message detected as spam"); - oSMTP.Send("surbltest@test.com", "surbltest@test.com", "SURBL-Match", + smtpClientSimulator.Send("surbltest@test.com", "surbltest@test.com", "SURBL-Match", "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-"); - sMessageContents = POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); + sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); if (!sMessageContents.Contains("X-hMailServer-Spam") || !sMessageContents.Contains("X-hMailServer-Reason") || !sMessageContents.Contains("ThisIsSpam")) @@ -453,12 +450,12 @@ public void TestSURBLCombinedWithSignature() oSURBLServer.Save(); // Send a messages to this account. - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); - oSMTP.Send("surbltest@test.com", "surbltest@test.com", "SURBL-No-Match", + smtpClientSimulator.Send("surbltest@test.com", "surbltest@test.com", "SURBL-No-Match", "This is a test message without a SURBL url."); - string sMessageContents = POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); + string sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); if (sMessageContents.Length == 0 || sMessageContents.Contains("X-hMailServer-Spam") || sMessageContents.Contains("X-hMailServer-Reason") || @@ -467,10 +464,10 @@ public void TestSURBLCombinedWithSignature() Assert.IsTrue(sMessageContents.Contains(_domain.SignaturePlainText)); - oSMTP.Send("surbltest@test.com", "surbltest@test.com", "SURBL-No-Match", + smtpClientSimulator.Send("surbltest@test.com", "surbltest@test.com", "SURBL-No-Match", "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-"); - sMessageContents = POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); + sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); if (!sMessageContents.Contains("X-hMailServer-Spam") || !sMessageContents.Contains("X-hMailServer-Reason") || !sMessageContents.Contains("ThisIsSpam")) @@ -499,10 +496,10 @@ public void TestSURBLCorrectNegative() oSURBLServer.Save(); // Send a messages to this account. - Assert.IsTrue(SMTPClientSimulator.StaticSend("surbltest@test.com", "surbltest@test.com", "SURBL-Match", - "This is a test message without a SURBL url: -> http://www.youtube.com/ <-")); + SmtpClientSimulator.StaticSend("surbltest@test.com", "surbltest@test.com", "SURBL-Match", + "This is a test message without a SURBL url: -> http://www.youtube.com/ <-"); - string sMessageContents = POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); + string sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); if (sMessageContents.Contains("X-hMailServer-Spam")) throw new Exception("Non-spam message detected as spam"); @@ -532,12 +529,12 @@ public void TestSURBLWithWrappedURL() oSURBLServer.Save(); // Send a messages to this account. - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); - oSMTP.Send("surbltest@test.com", "surbltest@test.com", "SURBL-Match", + smtpClientSimulator.Send("surbltest@test.com", "surbltest@test.com", "SURBL-Match", "Wrapped URL - Test"); - string sMessageContents = POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); + string sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); Assert.IsTrue(sMessageContents.Contains("X-hMailServer-Spam"), "Spam message not detected as spam"); oSURBLServer.Active = false; @@ -566,12 +563,12 @@ public void TestSingleLineUrlFollowedByNewline() oSURBLServer.Save(); // Send a messages to this account. - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); - oSMTP.Send("surbltest@test.com", "surbltest@test.com", "SURBL-Match", + smtpClientSimulator.Send("surbltest@test.com", "surbltest@test.com", "SURBL-Match", "Wrapped URL - Test"); - string sMessageContents = POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); + string sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); Assert.IsTrue(sMessageContents.Contains("X-hMailServer-Spam"), "Spam message not detected as spam"); oSURBLServer.Active = false; @@ -600,12 +597,12 @@ public void TestSurblMultipleAddresses() oSURBLServer.Save(); // Send a messages to this account. - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); - oSMTP.Send("surbltest@test.com", "surbltest@test.com", "SURBL-Match", + smtpClientSimulator.Send("surbltest@test.com", "surbltest@test.com", "SURBL-Match", "Wrapped URL - Test\r\nWrapped URL - Test\r\nWrapped URL - Test\r\n"); - string sMessageContents = POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); + string sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); Assert.IsTrue(sMessageContents.Contains("X-hMailServer-Spam"), "Spam message not detected as spam"); oSURBLServer.Active = false; @@ -637,9 +634,9 @@ public void TestSurblAddressEndingWithSingleQuote() oSURBLServer.Save(); // Send a messages to this account. - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); - oSMTP.Send("surbltest@test.com", "surbltest@test.com", "SURBL-Match", + smtpClientSimulator.Send("surbltest@test.com", "surbltest@test.com", "SURBL-Match", "Wrapped URL - Test\r\n"); oSURBLServer.Active = false; @@ -673,12 +670,12 @@ public void TestSurblMultipleNegatives() oSURBLServer.Save(); // Send a messages to this account. - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); - oSMTP.Send("surbltest@test.com", "surbltest@test.com", "SURBL-Match", + smtpClientSimulator.Send("surbltest@test.com", "surbltest@test.com", "SURBL-Match", "Wrapped URL - Test\r\nWrapped URL - Test\r\nWrapped URL - Test\r\n"); - string sMessageContents = POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); + string sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); Assert.IsFalse(sMessageContents.Contains("X-hMailServer-Spam"), "Spam message not detected as spam"); oSURBLServer.Active = false; @@ -713,11 +710,11 @@ public void SurblTestRealWorldBody1() oSURBLServer.Save(); // Send a messages to this account. - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); - oSMTP.Send("surbltest@test.com", "surbltest@test.com", "SURBL-Match", TestResources.SecuniaBody1); + smtpClientSimulator.Send("surbltest@test.com", "surbltest@test.com", "SURBL-Match", TestResources.SecuniaBody1); - string sMessageContents = POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); + string sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); Assert.IsFalse(sMessageContents.Contains("X-hMailServer-Spam"), "Spam message not detected as spam"); oSURBLServer.Active = false; diff --git a/hmailserver/test/RegressionTests/AntiSpam/Combinations.cs b/hmailserver/test/RegressionTests/AntiSpam/Combinations.cs index 337d4d64f..e7f34d860 100644 --- a/hmailserver/test/RegressionTests/AntiSpam/Combinations.cs +++ b/hmailserver/test/RegressionTests/AntiSpam/Combinations.cs @@ -1,6 +1,7 @@ // Copyright (c) 2010 Martin Knafve / hMailServer.com. // http://www.hmailserver.com +using System; using NUnit.Framework; using RegressionTests.Infrastructure; using RegressionTests.Shared; @@ -50,14 +51,14 @@ public void TestDeleteThresholdLowerThanMarkThreshold() // Send a messages to this account, containing both incorrect MX records an SURBL-hits. // We should only detect one of these two: - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); // Should not be possible to send this email since it's results in a spam // score over the delete threshold. - Assert.IsTrue(oSMTP.Send("test@example.com", oAccount1.Address, "INBOX", - "Test http://surbl-org-permanent-test-point.com/ Test 2")); + smtpClientSimulator.Send("test@example.com", oAccount1.Address, "INBOX", + "Test http://surbl-org-permanent-test-point.com/ Test 2"); - string message = POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); + string message = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); Assert.IsTrue(message.Contains("X-hMailServer-Reason-1:")); Assert.IsTrue(message.Contains("X-hMailServer-Reason-2:")); @@ -88,14 +89,14 @@ public void TestOneFailOnePass() // Send a messages to this account, containing both incorrect MX records an SURBL-hits. // We should only detect one of these two: - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); // Should not be possible to send this email since it's results in a spam // score over the delete threshold. - Assert.IsTrue(oSMTP.Send("test@domain_without_mx_records421dfsam430sasd.com", oAccount1.Address, "INBOX", - "This is a test message.")); + smtpClientSimulator.Send("test@domain_without_mx_records421dfsam430sasd.com", oAccount1.Address, "INBOX", + "This is a test message."); - string message = POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); + string message = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); Assert.IsTrue(message.Contains("X-hMailServer-Reason-1:")); Assert.IsFalse(message.Contains("X-hMailServer-Reason-2:")); @@ -132,7 +133,7 @@ public void TestSpamMultipleHits() // Send a messages to this account, containing both incorrect MX records an SURBL-hits. // We should only detect one of these two: - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); _settings.Logging.LogSMTP = true; _settings.Logging.LogDebug = true; @@ -144,7 +145,7 @@ public void TestSpamMultipleHits() // Should not be possible to send this email since it's results in a spam // score over the delete threshold. - Assert.IsFalse(oSMTP.Send("test@domain_without_mx_records421dfsam430sasd.com", oAccount1.Address, "INBOX", + CustomAsserts.Throws(() => smtpClientSimulator.Send("test@domain_without_mx_records421dfsam430sasd.com", oAccount1.Address, "INBOX", "This is a test message. It contains incorrect MX records and a SURBL string: http://surbl-org-permanent-test-point.com/ SpamAssassinString: XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X")); liveLog = _settings.Logging.LiveLog; diff --git a/hmailserver/test/RegressionTests/AntiSpam/DKIM/Signing.cs b/hmailserver/test/RegressionTests/AntiSpam/DKIM/Signing.cs index ef92df0d3..79421529d 100644 --- a/hmailserver/test/RegressionTests/AntiSpam/DKIM/Signing.cs +++ b/hmailserver/test/RegressionTests/AntiSpam/DKIM/Signing.cs @@ -51,7 +51,7 @@ private string SendMessage(string body) deliveryResults["test@example.com"] = 250; int port = TestSetup.GetNextFreePort(); - using (var server = new SMTPServerSimulator(1, port)) + using (var server = new SmtpServerSimulator(1, port)) { server.SecondsToWaitBeforeTerminate = 60; server.AddRecipientResult(deliveryResults); @@ -61,10 +61,10 @@ private string SendMessage(string body) AddRoutePointingAtLocalhost(5, port); // Send message to this route. - var smtp = new SMTPClientSimulator(); + var smtp = new SmtpClientSimulator(); var recipients = new List(); recipients.Add("test@example.com"); - Assert.IsTrue(smtp.Send("test@test.com", recipients, "Test", body)); + smtp.Send("test@test.com", recipients, "Test", body); // Wait for the client to disconnect. server.WaitForCompletion(); diff --git a/hmailserver/test/RegressionTests/AntiSpam/DKIM/Verification.cs b/hmailserver/test/RegressionTests/AntiSpam/DKIM/Verification.cs index 7171086fa..6eda839e0 100644 --- a/hmailserver/test/RegressionTests/AntiSpam/DKIM/Verification.cs +++ b/hmailserver/test/RegressionTests/AntiSpam/DKIM/Verification.cs @@ -1,7 +1,9 @@ // Copyright (c) 2010 Martin Knafve / hMailServer.com. // http://www.hmailserver.com +using System; using NUnit.Framework; +using RegressionTests.Infrastructure; using RegressionTests.Shared; using hMailServer; @@ -59,7 +61,7 @@ public void TestInvalidBodyHash() "" + "\r\n"; Account account1 = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - Assert.IsFalse(SMTPClientSimulator.StaticSendRaw(account1.Address, account1.Address, messageText)); + CustomAsserts.Throws(() => SmtpClientSimulator.StaticSendRaw(account1.Address, account1.Address, messageText)); } [Test] @@ -99,8 +101,8 @@ public void TestInvalidBodyHashMark() "" + "\r\n"; Account account1 = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - Assert.IsTrue(SMTPClientSimulator.StaticSendRaw(account1.Address, account1.Address, messageText)); - string text = POP3ClientSimulator.AssertGetFirstMessageText(account1.Address, "test"); + SmtpClientSimulator.StaticSendRaw(account1.Address, account1.Address, messageText); + string text = Pop3ClientSimulator.AssertGetFirstMessageText(account1.Address, "test"); Assert.IsTrue(text.Contains("Rejected by DKIM. - (Score: 6)")); } @@ -140,7 +142,7 @@ public void TestInvalidSignature() "" + "\r\n"; Account account1 = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - Assert.IsFalse(SMTPClientSimulator.StaticSendRaw(account1.Address, account1.Address, messageText)); + CustomAsserts.Throws(() => SmtpClientSimulator.StaticSendRaw(account1.Address, account1.Address, messageText)); } [Test] @@ -178,8 +180,8 @@ public void TestValidSignatureSHA1() "" + "\r\n"; Account account1 = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - Assert.IsTrue(SMTPClientSimulator.StaticSendRaw(account1.Address, account1.Address, messageText)); - string text = POP3ClientSimulator.AssertGetFirstMessageText(account1.Address, "test"); + SmtpClientSimulator.StaticSendRaw(account1.Address, account1.Address, messageText); + string text = Pop3ClientSimulator.AssertGetFirstMessageText(account1.Address, "test"); } [Test] @@ -217,8 +219,8 @@ public void TestValidSignatureSHA256() "The quick brown fox jumped over the lazy dog." + "\r\n"; Account account1 = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - Assert.IsTrue(SMTPClientSimulator.StaticSendRaw(account1.Address, account1.Address, messageText)); - string text = POP3ClientSimulator.AssertGetFirstMessageText(account1.Address, "test"); + SmtpClientSimulator.StaticSendRaw(account1.Address, account1.Address, messageText); + string text = Pop3ClientSimulator.AssertGetFirstMessageText(account1.Address, "test"); } } } \ No newline at end of file diff --git a/hmailserver/test/RegressionTests/AntiSpam/GreyListing.cs b/hmailserver/test/RegressionTests/AntiSpam/GreyListing.cs index c3cb67df8..29a29a5c1 100644 --- a/hmailserver/test/RegressionTests/AntiSpam/GreyListing.cs +++ b/hmailserver/test/RegressionTests/AntiSpam/GreyListing.cs @@ -1,8 +1,10 @@ // Copyright (c) 2010 Martin Knafve / hMailServer.com. // http://www.hmailserver.com +using System; using System.Collections.Generic; using NUnit.Framework; +using RegressionTests.Infrastructure; using RegressionTests.Shared; using hMailServer; @@ -31,15 +33,16 @@ public void ItShouldBePossibleToBypassGreylistingOnMessagesArrivingFromMXorA() _antiSpam.GreyListingEnabled = true; - Assert.IsFalse(SMTPClientSimulator.StaticSend("test@localhost.hmailserver.com", oAccount1.Address, "Test", - "Body")); + CustomAsserts.Throws( + () => SmtpClientSimulator.StaticSend("test@localhost.hmailserver.com", oAccount1.Address, "Test", + "Body")); _antiSpam.BypassGreylistingOnMailFromMX = true; - Assert.IsTrue(SMTPClientSimulator.StaticSend("test@localhost.hmailserver.com", oAccount1.Address, "Test", - "Body")); + SmtpClientSimulator.StaticSend("test@localhost.hmailserver.com", oAccount1.Address, "Test", + "Body"); - POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); + Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); } [Test] @@ -49,23 +52,23 @@ public void TestGreyListing() Account oAccount1 = SingletonProvider.Instance.AddAccount(_domain, "grey@test.com", "test"); - var smtp = new SMTPClientSimulator(); + var smtp = new SmtpClientSimulator(); var recipients = new List(); recipients.Add(oAccount1.Address); - bool result = smtp.Send("test@test.com", recipients, "Test", "Body"); - Assert.IsTrue(result); - POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); + smtp.Send("test@test.com", recipients, "Test", "Body"); + + Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); _antiSpam.GreyListingEnabled = true; - result = smtp.Send("test@test.com", recipients, "Test", "Body"); - Assert.IsFalse(result); + CustomAsserts.Throws(() => smtp.Send("test@test.com", recipients, "Test", "Body")); + _antiSpam.GreyListingEnabled = false; - result = smtp.Send("test@test.com", recipients, "Test", "Body"); - Assert.IsTrue(result); - POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); + smtp.Send("test@test.com", recipients, "Test", "Body"); + + Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); } [Test] @@ -80,14 +83,14 @@ public void TestGreyListingWhiteListWildcard() whiteAddress.IPAddress = "127.0.0.5"; whiteAddress.Save(); - Assert.IsFalse(SMTPClientSimulator.StaticSend("external@example.com", account.Address, "Test", "Test")); + CustomAsserts.Throws(() => SmtpClientSimulator.StaticSend("external@example.com", account.Address, "Test", "Test")); whiteAddress.IPAddress = "*"; whiteAddress.Save(); - Assert.IsTrue(SMTPClientSimulator.StaticSend("external@example.com", account.Address, "Test", "Test")); + SmtpClientSimulator.StaticSend("external@example.com", account.Address, "Test", "Test"); - POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); + Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); } [Test] @@ -97,24 +100,24 @@ public void TestGreyListingWithDomainAliases() Account oAccount1 = SingletonProvider.Instance.AddAccount(_domain, "grey@test.com", "test"); - var smtp = new SMTPClientSimulator(); + var smtp = new SmtpClientSimulator(); var recipients = new List(); recipients.Add(oAccount1.Address); - bool result = smtp.Send("test@test.com", recipients, "Test", "Body"); - Assert.IsTrue(result); - POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); + smtp.Send("test@test.com", recipients, "Test", "Body"); + + Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); _antiSpam.GreyListingEnabled = true; - result = smtp.Send("test@test.com", recipients, "Test", "Body"); - Assert.IsFalse(result); + CustomAsserts.Throws(() => smtp.Send("test@test.com", recipients, "Test", "Body")); + _domain.AntiSpamEnableGreylisting = false; _domain.Save(); - result = smtp.Send("test@test.com", recipients, "Test", "Body"); - Assert.IsTrue(result); - POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); + smtp.Send("test@test.com", recipients, "Test", "Body"); + + Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); DomainAlias da = _domain.DomainAliases.Add(); da.AliasName = "test2.com"; @@ -123,15 +126,13 @@ public void TestGreyListingWithDomainAliases() recipients = new List(); recipients.Add("grey@test2.com"); - result = smtp.Send("test@test.com", recipients, "Test", "Body"); - Assert.IsTrue(result); - POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); + smtp.Send("test@test.com", recipients, "Test", "Body"); + Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); _domain.AntiSpamEnableGreylisting = true; _domain.Save(); - result = smtp.Send("test@test.com", recipients, "Test", "Body"); - Assert.IsFalse(result); + CustomAsserts.Throws(() => smtp.Send("test@test.com", recipients, "Test", "Body")); } } } \ No newline at end of file diff --git a/hmailserver/test/RegressionTests/AntiSpam/SpamAssassin.cs b/hmailserver/test/RegressionTests/AntiSpam/SpamAssassin.cs index eb28b652c..579f987e7 100644 --- a/hmailserver/test/RegressionTests/AntiSpam/SpamAssassin.cs +++ b/hmailserver/test/RegressionTests/AntiSpam/SpamAssassin.cs @@ -73,10 +73,10 @@ public void ItShouldBePossibleToTestSAConnectionUsingAPIFailure() public void TestBasic() { // Send a messages to this account. - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); - Assert.IsTrue(oSMTP.Send(account.Address, account.Address, "SA test", "This is a test message.")); - string sMessageContents = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); + smtpClientSimulator.Send(account.Address, account.Address, "SA test", "This is a test message."); + string sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); if (!sMessageContents.Contains("X-Spam-Status")) { Assert.Fail("SpamAssassin did not run"); @@ -86,13 +86,13 @@ public void TestBasic() [Test] public void TestDisabled() { - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); _settings.AntiSpam.SpamAssassinEnabled = false; _settings.AntiSpam.SpamAssassinHost = "localhost"; - oSMTP.Send(account.Address, account.Address, "SA test", "This is a test message."); + smtpClientSimulator.Send(account.Address, account.Address, "SA test", "This is a test message."); - string sMessageContents = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); + string sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); if (sMessageContents.Contains("X-Spam-Status")) { _settings.AntiSpam.SpamAssassinEnabled = false; @@ -103,12 +103,12 @@ public void TestDisabled() [Test] public void TestIncorrectHost() { - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); _settings.AntiSpam.SpamAssassinEnabled = true; _settings.AntiSpam.SpamAssassinHost = "localholst"; // <- mispelled - oSMTP.Send(account.Address, account.Address, "SA test", "This is a test message."); - string sMessageContents = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); + smtpClientSimulator.Send(account.Address, account.Address, "SA test", "This is a test message."); + string sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); if (sMessageContents.Contains("X-Spam-Status")) { _settings.AntiSpam.SpamAssassinEnabled = false; @@ -121,14 +121,14 @@ public void TestIncorrectHost() [Test] public void TestIncorrectPort() { - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); _settings.AntiSpam.SpamAssassinEnabled = true; _settings.AntiSpam.SpamAssassinHost = "localhost"; // <- mispelled _settings.AntiSpam.SpamAssassinPort = 12345; - oSMTP.Send(account.Address, account.Address, "SA test", "This is a test message."); - string sMessageContents = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); + smtpClientSimulator.Send(account.Address, account.Address, "SA test", "This is a test message."); + string sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); if (sMessageContents.Contains("X-Spam-Status")) { _settings.AntiSpam.SpamAssassinEnabled = false; @@ -141,12 +141,12 @@ public void TestIncorrectPort() [Test] public void TestIpAddressAsHostName() { - var smtpClientSimulator = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); _settings.AntiSpam.SpamAssassinEnabled = true; _settings.AntiSpam.SpamAssassinHost = "127.0.0.1"; smtpClientSimulator.Send(account.Address, account.Address, "SA test", "This is a test message."); - string messageContents = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); + string messageContents = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); if (!messageContents.Contains("X-Spam-Status")) { @@ -160,12 +160,12 @@ public void TestIpAddressAsHostName() public void TestMessageScore() { // Send a messages to this account. - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); - oSMTP.Send(account.Address, account.Address, "SA test", + smtpClientSimulator.Send(account.Address, account.Address, "SA test", "This is a test message with spam.\r\n XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X."); - string sMessageContents = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); + string sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); int scoreStart = sMessageContents.IndexOf("X-Spam-Status: Yes, score") + "X-Spam-Status: Yes, score".Length + 1; @@ -182,12 +182,12 @@ public void TestMessageScore() public void TestMessageScoreNotMerged() { // Send a messages to this account. - var smtpClientSimulator = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); smtpClientSimulator.Send(account.Address, account.Address, "SA test", "This is a test message with spam.\r\n XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X."); - string sMessageContents = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); + string sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); int scoreStart = sMessageContents.IndexOf("X-hMailServer-Reason-Score"); Assert.AreNotEqual(0, scoreStart); @@ -207,10 +207,10 @@ public void TestSANotRunning() StopSpamAssassin(); // Send a messages to this account. - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); - Assert.IsTrue(oSMTP.Send(account.Address, account.Address, "SA test", "This is a test message.")); - string sMessageContents = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); + smtpClientSimulator.Send(account.Address, account.Address, "SA test", "This is a test message."); + string sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); Assert.IsFalse(sMessageContents.Contains("X-Spam-Status")); @@ -224,12 +224,12 @@ public void TestScoreMerge() _settings.AntiSpam.SpamAssassinMergeScore = true; // Send a messages to this account. - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); - oSMTP.Send(account.Address, account.Address, "SA test", + smtpClientSimulator.Send(account.Address, account.Address, "SA test", "This is a test message with spam.\r\n XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X."); - string sMessageContents = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); + string sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); int scoreStart = sMessageContents.IndexOf("X-hMailServer-Reason-Score"); Assert.AreNotEqual(-1, scoreStart, sMessageContents); @@ -259,12 +259,12 @@ public void TestScoreMerge() public void TestSpamMessage() { // Send a messages to this account. - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); - oSMTP.Send(account.Address, account.Address, "SA test", + smtpClientSimulator.Send(account.Address, account.Address, "SA test", "This is a test message with spam.\r\n XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X."); - string sMessageContents = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); + string sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); if (!sMessageContents.Contains("X-Spam-Status: Yes")) Assert.Fail("Spam message not treated as spam (no X-Spam-Status-header)."); @@ -283,11 +283,11 @@ public void TestSpamMessage() public void MessageHeaderShouldBeValidAfterSAHasRun() { // Send a messages to this account. - var smtpClient = new SMTPClientSimulator(); + var smtpClient = new SmtpClientSimulator(); smtpClient.Send(account.Address, account.Address, "SA test", "This is a test message with spam.\r\n XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X."); - string fullMessage = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); + string fullMessage = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); string messageHeader = fullMessage.Substring(0, fullMessage.IndexOf("\r\n\r\n")); Assert.IsTrue(messageHeader.Contains("Received:")); @@ -310,11 +310,11 @@ public void TestWhiteList() // Send a messages to this account. - var oSMTP = new SMTPClientSimulator(); - oSMTP.Send("test-sender@test.com", account.Address, "SA test", + var smtpClientSimulator = new SmtpClientSimulator(); + smtpClientSimulator.Send("test-sender@test.com", account.Address, "SA test", "This is a test message with spam.\r\n XJS*C4JDBQADN1.NSBN3*2IDNEN*GTUBE-STANDARD-ANTI-UBE-TEST-EMAIL*C.34X."); - string sMessageContents = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); + string sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); Assert.IsFalse(sMessageContents.Contains("X-Spam-Status: Yes")); } diff --git a/hmailserver/test/RegressionTests/AntiSpam/Whitelisting.cs b/hmailserver/test/RegressionTests/AntiSpam/Whitelisting.cs index f9e7b855b..05aa4ca8d 100644 --- a/hmailserver/test/RegressionTests/AntiSpam/Whitelisting.cs +++ b/hmailserver/test/RegressionTests/AntiSpam/Whitelisting.cs @@ -5,6 +5,7 @@ using System.Net; using System.Collections.Generic; using NUnit.Framework; +using RegressionTests.Infrastructure; using RegressionTests.Shared; using hMailServer; @@ -58,16 +59,16 @@ public void TestEnabled() oSURBLServer.Save(); // Send a messages to this account. - Assert.IsTrue(SMTPClientSimulator.StaticSend("whitelist@microsoft.com", "whitelist@test.com", "SURBL-Match", - "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-")); + SmtpClientSimulator.StaticSend("whitelist@microsoft.com", "whitelist@test.com", "SURBL-Match", + "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-"); obAddresses.DeleteByDBID(obAddress.ID); // Check that it's detected as spam again. - Assert.IsFalse(SMTPClientSimulator.StaticSend("whitelist@microsoft.com", "whitelist@test.com", "SURBL-Match", + CustomAsserts.Throws(() => SmtpClientSimulator.StaticSend("whitelist@microsoft.com", "whitelist@test.com", "SURBL-Match", "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-")); - POP3ClientSimulator.AssertMessageCount("whitelist@test.com", "test", 1); + Pop3ClientSimulator.AssertMessageCount("whitelist@test.com", "test", 1); } [Test] @@ -112,18 +113,18 @@ public void TestHelo() oSURBLServer.Save(); // Send a messages to this account. - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); - Assert.IsTrue(oSMTP.Send("whitelist@microsoft.com", "whitelist@test.com", "SURBL-Match", - "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-")); + smtpClientSimulator.Send("whitelist@microsoft.com", "whitelist@test.com", "SURBL-Match", + "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-"); obAddresses.DeleteByDBID(obAddress.ID); // Check that it's deteceted as spam again. - Assert.IsFalse(oSMTP.Send("whitelist@microsoft.com", "whitelist@test.com", "SURBL-Match", + CustomAsserts.Throws(() => smtpClientSimulator.Send("whitelist@microsoft.com", "whitelist@test.com", "SURBL-Match", "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-")); - POP3ClientSimulator.AssertMessageCount("whitelist@test.com", "test", 1); + Pop3ClientSimulator.AssertMessageCount("whitelist@test.com", "test", 1); } [Test] @@ -145,12 +146,13 @@ public void TestWildcardEscapeChar() oSURBLServer.Save(); // Send a messages to this account. - Assert.IsTrue(SMTPClientSimulator.StaticSend("white/list@microsoft.com", "whitelist@test.com", "SURBL-Match", - "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-")); - Assert.IsFalse(SMTPClientSimulator.StaticSend("whitelist@microsoft.com", "whitelist@test.com", "SURBL-Match", + SmtpClientSimulator.StaticSend("white/list@microsoft.com", "whitelist@test.com", "SURBL-Match", + "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-"); + + CustomAsserts.Throws(() => SmtpClientSimulator.StaticSend("whitelist@microsoft.com", "whitelist@test.com", "SURBL-Match", "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-")); - POP3ClientSimulator.AssertMessageCount("whitelist@test.com", "test", 1); + Pop3ClientSimulator.AssertMessageCount("whitelist@test.com", "test", 1); } [Test] @@ -172,17 +174,18 @@ public void TestWildcardEscapedCharacters() oSURBLServer.Save(); // Send a messages to this account. - Assert.IsTrue(SMTPClientSimulator.StaticSend("white%list@micro_soft.com", "whitelist@test.com", + SmtpClientSimulator.StaticSend("white%list@micro_soft.com", "whitelist@test.com", "SURBL-Match", - "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-")); - Assert.IsFalse(SMTPClientSimulator.StaticSend("whiteAlist@micro_soft.com", "whitelist@test.com", + "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-"); + CustomAsserts.Throws(() => SmtpClientSimulator.StaticSend("whiteAlist@micro_soft.com", "whitelist@test.com", "SURBL-Match", "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-")); - Assert.IsFalse(SMTPClientSimulator.StaticSend("whiteAlist@microEsoft.com", "whitelist@test.com", + + CustomAsserts.Throws(() => SmtpClientSimulator.StaticSend("whiteAlist@microEsoft.com", "whitelist@test.com", "SURBL-Match", "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-")); - POP3ClientSimulator.AssertMessageCount("whitelist@test.com", "test", 1); + Pop3ClientSimulator.AssertMessageCount("whitelist@test.com", "test", 1); } [Test] @@ -205,16 +208,16 @@ public void TestWildcardQuestionMark() oSURBLServer.Save(); // Send a messages to this account. - Assert.IsTrue(SMTPClientSimulator.StaticSend("whitelist@microsoft.com", "whitelist@test.com", "SURBL-Match", - "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-")); - Assert.IsFalse(SMTPClientSimulator.StaticSend("whitelist@icrosoft.com", "whitelist@test.com", "SURBL-Match", + SmtpClientSimulator.StaticSend("whitelist@microsoft.com", "whitelist@test.com", "SURBL-Match", + "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-"); + CustomAsserts.Throws(() => SmtpClientSimulator.StaticSend("whitelist@icrosoft.com", "whitelist@test.com", "SURBL-Match", "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-")); - Assert.IsTrue(SMTPClientSimulator.StaticSend("whitelist@microsoft.com", "whitelist@test.com", "SURBL-Match", - "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-")); - Assert.IsFalse(SMTPClientSimulator.StaticSend("whitelist@icrosoft.com", "whitelist@test.com", "SURBL-Match", + SmtpClientSimulator.StaticSend("whitelist@microsoft.com", "whitelist@test.com", "SURBL-Match", + "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-"); + CustomAsserts.Throws(() => SmtpClientSimulator.StaticSend("whitelist@icrosoft.com", "whitelist@test.com", "SURBL-Match", "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-")); - POP3ClientSimulator.AssertMessageCount("whitelist@test.com", "test", 2); + Pop3ClientSimulator.AssertMessageCount("whitelist@test.com", "test", 2); } @@ -237,14 +240,14 @@ public void TestWildcardSingleQuote() oSURBLServer.Save(); // Send a messages to this account. - Assert.IsTrue(SMTPClientSimulator.StaticSend("white'list@micro_soft.com", "whitelist@test.com", + SmtpClientSimulator.StaticSend("white'list@micro_soft.com", "whitelist@test.com", "SURBL-Match", - "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-")); - Assert.IsFalse(SMTPClientSimulator.StaticSend("whitelist@micro_soft.com", "whitelist@test.com", + "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-"); + CustomAsserts.Throws(() => SmtpClientSimulator.StaticSend("whitelist@micro_soft.com", "whitelist@test.com", "SURBL-Match", "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-")); - POP3ClientSimulator.AssertMessageCount("whitelist@test.com", "test", 1); + Pop3ClientSimulator.AssertMessageCount("whitelist@test.com", "test", 1); } [Test] @@ -266,18 +269,18 @@ public void TestWildcardStar() oSURBLServer.Save(); // Send a messages to this account. - Assert.IsTrue(SMTPClientSimulator.StaticSend("whitelist@microsoft.com", "whitelist@test.com", "SURBL-Match", - "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-")); - Assert.IsFalse(SMTPClientSimulator.StaticSend("blacklist@microsoft.com", "whitelist@test.com", "SURBL-Match", + SmtpClientSimulator.StaticSend("whitelist@microsoft.com", "whitelist@test.com", "SURBL-Match", + "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-"); + CustomAsserts.Throws(() => SmtpClientSimulator.StaticSend("blacklist@microsoft.com", "whitelist@test.com", "SURBL-Match", "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-")); - Assert.IsTrue(SMTPClientSimulator.StaticSend("whitesomething@microsoft.com", "whitelist@test.com", + SmtpClientSimulator.StaticSend("whitesomething@microsoft.com", "whitelist@test.com", "SURBL-Match", - "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-")); - Assert.IsFalse(SMTPClientSimulator.StaticSend("blacksomething@microsoft.com", "whitelist@test.com", + "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-"); + CustomAsserts.Throws(() => SmtpClientSimulator.StaticSend("blacksomething@microsoft.com", "whitelist@test.com", "SURBL-Match", "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-")); - POP3ClientSimulator.AssertMessageCount("whitelist@test.com", "test", 2); + Pop3ClientSimulator.AssertMessageCount("whitelist@test.com", "test", 2); } [Test] @@ -326,8 +329,8 @@ public void TestWhitelistSpecificIPv6Address() oSURBLServer.Save(); // Make sure we are now blacklisted. - var smtpClient = new SMTPClientSimulator(false, 25, IPAddress.Parse(firstAddress)); - Assert.IsFalse(smtpClient.Send("user@example.com", "whitelist@test.com", "Hello", SurblTestPointBody)); + var smtpClient = new SmtpClientSimulator(false, 25, IPAddress.Parse(firstAddress)); + CustomAsserts.Throws(() => smtpClient.Send("user@example.com", "whitelist@test.com", "Hello", SurblTestPointBody)); // White list all IPv6 addresses foreach (var address in addresses) @@ -341,9 +344,9 @@ public void TestWhitelistSpecificIPv6Address() } // Make sure we can now send again. - Assert.IsTrue(smtpClient.Send("user@example.com", "whitelist@test.com", "Hello", SurblTestPointBody)); + smtpClient.Send("user@example.com", "whitelist@test.com", "Hello", SurblTestPointBody); - POP3ClientSimulator.AssertMessageCount("whitelist@test.com", "test", 1); + Pop3ClientSimulator.AssertMessageCount("whitelist@test.com", "test", 1); } [Test] @@ -392,8 +395,8 @@ public void TestWhitelistOutOfRangeIPv6Address() oSURBLServer.Save(); // Make sure we are now blacklisted. - var smtpClient = new SMTPClientSimulator(false, 25, IPAddress.Parse(firstAddress)); - Assert.IsFalse(smtpClient.Send("user@example.com", "whitelist@test.com", "Hello", SurblTestPointBody)); + var smtpClient = new SmtpClientSimulator(false, 25, IPAddress.Parse(firstAddress)); + CustomAsserts.Throws(() => smtpClient.Send("user@example.com", "whitelist@test.com", "Hello", SurblTestPointBody)); // White list all IPv6 addresses var obAddress = _antiSpam.WhiteListAddresses.Add(); @@ -404,7 +407,7 @@ public void TestWhitelistOutOfRangeIPv6Address() obAddress.Save(); // Make sure we can now send again. - Assert.IsFalse(smtpClient.Send("user@example.com", "whitelist@test.com", "Hello", SurblTestPointBody)); + CustomAsserts.Throws(() => smtpClient.Send("user@example.com", "whitelist@test.com", "Hello", SurblTestPointBody)); } [Test] @@ -420,8 +423,8 @@ public void TestWhitelistSpecificIpV4Address() oSURBLServer.Save(); // Make sure we are now blacklisted. - var smtpClient = new SMTPClientSimulator(false, 25, IPAddress.Parse(firstAddress)); - Assert.IsFalse(smtpClient.Send("user@example.com", "whitelist@test.com", "Hello", SurblTestPointBody)); + var smtpClient = new SmtpClientSimulator(false, 25, IPAddress.Parse(firstAddress)); + CustomAsserts.Throws(() => smtpClient.Send("user@example.com", "whitelist@test.com", "Hello", SurblTestPointBody)); // White list all IPv4 addresses foreach (var address in addresses) @@ -435,9 +438,9 @@ public void TestWhitelistSpecificIpV4Address() } // Make sure we can now send again. - Assert.IsTrue(smtpClient.Send("user@example.com", "whitelist@test.com", "Hello", SurblTestPointBody)); + smtpClient.Send("user@example.com", "whitelist@test.com", "Hello", SurblTestPointBody); - POP3ClientSimulator.AssertMessageCount("whitelist@test.com", "test", 1); + Pop3ClientSimulator.AssertMessageCount("whitelist@test.com", "test", 1); } [Test] @@ -450,8 +453,8 @@ public void TestWhitelistOutOfRangeAddress() oSURBLServer.Save(); // Make sure we are now blacklisted. - var smtpClient = new SMTPClientSimulator(false, 25); - Assert.IsFalse(smtpClient.Send("user@example.com", "whitelist@test.com", "Hello", SurblTestPointBody)); + var smtpClient = new SmtpClientSimulator(false, 25); + CustomAsserts.Throws(() => smtpClient.Send("user@example.com", "whitelist@test.com", "Hello", SurblTestPointBody)); // White list all IPv4 addresses var obAddress = _antiSpam.WhiteListAddresses.Add(); @@ -462,7 +465,7 @@ public void TestWhitelistOutOfRangeAddress() obAddress.Save(); // Make sure we are still blacklisted. - Assert.IsFalse(smtpClient.Send("user@example.com", "whitelist@test.com", "Hello", SurblTestPointBody)); + CustomAsserts.Throws(() => smtpClient.Send("user@example.com", "whitelist@test.com", "Hello", SurblTestPointBody)); } [Test] @@ -511,8 +514,8 @@ public void TestWhitelistAllIPv6Addresses() oSURBLServer.Save(); // Make sure we are now blacklisted. - var smtpClient = new SMTPClientSimulator(false, 25, IPAddress.Parse(firstAddress)); - Assert.IsFalse(smtpClient.Send("user@example.com", "whitelist@test.com", "Hello", SurblTestPointBody)); + var smtpClient = new SmtpClientSimulator(false, 25, IPAddress.Parse(firstAddress)); + CustomAsserts.Throws(() => smtpClient.Send("user@example.com", "whitelist@test.com", "Hello", SurblTestPointBody)); // White list all IPv6 addresses var obAddress = _antiSpam.WhiteListAddresses.Add(); @@ -523,9 +526,9 @@ public void TestWhitelistAllIPv6Addresses() obAddress.Save(); // Make sure we can now send again. - Assert.IsTrue(smtpClient.Send("user@example.com", "whitelist@test.com", "Hello", SurblTestPointBody)); + smtpClient.Send("user@example.com", "whitelist@test.com", "Hello", SurblTestPointBody); - POP3ClientSimulator.AssertMessageCount("whitelist@test.com", "test", 1); + Pop3ClientSimulator.AssertMessageCount("whitelist@test.com", "test", 1); } diff --git a/hmailserver/test/RegressionTests/AntiVirus/ClamAV.cs b/hmailserver/test/RegressionTests/AntiVirus/ClamAV.cs index be4e8c648..8d326cf17 100644 --- a/hmailserver/test/RegressionTests/AntiVirus/ClamAV.cs +++ b/hmailserver/test/RegressionTests/AntiVirus/ClamAV.cs @@ -29,8 +29,8 @@ public void TestIncorrectPort() _antiVirus.ClamAVPort = 110; Account account1 = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - Assert.IsTrue(SMTPClientSimulator.StaticSend(account1.Address, account1.Address, "Mail 1", "DummyBody")); - POP3ClientSimulator.AssertMessageCount(account1.Address, "test", 1); + SmtpClientSimulator.StaticSend(account1.Address, account1.Address, "Mail 1", "DummyBody"); + Pop3ClientSimulator.AssertMessageCount(account1.Address, "test", 1); CustomAsserts.AssertReportedError("Protocol error. Unexpected response: +OK"); } @@ -40,8 +40,8 @@ public void TestNoVirus() _antiVirus.ClamAVEnabled = true; Account account1 = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - Assert.IsTrue(SMTPClientSimulator.StaticSend(account1.Address, account1.Address, "Mail 1", "Mail 1")); - POP3ClientSimulator.AssertMessageCount(account1.Address, "test", 1); + SmtpClientSimulator.StaticSend(account1.Address, account1.Address, "Mail 1", "Mail 1"); + Pop3ClientSimulator.AssertMessageCount(account1.Address, "test", 1); } [Test] @@ -49,8 +49,8 @@ public void TestNotEnabled() { LogHandler.DeleteCurrentDefaultLog(); Account account1 = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - Assert.IsTrue(SMTPClientSimulator.StaticSend(account1.Address, account1.Address, "Mail 1", "Mail 1")); - POP3ClientSimulator.AssertMessageCount(account1.Address, "test", 1); + SmtpClientSimulator.StaticSend(account1.Address, account1.Address, "Mail 1", "Mail 1"); + Pop3ClientSimulator.AssertMessageCount(account1.Address, "test", 1); string defaultLog = LogHandler.ReadCurrentDefaultLog(); Assert.IsFalse(defaultLog.Contains("Connecting to ClamAV")); } @@ -62,8 +62,8 @@ public void TestUnusedPort() _antiVirus.ClamAVPort = 54391; Account account1 = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - Assert.IsTrue(SMTPClientSimulator.StaticSend(account1.Address, account1.Address, "Mail 1", "DummyBody")); - POP3ClientSimulator.AssertMessageCount(account1.Address, "test", 1); + SmtpClientSimulator.StaticSend(account1.Address, account1.Address, "Mail 1", "DummyBody"); + Pop3ClientSimulator.AssertMessageCount(account1.Address, "test", 1); CustomAsserts.AssertReportedError("Unable to connect to ClamAV server at localhost:54391."); } @@ -76,11 +76,11 @@ public void TestWithVirus() Account account1 = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); string firstPart = @"X5O!P%@AP[4\PZX54(P^)7CC)7}"; string secondPart = @"$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*"; - Assert.IsTrue(SMTPClientSimulator.StaticSend(account1.Address, account1.Address, "Mail 1", - firstPart + secondPart)); + SmtpClientSimulator.StaticSend(account1.Address, account1.Address, "Mail 1", + firstPart + secondPart); CustomAsserts.AssertRecipientsInDeliveryQueue(0); - POP3ClientSimulator.AssertMessageCount(account1.Address, "test", 0); + Pop3ClientSimulator.AssertMessageCount(account1.Address, "test", 0); string defaultLog = LogHandler.ReadCurrentDefaultLog(); Assert.IsTrue(defaultLog.Contains("Connecting to ClamAV")); diff --git a/hmailserver/test/RegressionTests/IMAP/ACL.cs b/hmailserver/test/RegressionTests/IMAP/ACL.cs index e6b364eb4..1d1ab3e86 100644 --- a/hmailserver/test/RegressionTests/IMAP/ACL.cs +++ b/hmailserver/test/RegressionTests/IMAP/ACL.cs @@ -30,11 +30,11 @@ public void ExamineFolderRequiresReadPermission() string selectResult = string.Empty; - var oSimulator1 = new IMAPClientSimulator(); - oSimulator1.Connect(); - oSimulator1.LogonWithLiteral(account1.Address, "test"); - string examineResult = oSimulator1.ExamineFolder("#Public.Share1"); - oSimulator1.Disconnect(); + var imapClientSimulator = new ImapClientSimulator(); + imapClientSimulator.Connect(); + imapClientSimulator.LogonWithLiteral(account1.Address, "test"); + string examineResult = imapClientSimulator.ExamineFolder("#Public.Share1"); + imapClientSimulator.Disconnect(); Assert.IsTrue(examineResult.Contains("ACL: Read permission denied (Required for EXAMINE command)."), examineResult); @@ -60,11 +60,11 @@ public void FolderMarkedAsReadOnlyWhenUserHasReadOnlyRights() string selectResult = string.Empty; - var oSimulator1 = new IMAPClientSimulator(); - oSimulator1.Connect(); - oSimulator1.LogonWithLiteral(account1.Address, "test"); - oSimulator1.SelectFolder("#Public.Share1", out selectResult); - oSimulator1.Disconnect(); + var imapClientSimulator = new ImapClientSimulator(); + imapClientSimulator.Connect(); + imapClientSimulator.LogonWithLiteral(account1.Address, "test"); + imapClientSimulator.SelectFolder("#Public.Share1", out selectResult); + imapClientSimulator.Disconnect(); Assert.IsTrue(selectResult.Contains("[READ-ONLY]"), selectResult); Assert.IsFalse(selectResult.Contains("[READ-WRITE]"), selectResult); @@ -91,11 +91,11 @@ public void FolderMarkedAsReadWriteWhenUserHasChangeRights() string selectResult = string.Empty; - var oSimulator1 = new IMAPClientSimulator(); - oSimulator1.Connect(); - oSimulator1.LogonWithLiteral(account1.Address, "test"); - oSimulator1.SelectFolder("#Public.Share1", out selectResult); - oSimulator1.Disconnect(); + var imapClientSimulator = new ImapClientSimulator(); + imapClientSimulator.Connect(); + imapClientSimulator.LogonWithLiteral(account1.Address, "test"); + imapClientSimulator.SelectFolder("#Public.Share1", out selectResult); + imapClientSimulator.Disconnect(); Assert.IsTrue(selectResult.Contains("[READ-WRITE]"), selectResult); Assert.IsFalse(selectResult.Contains("[READ-ONLY]"), selectResult); @@ -121,7 +121,7 @@ public void TestAppendToPublicFolder() permission.set_Permission(eACLPermission.ePermissionPost, true); permission.Save(); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.LogonWithLiteral(account.Address, "test"); @@ -149,25 +149,25 @@ public void TestCopyMessageToPublicFolder() string folderName = "#Public.Share1"; - SMTPClientSimulator.StaticSend("test@test.com", account1.Address, "TestMessage", "Body"); + SmtpClientSimulator.StaticSend("test@test.com", account1.Address, "TestMessage", "Body"); CustomAsserts.AssertFolderMessageCount(account1.IMAPFolders.get_ItemByName("INBOX"), 1); CustomAsserts.AssertFolderMessageCount(folder, 0); - var oSimulator1 = new IMAPClientSimulator(); - oSimulator1.Connect(); - oSimulator1.Logon(account1.Address, "test"); - oSimulator1.SelectFolder("INBOX"); + var imapClientSimulator = new ImapClientSimulator(); + imapClientSimulator.Connect(); + imapClientSimulator.Logon(account1.Address, "test"); + imapClientSimulator.SelectFolder("INBOX"); // This should fails since we don't have ACL Insert permission. - Assert.IsFalse(oSimulator1.Copy(1, folderName)); + Assert.IsFalse(imapClientSimulator.Copy(1, folderName)); // Give permission... permission.set_Permission(eACLPermission.ePermissionInsert, true); permission.Save(); - Assert.IsTrue(oSimulator1.Copy(1, folderName)); + Assert.IsTrue(imapClientSimulator.Copy(1, folderName)); - oSimulator1.Disconnect(); + imapClientSimulator.Disconnect(); CustomAsserts.AssertFolderMessageCount(folder, 1); } @@ -185,11 +185,11 @@ public void TestCreateFolderWithSameNameAsPublic() Account account1 = SingletonProvider.Instance.AddAccount(_domain, "account10@test.com", "test"); - var oSimulator1 = new IMAPClientSimulator(); - oSimulator1.Connect(); - oSimulator1.Logon(account1.Address, "test"); - Assert.IsFalse(oSimulator1.CreateFolder("MyPublic")); - oSimulator1.Disconnect(); + var imapClientSimulator = new ImapClientSimulator(); + imapClientSimulator.Connect(); + imapClientSimulator.Logon(account1.Address, "test"); + Assert.IsFalse(imapClientSimulator.CreateFolder("MyPublic")); + imapClientSimulator.Disconnect(); } finally { @@ -206,11 +206,11 @@ public void TestCreateRootSharedFolder() Account account1 = SingletonProvider.Instance.AddAccount(_domain, "account1c@test.com", "test"); Account account2 = SingletonProvider.Instance.AddAccount(_domain, "account2c@test.com", "test"); - var oSimulator1 = new IMAPClientSimulator(); - oSimulator1.Connect(); - oSimulator1.Logon(account1.Address, "test"); - Assert.IsFalse(oSimulator1.CreateFolder("#Public.SharedFolder")); - oSimulator1.Disconnect(); + var imapClientSimulator = new ImapClientSimulator(); + imapClientSimulator.Connect(); + imapClientSimulator.Logon(account1.Address, "test"); + Assert.IsFalse(imapClientSimulator.CreateFolder("#Public.SharedFolder")); + imapClientSimulator.Disconnect(); } @@ -234,18 +234,18 @@ public void TestDelete() permission.set_Permission(eACLPermission.ePermissionLookup, true); permission.Save(); - var oSimulator1 = new IMAPClientSimulator(); - oSimulator1.ConnectAndLogon("account9@test.com", "test"); - Assert.IsTrue(oSimulator1.SelectFolder("#public.Share1")); - Assert.IsFalse(oSimulator1.DeleteFolder("#public.Share1")); + var imapClientSimulator = new ImapClientSimulator(); + imapClientSimulator.ConnectAndLogon("account9@test.com", "test"); + Assert.IsTrue(imapClientSimulator.SelectFolder("#public.Share1")); + Assert.IsFalse(imapClientSimulator.DeleteFolder("#public.Share1")); permission.set_Permission(eACLPermission.ePermissionDeleteMailbox, true); permission.Save(); - Assert.IsTrue(oSimulator1.DeleteFolder("#public.Share1")); - Assert.IsFalse(oSimulator1.SelectFolder("#public.Share1")); + Assert.IsTrue(imapClientSimulator.DeleteFolder("#public.Share1")); + Assert.IsFalse(imapClientSimulator.SelectFolder("#public.Share1")); - oSimulator1.Disconnect(); + imapClientSimulator.Disconnect(); } @@ -302,22 +302,22 @@ public void TestDeleteCheckAPI() permission.set_Permission(eACLPermission.ePermissionLookup, true); permission.Save(); - var oSimulator1 = new IMAPClientSimulator(); - oSimulator1.ConnectAndLogon("account9@test.com", "test"); - Assert.IsTrue(oSimulator1.SelectFolder("#public.Share1")); - Assert.IsFalse(oSimulator1.DeleteFolder("#public.Share1")); + var imapClientSimulator = new ImapClientSimulator(); + imapClientSimulator.ConnectAndLogon("account9@test.com", "test"); + Assert.IsTrue(imapClientSimulator.SelectFolder("#public.Share1")); + Assert.IsFalse(imapClientSimulator.DeleteFolder("#public.Share1")); Assert.AreEqual(1, publicFolders.Count); permission.set_Permission(eACLPermission.ePermissionDeleteMailbox, true); permission.Save(); - Assert.IsTrue(oSimulator1.DeleteFolder("#public.Share1")); - Assert.IsFalse(oSimulator1.SelectFolder("#public.Share1")); + Assert.IsTrue(imapClientSimulator.DeleteFolder("#public.Share1")); + Assert.IsFalse(imapClientSimulator.SelectFolder("#public.Share1")); Assert.AreEqual(0, publicFolders.Count); - oSimulator1.Disconnect(); + imapClientSimulator.Disconnect(); } [Test] @@ -375,21 +375,21 @@ public void TestDeleteSubFolderCheckAPI() permission.set_Permission(eACLPermission.ePermissionLookup, true); permission.Save(); - var oSimulator1 = new IMAPClientSimulator(); - oSimulator1.ConnectAndLogon("account9@test.com", "test"); - Assert.IsTrue(oSimulator1.CreateFolder("#public.Share1.MySub")); + var imapClientSimulator = new ImapClientSimulator(); + imapClientSimulator.ConnectAndLogon("account9@test.com", "test"); + Assert.IsTrue(imapClientSimulator.CreateFolder("#public.Share1.MySub")); Assert.AreEqual(1, mySubFolders.Count); permission.set_Permission(eACLPermission.ePermissionDeleteMailbox, true); permission.Save(); - Assert.IsTrue(oSimulator1.DeleteFolder("#public.Share1.MySub")); - Assert.IsFalse(oSimulator1.SelectFolder("#public.Share1.MySub")); + Assert.IsTrue(imapClientSimulator.DeleteFolder("#public.Share1.MySub")); + Assert.IsFalse(imapClientSimulator.SelectFolder("#public.Share1.MySub")); Assert.AreEqual(0, mySubFolders.Count); Assert.AreEqual(1, publicFolders.Count); - oSimulator1.Disconnect(); + imapClientSimulator.Disconnect(); } [Test] @@ -428,11 +428,11 @@ public void TestDuplicateConflictingGroupPermission() string folderName = "#Public.Share1"; // The account should not have permission since the first permission doesn't give him this. - var oSimulator1 = new IMAPClientSimulator(); - oSimulator1.Connect(); - oSimulator1.Logon(account1.Address, "test"); - Assert.IsFalse(oSimulator1.List().Contains(folderName)); - oSimulator1.Disconnect(); + var imapClientSimulator = new ImapClientSimulator(); + imapClientSimulator.Connect(); + imapClientSimulator.Logon(account1.Address, "test"); + Assert.IsFalse(imapClientSimulator.List().Contains(folderName)); + imapClientSimulator.Disconnect(); // Now delete the permissions and in the first permission give the group the rights. while (permissions.Count > 0) @@ -450,11 +450,11 @@ public void TestDuplicateConflictingGroupPermission() permission2.Save(); // The account should not have permission since the first permission does give him this. - oSimulator1 = new IMAPClientSimulator(); - oSimulator1.Connect(); - oSimulator1.Logon(account1.Address, "test"); - Assert.IsTrue(oSimulator1.List().Contains(folderName)); - oSimulator1.Disconnect(); + imapClientSimulator = new ImapClientSimulator(); + imapClientSimulator.Connect(); + imapClientSimulator.Logon(account1.Address, "test"); + Assert.IsTrue(imapClientSimulator.List().Contains(folderName)); + imapClientSimulator.Disconnect(); } [Test] @@ -478,26 +478,26 @@ public void TestExpunge() permission.Save(); string folderName = "#Public.Share1"; - SMTPClientSimulator.StaticSend("test@test.com", account1.Address, "TestMessage", "Body"); + SmtpClientSimulator.StaticSend("test@test.com", account1.Address, "TestMessage", "Body"); CustomAsserts.AssertFolderMessageCount(account1.IMAPFolders.get_ItemByName("INBOX"), 1); CustomAsserts.AssertFolderMessageCount(folder, 0); - var oSimulator1 = new IMAPClientSimulator(); - oSimulator1.Connect(); - oSimulator1.Logon(account1.Address, "test"); - oSimulator1.SelectFolder("INBOX"); - Assert.IsTrue(oSimulator1.Copy(1, folderName)); - Assert.IsTrue(oSimulator1.SelectFolder(folderName)); - Assert.IsTrue(oSimulator1.SetDeletedFlag(1)); + var imapClientSimulator = new ImapClientSimulator(); + imapClientSimulator.Connect(); + imapClientSimulator.Logon(account1.Address, "test"); + imapClientSimulator.SelectFolder("INBOX"); + Assert.IsTrue(imapClientSimulator.Copy(1, folderName)); + Assert.IsTrue(imapClientSimulator.SelectFolder(folderName)); + Assert.IsTrue(imapClientSimulator.SetDeletedFlag(1)); - Assert.IsFalse(oSimulator1.Expunge()); + Assert.IsFalse(imapClientSimulator.Expunge()); permission.set_Permission(eACLPermission.ePermissionExpunge, true); permission.Save(); - Assert.IsTrue(oSimulator1.Expunge()); + Assert.IsTrue(imapClientSimulator.Expunge()); - oSimulator1.Disconnect(); + imapClientSimulator.Disconnect(); } [Test] @@ -519,29 +519,29 @@ public void TestGetACL() permission.Save(); string folderName = "#Public.Share1"; - var oSimulator1 = new IMAPClientSimulator(); - oSimulator1.Connect(); - oSimulator1.LogonWithLiteral(account1.Address, "test"); - string result = oSimulator1.GetACL(folderName); + var imapClientSimulator = new ImapClientSimulator(); + imapClientSimulator.Connect(); + imapClientSimulator.LogonWithLiteral(account1.Address, "test"); + string result = imapClientSimulator.GetACL(folderName); Assert.IsTrue(result.StartsWith("* ACL \"" + folderName + "\" " + account1.Address + " ka")); permission.set_Permission(eACLPermission.ePermissionDeleteMailbox, true); permission.Save(); - result = oSimulator1.GetACL(folderName); + result = imapClientSimulator.GetACL(folderName); Assert.IsTrue(result.StartsWith("* ACL \"" + folderName + "\" " + account1.Address + " kxa")); permission.set_Permission(eACLPermission.ePermissionRead, true); permission.Save(); - result = oSimulator1.GetACL(folderName); + result = imapClientSimulator.GetACL(folderName); Assert.IsTrue(result.StartsWith("* ACL \"" + folderName + "\" " + account1.Address + " rkxa")); permission.set_Permission(eACLPermission.ePermissionExpunge, true); permission.Save(); - result = oSimulator1.GetACL(folderName); + result = imapClientSimulator.GetACL(folderName); Assert.IsTrue(result.StartsWith("* ACL \"" + folderName + "\" " + account1.Address + " rkxea")); - oSimulator1.Disconnect(); + imapClientSimulator.Disconnect(); } /// @@ -566,19 +566,19 @@ public void TestLISTPublicFolderParent() permission.Save(); string folderName = "#Public.Share1"; - var oSimulator1 = new IMAPClientSimulator(); - oSimulator1.Connect(); - oSimulator1.Logon(account1.Address, "test"); - Assert.IsFalse(oSimulator1.List().Contains(folderName)); + var imapClientSimulator = new ImapClientSimulator(); + imapClientSimulator.Connect(); + imapClientSimulator.Logon(account1.Address, "test"); + Assert.IsFalse(imapClientSimulator.List().Contains(folderName)); // Add permissions to select and lookup permission.set_Permission(eACLPermission.ePermissionLookup, true); permission.Save(); - Assert.IsTrue(oSimulator1.List().Contains("#Public\"\r\n")); - Assert.IsTrue(oSimulator1.List().Contains(folderName)); + Assert.IsTrue(imapClientSimulator.List().Contains("#Public\"\r\n")); + Assert.IsTrue(imapClientSimulator.List().Contains(folderName)); - oSimulator1.Disconnect(); + imapClientSimulator.Disconnect(); } /// @@ -603,19 +603,19 @@ public void TestLSUBPublicFolderParent() permission.Save(); string folderName = "#Public.Share1"; - var oSimulator1 = new IMAPClientSimulator(); - oSimulator1.Connect(); - oSimulator1.Logon(account1.Address, "test"); - Assert.IsFalse(oSimulator1.LSUB().Contains(folderName)); + var imapClientSimulator = new ImapClientSimulator(); + imapClientSimulator.Connect(); + imapClientSimulator.Logon(account1.Address, "test"); + Assert.IsFalse(imapClientSimulator.LSUB().Contains(folderName)); // Add permissions to select and lookup permission.set_Permission(eACLPermission.ePermissionLookup, true); permission.Save(); - Assert.IsTrue(oSimulator1.LSUB().Contains("#Public\"\r\n")); - Assert.IsTrue(oSimulator1.LSUB().Contains(folderName)); + Assert.IsTrue(imapClientSimulator.LSUB().Contains("#Public\"\r\n")); + Assert.IsTrue(imapClientSimulator.LSUB().Contains(folderName)); - oSimulator1.Disconnect(); + imapClientSimulator.Disconnect(); } /// @@ -638,15 +638,15 @@ public void TestListPublicFolder() permission.set_Permission(eACLPermission.ePermissionLookup, true); permission.Save(); - var oSimulator1 = new IMAPClientSimulator(); - oSimulator1.Connect(); - oSimulator1.LogonWithLiteral(account1.Address, "test"); + var imapClientSimulator = new ImapClientSimulator(); + imapClientSimulator.Connect(); + imapClientSimulator.LogonWithLiteral(account1.Address, "test"); - string result = oSimulator1.List(); + string result = imapClientSimulator.List(); Assert.IsTrue(result.Contains(folder.Name)); - oSimulator1.Disconnect(); + imapClientSimulator.Disconnect(); } [Test] @@ -665,11 +665,11 @@ public void TestListPublicFolderAnyonePermission() string folderName = "#Public.Share1"; // account 1 should not have permission since they aren't added yet. - var oSimulator1 = new IMAPClientSimulator(); - oSimulator1.Connect(); - oSimulator1.Logon(account1.Address, "test"); - Assert.IsFalse(oSimulator1.List().Contains(folderName)); - oSimulator1.Disconnect(); + var imapClientSimulator = new ImapClientSimulator(); + imapClientSimulator.Connect(); + imapClientSimulator.Logon(account1.Address, "test"); + Assert.IsFalse(imapClientSimulator.List().Contains(folderName)); + imapClientSimulator.Disconnect(); IMAPFolderPermission permission = folder.Permissions.Add(); permission.PermissionType = eACLPermissionType.ePermissionTypeAnyone; @@ -679,11 +679,11 @@ public void TestListPublicFolderAnyonePermission() // account 1 should not have permission since he's not in the group - oSimulator1 = new IMAPClientSimulator(); - oSimulator1.Connect(); - oSimulator1.Logon(account1.Address, "test"); - Assert.IsTrue(oSimulator1.List().Contains(folderName)); - oSimulator1.Disconnect(); + imapClientSimulator = new ImapClientSimulator(); + imapClientSimulator.Connect(); + imapClientSimulator.Logon(account1.Address, "test"); + Assert.IsTrue(imapClientSimulator.List().Contains(folderName)); + imapClientSimulator.Disconnect(); } [Test] @@ -713,41 +713,41 @@ public void TestListPublicFolderGroupPermission() string folderName = "#Public.Share1"; // account 1 should not have permission since he's not in the group - var oSimulator1 = new IMAPClientSimulator(); - oSimulator1.Connect(); - oSimulator1.Logon(account1.Address, "test"); - Assert.IsFalse(oSimulator1.List().Contains(folderName)); - oSimulator1.Disconnect(); + var imapClientSimulator = new ImapClientSimulator(); + imapClientSimulator.Connect(); + imapClientSimulator.Logon(account1.Address, "test"); + Assert.IsFalse(imapClientSimulator.List().Contains(folderName)); + imapClientSimulator.Disconnect(); // account 2 should have permission since he is in the group - oSimulator1 = new IMAPClientSimulator(); - oSimulator1.Connect(); - oSimulator1.Logon(account2.Address, "test"); - Assert.IsTrue(oSimulator1.List().Contains(folderName)); - oSimulator1.Disconnect(); + imapClientSimulator = new ImapClientSimulator(); + imapClientSimulator.Connect(); + imapClientSimulator.Logon(account2.Address, "test"); + Assert.IsTrue(imapClientSimulator.List().Contains(folderName)); + imapClientSimulator.Disconnect(); // account 3 should not have permission since he's not in the group - oSimulator1 = new IMAPClientSimulator(); - oSimulator1.Connect(); - oSimulator1.Logon(account3.Address, "test"); - Assert.IsFalse(oSimulator1.List().Contains(folderName)); - oSimulator1.Disconnect(); + imapClientSimulator = new ImapClientSimulator(); + imapClientSimulator.Connect(); + imapClientSimulator.Logon(account3.Address, "test"); + Assert.IsFalse(imapClientSimulator.List().Contains(folderName)); + imapClientSimulator.Disconnect(); // add account 1 to the group to give him permission. GroupMember member = SingletonProvider.Instance.AddGroupMember(group, account1); - oSimulator1 = new IMAPClientSimulator(); - oSimulator1.Connect(); - oSimulator1.Logon(account1.Address, "test"); - Assert.IsTrue(oSimulator1.List().Contains(folderName)); - oSimulator1.Disconnect(); + imapClientSimulator = new ImapClientSimulator(); + imapClientSimulator.Connect(); + imapClientSimulator.Logon(account1.Address, "test"); + Assert.IsTrue(imapClientSimulator.List().Contains(folderName)); + imapClientSimulator.Disconnect(); // delete account 1 from the group again to remove permissios. group.Members.DeleteByDBID(member.ID); - oSimulator1 = new IMAPClientSimulator(); - oSimulator1.Connect(); - oSimulator1.Logon(account1.Address, "test"); - Assert.IsFalse(oSimulator1.List().Contains(folderName)); - oSimulator1.Disconnect(); + imapClientSimulator = new ImapClientSimulator(); + imapClientSimulator.Connect(); + imapClientSimulator.Logon(account1.Address, "test"); + Assert.IsFalse(imapClientSimulator.List().Contains(folderName)); + imapClientSimulator.Disconnect(); } [Test] @@ -768,13 +768,13 @@ public void TestListPublicFolderOnly() permission.set_Permission(eACLPermission.ePermissionLookup, true); permission.Save(); - var oSimulator1 = new IMAPClientSimulator(); - oSimulator1.Connect(); - oSimulator1.Logon(account1.Address, "test"); + var imapClientSimulator = new ImapClientSimulator(); + imapClientSimulator.Connect(); + imapClientSimulator.Logon(account1.Address, "test"); - Assert.IsTrue(oSimulator1.List("#Public").Contains("#Public")); + Assert.IsTrue(imapClientSimulator.List("#Public").Contains("#Public")); - oSimulator1.Disconnect(); + imapClientSimulator.Disconnect(); } [Test] @@ -795,13 +795,13 @@ public void TestListPublicFolderSubFolderOnly() permission.set_Permission(eACLPermission.ePermissionLookup, true); permission.Save(); - var oSimulator1 = new IMAPClientSimulator(); - oSimulator1.Connect(); - oSimulator1.Logon(account1.Address, "test"); + var imapClientSimulator = new ImapClientSimulator(); + imapClientSimulator.Connect(); + imapClientSimulator.Logon(account1.Address, "test"); - Assert.IsFalse(oSimulator1.List("#Public.Share1").Contains("#Public\r\n")); + Assert.IsFalse(imapClientSimulator.List("#Public.Share1").Contains("#Public\r\n")); - oSimulator1.Disconnect(); + imapClientSimulator.Disconnect(); } [Test] @@ -826,14 +826,14 @@ public void TestListRights() permission.set_Permission(eACLPermission.ePermissionRead, true); permission.Save(); - var oSimulator1 = new IMAPClientSimulator(); - oSimulator1.Connect(); - oSimulator1.LogonWithLiteral(account1.Address, "test"); + var imapClientSimulator = new ImapClientSimulator(); + imapClientSimulator.Connect(); + imapClientSimulator.LogonWithLiteral(account1.Address, "test"); string folderName = "#Public.Share1"; - string rights = oSimulator1.ListRights(folderName, account1.Address); + string rights = imapClientSimulator.ListRights(folderName, account1.Address); Assert.IsTrue(rights.StartsWith("* LISTRIGHTS #Public.Share1 account1b@test.com l r s w i k x t e a")); - oSimulator1.Disconnect(); + imapClientSimulator.Disconnect(); } [Test] @@ -857,14 +857,14 @@ public void TestMyRights() permission.set_Permission(eACLPermission.ePermissionRead, true); permission.Save(); - var oSimulator1 = new IMAPClientSimulator(); - oSimulator1.Connect(); - oSimulator1.LogonWithLiteral(account1.Address, "test"); + var imapClientSimulator = new ImapClientSimulator(); + imapClientSimulator.Connect(); + imapClientSimulator.LogonWithLiteral(account1.Address, "test"); string folderName = "#Public.Share1"; - string result = oSimulator1.GetMyRights(folderName); + string result = imapClientSimulator.GetMyRights(folderName); Assert.IsTrue(result.StartsWith("* MYRIGHTS \"" + folderName + "\" rkxea")); - oSimulator1.Disconnect(); + imapClientSimulator.Disconnect(); } [Test] @@ -887,13 +887,13 @@ public void TestPublicFolderCreateDeep() permission.set_Permission(eACLPermission.ePermissionLookup, true); permission.Save(); - var oSimulator1 = new IMAPClientSimulator(); - oSimulator1.Connect(); - oSimulator1.Logon(account1.Address, "test"); + var imapClientSimulator = new ImapClientSimulator(); + imapClientSimulator.Connect(); + imapClientSimulator.Logon(account1.Address, "test"); string folderName = "#Public.Share1.MySub1.MySub2.MySub3.MySub4"; - Assert.IsTrue(oSimulator1.CreateFolder(folderName)); + Assert.IsTrue(imapClientSimulator.CreateFolder(folderName)); - oSimulator1.Disconnect(); + imapClientSimulator.Disconnect(); } [Test] @@ -914,15 +914,15 @@ public void TestPublicFolderNoSelectAttribute() permission.set_Permission(eACLPermission.ePermissionLookup, true); permission.Save(); - var oSimulator1 = new IMAPClientSimulator(); - oSimulator1.Connect(); - oSimulator1.Logon(account1.Address, "test"); + var imapClientSimulator = new ImapClientSimulator(); + imapClientSimulator.Connect(); + imapClientSimulator.Logon(account1.Address, "test"); - Assert.IsTrue(oSimulator1.List("#Public").Contains("Noselect")); - Assert.IsTrue(oSimulator1.List("#Public.Share1").Contains("#Public.Share1")); - Assert.IsFalse(oSimulator1.List("#Public.Share1").Contains("Noselect")); + Assert.IsTrue(imapClientSimulator.List("#Public").Contains("Noselect")); + Assert.IsTrue(imapClientSimulator.List("#Public.Share1").Contains("#Public.Share1")); + Assert.IsFalse(imapClientSimulator.List("#Public.Share1").Contains("Noselect")); - oSimulator1.Disconnect(); + imapClientSimulator.Disconnect(); } [Test] @@ -961,17 +961,17 @@ public void TestPublicFolderSubscriptionCreate() permission.set_Permission(eACLPermission.ePermissionRead, true); permission.Save(); - var oSimulator1 = new IMAPClientSimulator(); - oSimulator1.Connect(); - oSimulator1.Logon(account1.Address, "test"); + var imapClientSimulator = new ImapClientSimulator(); + imapClientSimulator.Connect(); + imapClientSimulator.Logon(account1.Address, "test"); string folderName = "#Public.Share1.MySub"; - oSimulator1.CreateFolder(folderName); + imapClientSimulator.CreateFolder(folderName); IMAPFolder theNewFolder = folder.SubFolders[0]; Assert.IsTrue(theNewFolder.Name.Equals("MySub")); Assert.IsTrue(theNewFolder.Subscribed); - oSimulator1.Disconnect(); + imapClientSimulator.Disconnect(); } [Test] @@ -996,14 +996,14 @@ public void TestPublicFolderUnsubscribe() permission.set_Permission(eACLPermission.ePermissionRead, true); permission.Save(); - var oSimulator1 = new IMAPClientSimulator(); - oSimulator1.Connect(); - oSimulator1.Logon(account1.Address, "test"); + var imapClientSimulator = new ImapClientSimulator(); + imapClientSimulator.Connect(); + imapClientSimulator.Logon(account1.Address, "test"); string folderName = "#Public.Share1"; - Assert.IsFalse(oSimulator1.Unsubscribe(folderName)); + Assert.IsFalse(imapClientSimulator.Unsubscribe(folderName)); - oSimulator1.Disconnect(); + imapClientSimulator.Disconnect(); } [Test] @@ -1029,23 +1029,23 @@ public void TestRenameFolderToAndFromPublic() string newFolderName = "AccountLevelFolder"; // Test renaming from local folder name to shared folder. - var oSimulator1 = new IMAPClientSimulator(); - oSimulator1.Connect(); - oSimulator1.Logon(account1.Address, "test"); - Assert.IsFalse(oSimulator1.RenameFolder(oldFolderName, newFolderName)); - oSimulator1.Disconnect(); + var imapClientSimulator = new ImapClientSimulator(); + imapClientSimulator.Connect(); + imapClientSimulator.Logon(account1.Address, "test"); + Assert.IsFalse(imapClientSimulator.RenameFolder(oldFolderName, newFolderName)); + imapClientSimulator.Disconnect(); // Test renaming from local folder name to shared folder. oldFolderName = "LocalFolder"; newFolderName = "#Public.Share1"; - oSimulator1 = new IMAPClientSimulator(); - oSimulator1.Connect(); - oSimulator1.Logon(account1.Address, "test"); - oSimulator1.CreateFolder(oldFolderName); - Assert.IsFalse(oSimulator1.RenameFolder(oldFolderName, newFolderName)); - oSimulator1.Disconnect(); + imapClientSimulator = new ImapClientSimulator(); + imapClientSimulator.Connect(); + imapClientSimulator.Logon(account1.Address, "test"); + imapClientSimulator.CreateFolder(oldFolderName); + Assert.IsFalse(imapClientSimulator.RenameFolder(oldFolderName, newFolderName)); + imapClientSimulator.Disconnect(); } [Test] @@ -1068,23 +1068,23 @@ public void TestRenamePublicFolder() string oldFolderName = "#Public.Share1.MySub1"; string newFolderName = "#Public.Share1.MySub2"; - var oSimulator1 = new IMAPClientSimulator(); - oSimulator1.Connect(); - oSimulator1.Logon(account1.Address, "test"); - Assert.IsTrue(oSimulator1.CreateFolder(oldFolderName)); + var imapClientSimulator = new ImapClientSimulator(); + imapClientSimulator.Connect(); + imapClientSimulator.Logon(account1.Address, "test"); + Assert.IsTrue(imapClientSimulator.CreateFolder(oldFolderName)); - Assert.IsFalse(oSimulator1.RenameFolder(oldFolderName, newFolderName)); + Assert.IsFalse(imapClientSimulator.RenameFolder(oldFolderName, newFolderName)); // Add permissions to delete the mailbox. permission.set_Permission(eACLPermission.ePermissionDeleteMailbox, true); permission.Save(); - Assert.IsTrue(oSimulator1.RenameFolder(oldFolderName, newFolderName)); + Assert.IsTrue(imapClientSimulator.RenameFolder(oldFolderName, newFolderName)); - Assert.IsFalse(oSimulator1.List().Contains(oldFolderName)); - Assert.IsTrue(oSimulator1.List().Contains(newFolderName)); + Assert.IsFalse(imapClientSimulator.List().Contains(oldFolderName)); + Assert.IsTrue(imapClientSimulator.List().Contains(newFolderName)); - oSimulator1.Disconnect(); + imapClientSimulator.Disconnect(); } [Test] @@ -1109,16 +1109,16 @@ public void TestRenamePublicFolderToRootPublicFolder() string oldFolderName = "#Public.Share1.MySub1"; string newFolderName = "#Public.Share2"; - var oSimulator1 = new IMAPClientSimulator(); - oSimulator1.Connect(); - oSimulator1.Logon(account1.Address, "test"); - Assert.IsTrue(oSimulator1.CreateFolder(oldFolderName)); - Assert.IsFalse(oSimulator1.RenameFolder(oldFolderName, newFolderName)); + var imapClientSimulator = new ImapClientSimulator(); + imapClientSimulator.Connect(); + imapClientSimulator.Logon(account1.Address, "test"); + Assert.IsTrue(imapClientSimulator.CreateFolder(oldFolderName)); + Assert.IsFalse(imapClientSimulator.RenameFolder(oldFolderName, newFolderName)); - Assert.IsTrue(oSimulator1.List().Contains(oldFolderName)); - Assert.IsFalse(oSimulator1.List().Contains(newFolderName)); + Assert.IsTrue(imapClientSimulator.List().Contains(oldFolderName)); + Assert.IsFalse(imapClientSimulator.List().Contains(newFolderName)); - oSimulator1.Disconnect(); + imapClientSimulator.Disconnect(); } [Test] @@ -1139,14 +1139,14 @@ public void TestSelectPublicFolder() permission.Save(); string folderName = "#Public.Share1.MySub1"; - var oSimulator1 = new IMAPClientSimulator(); - oSimulator1.Connect(); - oSimulator1.LogonWithLiteral(account1.Address, "test"); - Assert.IsTrue(oSimulator1.CreateFolder(folderName)); + var imapClientSimulator = new ImapClientSimulator(); + imapClientSimulator.Connect(); + imapClientSimulator.LogonWithLiteral(account1.Address, "test"); + Assert.IsTrue(imapClientSimulator.CreateFolder(folderName)); - Assert.IsFalse(oSimulator1.SelectFolderWithoutLiteral(folderName)); + Assert.IsFalse(imapClientSimulator.SelectFolderWithoutLiteral(folderName)); - oSimulator1.Disconnect(); + imapClientSimulator.Disconnect(); } [Test] @@ -1157,12 +1157,12 @@ public void TestSetACLOnAccountFolder() Account account1 = SingletonProvider.Instance.AddAccount(_domain, "account1@test.com", "test"); Account account2 = SingletonProvider.Instance.AddAccount(_domain, "account2@test.com", "test"); - var oSimulator1 = new IMAPClientSimulator(); - oSimulator1.Connect(); - oSimulator1.LogonWithLiteral(account1.Address, "test"); - Assert.IsTrue(oSimulator1.CreateFolder("SharedFolder")); - Assert.IsFalse(oSimulator1.SetACL("SharedFolder", account2.Address, "lrswipkxtea")); - oSimulator1.Disconnect(); + var imapClientSimulator = new ImapClientSimulator(); + imapClientSimulator.Connect(); + imapClientSimulator.LogonWithLiteral(account1.Address, "test"); + Assert.IsTrue(imapClientSimulator.CreateFolder("SharedFolder")); + Assert.IsFalse(imapClientSimulator.SetACL("SharedFolder", account2.Address, "lrswipkxtea")); + imapClientSimulator.Disconnect(); } [Test] @@ -1176,11 +1176,11 @@ public void TestSetAclOnPublicFolderNormalUser() IMAPFolder folder = publicFolders.Add("Share1"); folder.Save(); - var oSimulator1 = new IMAPClientSimulator(); - oSimulator1.Connect(); - oSimulator1.LogonWithLiteral(account1.Address, "test"); - Assert.IsFalse(oSimulator1.CreateFolder("#Public.Share1.MySub1")); - oSimulator1.Disconnect(); + var imapClientSimulator = new ImapClientSimulator(); + imapClientSimulator.Connect(); + imapClientSimulator.LogonWithLiteral(account1.Address, "test"); + Assert.IsFalse(imapClientSimulator.CreateFolder("#Public.Share1.MySub1")); + imapClientSimulator.Disconnect(); } [Test] @@ -1200,11 +1200,11 @@ public void TestSetAclOnPublicFolderNormalUserWithPrivilegies() permission.set_Permission(eACLPermission.ePermissionCreate, true); permission.Save(); - var oSimulator1 = new IMAPClientSimulator(); - oSimulator1.Connect(); - oSimulator1.LogonWithLiteral(account1.Address, "test"); - Assert.IsTrue(oSimulator1.CreateFolder("#Public.Share1.MySub1")); - oSimulator1.Disconnect(); + var imapClientSimulator = new ImapClientSimulator(); + imapClientSimulator.Connect(); + imapClientSimulator.LogonWithLiteral(account1.Address, "test"); + Assert.IsTrue(imapClientSimulator.CreateFolder("#Public.Share1.MySub1")); + imapClientSimulator.Disconnect(); } [Test] @@ -1227,25 +1227,25 @@ public void TestSetDeletedFlag() permission.Save(); string folderName = "#Public.Share1"; - SMTPClientSimulator.StaticSend("test@test.com", account1.Address, "TestMessage", "Body"); + SmtpClientSimulator.StaticSend("test@test.com", account1.Address, "TestMessage", "Body"); CustomAsserts.AssertFolderMessageCount(account1.IMAPFolders.get_ItemByName("INBOX"), 1); CustomAsserts.AssertFolderMessageCount(folder, 0); - var oSimulator1 = new IMAPClientSimulator(); - oSimulator1.Connect(); - oSimulator1.Logon(account1.Address, "test"); - oSimulator1.SelectFolder("INBOX"); - Assert.IsTrue(oSimulator1.Copy(1, folderName)); + var imapClientSimulator = new ImapClientSimulator(); + imapClientSimulator.Connect(); + imapClientSimulator.Logon(account1.Address, "test"); + imapClientSimulator.SelectFolder("INBOX"); + Assert.IsTrue(imapClientSimulator.Copy(1, folderName)); CustomAsserts.AssertFolderMessageCount(folder, 1); - oSimulator1.SelectFolder(folderName); - Assert.IsFalse(oSimulator1.SetDeletedFlag(1)); + imapClientSimulator.SelectFolder(folderName); + Assert.IsFalse(imapClientSimulator.SetDeletedFlag(1)); permission.set_Permission(eACLPermission.ePermissionWriteDeleted, true); permission.Save(); - Assert.IsTrue(oSimulator1.SetDeletedFlag(1)); + Assert.IsTrue(imapClientSimulator.SetDeletedFlag(1)); - oSimulator1.Disconnect(); + imapClientSimulator.Disconnect(); } } } \ No newline at end of file diff --git a/hmailserver/test/RegressionTests/IMAP/Append.cs b/hmailserver/test/RegressionTests/IMAP/Append.cs index 6ff50a81d..9ea12074e 100644 --- a/hmailserver/test/RegressionTests/IMAP/Append.cs +++ b/hmailserver/test/RegressionTests/IMAP/Append.cs @@ -16,7 +16,7 @@ public void ConfirmFileAddedToCorrectAccountFolder() { TestSetup testSetup = SingletonProvider.Instance; Account oAccount = testSetup.AddAccount(_domain, "check@test.com", "test"); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); // Confirm that the public folder is empty before we start our test. string publicDir = GetPublicDirectory(); @@ -44,7 +44,7 @@ public void ConfirmFileAddedToCorrectPublicFolder() { TestSetup testSetup = SingletonProvider.Instance; Account oAccount = testSetup.AddAccount(_domain, "check@test.com", "test"); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); // Confirm that the public folder is empty before we start our test. string publicDir = GetPublicDirectory(); @@ -84,7 +84,7 @@ public void ConfirmFileAddedToCorrectPublicFolder() public void TestAppend() { Account oAccount = SingletonProvider.Instance.AddAccount(_domain, "check@test.com", "test"); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.LogonWithLiteral("check@test.com", "test"); @@ -107,7 +107,7 @@ public void TestDomainMaxMessageSizeLimitDisabled() _domain.MaxMessageSize = 0; // 1 kb _domain.Save(); - var imapSim = new IMAPClientSimulator("test@test.com", "test", "INBOX"); + var imapSim = new ImapClientSimulator("test@test.com", "test", "INBOX"); string result = imapSim.SendSingleCommandWithLiteral("A01 APPEND INBOX {" + message.Length + "}", message.ToString()); imapSim.Logout(); @@ -129,7 +129,7 @@ public void TestDomainMaxMessageSizeLimitEnabled() _domain.MaxMessageSize = 1; // 1 kb _domain.Save(); - var imapSim = new IMAPClientSimulator("test@test.com", "test", "INBOX"); + var imapSim = new ImapClientSimulator("test@test.com", "test", "INBOX"); string result = imapSim.SendSingleCommandWithLiteral("A01 APPEND INBOX {" + message.Length + "}", message.ToString()); imapSim.Logout(); @@ -150,7 +150,7 @@ public void TestGlobalMaxMessageSizeLimitDisabled() _settings.MaxMessageSize = 0; - var imapSim = new IMAPClientSimulator("test@test.com", "test", "INBOX"); + var imapSim = new ImapClientSimulator("test@test.com", "test", "INBOX"); string result = imapSim.SendSingleCommandWithLiteral("A01 APPEND INBOX {" + message.Length + "}", message.ToString()); imapSim.Logout(); @@ -171,7 +171,7 @@ public void TestGlobalMaxMessageSizeLimitEnabled() _settings.MaxMessageSize = 1; - var imapSim = new IMAPClientSimulator("test@test.com", "test", "INBOX"); + var imapSim = new ImapClientSimulator("test@test.com", "test", "INBOX"); string result = imapSim.SendSingleCommandWithLiteral("A01 APPEND INBOX {" + message.Length + "}", message.ToString()); imapSim.Logout(); diff --git a/hmailserver/test/RegressionTests/IMAP/Basics.cs b/hmailserver/test/RegressionTests/IMAP/Basics.cs index d8decffd4..0d1ea4fc9 100644 Binary files a/hmailserver/test/RegressionTests/IMAP/Basics.cs and b/hmailserver/test/RegressionTests/IMAP/Basics.cs differ diff --git a/hmailserver/test/RegressionTests/IMAP/CommandSequences.cs b/hmailserver/test/RegressionTests/IMAP/CommandSequences.cs index f2791c2bd..39f4f03d9 100644 --- a/hmailserver/test/RegressionTests/IMAP/CommandSequences.cs +++ b/hmailserver/test/RegressionTests/IMAP/CommandSequences.cs @@ -16,7 +16,7 @@ public void TestBatchOfCommands() { Account account = SingletonProvider.Instance.AddAccount(_domain, "batch@test.com", "test"); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon(account.Address, "test"); @@ -51,7 +51,7 @@ public void TestLongCommand() { Account account = SingletonProvider.Instance.AddAccount(_domain, "batch@test.com", "test"); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon(account.Address, "test"); diff --git a/hmailserver/test/RegressionTests/IMAP/Examine.cs b/hmailserver/test/RegressionTests/IMAP/Examine.cs index 8b453ad8b..95ba4e961 100644 --- a/hmailserver/test/RegressionTests/IMAP/Examine.cs +++ b/hmailserver/test/RegressionTests/IMAP/Examine.cs @@ -14,10 +14,10 @@ public void TestChangeFlags() { Account oAccount = SingletonProvider.Instance.AddAccount(_domain, "examine@test.com", "test"); - Assert.IsTrue(SMTPClientSimulator.StaticSend("test@test.com", oAccount.Address, "Test", "test")); - POP3ClientSimulator.AssertMessageCount(oAccount.Address, "test", 1); + SmtpClientSimulator.StaticSend("test@test.com", oAccount.Address, "Test", "test"); + Pop3ClientSimulator.AssertMessageCount(oAccount.Address, "test", 1); - var simulator = new IMAPClientSimulator(); + var simulator = new ImapClientSimulator(); simulator.ConnectAndLogon(oAccount.Address, "test"); simulator.ExamineFolder("Inbox"); Assert.IsFalse(simulator.SetFlagOnMessage(1, true, @"\Deleted")); @@ -30,24 +30,24 @@ public void TestChangeRecentFlag() { Account oAccount = SingletonProvider.Instance.AddAccount(_domain, "examine@test.com", "test"); - Assert.IsTrue(SMTPClientSimulator.StaticSend("test@test.com", oAccount.Address, "Test", "test")); - POP3ClientSimulator.AssertMessageCount(oAccount.Address, "test", 1); + SmtpClientSimulator.StaticSend("test@test.com", oAccount.Address, "Test", "test"); + Pop3ClientSimulator.AssertMessageCount(oAccount.Address, "test", 1); - var simulator = new IMAPClientSimulator(); + var simulator = new ImapClientSimulator(); simulator.ConnectAndLogon(oAccount.Address, "test"); string result = simulator.ExamineFolder("Inbox"); Assert.IsTrue(result.Contains("* 1 RECENT"), result); simulator.Close(); simulator.Disconnect(); - simulator = new IMAPClientSimulator(); + simulator = new ImapClientSimulator(); simulator.ConnectAndLogon(oAccount.Address, "test"); Assert.IsTrue(simulator.SelectFolder("Inbox", out result)); Assert.IsTrue(result.Contains("* 1 RECENT"), result); simulator.Close(); simulator.Disconnect(); - simulator = new IMAPClientSimulator(); + simulator = new ImapClientSimulator(); simulator.ConnectAndLogon(oAccount.Address, "test"); result = simulator.ExamineFolder("Inbox"); Assert.IsTrue(result.Contains("* 0 RECENT"), result); @@ -62,10 +62,10 @@ public void TestChangeSeenFlag() { Account oAccount = SingletonProvider.Instance.AddAccount(_domain, "examine@test.com", "test"); - Assert.IsTrue(SMTPClientSimulator.StaticSend("test@test.com", oAccount.Address, "Test", "test")); - POP3ClientSimulator.AssertMessageCount(oAccount.Address, "test", 1); + SmtpClientSimulator.StaticSend("test@test.com", oAccount.Address, "Test", "test"); + Pop3ClientSimulator.AssertMessageCount(oAccount.Address, "test", 1); - var simulator = new IMAPClientSimulator(); + var simulator = new ImapClientSimulator(); simulator.ConnectAndLogon(oAccount.Address, "test"); simulator.ExamineFolder("Inbox"); string flags = simulator.GetFlags(1); @@ -76,7 +76,7 @@ public void TestChangeSeenFlag() Assert.AreEqual(flags, flagsAfter); - var secondSimulator = new IMAPClientSimulator(); + var secondSimulator = new ImapClientSimulator(); secondSimulator.ConnectAndLogon(oAccount.Address, "test"); secondSimulator.SelectFolder("Inbox"); string secondFlags = secondSimulator.GetFlags(1); @@ -93,7 +93,7 @@ public void TestExamine() { Account oAccount = SingletonProvider.Instance.AddAccount(_domain, "examine@test.com", "test"); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon(oAccount.Address, "test"); @@ -110,15 +110,15 @@ public void TestExpunge() { Account oAccount = SingletonProvider.Instance.AddAccount(_domain, "examine@test.com", "test"); - Assert.IsTrue(SMTPClientSimulator.StaticSend("test@test.com", oAccount.Address, "Test", "test")); - POP3ClientSimulator.AssertMessageCount(oAccount.Address, "test", 1); + SmtpClientSimulator.StaticSend("test@test.com", oAccount.Address, "Test", "test"); + Pop3ClientSimulator.AssertMessageCount(oAccount.Address, "test", 1); - var simulator = new IMAPClientSimulator(); + var simulator = new ImapClientSimulator(); simulator.ConnectAndLogon(oAccount.Address, "test"); simulator.SelectFolder("Inbox"); Assert.IsTrue(simulator.SetFlagOnMessage(1, true, @"\Deleted")); - var secondSimulator = new IMAPClientSimulator(); + var secondSimulator = new ImapClientSimulator(); secondSimulator.ConnectAndLogon(oAccount.Address, "test"); string result = secondSimulator.ExamineFolder("INBOX"); Assert.IsTrue(result.Contains("1 EXISTS"), result); diff --git a/hmailserver/test/RegressionTests/IMAP/Fetch.cs b/hmailserver/test/RegressionTests/IMAP/Fetch.cs index 88d056afe..4e39164f4 100644 --- a/hmailserver/test/RegressionTests/IMAP/Fetch.cs +++ b/hmailserver/test/RegressionTests/IMAP/Fetch.cs @@ -35,7 +35,7 @@ public void TestBodyStructureWithNonLatinCharacter() CustomAsserts.AssertFolderMessageCount(account.IMAPFolders[0], 1); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); oSimulator.ConnectAndLogon(account.Address, "test"); oSimulator.SelectFolder("INBOX"); string result = oSimulator.Fetch("1 BODYSTRUCTURE"); @@ -50,17 +50,17 @@ public void TestFetch() { Account account = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody1"); - IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 1); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody1"); + ImapClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 1); - SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody2"); - IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 2); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody2"); + ImapClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 2); - SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody3"); - IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 3); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody3"); + ImapClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 3); - var sim = new IMAPClientSimulator(); + var sim = new ImapClientSimulator(); sim.ConnectAndLogon(account.Address, "test"); sim.SelectFolder("INBOX"); string result = sim.Fetch("1 BODY[1]"); @@ -93,7 +93,7 @@ public void TestFetchBody() CustomAsserts.AssertFolderMessageCount(account.IMAPFolders[0], 1); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); oSimulator.ConnectAndLogon(account.Address, "test"); oSimulator.SelectFolder("INBOX"); string bodyStructureResponse = oSimulator.Fetch("1 BODYSTRUCTURE"); @@ -117,12 +117,12 @@ public void TestFetchEnvelopeWithDateContainingQuote() Environment.NewLine + "Hello" + Environment.NewLine; - var smtpSimulator = new SMTPClientSimulator(); + var smtpSimulator = new SmtpClientSimulator(); smtpSimulator.SendRaw(account.Address, account.Address, message); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon(account.Address, "test"); oSimulator.SelectFolder("INBOX"); @@ -144,12 +144,12 @@ public void IfInReplyToFieldContainsQuoteThenFetchHeadersShouldEncodeIt() Environment.NewLine + "Hello" + Environment.NewLine; - var smtpSimulator = new SMTPClientSimulator(); + var smtpSimulator = new SmtpClientSimulator(); smtpSimulator.SendRaw(account.Address, account.Address, message); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon(account.Address, "test"); oSimulator.SelectFolder("INBOX"); @@ -173,12 +173,12 @@ public void TestFetchHeaderFields() Environment.NewLine + "Hello" + Environment.NewLine; - var smtpSimulator = new SMTPClientSimulator(); - Assert.IsTrue(smtpSimulator.SendRaw(account.Address, account.Address, message)); + var smtpSimulator = new SmtpClientSimulator(); + smtpSimulator.SendRaw(account.Address, account.Address, message); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon(account.Address, "test"); oSimulator.SelectFolder("INBOX"); @@ -205,12 +205,12 @@ public void RequestingSameHeaderFieldMultipleTimesShouldReturnItOnce() Environment.NewLine + "Hello" + Environment.NewLine; - var smtpSimulator = new SMTPClientSimulator(); - Assert.IsTrue(smtpSimulator.SendRaw(account.Address, account.Address, message)); + var smtpSimulator = new SmtpClientSimulator(); + smtpSimulator.SendRaw(account.Address, account.Address, message); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon(account.Address, "test"); oSimulator.SelectFolder("INBOX"); @@ -234,12 +234,12 @@ public void TestFetchHeaderFieldsNot() Environment.NewLine + "Hello" + Environment.NewLine; - var smtpSimulator = new SMTPClientSimulator(); - Assert.IsTrue(smtpSimulator.SendRaw(account.Address, account.Address, message)); + var smtpSimulator = new SmtpClientSimulator(); + smtpSimulator.SendRaw(account.Address, account.Address, message); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon(account.Address, "test"); oSimulator.SelectFolder("INBOX"); @@ -258,13 +258,13 @@ public void TestFetchHeaderFieldsNot() public void TestFetchInvalid() { Account account = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody1"); - SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody2"); - SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody3"); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody1"); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody2"); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody3"); - IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 3); + ImapClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 3); - var sim = new IMAPClientSimulator(); + var sim = new ImapClientSimulator(); sim.ConnectAndLogon(account.Address, "test"); sim.SelectFolder("INBOX"); string result = sim.Fetch("0 BODY[1]"); diff --git a/hmailserver/test/RegressionTests/IMAP/Folders.cs b/hmailserver/test/RegressionTests/IMAP/Folders.cs index 3bf44cdbf..0f8758445 100644 --- a/hmailserver/test/RegressionTests/IMAP/Folders.cs +++ b/hmailserver/test/RegressionTests/IMAP/Folders.cs @@ -15,7 +15,7 @@ public void TestCreateDeepFolder() { Account oAccount = SingletonProvider.Instance.AddAccount(_domain, "folder4@test.com", "test"); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); oSimulator.Connect(); oSimulator.LogonWithLiteral(oAccount.Address, "test"); @@ -32,7 +32,7 @@ public void TestCreateFolderWithHash() { Account oAccount = SingletonProvider.Instance.AddAccount(_domain, "folder6@test.com", "test"); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); oSimulator.Connect(); oSimulator.Logon(oAccount.Address, "test"); @@ -50,7 +50,7 @@ public void TestCreateFolderWithQuote() const string folderName = "ABC\"123"; - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); oSimulator.Connect(); oSimulator.Logon(oAccount.Address, "test"); Assert.IsTrue(oSimulator.CreateFolder(folderName)); @@ -66,7 +66,7 @@ public void TestCreateFolderWithSlash() const string folderName = "ABC\\123"; - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); oSimulator.Connect(); oSimulator.Logon(oAccount.Address, "test"); Assert.IsTrue(oSimulator.CreateFolder(folderName)); @@ -80,7 +80,7 @@ public void TestCreateLongFolder() { Account oAccount = SingletonProvider.Instance.AddAccount(_domain, "folder9@test.com", "test"); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); oSimulator.Connect(); oSimulator.LogonWithLiteral(oAccount.Address, "test"); @@ -109,7 +109,7 @@ public void TestCreateParallelFolder() { Account oAccount = SingletonProvider.Instance.AddAccount(_domain, "folder5@test.com", "test"); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); oSimulator.Connect(); oSimulator.LogonWithLiteral(oAccount.Address, "test"); @@ -126,7 +126,7 @@ public void TestCreateUnnamedSubFolder() { Account oAccount = SingletonProvider.Instance.AddAccount(_domain, "folder7@test.com", "test"); - var simulator = new IMAPClientSimulator(); + var simulator = new ImapClientSimulator(); simulator.Connect(); simulator.LogonWithLiteral(oAccount.Address, "test"); @@ -148,7 +148,7 @@ public void TestFolderCaseInLIST() string folderName = "ABC.def.GHI"; - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); oSimulator.Connect(); oSimulator.Logon(oAccount.Address, "test"); Assert.IsTrue(oSimulator.CreateFolder(folderName)); @@ -167,7 +167,7 @@ public void TestFolderCaseInLSUB() string folderName = "ABC.def.GHI"; - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon(oAccount.Address, "test"); Assert.IsTrue(oSimulator.CreateFolder(folderName)); @@ -190,7 +190,7 @@ public void TestFolderLSUBUnsubscribedFolder() const string folderName = "ABC.def.GHI"; - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); oSimulator.Connect(); oSimulator.Logon(oAccount.Address, "test"); Assert.IsTrue(oSimulator.CreateFolder(folderName)); @@ -211,7 +211,7 @@ public void TestFolderQuote() const string folderName = "Test*"; - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon(oAccount.Address, "test"); Assert.IsTrue(oSimulator.CreateFolder(folderName)); @@ -226,7 +226,7 @@ public void TestListCommandChangedHierarchyDelimiter() Account account = SingletonProvider.Instance.AddAccount(_domain, "folder1@test.com", "test"); _settings.IMAPHierarchyDelimiter = "\\"; - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); oSimulator.Connect(); oSimulator.LogonWithLiteral(account.Address, "test"); @@ -249,7 +249,7 @@ public void TestListSpecial() { Account oAccount = SingletonProvider.Instance.AddAccount(_domain, "quote@test.com", "test"); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon(oAccount.Address, "test"); string response = oSimulator.List(""); @@ -258,7 +258,7 @@ public void TestListSpecial() _settings.IMAPHierarchyDelimiter = "/"; - oSimulator = new IMAPClientSimulator(); + oSimulator = new ImapClientSimulator(); sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon(oAccount.Address, "test"); response = oSimulator.List(""); @@ -267,7 +267,7 @@ public void TestListSpecial() _settings.IMAPHierarchyDelimiter = "\\"; - oSimulator = new IMAPClientSimulator(); + oSimulator = new ImapClientSimulator(); sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon(oAccount.Address, "test"); response = oSimulator.List("", false); @@ -282,7 +282,7 @@ public void TestListWithReference() { Account oAccount = SingletonProvider.Instance.AddAccount(_domain, "quote@test.com", "test"); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); oSimulator.ConnectAndLogon(oAccount.Address, "test"); oSimulator.CreateFolder("Main.Sub1.Sub2.Sub3"); oSimulator.CreateFolder("SomeOtherFolder"); @@ -328,7 +328,7 @@ public void TestListWithReferenceTestCase2() { Account oAccount = SingletonProvider.Instance.AddAccount(_domain, "quote@test.com", "test"); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); oSimulator.ConnectAndLogon(oAccount.Address, "test"); oSimulator.CreateFolder("INBOX.MyApp.SubFolder1"); oSimulator.CreateFolder("INBOX.MyApp.SubFolder2"); @@ -354,7 +354,7 @@ public void TestLsubInclusion() string folderName = "Folder1"; - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon(oAccount.Address, "test"); Assert.IsTrue(oSimulator.CreateFolder(folderName)); @@ -370,7 +370,7 @@ public void TestRenameIncorrectParameters() { Account oAccount = SingletonProvider.Instance.AddAccount(_domain, "folder8@test.com", "test"); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.LogonWithLiteral(oAccount.Address, "test"); @@ -387,7 +387,7 @@ public void TestRenameLongFolder() { Account oAccount = SingletonProvider.Instance.AddAccount(_domain, "folder2@test.com", "test"); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.LogonWithLiteral(oAccount.Address, "test"); @@ -428,7 +428,7 @@ public void TestRenameRootPublicFolder() Account account = SingletonProvider.Instance.AddAccount(_domain, "shared@test.com", "test"); - var simulator1 = new IMAPClientSimulator(); + var simulator1 = new ImapClientSimulator(); simulator1.ConnectAndLogon(account.Address, "test"); Assert.IsTrue(simulator1.SelectFolder("#Public.ShareA")); Assert.IsTrue(simulator1.SelectFolder("#Public.ShareB")); @@ -444,7 +444,7 @@ public void TestRenameSubFolderToChildSub() { Account account = SingletonProvider.Instance.AddAccount(_domain, "folder1@test.com", "test"); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); Assert.IsTrue(oSimulator.ConnectAndLogon(account.Address, "test")); Assert.IsTrue(oSimulator.CreateFolder("A.B")); @@ -463,7 +463,7 @@ public void TestRenameSubFolderToMatchingName() { Account account = SingletonProvider.Instance.AddAccount(_domain, "folder1@test.com", "test"); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); Assert.IsTrue(oSimulator.ConnectAndLogon(account.Address, "test")); Assert.IsTrue(oSimulator.CreateFolder("Folder1")); Assert.IsTrue(oSimulator.SelectFolder("Folder1")); @@ -485,7 +485,7 @@ public void TestRenameToAndFromINBOX() { Account oAccount = SingletonProvider.Instance.AddAccount(_domain, "folder3@test.com", "test"); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.LogonWithLiteral(oAccount.Address, "test"); @@ -502,7 +502,7 @@ public void TestRenameToParallelFolder() { Account oAccount = SingletonProvider.Instance.AddAccount(_domain, "folder1@test.com", "test"); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.LogonWithLiteral(oAccount.Address, "test"); @@ -522,7 +522,7 @@ public void TestRenameToSubFolder() { Account oAccount = SingletonProvider.Instance.AddAccount(_domain, "folder1@test.com", "test"); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); oSimulator.Connect(); oSimulator.LogonWithLiteral(oAccount.Address, "test"); @@ -545,7 +545,7 @@ public void TestTryCreateInvalidStructure() { Account oAccount = SingletonProvider.Instance.AddAccount(_domain, "folder1@test.com", "test"); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); oSimulator.Connect(); oSimulator.LogonWithLiteral(oAccount.Address, "test"); diff --git a/hmailserver/test/RegressionTests/IMAP/HierarchyDelimiter.cs b/hmailserver/test/RegressionTests/IMAP/HierarchyDelimiter.cs index b5ec3c287..ae8108c39 100644 --- a/hmailserver/test/RegressionTests/IMAP/HierarchyDelimiter.cs +++ b/hmailserver/test/RegressionTests/IMAP/HierarchyDelimiter.cs @@ -22,7 +22,7 @@ public void TestHierarchyDelimiterCreate() string folderName = "Test.Test"; - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon(account.Address, "test"); Assert.IsTrue(oSimulator.CreateFolder(folderName)); @@ -44,7 +44,7 @@ public void TestHierarchyDelimiterDelete() string folderName = "Test\\Test"; - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon(account.Address, "test"); Assert.IsTrue(oSimulator.CreateFolder(folderName)); @@ -70,7 +70,7 @@ public void TestHierarchyDelimiterListResponse() string folderName = "Test\\Test"; - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon(account.Address, "test"); Assert.IsTrue(oSimulator.CreateFolder(folderName)); @@ -92,7 +92,7 @@ public void TestHierarchyDelimiterLsubResponse() string folderName = "Test/Test"; - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon(account.Address, "test"); Assert.IsTrue(oSimulator.CreateFolder(folderName)); @@ -115,7 +115,7 @@ public void TestHierarchyDelimiterNamespaceResponse() Account account = SingletonProvider.Instance.AddAccount(_domain, "quote@test.com", "test"); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); oSimulator.ConnectAndLogon(account.Address, "test"); string result = oSimulator.Send("A01 NAMESPACE"); string correctNamespaceSetting = "* NAMESPACE ((\"\" \"\\\\\")) NIL ((\"" + publicFolderName + @@ -125,7 +125,7 @@ public void TestHierarchyDelimiterNamespaceResponse() settings.IMAPHierarchyDelimiter = "."; - oSimulator = new IMAPClientSimulator(); + oSimulator = new ImapClientSimulator(); oSimulator.ConnectAndLogon(account.Address, "test"); result = oSimulator.Send("A01 NAMESPACE"); @@ -135,7 +135,7 @@ public void TestHierarchyDelimiterNamespaceResponse() settings.IMAPHierarchyDelimiter = "/"; - oSimulator = new IMAPClientSimulator(); + oSimulator = new ImapClientSimulator(); oSimulator.ConnectAndLogon(account.Address, "test"); result = oSimulator.Send("A01 NAMESPACE"); @@ -157,7 +157,7 @@ public void TestHierarchyDelimiterRename() string folderName = "Test/Test"; string newFolderName = "Apa/Test"; - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon(account.Address, "test"); Assert.IsTrue(oSimulator.CreateFolder(folderName)); @@ -183,7 +183,7 @@ public void TestHierarchyDelimiterSlash() string folderName = "Test\\Test"; - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon(account.Address, "test"); Assert.IsTrue(oSimulator.CreateFolder(folderName)); diff --git a/hmailserver/test/RegressionTests/IMAP/MessageIndexing.cs b/hmailserver/test/RegressionTests/IMAP/MessageIndexing.cs index caa07addc..e4f27d05d 100644 --- a/hmailserver/test/RegressionTests/IMAP/MessageIndexing.cs +++ b/hmailserver/test/RegressionTests/IMAP/MessageIndexing.cs @@ -66,17 +66,17 @@ public void TestMetaDataSortCC() // disable... SendMessage("Test C", "Body", "", "ÄÄÄ"); - IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 1); + ImapClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 1); SendMessage("Test B", "Body", "", "ÖÖÖ"); - IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 2); + ImapClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 2); SendMessage("Test A", "Body", "", "ÅÅÅ"); - IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 3); + ImapClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 3); AssertAllMessagesIndexed(); - var sim = new IMAPClientSimulator(account.Address, "test", "Inbox"); + var sim = new ImapClientSimulator(account.Address, "test", "Inbox"); string result = sim.Sort("(CC) UTF-8 ALL"); @@ -101,23 +101,23 @@ public void TestMetaDataSortDate() // disable... SendMessage("Test A", "Body", "", ""); - IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 1); + ImapClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 1); SendMessage("Test B", "Body", "", ""); - IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 2); + ImapClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 2); SendMessage("Test C", "Body", "", ""); - IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 3); + ImapClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 3); SendMessage("Test D", "Body", "", ""); - IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 4); + ImapClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 4); SendMessage("Test E", "Body", "", ""); - IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 5); + ImapClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 5); AssertAllMessagesIndexed(); - var sim = new IMAPClientSimulator(account.Address, "test", "Inbox"); + var sim = new ImapClientSimulator(account.Address, "test", "Inbox"); string result = sim.Sort("(DATE) UTF-8 ALL"); @@ -142,14 +142,14 @@ public void TestMetaDataSortSubjectAnsi() // disable... SendMessage("Test 1", "Body", "", ""); - IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 1); + ImapClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 1); SendMessage("Test 2", "Body", "", ""); - IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 2); + ImapClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 2); AssertAllMessagesIndexed(); - var sim = new IMAPClientSimulator(account.Address, "test", "Inbox"); + var sim = new ImapClientSimulator(account.Address, "test", "Inbox"); string result = sim.Sort("(SUBJECT) UTF-8 ALL"); @@ -175,32 +175,32 @@ public void TestMetaDataSortSubjectGreek() // disable... SendMessage("Test Σ", "Body", "", ""); - IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 1); + ImapClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 1); // pos: 18 SendMessage("Test Α", "Body", "", ""); - IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 2); + ImapClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 2); // pos: 1 SendMessage("Test Δ", "Body", "", ""); - IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 3); + ImapClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 3); // pos: 4 SendMessage("Test β", "Body", "", ""); - IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 4); + ImapClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 4); // pos: 2 SendMessage("Test κ", "Body", "", ""); - IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 5); + ImapClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 5); // pos: 10 SendMessage("Test Ψ", "Body", "", ""); - IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 6); + ImapClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 6); // pos: 23 AssertAllMessagesIndexed(); - var sim = new IMAPClientSimulator(account.Address, "test", "Inbox"); + var sim = new ImapClientSimulator(account.Address, "test", "Inbox"); string result = sim.Sort("(SUBJECT) UTF-8 ALL"); @@ -225,17 +225,17 @@ public void TestMetaDataSortSubjectSwedish() // disable... SendMessage("Test Ä", "Body", "", ""); - IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 1); + ImapClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 1); SendMessage("Test Ö", "Body", "", ""); - IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 2); + ImapClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 2); SendMessage("Test Å", "Body", "", ""); - IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 3); + ImapClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 3); AssertAllMessagesIndexed(); - var sim = new IMAPClientSimulator(account.Address, "test", "Inbox"); + var sim = new ImapClientSimulator(account.Address, "test", "Inbox"); string result = sim.Sort("(SUBJECT) UTF-8 ALL"); @@ -260,28 +260,28 @@ public void TestMetaDataSortSubjectTurkish() // disable... SendMessage("Test Ç", "Body", "", ""); - IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 1); + ImapClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 1); // pos: 4 SendMessage("Test C", "Body", "", ""); - IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 2); + ImapClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 2); // pos: 3 SendMessage("Test B", "Body", "", ""); - IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 3); + ImapClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 3); // pos: 2 SendMessage("Test Ğ", "Body", "", ""); - IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 4); + ImapClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 4); // pos: 9 SendMessage("Test G", "Body", "", ""); - IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 5); + ImapClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 5); // pos: 8 AssertAllMessagesIndexed(); - var sim = new IMAPClientSimulator(account.Address, "test", "Inbox"); + var sim = new ImapClientSimulator(account.Address, "test", "Inbox"); string result = sim.Sort("(SUBJECT) UTF-8 ALL"); @@ -306,17 +306,17 @@ public void TestMetaDataSortTo() // disable... SendMessage("Test A", "Body", "ÅÅÅ", ""); - IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 1); + ImapClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 1); SendMessage("Test B", "Body", "ÖÖÖ", ""); - IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 2); + ImapClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 2); SendMessage("Test C", "Body", "ÄÄÄ", ""); - IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 3); + ImapClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 3); AssertAllMessagesIndexed(); - var sim = new IMAPClientSimulator(account.Address, "test", "Inbox"); + var sim = new ImapClientSimulator(account.Address, "test", "Inbox"); string result = sim.Sort("(TO) UTF-8 ALL"); diff --git a/hmailserver/test/RegressionTests/IMAP/MessageUids.cs b/hmailserver/test/RegressionTests/IMAP/MessageUids.cs index 4d1b92407..b1d9af2c6 100644 --- a/hmailserver/test/RegressionTests/IMAP/MessageUids.cs +++ b/hmailserver/test/RegressionTests/IMAP/MessageUids.cs @@ -70,22 +70,22 @@ public void TestBasicIncrements() Account testAccount = SingletonProvider.Instance.AddAccount(_domain, "Test'Account@test.com", "test"); - SMTPClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test"); - POP3ClientSimulator.AssertMessageCount(testAccount.Address, "test", 1); + SmtpClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test"); + Pop3ClientSimulator.AssertMessageCount(testAccount.Address, "test", 1); IMAPFolder inboxFolder = testAccount.IMAPFolders[0]; Assert.AreEqual(1, inboxFolder.CurrentUID); Assert.AreEqual(1, inboxFolder.Messages[0].UID); - SMTPClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test"); - POP3ClientSimulator.AssertMessageCount(testAccount.Address, "test", 2); + SmtpClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test"); + Pop3ClientSimulator.AssertMessageCount(testAccount.Address, "test", 2); Assert.AreEqual(2, inboxFolder.CurrentUID); Assert.AreEqual(2, inboxFolder.Messages[1].UID); - SMTPClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test"); - POP3ClientSimulator.AssertMessageCount(testAccount.Address, "test", 3); + SmtpClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test"); + Pop3ClientSimulator.AssertMessageCount(testAccount.Address, "test", 3); Assert.AreEqual(3, inboxFolder.CurrentUID); Assert.AreEqual(3, inboxFolder.Messages[2].UID); @@ -98,25 +98,25 @@ public void TestBasicIncrementsWithDeletion() Account testAccount = SingletonProvider.Instance.AddAccount(_domain, "Test'Account@test.com", "test"); - SMTPClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test"); - POP3ClientSimulator.AssertMessageCount(testAccount.Address, "test", 1); + SmtpClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test"); + Pop3ClientSimulator.AssertMessageCount(testAccount.Address, "test", 1); IMAPFolder inboxFolder = testAccount.IMAPFolders[0]; Assert.AreEqual(1, inboxFolder.CurrentUID); Assert.AreEqual(1, inboxFolder.Messages[0].UID); - POP3ClientSimulator.AssertGetFirstMessageText(testAccount.Address, "test"); + Pop3ClientSimulator.AssertGetFirstMessageText(testAccount.Address, "test"); - SMTPClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test"); - POP3ClientSimulator.AssertMessageCount(testAccount.Address, "test", 1); + SmtpClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test"); + Pop3ClientSimulator.AssertMessageCount(testAccount.Address, "test", 1); Assert.AreEqual(2, inboxFolder.CurrentUID); Assert.AreEqual(2, inboxFolder.Messages[0].UID); - POP3ClientSimulator.AssertGetFirstMessageText(testAccount.Address, "test"); + Pop3ClientSimulator.AssertGetFirstMessageText(testAccount.Address, "test"); - SMTPClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test"); - POP3ClientSimulator.AssertMessageCount(testAccount.Address, "test", 1); + SmtpClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test"); + Pop3ClientSimulator.AssertMessageCount(testAccount.Address, "test", 1); Assert.AreEqual(3, inboxFolder.CurrentUID); Assert.AreEqual(3, inboxFolder.Messages[0].UID); @@ -130,21 +130,21 @@ public void TestMoveMessageWithAccountLevelRule() "test"); // First deliver two messages to the inbox. - SMTPClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test"); - POP3ClientSimulator.AssertMessageCount(testAccount.Address, "test", 1); + SmtpClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test"); + Pop3ClientSimulator.AssertMessageCount(testAccount.Address, "test", 1); IMAPFolder inboxFolder = testAccount.IMAPFolders[0]; Assert.AreEqual(1, inboxFolder.CurrentUID); Assert.AreEqual(1, inboxFolder.Messages[0].UID); - SMTPClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test"); - POP3ClientSimulator.AssertMessageCount(testAccount.Address, "test", 2); + SmtpClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test"); + Pop3ClientSimulator.AssertMessageCount(testAccount.Address, "test", 2); Assert.AreEqual(2, inboxFolder.CurrentUID); Assert.AreEqual(2, inboxFolder.Messages[1].UID); CreateMoveRule(testAccount.Rules, "TestFolder"); // This message will be moved into the test folder. - SMTPClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test"); + SmtpClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test"); // Wait for the message to arrive. CustomAsserts.AssertFolderExists(testAccount.IMAPFolders, "TestFolder"); @@ -165,21 +165,21 @@ public void TestMoveMessageWithGlobalRule() "test"); // First deliver two messages to the inbox. - SMTPClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test"); - POP3ClientSimulator.AssertMessageCount(testAccount.Address, "test", 1); + SmtpClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test"); + Pop3ClientSimulator.AssertMessageCount(testAccount.Address, "test", 1); IMAPFolder inboxFolder = testAccount.IMAPFolders[0]; Assert.AreEqual(1, inboxFolder.CurrentUID); Assert.AreEqual(1, inboxFolder.Messages[0].UID); - SMTPClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test"); - POP3ClientSimulator.AssertMessageCount(testAccount.Address, "test", 2); + SmtpClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test"); + Pop3ClientSimulator.AssertMessageCount(testAccount.Address, "test", 2); Assert.AreEqual(2, inboxFolder.CurrentUID); Assert.AreEqual(2, inboxFolder.Messages[1].UID); CreateMoveRule(_application.Rules, "TestFolder"); // This message will be moved into the test folder. - SMTPClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test"); + SmtpClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test"); // Wait for the message to arrive. CustomAsserts.AssertFolderExists(testAccount.IMAPFolders, "TestFolder"); @@ -205,19 +205,19 @@ public void TestSaveMessageWithScriptAndMoveMessageWithAccountRule() Account testAccount = SingletonProvider.Instance.AddAccount(_domain, "Test'Account@test.com", "test"); - var sim = new IMAPClientSimulator(); + var sim = new ImapClientSimulator(); Assert.IsTrue(sim.ConnectAndLogon(testAccount.Address, "test")); // First deliver two messages to the inbox. - SMTPClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test"); - POP3ClientSimulator.AssertMessageCount(testAccount.Address, "test", 1); + SmtpClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test"); + Pop3ClientSimulator.AssertMessageCount(testAccount.Address, "test", 1); IMAPFolder inboxFolder = testAccount.IMAPFolders[0]; Assert.AreEqual(1, inboxFolder.CurrentUID); Assert.AreEqual(1, inboxFolder.Messages[0].UID); Assert.IsTrue(sim.Status("INBOX", "UIDNEXT").Contains("UIDNEXT 2")); - SMTPClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test"); - POP3ClientSimulator.AssertMessageCount(testAccount.Address, "test", 2); + SmtpClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test"); + Pop3ClientSimulator.AssertMessageCount(testAccount.Address, "test", 2); Assert.IsTrue(sim.Status("INBOX", "UIDNEXT").Contains("UIDNEXT 3")); Assert.AreEqual(2, inboxFolder.CurrentUID); Assert.AreEqual(2, inboxFolder.Messages[1].UID); @@ -226,7 +226,7 @@ public void TestSaveMessageWithScriptAndMoveMessageWithAccountRule() CreateMoveRule(testAccount.Rules, "TestFolder"); // This message will be moved into the test folder. - SMTPClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test"); + SmtpClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test"); // Wait for the message to arrive. CustomAsserts.AssertFolderExists(testAccount.IMAPFolders, "TestFolder"); @@ -255,19 +255,19 @@ public void TestSaveMessageWithScriptAndMoveMessageWithGlobalRule() Account testAccount = SingletonProvider.Instance.AddAccount(_domain, "Test'Account@test.com", "test"); - var sim = new IMAPClientSimulator(); + var sim = new ImapClientSimulator(); Assert.IsTrue(sim.ConnectAndLogon(testAccount.Address, "test")); // First deliver two messages to the inbox. - SMTPClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test"); - POP3ClientSimulator.AssertMessageCount(testAccount.Address, "test", 1); + SmtpClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test"); + Pop3ClientSimulator.AssertMessageCount(testAccount.Address, "test", 1); IMAPFolder inboxFolder = testAccount.IMAPFolders[0]; Assert.AreEqual(1, inboxFolder.CurrentUID); Assert.AreEqual(1, inboxFolder.Messages[0].UID); Assert.IsTrue(sim.Status("INBOX", "UIDNEXT").Contains("UIDNEXT 2")); - SMTPClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test"); - POP3ClientSimulator.AssertMessageCount(testAccount.Address, "test", 2); + SmtpClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test"); + Pop3ClientSimulator.AssertMessageCount(testAccount.Address, "test", 2); Assert.AreEqual(2, inboxFolder.CurrentUID); Assert.AreEqual(2, inboxFolder.Messages[1].UID); Assert.IsTrue(sim.Status("INBOX", "UIDNEXT").Contains("UIDNEXT 3")); @@ -277,7 +277,7 @@ public void TestSaveMessageWithScriptAndMoveMessageWithGlobalRule() // This message will be moved into the test folder. - SMTPClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test"); + SmtpClientSimulator.StaticSend(testAccount.Address, testAccount.Address, "Test", "Test"); // Wait for the message to arrive. CustomAsserts.AssertFolderExists(testAccount.IMAPFolders, "TestFolder"); diff --git a/hmailserver/test/RegressionTests/IMAP/Search.cs b/hmailserver/test/RegressionTests/IMAP/Search.cs index 6f42d0c07..00aa337b1 100644 --- a/hmailserver/test/RegressionTests/IMAP/Search.cs +++ b/hmailserver/test/RegressionTests/IMAP/Search.cs @@ -24,12 +24,12 @@ public void TestNestedOr() Account oAccount = SingletonProvider.Instance.AddAccount(_domain, "search@test.com", "test"); // Send a message to this account. - var oSMTP = new SMTPClientSimulator(); - oSMTP.Send("search@test.com", "search@test.com", "Search test", "This is a test of IMAP Search"); + var smtpClientSimulator = new SmtpClientSimulator(); + smtpClientSimulator.Send("search@test.com", "search@test.com", "Search test", "This is a test of IMAP Search"); - IMAPClientSimulator.AssertMessageCount(oAccount.Address, "test", "Inbox", 1); + ImapClientSimulator.AssertMessageCount(oAccount.Address, "test", "Inbox", 1); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon("search@test.com", "test"); oSimulator.SelectFolder("INBOX"); @@ -55,12 +55,12 @@ public void TestNestedOrSearch() Account oAccount = SingletonProvider.Instance.AddAccount(_domain, "search@test.com", "test"); // Send a message to this account. - var oSMTP = new SMTPClientSimulator(); - oSMTP.Send("search@test.com", "search@test.com", "Search test", "This is a test of IMAP Search"); + var smtpClientSimulator = new SmtpClientSimulator(); + smtpClientSimulator.Send("search@test.com", "search@test.com", "Search test", "This is a test of IMAP Search"); - IMAPClientSimulator.AssertMessageCount(oAccount.Address, "test", "Inbox", 1); + ImapClientSimulator.AssertMessageCount(oAccount.Address, "test", "Inbox", 1); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon("search@test.com", "test"); oSimulator.SelectFolder("INBOX"); @@ -84,12 +84,12 @@ public void TestSearch() Account oAccount = SingletonProvider.Instance.AddAccount(_domain, "se'arch@test.com", "test"); // Send a message to this account. - var oSMTP = new SMTPClientSimulator(); - oSMTP.Send(oAccount.Address, oAccount.Address, "Search test", "This is a test of IMAP Search"); + var smtpClientSimulator = new SmtpClientSimulator(); + smtpClientSimulator.Send(oAccount.Address, oAccount.Address, "Search test", "This is a test of IMAP Search"); - IMAPClientSimulator.AssertMessageCount(oAccount.Address, "test", "INBOX", 1); + ImapClientSimulator.AssertMessageCount(oAccount.Address, "test", "INBOX", 1); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon(oAccount.Address, "test"); @@ -186,11 +186,11 @@ public void TestSearchInvalidCharset() { Account account = SingletonProvider.Instance.AddAccount(_domain, "search@test.com", "test"); - SMTPClientSimulator.StaticSend(account.Address, account.Address, "MySubject", "MyBody"); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "MySubject", "MyBody"); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); Assert.IsTrue(oSimulator.ConnectAndLogon(account.Address, "test")); Assert.IsTrue(oSimulator.SelectFolder("INBOX")); @@ -211,11 +211,11 @@ public void TestSearchLargeBody() body.AppendLine("TestString"); body.AppendLine(); - SMTPClientSimulator.StaticSendRaw(account.Address, account.Address, body.ToString()); + SmtpClientSimulator.StaticSendRaw(account.Address, account.Address, body.ToString()); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); Assert.IsTrue(oSimulator.ConnectAndLogon(account.Address, "test")); Assert.IsTrue(oSimulator.SelectFolder("INBOX")); string result = oSimulator.Search("CHARSET UTF-8 ALL TEXT InvalidText"); @@ -245,11 +245,11 @@ public void TestSearchON() Account oAccount = SingletonProvider.Instance.AddAccount(_domain, "search@test.com", "test"); // Send a message to this account. - var oSMTP = new SMTPClientSimulator(); - oSMTP.Send("search@test.com", "search@test.com", "Search test", "This is a test of IMAP Search"); - IMAPClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 1); + var smtpClientSimulator = new SmtpClientSimulator(); + smtpClientSimulator.Send("search@test.com", "search@test.com", "Search test", "This is a test of IMAP Search"); + ImapClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 1); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon("search@test.com", "test"); @@ -277,11 +277,11 @@ public void TestSearchOR() SingletonProvider.Instance.AddAccount(_domain, "search@test.com", "test"); // Send a message to this account. - var oSMTP = new SMTPClientSimulator(); - oSMTP.Send("search@test.com", "search@test.com", "Search test", "This is a test of IMAP Search"); - IMAPClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 1); + var smtpClientSimulator = new SmtpClientSimulator(); + smtpClientSimulator.Send("search@test.com", "search@test.com", "Search test", "This is a test of IMAP Search"); + ImapClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 1); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon("search@test.com", "test"); @@ -306,13 +306,13 @@ public void TestSearchORWithLiterals() Account oAccount = SingletonProvider.Instance.AddAccount(_domain, "search@test.com", "test"); // Send a message to this account. - var oSMTP = new SMTPClientSimulator(); - oSMTP.Send("search@test.com", "search@test.com", "Test1", "This is a test of IMAP Search"); - IMAPClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 1); - oSMTP.Send("search@test.com", "search@test.com", "Test2", "This is a test of IMAP Search"); - IMAPClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 2); + var smtpClientSimulator = new SmtpClientSimulator(); + smtpClientSimulator.Send("search@test.com", "search@test.com", "Test1", "This is a test of IMAP Search"); + ImapClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 1); + smtpClientSimulator.Send("search@test.com", "search@test.com", "Test2", "This is a test of IMAP Search"); + ImapClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 2); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon("search@test.com", "test"); @@ -334,13 +334,13 @@ public void TestSearchORWithLiterals2() Account oAccount = SingletonProvider.Instance.AddAccount(_domain, "search@test.com", "test"); // Send a message to this account. - var oSMTP = new SMTPClientSimulator(); - oSMTP.Send("search@test.com", "search@test.com", "Test1", "This is a test of IMAP Search"); - IMAPClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 1); - oSMTP.Send("search@test.com", "search@test.com", "Test2", "This is a test of IMAP Search"); - IMAPClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 2); + var smtpClientSimulator = new SmtpClientSimulator(); + smtpClientSimulator.Send("search@test.com", "search@test.com", "Test1", "This is a test of IMAP Search"); + ImapClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 1); + smtpClientSimulator.Send("search@test.com", "search@test.com", "Test2", "This is a test of IMAP Search"); + ImapClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 2); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon("search@test.com", "test"); @@ -362,13 +362,13 @@ public void TestSearchORWithLiterals3() Account oAccount = SingletonProvider.Instance.AddAccount(_domain, "search@test.com", "test"); // Send a message to this account. - var oSMTP = new SMTPClientSimulator(); - oSMTP.Send("search@test.com", "search@test.com", "Test1", "This is a test of IMAP Search"); - IMAPClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 1); - oSMTP.Send("search@test.com", "search@test.com", "Test2", "This is a test of IMAP Search"); - IMAPClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 2); + var smtpClientSimulator = new SmtpClientSimulator(); + smtpClientSimulator.Send("search@test.com", "search@test.com", "Test1", "This is a test of IMAP Search"); + ImapClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 1); + smtpClientSimulator.Send("search@test.com", "search@test.com", "Test2", "This is a test of IMAP Search"); + ImapClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 2); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon("search@test.com", "test"); @@ -390,13 +390,13 @@ public void TestSearchORWithParenthesis() Account oAccount = SingletonProvider.Instance.AddAccount(_domain, "search@test.com", "test"); // Send a message to this account. - var oSMTP = new SMTPClientSimulator(); - oSMTP.Send("search@test.com", "search@test.com", "Search test", "This is a test of IMAP Search"); - IMAPClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 1); - oSMTP.Send("search@test.com", "search@test.com", "Search test", "This is a test of IMAP Search"); - IMAPClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 2); + var smtpClientSimulator = new SmtpClientSimulator(); + smtpClientSimulator.Send("search@test.com", "search@test.com", "Search test", "This is a test of IMAP Search"); + ImapClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 1); + smtpClientSimulator.Send("search@test.com", "search@test.com", "Search test", "This is a test of IMAP Search"); + ImapClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 2); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon("search@test.com", "test"); @@ -417,13 +417,13 @@ public void TestSearchORWithParenthesisSubject() Account oAccount = SingletonProvider.Instance.AddAccount(_domain, "search@test.com", "test"); // Send a message to this account. - var oSMTP = new SMTPClientSimulator(); - oSMTP.Send("search@test.com", "search@test.com", "Test1", "This is a test of IMAP Search"); - IMAPClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 1); - oSMTP.Send("search@test.com", "search@test.com", "Test2", "This is a test of IMAP Search"); - IMAPClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 2); + var smtpClientSimulator = new SmtpClientSimulator(); + smtpClientSimulator.Send("search@test.com", "search@test.com", "Test1", "This is a test of IMAP Search"); + ImapClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 1); + smtpClientSimulator.Send("search@test.com", "search@test.com", "Test2", "This is a test of IMAP Search"); + ImapClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 2); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon("search@test.com", "test"); @@ -449,13 +449,13 @@ public void TestSearchORWithParenthesisSubjectNested() Account oAccount = SingletonProvider.Instance.AddAccount(_domain, "search@test.com", "test"); // Send a message to this account. - var oSMTP = new SMTPClientSimulator(); - oSMTP.Send("search@test.com", "search@test.com", "Test1", "This is a test of IMAP Search"); - IMAPClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 1); - oSMTP.Send("search@test.com", "search@test.com", "Test2", "This is a test of IMAP Search"); - IMAPClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 2); + var smtpClientSimulator = new SmtpClientSimulator(); + smtpClientSimulator.Send("search@test.com", "search@test.com", "Test1", "This is a test of IMAP Search"); + ImapClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 1); + smtpClientSimulator.Send("search@test.com", "search@test.com", "Test2", "This is a test of IMAP Search"); + ImapClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 2); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon("search@test.com", "test"); @@ -477,13 +477,13 @@ public void TestSearchRange() Account oAccount = SingletonProvider.Instance.AddAccount(_domain, "search@test.com", "test"); // Send a message to this account. - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); for (int i = 0; i < 5; i++) - oSMTP.Send("search@test.com", "search@test.com", "Test1", "This is a test of IMAP Search"); + smtpClientSimulator.Send("search@test.com", "search@test.com", "Test1", "This is a test of IMAP Search"); - IMAPClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 5); + ImapClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 5); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon("search@test.com", "test"); Assert.IsTrue(oSimulator.SelectFolder("INBOX")); @@ -514,14 +514,14 @@ public void TestSearchUID() Account account = SingletonProvider.Instance.AddAccount(_domain, "search@test.com", "test"); // Send a message to this account. - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); for (int i = 0; i < 3; i++) - oSMTP.Send("search@test.com", "search@test.com", "Test1", "This is a test of IMAP Search"); + smtpClientSimulator.Send("search@test.com", "search@test.com", "Test1", "This is a test of IMAP Search"); - IMAPClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 3); + ImapClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 3); // There should be 3 UID's, 1,2,3 or similar. No skips in the middle fo them. - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon("search@test.com", "test"); Assert.IsTrue(oSimulator.SelectFolder("INBOX")); @@ -555,11 +555,11 @@ public void TestSearchUSASCII() { Account account = SingletonProvider.Instance.AddAccount(_domain, "search@test.com", "test"); - SMTPClientSimulator.StaticSend(account.Address, account.Address, "MySubject", "MyBody"); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "MySubject", "MyBody"); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); Assert.IsTrue(oSimulator.ConnectAndLogon(account.Address, "test")); Assert.IsTrue(oSimulator.SelectFolder("INBOX")); @@ -577,11 +577,11 @@ public void TestSearchUTF8() string body = TestSetup.GetResource("Messages.MessageContainingGreekAndJapanese.txt"); - SMTPClientSimulator.StaticSendRaw(account.Address, account.Address, body); + SmtpClientSimulator.StaticSendRaw(account.Address, account.Address, body); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); Assert.IsTrue(oSimulator.ConnectAndLogon(account.Address, "test")); Assert.IsTrue(oSimulator.SelectFolder("INBOX")); @@ -616,11 +616,11 @@ public void TestSearchUTF8TEXT() { Account account = SingletonProvider.Instance.AddAccount(_domain, "search@test.com", "test"); string body = TestSetup.GetResource("Messages.MessageContainingGreekSubject.txt"); - SMTPClientSimulator.StaticSendRaw(account.Address, account.Address, body); + SmtpClientSimulator.StaticSendRaw(account.Address, account.Address, body); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); Assert.IsTrue(oSimulator.ConnectAndLogon(account.Address, "test")); Assert.IsTrue(oSimulator.SelectFolder("INBOX")); @@ -645,13 +645,13 @@ public void TestSearchWithLiterals() Account oAccount = SingletonProvider.Instance.AddAccount(_domain, "search@test.com", "test"); // Send a message to this account. - var oSMTP = new SMTPClientSimulator(); - oSMTP.Send("search@test.com", "search@test.com", "Test1", "This is a test of IMAP Search"); - IMAPClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 1); - oSMTP.Send("search@test.com", "search@test.com", "Test2", "This is a test of IMAP Search"); - IMAPClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 2); + var smtpClientSimulator = new SmtpClientSimulator(); + smtpClientSimulator.Send("search@test.com", "search@test.com", "Test1", "This is a test of IMAP Search"); + ImapClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 1); + smtpClientSimulator.Send("search@test.com", "search@test.com", "Test2", "This is a test of IMAP Search"); + ImapClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 2); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon("search@test.com", "test"); diff --git a/hmailserver/test/RegressionTests/IMAP/Sort.cs b/hmailserver/test/RegressionTests/IMAP/Sort.cs index 039613960..68832d8fc 100644 --- a/hmailserver/test/RegressionTests/IMAP/Sort.cs +++ b/hmailserver/test/RegressionTests/IMAP/Sort.cs @@ -31,7 +31,7 @@ public class Sort : TestFixtureBase public void TestDateSortOrder() { Account oAccount = SingletonProvider.Instance.AddAccount(_domain, "imapsort@test.com", "test"); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.LogonWithLiteral("imapsort@test.com", "test"); @@ -65,7 +65,7 @@ public void TestDateSortOrder() public void TestDateSortOrderNonexistantDate() { Account oAccount = SingletonProvider.Instance.AddAccount(_domain, "imapsort@test.com", "test"); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.LogonWithLiteral("imapsort@test.com", "test"); @@ -107,11 +107,11 @@ public void TestSearchSpecficUID() Account oAccount = SingletonProvider.Instance.AddAccount(_domain, "search@test.com", "test"); // Send a message to this account. - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); for (int i = 0; i < 5; i++) - oSMTP.Send("search@test.com", "search@test.com", "Test1", "This is a test of IMAP Search"); + smtpClientSimulator.Send("search@test.com", "search@test.com", "Test1", "This is a test of IMAP Search"); - IMAPClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 5); + ImapClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 5); Messages messages = oAccount.IMAPFolders.get_ItemByName("Inbox").Messages; @@ -120,7 +120,7 @@ public void TestSearchSpecficUID() int fourth = messages[3].UID; - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); oSimulator.Connect(); oSimulator.Logon("search@test.com", "test"); Assert.IsTrue(oSimulator.SelectFolder("INBOX")); @@ -173,13 +173,13 @@ public void TestSortDeletedOrAnswered() Account oAccount = SingletonProvider.Instance.AddAccount(_domain, "search@test.com", "test"); // Send a message to this account. - var oSMTP = new SMTPClientSimulator(); - oSMTP.Send("search@test.com", "search@test.com", "aa", "This is a test of IMAP Search"); - IMAPClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 1); - oSMTP.Send("search@test.com", "search@test.com", "bb", "This is a test of IMAP Search"); - IMAPClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 2); + var smtpClientSimulator = new SmtpClientSimulator(); + smtpClientSimulator.Send("search@test.com", "search@test.com", "aa", "This is a test of IMAP Search"); + ImapClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 1); + smtpClientSimulator.Send("search@test.com", "search@test.com", "bb", "This is a test of IMAP Search"); + ImapClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 2); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon("search@test.com", "test"); Assert.IsTrue(oSimulator.SelectFolder("INBOX")); @@ -194,17 +194,17 @@ public void TestSortReverseArrival() Account oAccount = SingletonProvider.Instance.AddAccount(_domain, "search@test.com", "test"); // Send a message to this account. - var oSMTP = new SMTPClientSimulator(); - oSMTP.Send("search@test.com", "search@test.com", "Test1", "This is a test of IMAP Search"); - IMAPClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 1); + var smtpClientSimulator = new SmtpClientSimulator(); + smtpClientSimulator.Send("search@test.com", "search@test.com", "Test1", "This is a test of IMAP Search"); + ImapClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 1); // The two messages needs to be sent a second apart, so we actually need to pause a bit here. Thread.Sleep(1000); - oSMTP.Send("search@test.com", "search@test.com", "Test2", "This is a test of IMAP Search"); - IMAPClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 2); + smtpClientSimulator.Send("search@test.com", "search@test.com", "Test2", "This is a test of IMAP Search"); + ImapClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 2); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon("search@test.com", "test"); @@ -224,14 +224,14 @@ public void TestSortReverseSize() longBodyString.Append('A', 10000); // Send a message to this account. - var oSMTP = new SMTPClientSimulator(); - oSMTP.Send("search@test.com", "search@test.com", "Test1", longBodyString.ToString()); - IMAPClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 1); + var smtpClientSimulator = new SmtpClientSimulator(); + smtpClientSimulator.Send("search@test.com", "search@test.com", "Test1", longBodyString.ToString()); + ImapClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 1); - oSMTP.Send("search@test.com", "search@test.com", "Test2", "Test body"); - IMAPClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 2); + smtpClientSimulator.Send("search@test.com", "search@test.com", "Test2", "Test body"); + ImapClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 2); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon("search@test.com", "test"); @@ -248,13 +248,13 @@ public void TestSortSubject() Account oAccount = SingletonProvider.Instance.AddAccount(_domain, "search@test.com", "test"); // Send a message to this account. - var oSMTP = new SMTPClientSimulator(); - oSMTP.Send("search@test.com", "search@test.com", "Test1", "This is a test of IMAP Search"); - IMAPClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 1); - oSMTP.Send("search@test.com", "search@test.com", "Test2", "This is a test of IMAP Search"); - IMAPClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 2); + var smtpClientSimulator = new SmtpClientSimulator(); + smtpClientSimulator.Send("search@test.com", "search@test.com", "Test1", "This is a test of IMAP Search"); + ImapClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 1); + smtpClientSimulator.Send("search@test.com", "search@test.com", "Test2", "This is a test of IMAP Search"); + ImapClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 2); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon("search@test.com", "test"); @@ -270,13 +270,13 @@ public void TestSortSubjectReverse() Account oAccount = SingletonProvider.Instance.AddAccount(_domain, "search@test.com", "test"); // Send a message to this account. - var oSMTP = new SMTPClientSimulator(); - oSMTP.Send("search@test.com", "search@test.com", "Test1", "This is a test of IMAP Search"); - IMAPClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 1); - oSMTP.Send("search@test.com", "search@test.com", "Test2", "This is a test of IMAP Search"); - IMAPClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 2); + var smtpClientSimulator = new SmtpClientSimulator(); + smtpClientSimulator.Send("search@test.com", "search@test.com", "Test1", "This is a test of IMAP Search"); + ImapClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 1); + smtpClientSimulator.Send("search@test.com", "search@test.com", "Test2", "This is a test of IMAP Search"); + ImapClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 2); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon("search@test.com", "test"); @@ -292,13 +292,13 @@ public void TestSortSubjectSearch() Account oAccount = SingletonProvider.Instance.AddAccount(_domain, "search@test.com", "test"); // Send a message to this account. - var oSMTP = new SMTPClientSimulator(); - oSMTP.Send("search@test.com", "search@test.com", "aa", "This is a test of IMAP Search"); - IMAPClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 1); - oSMTP.Send("search@test.com", "search@test.com", "bb", "This is a test of IMAP Search"); - IMAPClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 2); + var smtpClientSimulator = new SmtpClientSimulator(); + smtpClientSimulator.Send("search@test.com", "search@test.com", "aa", "This is a test of IMAP Search"); + ImapClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 1); + smtpClientSimulator.Send("search@test.com", "search@test.com", "bb", "This is a test of IMAP Search"); + ImapClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 2); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon("search@test.com", "test"); Assert.IsTrue(oSimulator.SelectFolder("INBOX")); @@ -328,13 +328,13 @@ public void TestSubjectSearch() Account oAccount = SingletonProvider.Instance.AddAccount(_domain, "search@test.com", "test"); // Send a message to this account. - var oSMTP = new SMTPClientSimulator(); - oSMTP.Send("search@test.com", "search@test.com", "Test1", "This is a test of IMAP Search"); - IMAPClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 1); - oSMTP.Send("search@test.com", "search@test.com", "Test2", "This is a test of IMAP Search"); - IMAPClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 2); + var smtpClientSimulator = new SmtpClientSimulator(); + smtpClientSimulator.Send("search@test.com", "search@test.com", "Test1", "This is a test of IMAP Search"); + ImapClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 1); + smtpClientSimulator.Send("search@test.com", "search@test.com", "Test2", "This is a test of IMAP Search"); + ImapClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 2); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon("search@test.com", "test"); @@ -354,15 +354,15 @@ public void TestSubjectSearchMultipleMatches() Account oAccount = SingletonProvider.Instance.AddAccount(_domain, "search@test.com", "test"); // Send a message to this account. - var oSMTP = new SMTPClientSimulator(); - oSMTP.Send("search@test.com", "search@test.com", "Test1", "This is a test of IMAP Search"); - IMAPClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 1); - oSMTP.Send("search@test.com", "search@test.com", "TestA", "This is a test of IMAP Search"); - IMAPClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 2); - oSMTP.Send("search@test.com", "search@test.com", "Test1", "This is a test of IMAP Search"); - IMAPClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 3); + var smtpClientSimulator = new SmtpClientSimulator(); + smtpClientSimulator.Send("search@test.com", "search@test.com", "Test1", "This is a test of IMAP Search"); + ImapClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 1); + smtpClientSimulator.Send("search@test.com", "search@test.com", "TestA", "This is a test of IMAP Search"); + ImapClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 2); + smtpClientSimulator.Send("search@test.com", "search@test.com", "Test1", "This is a test of IMAP Search"); + ImapClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 3); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon("search@test.com", "test"); @@ -383,13 +383,13 @@ public void TestSubjectSearchValueWithParanthesis() Account oAccount = SingletonProvider.Instance.AddAccount(_domain, "search@test.com", "test"); // Send a message to this account. - var oSMTP = new SMTPClientSimulator(); - oSMTP.Send("search@test.com", "search@test.com", "Te(st1", "This is a test of IMAP Search"); - IMAPClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 1); - oSMTP.Send("search@test.com", "search@test.com", "Te)st2", "This is a test of IMAP Search"); - IMAPClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 2); + var smtpClientSimulator = new SmtpClientSimulator(); + smtpClientSimulator.Send("search@test.com", "search@test.com", "Te(st1", "This is a test of IMAP Search"); + ImapClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 1); + smtpClientSimulator.Send("search@test.com", "search@test.com", "Te)st2", "This is a test of IMAP Search"); + ImapClientSimulator.AssertMessageCount("search@test.com", "test", "INBOX", 2); - var oSimulator = new IMAPClientSimulator(); + var oSimulator = new ImapClientSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon("search@test.com", "test"); diff --git a/hmailserver/test/RegressionTests/Infrastructure/AccountProperties.cs b/hmailserver/test/RegressionTests/Infrastructure/AccountProperties.cs index 5addf241b..c306360c3 100644 --- a/hmailserver/test/RegressionTests/Infrastructure/AccountProperties.cs +++ b/hmailserver/test/RegressionTests/Infrastructure/AccountProperties.cs @@ -22,10 +22,10 @@ public void SizeAfterSend() // Send a message for (int i = 0; i < 30; i++) - SMTPClientSimulator.StaticSend("test@test.com", "test@test.com", "Test message", + SmtpClientSimulator.StaticSend("test@test.com", "test@test.com", "Test message", "123456789012345678901234567890123456789012345678901234567890"); - IMAPClientSimulator.AssertMessageCount("test@test.com", "test", "Inbox", 30); + ImapClientSimulator.AssertMessageCount("test@test.com", "test", "Inbox", 30); float size = account.Size; if (size == 0) @@ -56,13 +56,13 @@ public void SizeIncreasedWhenMessageReceived() string body = TestSetup.CreateLargeDummyMailBody(); // Send a message - SMTPClientSimulator.StaticSend("test@test.com", "test@test.com", "Test message", body); - IMAPClientSimulator.AssertMessageCount("test@test.com", "test", "Inbox", 1); + SmtpClientSimulator.StaticSend("test@test.com", "test@test.com", "Test message", body); + ImapClientSimulator.AssertMessageCount("test@test.com", "test", "Inbox", 1); float sizeBefore = account.Size; - SMTPClientSimulator.StaticSend("test@test.com", "test@test.com", "Test message", body); - IMAPClientSimulator.AssertMessageCount("test@test.com", "test", "Inbox", 2); + SmtpClientSimulator.StaticSend("test@test.com", "test@test.com", "Test message", body); + ImapClientSimulator.AssertMessageCount("test@test.com", "test", "Inbox", 2); float sizeAfter = account.Size; diff --git a/hmailserver/test/RegressionTests/Infrastructure/AccountServices.cs b/hmailserver/test/RegressionTests/Infrastructure/AccountServices.cs index c77de9619..2f18ff12a 100644 --- a/hmailserver/test/RegressionTests/Infrastructure/AccountServices.cs +++ b/hmailserver/test/RegressionTests/Infrastructure/AccountServices.cs @@ -27,14 +27,14 @@ public void ConfirmSingleReturnPathAfterAccountForward() oAccount1.Save(); // Send a message... - var oSMTP = new SMTPClientSimulator(); - oSMTP.Send("original-address@test.com", oAccount1.Address, "Test message", "This is the body"); + var smtpClientSimulator = new SmtpClientSimulator(); + smtpClientSimulator.Send("original-address@test.com", oAccount1.Address, "Test message", "This is the body"); CustomAsserts.AssertRecipientsInDeliveryQueue(0); _application.SubmitEMail(); // Wait for the auto-reply. - string text = POP3ClientSimulator.AssertGetFirstMessageText(oAccount2.Address, "test"); + string text = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount2.Address, "test"); Assert.IsFalse(text.Contains("Return-Path: account2@test.com")); Assert.IsFalse(text.Contains("Return-Path: original-address@test.com")); @@ -73,12 +73,12 @@ public void ConfirmSingleReturnPathAfterRuleForward() oRule.Save(); // Make sure that that a forward is made if no rule is set up. - SMTPClientSimulator.StaticSend("external@test.com", oAccount1.Address, "Test message", "This is the body"); - POP3ClientSimulator.AssertMessageCount(oAccount1.Address, "test", 1); + SmtpClientSimulator.StaticSend("external@test.com", oAccount1.Address, "Test message", "This is the body"); + Pop3ClientSimulator.AssertMessageCount(oAccount1.Address, "test", 1); _application.SubmitEMail(); // Wait for the auto-reply. - string text = POP3ClientSimulator.AssertGetFirstMessageText(oAccount2.Address, "test"); + string text = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount2.Address, "test"); Assert.IsTrue(text.Contains("Return-Path: account-a@test.com")); Assert.IsFalse(text.Contains("Return-Path: account2@test.com")); @@ -97,11 +97,11 @@ public void TestAddressContainingSingleQuote() SingletonProvider.Instance.AddAlias(_domain, "alias2'quoted@test.com", "Addr'ess2@test.com"); // Send 5 messages to this account. - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); for (int i = 0; i < 5; i++) - oSMTP.Send(oAccount1.Address, "alias2'quoted@test.com", "INBOX", "Quoted message test message"); + smtpClientSimulator.Send(oAccount1.Address, "alias2'quoted@test.com", "INBOX", "Quoted message test message"); - POP3ClientSimulator.AssertMessageCount(oAccount2.Address, "test", 5); + Pop3ClientSimulator.AssertMessageCount(oAccount2.Address, "test", 5); } [Test] @@ -124,13 +124,13 @@ public void TestAutoReply() oAccount2.Save(); // Send 2 messages to this account. - var oSMTP = new SMTPClientSimulator(); - oSMTP.Send(oAccount1.Address, oAccount2.Address, "Test message", "This is the body"); + var smtpClientSimulator = new SmtpClientSimulator(); + smtpClientSimulator.Send(oAccount1.Address, oAccount2.Address, "Test message", "This is the body"); - var oPOP3 = new POP3ClientSimulator(); - POP3ClientSimulator.AssertMessageCount(oAccount1.Address, "test", 1); - POP3ClientSimulator.AssertMessageCount(oAccount2.Address, "test", 1); - string s = oPOP3.GetFirstMessageText(oAccount1.Address, "test"); + var pop3ClientSimulator = new Pop3ClientSimulator(); + Pop3ClientSimulator.AssertMessageCount(oAccount1.Address, "test", 1); + Pop3ClientSimulator.AssertMessageCount(oAccount2.Address, "test", 1); + string s = pop3ClientSimulator.GetFirstMessageText(oAccount1.Address, "test"); if (s.IndexOf("Out of office!") < 0) throw new Exception("ERROR - Auto reply subject not set properly."); @@ -142,12 +142,12 @@ public void TestAutoReply() oAccount2.Save(); // Send another - oSMTP.Send(oAccount1.Address, oAccount2.Address, "Test message", "This is the body"); + smtpClientSimulator.Send(oAccount1.Address, oAccount2.Address, "Test message", "This is the body"); - POP3ClientSimulator.AssertMessageCount(oAccount2.Address, "test", 2); - POP3ClientSimulator.AssertMessageCount(oAccount1.Address, "test", 1); + Pop3ClientSimulator.AssertMessageCount(oAccount2.Address, "test", 2); + Pop3ClientSimulator.AssertMessageCount(oAccount1.Address, "test", 1); - s = oPOP3.GetFirstMessageText(oAccount1.Address, "test"); + s = pop3ClientSimulator.GetFirstMessageText(oAccount1.Address, "test"); if (s.ToLower().IndexOf("re: test message") < 0) throw new Exception("ERROR - Auto reply subject not set properly."); @@ -184,16 +184,16 @@ public void TestAutoReplyCombinedWithForwarding() oAccount2.Save(); // Send a message... - var oSMTP = new SMTPClientSimulator(); - oSMTP.Send(oAccount1.Address, oAccount2.Address, "Test message", "This is the body"); + var smtpClientSimulator = new SmtpClientSimulator(); + smtpClientSimulator.Send(oAccount1.Address, oAccount2.Address, "Test message", "This is the body"); SingletonProvider.Instance.GetApp().SubmitEMail(); CustomAsserts.AssertRecipientsInDeliveryQueue(0); // Wait for the auto-reply. - POP3ClientSimulator.AssertMessageCount(oAccount1.Address, "test", 1); - POP3ClientSimulator.AssertMessageCount(oAccount2.Address, "test", 1); - POP3ClientSimulator.AssertMessageCount(oAccount3.Address, "test", 1); + Pop3ClientSimulator.AssertMessageCount(oAccount1.Address, "test", 1); + Pop3ClientSimulator.AssertMessageCount(oAccount2.Address, "test", 1); + Pop3ClientSimulator.AssertMessageCount(oAccount3.Address, "test", 1); } [Test] @@ -216,17 +216,17 @@ public void TestAutoReplySubject() oAccount2.Save(); // Send 1 message to this account - var oSMTP = new SMTPClientSimulator(); - oSMTP.Send(oAccount1.Address, oAccount2.Address, "Test message", "This is the body"); + var smtpClientSimulator = new SmtpClientSimulator(); + smtpClientSimulator.Send(oAccount1.Address, oAccount2.Address, "Test message", "This is the body"); // Wait a second to be sure that the message // are delivered. // Check using POP3 that 2 messages exists. - var oPOP3 = new POP3ClientSimulator(); + var pop3ClientSimulator = new Pop3ClientSimulator(); - POP3ClientSimulator.AssertMessageCount(oAccount1.Address, "test", 1); - string s = oPOP3.GetFirstMessageText(oAccount1.Address, "test"); + Pop3ClientSimulator.AssertMessageCount(oAccount1.Address, "test", 1); + string s = pop3ClientSimulator.GetFirstMessageText(oAccount1.Address, "test"); if (s.IndexOf("Subject: Auto-Reply: Test message") < 0) throw new Exception("ERROR - Auto reply subject not set properly."); } @@ -251,10 +251,10 @@ public void TestAutoReplySubjectInBody() oAccount2.Save(); // Send 1 message to this account - var oSMTP = new SMTPClientSimulator(); - oSMTP.Send(oAccount1.Address, oAccount2.Address, "Test message", "This is the body"); + var smtpClientSimulator = new SmtpClientSimulator(); + smtpClientSimulator.Send(oAccount1.Address, oAccount2.Address, "Test message", "This is the body"); - string s = POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); + string s = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); if (s.IndexOf("Your message regarding -Test message- was not received.") < 0) throw new Exception("ERROR - Auto reply subject not set properly."); } @@ -277,16 +277,16 @@ public void TestForwarding() oAccount1.Save(); // Send 2 messages to this account. - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); for (int i = 0; i < 2; i++) - oSMTP.Send("Forward1@test.com", "Forward1@test.com", "INBOX", "POP3 test message"); + smtpClientSimulator.Send("Forward1@test.com", "Forward1@test.com", "INBOX", "POP3 test message"); - POP3ClientSimulator.AssertMessageCount(oAccount1.Address, "test", 2); + Pop3ClientSimulator.AssertMessageCount(oAccount1.Address, "test", 2); // Tell hMailServer to deliver now, so that the forward takes effect. SingletonProvider.Instance.GetApp().SubmitEMail(); - POP3ClientSimulator.AssertMessageCount(oAccount2.Address, "test", 2); + Pop3ClientSimulator.AssertMessageCount(oAccount2.Address, "test", 2); } [Test] @@ -303,16 +303,16 @@ public void WhenForwardingFromAddressShouldBeSetToForwardingAccount() forwarder.ForwardKeepOriginal = true; forwarder.Save(); - var smtpClientSimulator = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); smtpClientSimulator.Send(sender.Address, forwarder.Address, "INBOX", "POP3 test message"); - POP3ClientSimulator.AssertMessageCount(forwarder.Address, "test", 1); + Pop3ClientSimulator.AssertMessageCount(forwarder.Address, "test", 1); // Tell hMailServer to deliver now, so that the forward takes effect. SingletonProvider.Instance.GetApp().SubmitEMail(); - var message = POP3ClientSimulator.AssertGetFirstMessageText(recipient.Address, "test"); + var message = Pop3ClientSimulator.AssertGetFirstMessageText(recipient.Address, "test"); Assert.IsTrue(message.Contains("Return-Path: forwarder@test.com")); @@ -335,10 +335,10 @@ public void TestForwardingAndDelete() oAccount1.Save(); // Send 2 messages to this account. - var oSMTP = new SMTPClientSimulator(); - oSMTP.Send("Forward1@test.com", "Forward1@test.com", "INBOX", "POP3 test message"); + var smtpClientSimulator = new SmtpClientSimulator(); + smtpClientSimulator.Send("Forward1@test.com", "Forward1@test.com", "INBOX", "POP3 test message"); CustomAsserts.AssertRecipientsInDeliveryQueue(0); - POP3ClientSimulator.AssertMessageCount(oAccount2.Address, "test", 1); + Pop3ClientSimulator.AssertMessageCount(oAccount2.Address, "test", 1); string domainDir = Path.Combine(_settings.Directories.DataDirectory, "test.com"); string userDir = Path.Combine(domainDir, "Forward1"); @@ -374,13 +374,13 @@ public void TestForwardingCombinedWithAccountRule() oAccount2.ForwardKeepOriginal = true; oAccount2.Save(); - var oSMTP = new SMTPClientSimulator(); - Assert.IsTrue(oSMTP.Send(oAccount1.Address, oAccount2.Address, "Test message", "This is the body")); + var smtpClientSimulator = new SmtpClientSimulator(); + smtpClientSimulator.Send(oAccount1.Address, oAccount2.Address, "Test message", "This is the body"); // Make sure that that a forward is made if no rule is set up. - POP3ClientSimulator.AssertMessageCount(oAccount2.Address, "test", 1); + Pop3ClientSimulator.AssertMessageCount(oAccount2.Address, "test", 1); _application.SubmitEMail(); - POP3ClientSimulator.AssertMessageCount(oAccount3.Address, "test", 1); + Pop3ClientSimulator.AssertMessageCount(oAccount3.Address, "test", 1); // Start over again. oAccount2.DeleteMessages(); @@ -407,10 +407,10 @@ public void TestForwardingCombinedWithAccountRule() oRule.Save(); // Make sure that that a forward is made if no rule is set up. - Assert.IsTrue(oSMTP.Send(oAccount1.Address, oAccount2.Address, "Test message", "This is the body")); - POP3ClientSimulator.AssertMessageCount(oAccount2.Address, "test", 0); + smtpClientSimulator.Send(oAccount1.Address, oAccount2.Address, "Test message", "This is the body"); + Pop3ClientSimulator.AssertMessageCount(oAccount2.Address, "test", 0); _application.SubmitEMail(); - POP3ClientSimulator.AssertMessageCount(oAccount3.Address, "test", 0); + Pop3ClientSimulator.AssertMessageCount(oAccount3.Address, "test", 0); } [Test] @@ -428,11 +428,11 @@ public void TestLongEmailAddresses() "test"); // Send 5 messages to this account. - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); for (int i = 0; i < 5; i++) - oSMTP.Send(oAccount1.Address, oAccount2.Address, "INBOX", "POP3 test message"); + smtpClientSimulator.Send(oAccount1.Address, oAccount2.Address, "INBOX", "POP3 test message"); - POP3ClientSimulator.AssertMessageCount(oAccount2.Address, "test", 5); + Pop3ClientSimulator.AssertMessageCount(oAccount2.Address, "test", 5); } @@ -448,11 +448,11 @@ public void TestRefreshOfCache() SingletonProvider.Instance.AddAlias(_domain, "alias2'quoted@test.com", "Addr'ess2@test.com"); // Send 5 messages to this account. - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); for (int i = 0; i < 5; i++) - oSMTP.Send(oAccount1.Address, "alias2'quoted@test.com", "INBOX", "Quoted message test message"); + smtpClientSimulator.Send(oAccount1.Address, "alias2'quoted@test.com", "INBOX", "Quoted message test message"); - POP3ClientSimulator.AssertMessageCount(oAccount2.Address, "test", 5); + Pop3ClientSimulator.AssertMessageCount(oAccount2.Address, "test", 5); } } } \ No newline at end of file diff --git a/hmailserver/test/RegressionTests/Infrastructure/BackupRestore.cs b/hmailserver/test/RegressionTests/Infrastructure/BackupRestore.cs index b34325988..a47376f80 100644 --- a/hmailserver/test/RegressionTests/Infrastructure/BackupRestore.cs +++ b/hmailserver/test/RegressionTests/Infrastructure/BackupRestore.cs @@ -437,19 +437,20 @@ private void SetupAccountObject(Domain domain) Account account = SingletonProvider.Instance.AddAccount(domain, "test@test.com", "test"); // Make sure the inbox contains two messages which should be backed up. - Assert.IsTrue(SMTPClientSimulator.StaticSend(account.Address, account.Address, "Message 1 Subject", - "Message 1 Body")); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "Message 1 Subject", + "Message 1 Body"); - Assert.IsTrue(SMTPClientSimulator.StaticSend(account.Address, account.Address, "Message 2 Subject", - "Message 2 Body")); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 2); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1); - Assert.IsTrue(SMTPClientSimulator.StaticSend(account.Address, account.Address, "Message 3 Subject", - "Message 3 Body")); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 3); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "Message 2 Subject", + "Message 2 Body"); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 2); - var sim = new IMAPClientSimulator(); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "Message 3 Subject", + "Message 3 Body"); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 3); + + var sim = new ImapClientSimulator(); Assert.IsTrue(sim.ConnectAndLogon(account.Address, "test")); Assert.IsTrue(sim.SelectFolder("Inbox")); Assert.IsTrue(sim.SetDeletedFlag(2)); @@ -535,7 +536,7 @@ private void DownloadFromExternalAccount(Account account, FetchAccount fa) messages.Add("Subject: Message 2\r\n"); messages.Add("Subject: Message 3\r\n"); - using (var pop3Server = new POP3Server(1, fa.Port, messages)) + using (var pop3Server = new Pop3ServerSimulator(1, fa.Port, messages)) { pop3Server.StartListen(); fa.DownloadNow(); @@ -543,7 +544,7 @@ private void DownloadFromExternalAccount(Account account, FetchAccount fa) } CustomAsserts.AssertRecipientsInDeliveryQueue(0); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 5); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 5); } private bool BackupEnvironment() diff --git a/hmailserver/test/RegressionTests/Infrastructure/CustomAsserts.cs b/hmailserver/test/RegressionTests/Infrastructure/CustomAsserts.cs index 02f6a6f8d..a9de8a8b5 100644 --- a/hmailserver/test/RegressionTests/Infrastructure/CustomAsserts.cs +++ b/hmailserver/test/RegressionTests/Infrastructure/CustomAsserts.cs @@ -13,6 +13,8 @@ namespace RegressionTests.Infrastructure { public static class CustomAsserts { + public delegate void AssertionBody(); + private static Application GetApp() { return SingletonProvider.Instance.GetApp(); @@ -352,5 +354,24 @@ public static void AssertFilesInDirectory(string directory, int expectedFileCoun Assert.AreEqual(expectedFileCount, count); } + public static void Throws(AssertionBody func) where T : Exception + { + var exceptionThrown = false; + try + { + func.Invoke(); + } + catch (T) + { + exceptionThrown = true; + } + + if (!exceptionThrown) + { + throw new InvalidOperationException( + String.Format("An exception of type {0} was expected, but not thrown", typeof(T)) + ); + } + } } } diff --git a/hmailserver/test/RegressionTests/Infrastructure/Delivery.cs b/hmailserver/test/RegressionTests/Infrastructure/Delivery.cs index 266248be0..fa2e6f9df 100644 --- a/hmailserver/test/RegressionTests/Infrastructure/Delivery.cs +++ b/hmailserver/test/RegressionTests/Infrastructure/Delivery.cs @@ -32,14 +32,14 @@ public void TestAliases() // Add aliases SingletonProvider.Instance.AddAlias(_domain, "alias1@test.com", "test2@test.com"); SingletonProvider.Instance.AddAlias(_domain, "alias2@test.com", "test2@test.com"); - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); // Spam folder - oSMTP.Send("test@test.com", "test2@test.com", "Mail 1", "Mail 1"); - oSMTP.Send("test@test.com", "alias1@test.com", "Mail 2", "Mail 2"); - oSMTP.Send("test@test.com", "alias2@test.com", "Mail 3", "Mail 3"); + smtpClientSimulator.Send("test@test.com", "test2@test.com", "Mail 1", "Mail 1"); + smtpClientSimulator.Send("test@test.com", "alias1@test.com", "Mail 2", "Mail 2"); + smtpClientSimulator.Send("test@test.com", "alias2@test.com", "Mail 3", "Mail 3"); - IMAPClientSimulator.AssertMessageCount("test2@test.com", "test", "Inbox", 3); + ImapClientSimulator.AssertMessageCount("test2@test.com", "test", "Inbox", 3); } [Test] @@ -54,14 +54,14 @@ public void TestMirror() _settings.AddDeliveredToHeader = true; // Send 5 messages to this account. - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); for (int i = 0; i < 5; i++) - oSMTP.Send("test@test.com", "mirror@test.com", "INBOX", "Mirror test message"); + smtpClientSimulator.Send("test@test.com", "mirror@test.com", "INBOX", "Mirror test message"); // Check using POP3 that 5 messages exists. - POP3ClientSimulator.AssertMessageCount("mirror-test@test.com", "test", 5); + Pop3ClientSimulator.AssertMessageCount("mirror-test@test.com", "test", 5); - string message = POP3ClientSimulator.AssertGetFirstMessageText(oAccount2.Address, "test"); + string message = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount2.Address, "test"); Assert.IsTrue(message.Contains("Delivered-To: mirror@test.com")); } @@ -83,13 +83,13 @@ public void TestMirrorMultipleRecipients() _settings.AddDeliveredToHeader = true; // Send 5 messages to this account. - var oSMTP = new SMTPClientSimulator(); - oSMTP.Send("test@test.com", new List {oAccount1.Address, oAccount2.Address, oAccount3.Address}, + var smtpClientSimulator = new SmtpClientSimulator(); + smtpClientSimulator.Send("test@test.com", new List {oAccount1.Address, oAccount2.Address, oAccount3.Address}, "INBOX", "Mirror test message"); - POP3ClientSimulator.AssertMessageCount(mirrorAccount.Address, "test", 1); + Pop3ClientSimulator.AssertMessageCount(mirrorAccount.Address, "test", 1); - string message = POP3ClientSimulator.AssertGetFirstMessageText(mirrorAccount.Address, "test"); + string message = Pop3ClientSimulator.AssertGetFirstMessageText(mirrorAccount.Address, "test"); Assert.IsTrue(message.Contains("Delivered-To: mirror1@test.com,mirror2@test.com,mirror3@test.com")); @@ -117,12 +117,12 @@ public void TestMirrorMultipleRecipientsOver255Chars() _settings.AddDeliveredToHeader = true; // Send 1 messages to this account. - var oSMTP = new SMTPClientSimulator(); - oSMTP.Send("test@test.com", recipients, "INBOX", "Mirror test message"); + var smtpClientSimulator = new SmtpClientSimulator(); + smtpClientSimulator.Send("test@test.com", recipients, "INBOX", "Mirror test message"); - POP3ClientSimulator.AssertMessageCount(mirrorAccount.Address, "test", 1); + Pop3ClientSimulator.AssertMessageCount(mirrorAccount.Address, "test", 1); - string message = POP3ClientSimulator.AssertGetFirstMessageText(mirrorAccount.Address, "test"); + string message = Pop3ClientSimulator.AssertGetFirstMessageText(mirrorAccount.Address, "test"); Assert.IsTrue( message.Contains( diff --git a/hmailserver/test/RegressionTests/Infrastructure/DomainServices.cs b/hmailserver/test/RegressionTests/Infrastructure/DomainServices.cs index eeffecafe..cb70f711f 100644 --- a/hmailserver/test/RegressionTests/Infrastructure/DomainServices.cs +++ b/hmailserver/test/RegressionTests/Infrastructure/DomainServices.cs @@ -23,11 +23,11 @@ public void TestDomainAliases() "test"); // Send 5 messages to this account. - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); for (int i = 0; i < 5; i++) - oSMTP.Send("domain-alias-test@alias.com", "domain-alias-test@alias.com", "INBOX", "Alias test message"); + smtpClientSimulator.Send("domain-alias-test@alias.com", "domain-alias-test@alias.com", "INBOX", "Alias test message"); - POP3ClientSimulator.AssertMessageCount("domain-alias-test@alias.com", "test", 5); + Pop3ClientSimulator.AssertMessageCount("domain-alias-test@alias.com", "test", 5); { oAccount = SingletonProvider.Instance.AddAccount(_domain, @@ -39,10 +39,10 @@ public void TestDomainAliases() // Send to the alias for (int i = 0; i < 5; i++) - oSMTP.Send(oAccount.Address, "datestalias@test.com", "INBOX", "Plus addressing message"); + smtpClientSimulator.Send(oAccount.Address, "datestalias@test.com", "INBOX", "Plus addressing message"); // Wait for completion - POP3ClientSimulator.AssertMessageCount(oAccount.Address, "test", 5); + Pop3ClientSimulator.AssertMessageCount(oAccount.Address, "test", 5); } } @@ -60,16 +60,16 @@ public void TestMultipleDomains() Account account3 = SingletonProvider.Instance.AddAccount(domain2, "test1@test2.com", "test"); Account account4 = SingletonProvider.Instance.AddAccount(domain2, "test2@test2.com", "test"); - var smtpSimulator = new SMTPClientSimulator(); + var smtpSimulator = new SmtpClientSimulator(); smtpSimulator.Send("test@alias.com", account1.Address, "Test", "test1@test.com"); smtpSimulator.Send("test@alias.com", account2.Address, "Test", "test2@test.com"); smtpSimulator.Send("test@alias.com", account3.Address, "Test", "test1@test1.com"); smtpSimulator.Send("test@alias.com", account4.Address, "Test", "test2@test1.com"); - Assert.IsTrue(POP3ClientSimulator.AssertGetFirstMessageText(account1.Address, "test").Contains(account1.Address)); - Assert.IsTrue(POP3ClientSimulator.AssertGetFirstMessageText(account2.Address, "test").Contains(account2.Address)); - Assert.IsTrue(POP3ClientSimulator.AssertGetFirstMessageText(account3.Address, "test").Contains(account3.Address)); - Assert.IsTrue(POP3ClientSimulator.AssertGetFirstMessageText(account4.Address, "test").Contains(account4.Address)); + Assert.IsTrue(Pop3ClientSimulator.AssertGetFirstMessageText(account1.Address, "test").Contains(account1.Address)); + Assert.IsTrue(Pop3ClientSimulator.AssertGetFirstMessageText(account2.Address, "test").Contains(account2.Address)); + Assert.IsTrue(Pop3ClientSimulator.AssertGetFirstMessageText(account3.Address, "test").Contains(account3.Address)); + Assert.IsTrue(Pop3ClientSimulator.AssertGetFirstMessageText(account4.Address, "test").Contains(account4.Address)); } [Test] @@ -88,20 +88,20 @@ public void TestPlusAddressing() Account oAccount2 = SingletonProvider.Instance.AddAccount(_domain, "plustest2@test.com", "test"); // Send 5 messages to this account, without using plus addressing. - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); for (int i = 0; i < 5; i++) - oSMTP.Send("plustest@test.com", "plustest2@test.com", "INBOX", "Plus addressing message"); + smtpClientSimulator.Send("plustest@test.com", "plustest2@test.com", "INBOX", "Plus addressing message"); // Wait for completion // Check using POP3 that 5 messages exists. - POP3ClientSimulator.AssertMessageCount("plustest2@test.com", "test", 5); + Pop3ClientSimulator.AssertMessageCount("plustest2@test.com", "test", 5); // Send using plus addressing for (int i = 0; i < 5; i++) - oSMTP.Send("plustest@test.com", "plustest2+hejsan@test.com", "INBOX", "Plus addressing message"); + smtpClientSimulator.Send("plustest@test.com", "plustest2+hejsan@test.com", "INBOX", "Plus addressing message"); // Wait for completion - POP3ClientSimulator.AssertMessageCount("plustest2@test.com", "test", 10); + Pop3ClientSimulator.AssertMessageCount("plustest2@test.com", "test", 10); { Account oAccount3 = SingletonProvider.Instance.AddAccount(_domain, "plustest3@test.com", @@ -112,10 +112,10 @@ public void TestPlusAddressing() // Send to the alias for (int i = 0; i < 5; i++) - oSMTP.Send("plustest@test.com", "plusalias@test.com", "INBOX", "Plus addressing message"); + smtpClientSimulator.Send("plustest@test.com", "plusalias@test.com", "INBOX", "Plus addressing message"); // Wait for completion - POP3ClientSimulator.AssertMessageCount("plustest3@test.com", "test", 5); + Pop3ClientSimulator.AssertMessageCount("plustest3@test.com", "test", 5); } _domain.PlusAddressingEnabled = false; diff --git a/hmailserver/test/RegressionTests/Infrastructure/LogHandler.cs b/hmailserver/test/RegressionTests/Infrastructure/LogHandler.cs index 6bddcf177..468c25019 100644 --- a/hmailserver/test/RegressionTests/Infrastructure/LogHandler.cs +++ b/hmailserver/test/RegressionTests/Infrastructure/LogHandler.cs @@ -8,7 +8,7 @@ namespace RegressionTests.Infrastructure { - class LogHandler + public class LogHandler { public static void DeleteEventLog() { diff --git a/hmailserver/test/RegressionTests/Infrastructure/Persistence/Basics.cs b/hmailserver/test/RegressionTests/Infrastructure/Persistence/Basics.cs index 7feecd6d4..cd2ee6ea9 100644 --- a/hmailserver/test/RegressionTests/Infrastructure/Persistence/Basics.cs +++ b/hmailserver/test/RegressionTests/Infrastructure/Persistence/Basics.cs @@ -55,11 +55,11 @@ public void TestCaseInsensitivtyAccount() { Account testAccount = SingletonProvider.Instance.AddAccount(_domain, "lowercase@test.com", "test"); - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); string upperCase = testAccount.Address.ToUpper(); - Assert.IsTrue(oSMTP.Send("someone@dummy-example.com", upperCase, "test mail", "test body")); + smtpClientSimulator.Send("someone@dummy-example.com", upperCase, "test mail", "test body"); - POP3ClientSimulator.AssertMessageCount("lowercase@test.com", "test", 1); + Pop3ClientSimulator.AssertMessageCount("lowercase@test.com", "test", 1); } [Test] @@ -69,11 +69,11 @@ public void TestCaseInsensitivtyAlias() Alias testAlias = SingletonProvider.Instance.AddAlias(_domain, "sometext@test.com", "LowerCase@test.com"); - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); string upperCase = testAlias.Name.ToUpper(); - Assert.IsTrue(oSMTP.Send("someone@dummy-example.com", upperCase, "test mail", "test body")); + smtpClientSimulator.Send("someone@dummy-example.com", upperCase, "test mail", "test body"); - POP3ClientSimulator.AssertMessageCount("lowercase@test.com", "test", 1); + Pop3ClientSimulator.AssertMessageCount("lowercase@test.com", "test", 1); } [Test] @@ -87,11 +87,11 @@ public void TestCaseInsensitivtyList() DistributionList list = SingletonProvider.Instance.AddDistributionList(_domain, "myList@test.com", recipients); - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); string upperCase = list.Address.ToUpper(); - Assert.IsTrue(oSMTP.Send("someone@dummy-example.com", upperCase, "test mail", "test body")); + smtpClientSimulator.Send("someone@dummy-example.com", upperCase, "test mail", "test body"); - POP3ClientSimulator.AssertMessageCount("lowercase@test.com", "test", 1); + Pop3ClientSimulator.AssertMessageCount("lowercase@test.com", "test", 1); } [Test] @@ -299,7 +299,7 @@ public void TestIncomingRelays() public void TestRenameAccountOrDomainWithMessagesWithFullPath() { Account account = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test message", "Test body"); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test message", "Test body"); IMAPFolder folder = account.IMAPFolders.get_ItemByName("Inbox"); CustomAsserts.AssertFolderMessageCount(folder, 1); @@ -361,13 +361,13 @@ public void TestRenameAccountWithMessages() Account account = SingletonProvider.Instance.AddAccount(_domain, "account1@test.com", "test"); string messageBody = Guid.NewGuid().ToString(); - SMTPClientSimulator.StaticSend(account.Address, account.Address, "Subj", messageBody); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "Subj", messageBody); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1); account.Address = "account2@test.com"; account.Save(); - string messageText = POP3ClientSimulator.AssertGetFirstMessageText("account2@test.com", "test"); + string messageText = Pop3ClientSimulator.AssertGetFirstMessageText("account2@test.com", "test"); Assert.IsTrue(messageText.Contains(messageBody), messageText); } @@ -461,13 +461,13 @@ public void TestRenameDomainWithMessages() account.Save(); string messageBody = Guid.NewGuid().ToString(); - SMTPClientSimulator.StaticSend(account.Address, account.Address, "Subj", messageBody); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "Subj", messageBody); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1); _domain.Name = "example.com"; _domain.Save(); - string messageText = POP3ClientSimulator.AssertGetFirstMessageText("account1@example.com", "test"); + string messageText = Pop3ClientSimulator.AssertGetFirstMessageText("account1@example.com", "test"); Assert.IsTrue(messageText.Contains(messageBody), messageText); } diff --git a/hmailserver/test/RegressionTests/Infrastructure/Persistence/Limitations.cs b/hmailserver/test/RegressionTests/Infrastructure/Persistence/Limitations.cs index 58eab7480..6228585fa 100644 --- a/hmailserver/test/RegressionTests/Infrastructure/Persistence/Limitations.cs +++ b/hmailserver/test/RegressionTests/Infrastructure/Persistence/Limitations.cs @@ -213,13 +213,13 @@ public void TestDomainMaxMessageSizeLimit() message.Append("ABCDEFGH"); } - Assert.IsTrue(SMTPClientSimulator.StaticSend("test@test.com", "test@test.com", "TestSubject", - message.ToString())); - POP3ClientSimulator.AssertMessageCount("test@test.com", "secret1", 1); + SmtpClientSimulator.StaticSend("test@test.com", "test@test.com", "TestSubject", + message.ToString()); + Pop3ClientSimulator.AssertMessageCount("test@test.com", "secret1", 1); _domain.MaxMessageSize = 50; _domain.Save(); - Assert.IsFalse(SMTPClientSimulator.StaticSend("test@test.com", "test@test.com", "TestSubject", + CustomAsserts.Throws(() => SmtpClientSimulator.StaticSend("test@test.com", "test@test.com", "TestSubject", message.ToString())); } diff --git a/hmailserver/test/RegressionTests/Infrastructure/SessionLimitingTests.cs b/hmailserver/test/RegressionTests/Infrastructure/SessionLimitingTests.cs index b8364a60d..103b09fd8 100644 --- a/hmailserver/test/RegressionTests/Infrastructure/SessionLimitingTests.cs +++ b/hmailserver/test/RegressionTests/Infrastructure/SessionLimitingTests.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using hMailServer; using NUnit.Framework; using RegressionTests.Shared; @@ -163,6 +164,32 @@ public void TestDisconnectingFromPop3ServerDecreasesPop3SessionCount() AssertMaxSessionCount(eSessionType.eSTPOP3, countBefore); } + [Test] + public void TestDisconnectingClientWithOnClientConnectEventShouldDecreaseConnectionCount() + { + Application app = SingletonProvider.Instance.GetApp(); + + var status = app.Status; + int countBefore = status.get_SessionCount(eSessionType.eSTSMTP); + + Scripting scripting = app.Settings.Scripting; + + string script = "Sub OnClientConnect(oClient) " + Environment.NewLine + + " Result.Value = 1" + Environment.NewLine + + "End Sub" + Environment.NewLine + Environment.NewLine; + + File.WriteAllText(scripting.CurrentScriptFile, script); + scripting.Enabled = true; + scripting.Reload(); + + var socket = new TcpConnection(); + Assert.IsTrue(socket.Connect(110)); + Assert.IsEmpty(socket.Receive()); + + AssertMaxSessionCount(eSessionType.eSTSMTP, countBefore); + } + + public static void AssertMaxSessionCount(eSessionType sessionType, int maxExpectedCount) { Application application = SingletonProvider.Instance.GetApp(); diff --git a/hmailserver/test/RegressionTests/Infrastructure/TCPIP.cs b/hmailserver/test/RegressionTests/Infrastructure/TCPIP.cs index 80d1b02d4..1f9c69800 100644 --- a/hmailserver/test/RegressionTests/Infrastructure/TCPIP.cs +++ b/hmailserver/test/RegressionTests/Infrastructure/TCPIP.cs @@ -45,8 +45,8 @@ public void TestPortOpening() oApp.Settings.TCPIPPorts.SetDefault(); var pSMTPSimulator = new TcpConnection(); - var pPOP3Simulator = new POP3ClientSimulator(); - var pIMAPSimulator = new IMAPClientSimulator(); + var pPOP3Simulator = new Pop3ClientSimulator(); + var pIMAPSimulator = new ImapClientSimulator(); oApp.Stop(); diff --git a/hmailserver/test/RegressionTests/Infrastructure/Timeouts.cs b/hmailserver/test/RegressionTests/Infrastructure/Timeouts.cs index 5d9a2bf69..fa8e2e462 100644 --- a/hmailserver/test/RegressionTests/Infrastructure/Timeouts.cs +++ b/hmailserver/test/RegressionTests/Infrastructure/Timeouts.cs @@ -23,10 +23,10 @@ public void TestImproperDisconnect() var account = SingletonProvider.Instance.AddAccount(_domain, "TimeoutTest@test.com", "test"); int iCount = application.Status.get_SessionCount(eSessionType.eSTPOP3); - var oPOP3 = new POP3ClientSimulator(); - oPOP3.ConnectAndLogon(account.Address, "test"); + var pop3ClientSimulator = new Pop3ClientSimulator(); + pop3ClientSimulator.ConnectAndLogon(account.Address, "test"); CustomAsserts.AssertSessionCount(eSessionType.eSTPOP3, iCount + 1); - oPOP3.Disconnect(); // Disconnect without sending quit + pop3ClientSimulator.Disconnect(); // Disconnect without sending quit CustomAsserts.AssertSessionCount(eSessionType.eSTPOP3, iCount); } diff --git a/hmailserver/test/RegressionTests/MIME/MessageParsing.cs b/hmailserver/test/RegressionTests/MIME/MessageParsing.cs index 2046d202e..e1b7e9b25 100644 --- a/hmailserver/test/RegressionTests/MIME/MessageParsing.cs +++ b/hmailserver/test/RegressionTests/MIME/MessageParsing.cs @@ -13,11 +13,11 @@ public void TestParseMultipartNoBody() { Account account = SingletonProvider.Instance.AddAccount(_domain, "search@test.com", "test"); string body = TestSetup.GetResource("Messages.MultipartMessageWithNoMainBodyText.txt"); - SMTPClientSimulator.StaticSendRaw(account.Address, account.Address, body); + SmtpClientSimulator.StaticSendRaw(account.Address, account.Address, body); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1); - var imapSim = new IMAPClientSimulator("search@test.com", "test", "INBOX"); + var imapSim = new ImapClientSimulator("search@test.com", "test", "INBOX"); string result = imapSim.Fetch("1 (BODY.PEEK[HEADER] BODY.PEEK[TEXT])"); imapSim.Logout(); diff --git a/hmailserver/test/RegressionTests/MIME/Parameters.cs b/hmailserver/test/RegressionTests/MIME/Parameters.cs index 410ff00e3..dd712b943 100644 --- a/hmailserver/test/RegressionTests/MIME/Parameters.cs +++ b/hmailserver/test/RegressionTests/MIME/Parameters.cs @@ -16,15 +16,15 @@ public void TestFetchCharsetInQuotesWithSpaceAfter() { Account account = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - SMTPClientSimulator.StaticSendRaw(account.Address, account.Address, + SmtpClientSimulator.StaticSendRaw(account.Address, account.Address, "From: test@test.com\r\n" + "Content-Type: text/plain; charset =\"iso-8859-1\" \r\n" + "\r\n" + "Test\r\n"); - IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 1); + ImapClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 1); - var sim = new IMAPClientSimulator(account.Address, "test", "Inbox"); + var sim = new ImapClientSimulator(account.Address, "test", "Inbox"); string result = sim.Fetch("1 BODYSTRUCTURE"); sim.Disconnect(); @@ -37,15 +37,15 @@ public void TestFetchCharsetInQuotesWithSpaceBefore() { Account account = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - SMTPClientSimulator.StaticSendRaw(account.Address, account.Address, + SmtpClientSimulator.StaticSendRaw(account.Address, account.Address, "From: test@test.com\r\n" + "Content-Type: text/plain; charset = \"iso-8859-1\"\r\n" + "\r\n" + "Test\r\n"); - IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 1); + ImapClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 1); - var sim = new IMAPClientSimulator(account.Address, "test", "Inbox"); + var sim = new ImapClientSimulator(account.Address, "test", "Inbox"); string result = sim.Fetch("1 BODYSTRUCTURE"); sim.Disconnect(); @@ -58,15 +58,15 @@ public void TestFetchCharsetInQuotesWithoutQuotesWithSpace() { Account account = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - SMTPClientSimulator.StaticSendRaw(account.Address, account.Address, + SmtpClientSimulator.StaticSendRaw(account.Address, account.Address, "From: test@test.com\r\n" + "Content-Type: text/plain; charset = iso-8859-1 \r\n" + "\r\n" + "Test\r\n"); - IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 1); + ImapClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 1); - var sim = new IMAPClientSimulator(account.Address, "test", "Inbox"); + var sim = new ImapClientSimulator(account.Address, "test", "Inbox"); string result = sim.Fetch("1 BODYSTRUCTURE"); sim.Disconnect(); @@ -79,15 +79,15 @@ public void TestFetchCharsetInQuotesWithoutQuotesWithoutSpace() { Account account = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - SMTPClientSimulator.StaticSendRaw(account.Address, account.Address, + SmtpClientSimulator.StaticSendRaw(account.Address, account.Address, "From: test@test.com\r\n" + "Content-Type: text/plain; charset=iso-8859-1 \r\n" + "\r\n" + "Test\r\n"); - IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 1); + ImapClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 1); - var sim = new IMAPClientSimulator(account.Address, "test", "Inbox"); + var sim = new ImapClientSimulator(account.Address, "test", "Inbox"); string result = sim.Fetch("1 BODYSTRUCTURE"); sim.Disconnect(); @@ -100,15 +100,15 @@ public void TestFetchCharsetInQuotesWithoutSpace() { Account account = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - SMTPClientSimulator.StaticSendRaw(account.Address, account.Address, + SmtpClientSimulator.StaticSendRaw(account.Address, account.Address, "From: test@test.com\r\n" + "Content-Type: text/plain; charset =\"iso-8859-1\"\r\n" + "\r\n" + "Test\r\n"); - IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 1); + ImapClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 1); - var sim = new IMAPClientSimulator(account.Address, "test", "Inbox"); + var sim = new ImapClientSimulator(account.Address, "test", "Inbox"); string result = sim.Fetch("1 BODYSTRUCTURE"); sim.Disconnect(); diff --git a/hmailserver/test/RegressionTests/POP3/Basics.cs b/hmailserver/test/RegressionTests/POP3/Basics.cs index a3005b0e5..f81e747d6 100644 --- a/hmailserver/test/RegressionTests/POP3/Basics.cs +++ b/hmailserver/test/RegressionTests/POP3/Basics.cs @@ -61,9 +61,9 @@ public void TestAttachmentEncoding() SendMessage(mail); - POP3ClientSimulator.AssertMessageCount("test@test.com", "test", 1); + Pop3ClientSimulator.AssertMessageCount("test@test.com", "test", 1); - var sim = new POP3ClientSimulator(); + var sim = new Pop3ClientSimulator(); sim.ConnectAndLogon("test@test.com", "test"); string fileContent = sim.RETR(1); sim.DELE(1); @@ -97,12 +97,12 @@ public void TestConnection() SingletonProvider.Instance.AddAccount(_domain, "pop3user@test.com", "test"); // Send 5 messages to this account. - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); for (int i = 0; i < 5; i++) - oSMTP.Send("test@test.com", "pop3user@test.com", "INBOX", "POP3 test message"); + smtpClientSimulator.Send("test@test.com", "pop3user@test.com", "INBOX", "POP3 test message"); - POP3ClientSimulator.AssertMessageCount("pop3user@test.com", "test", 5); + Pop3ClientSimulator.AssertMessageCount("pop3user@test.com", "test", 5); } [Test] @@ -111,11 +111,11 @@ public void TestDELEInvalid() Account account = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); for (int i = 1; i <= 10; i++) - SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody" + i.ToString()); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody" + i.ToString()); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 10); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 10); - var sim = new POP3ClientSimulator(); + var sim = new Pop3ClientSimulator(); sim.ConnectAndLogon(account.Address, "test"); Assert.IsFalse(sim.DELE(0)); Assert.IsFalse(sim.DELE(-1)); @@ -129,13 +129,13 @@ public void TestLIST() { Account account = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody1"); - SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody2"); - SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody3"); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody1"); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody2"); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody3"); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 3); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 3); - var sim = new POP3ClientSimulator(); + var sim = new Pop3ClientSimulator(); sim.ConnectAndLogon(account.Address, "test"); string result = sim.LIST(); @@ -152,11 +152,11 @@ public void TestLISTInvalid() Account account = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); for (int i = 1; i <= 10; i++) - SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody" + i.ToString()); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody" + i.ToString()); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 10); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 10); - var sim = new POP3ClientSimulator(); + var sim = new Pop3ClientSimulator(); sim.ConnectAndLogon(account.Address, "test"); string result = sim.LIST(0); Assert.IsTrue(result.Contains("No such message")); @@ -171,13 +171,13 @@ public void TestLISTSpecific() { Account account = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody1"); - SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody2"); - SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody3"); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody1"); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody2"); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody3"); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 3); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 3); - var sim = new POP3ClientSimulator(); + var sim = new Pop3ClientSimulator(); sim.ConnectAndLogon(account.Address, "test"); string result = sim.LIST(2); @@ -193,11 +193,11 @@ public void TestLISTWithDeleted() Account account = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); for (int i = 1; i <= 10; i++) - SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody" + i.ToString()); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody" + i.ToString()); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 10); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 10); - var sim = new POP3ClientSimulator(); + var sim = new Pop3ClientSimulator(); sim.ConnectAndLogon(account.Address, "test"); sim.DELE(2); sim.DELE(4); @@ -217,13 +217,13 @@ public void TestLogonMailboxWithDeletedMessage() Account account = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); for (int i = 1; i <= 3; i++) - SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", + SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "Line1\r\nLine2\r\nLine3\r\nLine4\r\nLine\r\n"); // Mark the second message as deleted using IMAP. - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 3); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 3); - var sim = new IMAPClientSimulator(); + var sim = new ImapClientSimulator(); sim.ConnectAndLogon(account.Address, "test"); sim.SelectFolder("INBOX"); sim.SetDeletedFlag(2); @@ -231,7 +231,7 @@ public void TestLogonMailboxWithDeletedMessage() // Now list messages and confirm that all are listed. - var pop3Client = new POP3ClientSimulator(); + var pop3Client = new Pop3ClientSimulator(); pop3Client.ConnectAndLogon(account.Address, "test"); string listResponse = pop3Client.LIST(); string uidlResponse = pop3Client.UIDL(); @@ -254,22 +254,22 @@ public void TestPOP3TransactionSafety() { Account account = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - Assert.IsTrue(SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody")); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody"); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1); - var sim = new POP3ClientSimulator(); + var sim = new Pop3ClientSimulator(); sim.ConnectAndLogon(account.Address, "test"); // Now delete the message using an IMAP client. - var imapSimulator = new IMAPClientSimulator(); + var imapSimulator = new ImapClientSimulator(); Assert.IsTrue(imapSimulator.ConnectAndLogon(account.Address, "test")); Assert.IsTrue(imapSimulator.SelectFolder("INBOX")); Assert.IsTrue(imapSimulator.SetDeletedFlag(1)); Assert.IsTrue(imapSimulator.Expunge()); Assert.AreEqual(0, imapSimulator.GetMessageCount("Inbox")); - Assert.IsTrue(SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody")); - IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 1); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody"); + ImapClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 1); // This deletion should not have any effect, since the POP3 connection is referencing an old message. sim.DELE(1); @@ -283,16 +283,16 @@ public void TestRETR() { Account account = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody1"); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody1"); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1); - SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody2"); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 2); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody2"); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 2); - SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody3"); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 3); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody3"); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 3); - var sim = new POP3ClientSimulator(); + var sim = new Pop3ClientSimulator(); sim.ConnectAndLogon(account.Address, "test"); string result = sim.RETR(1); Assert.IsTrue(result.Contains("TestBody1"), result); @@ -311,11 +311,11 @@ public void TestTOPInvalid() Account account = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); for (int i = 1; i <= 10; i++) - SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody" + i.ToString()); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody" + i.ToString()); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 10); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 10); - var sim = new POP3ClientSimulator(); + var sim = new Pop3ClientSimulator(); sim.ConnectAndLogon(account.Address, "test"); Assert.IsTrue(sim.TOP(-1, 0).Contains("No such message")); Assert.IsTrue(sim.TOP(0, 0).Contains("No such message")); @@ -328,11 +328,11 @@ public void TestTOPSpecificEntire() Account account = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); for (int i = 1; i <= 10; i++) - SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody" + i.ToString()); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody" + i.ToString()); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 10); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 10); - var sim = new POP3ClientSimulator(); + var sim = new Pop3ClientSimulator(); sim.ConnectAndLogon(account.Address, "test"); string result = sim.TOP(1, 0); @@ -346,12 +346,12 @@ public void TestTOPSpecificPartial() Account account = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); for (int i = 1; i <= 10; i++) - SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", + SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "Line1\r\nLine2\r\nLine3\r\nLine4\r\nLine\r\n"); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 10); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 10); - var sim = new POP3ClientSimulator(); + var sim = new Pop3ClientSimulator(); sim.ConnectAndLogon(account.Address, "test"); string result = sim.TOP(4, 2); @@ -368,11 +368,11 @@ public void TestUIDLInvalid() Account account = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); for (int i = 1; i <= 10; i++) - SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody" + i.ToString()); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody" + i.ToString()); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 10); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 10); - var sim = new POP3ClientSimulator(); + var sim = new Pop3ClientSimulator(); sim.ConnectAndLogon(account.Address, "test"); string result = sim.UIDL(0); Assert.IsTrue(result.Contains("No such message")); @@ -387,13 +387,13 @@ public void TestUIDLSpecific() { Account account = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody1"); - SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody2"); - SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody3"); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody1"); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody2"); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody3"); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 3); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 3); - var sim = new POP3ClientSimulator(); + var sim = new Pop3ClientSimulator(); sim.ConnectAndLogon(account.Address, "test"); string result = sim.UIDL(2); @@ -409,11 +409,11 @@ public void TestUIDLWithDeleted() Account account = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); for (int i = 1; i <= 10; i++) - SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody" + i.ToString()); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody" + i.ToString()); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 10); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 10); - var sim = new POP3ClientSimulator(); + var sim = new Pop3ClientSimulator(); sim.ConnectAndLogon(account.Address, "test"); sim.DELE(2); sim.DELE(4); @@ -431,7 +431,7 @@ public void WelcomeMessage() { SingletonProvider.Instance.GetApp().Settings.WelcomePOP3 = "HOWDYHO POP3"; - var oSimulator = new POP3ClientSimulator(); + var oSimulator = new Pop3ClientSimulator(); string sWelcomeMessage = oSimulator.GetWelcomeMessage(); diff --git a/hmailserver/test/RegressionTests/POP3/Fetching/Basics.cs b/hmailserver/test/RegressionTests/POP3/Fetching/Basics.cs index 2220bd2f7..443f7b673 100644 --- a/hmailserver/test/RegressionTests/POP3/Fetching/Basics.cs +++ b/hmailserver/test/RegressionTests/POP3/Fetching/Basics.cs @@ -51,7 +51,7 @@ public void TestAntiVirusDisabled() messages.Add(messageText); int port = TestSetup.GetNextFreePort(); - using (var pop3Server = new POP3Server(1, port, messages)) + using (var pop3Server = new Pop3ServerSimulator(1, port, messages)) { pop3Server.StartListen(); @@ -64,7 +64,7 @@ public void TestAntiVirusDisabled() fa.Delete(); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1); Message message = account.IMAPFolders.get_ItemByName("INBOX").Messages[0]; Assert.IsFalse(message.get_Flag(eMessageFlag.eMFVirusScan)); @@ -85,7 +85,7 @@ public void TestAntiVirusEnabled() messages.Add(messageText); int port = TestSetup.GetNextFreePort(); - using (var pop3Server = new POP3Server(1, port, messages)) + using (var pop3Server = new Pop3ServerSimulator(1, port, messages)) { pop3Server.StartListen(); @@ -98,7 +98,7 @@ public void TestAntiVirusEnabled() fa.Delete(); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1); Message message = account.IMAPFolders.get_ItemByName("INBOX").Messages[0]; Assert.IsTrue(message.get_Flag(eMessageFlag.eMFVirusScan)); @@ -120,7 +120,7 @@ public void TestBasicExternalAccount() messages.Add(message); int port = TestSetup.GetNextFreePort(); - using (var pop3Server = new POP3Server(1, port, messages)) + using (var pop3Server = new Pop3ServerSimulator(1, port, messages)) { pop3Server.StartListen(); @@ -144,7 +144,7 @@ public void TestBasicExternalAccount() fa.Delete(); - string downloadedMessage = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); + string downloadedMessage = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); Assert.IsTrue(downloadedMessage.Contains(message)); } @@ -195,7 +195,7 @@ public void TestDelete() messages.Add(message); int port = TestSetup.GetNextFreePort(); - using (var pop3Server = new POP3Server(1, port, messages)) + using (var pop3Server = new Pop3ServerSimulator(1, port, messages)) { pop3Server.StartListen(); @@ -221,7 +221,7 @@ public void TestDelete() fa.Delete(); - string downloadedMessage = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); + string downloadedMessage = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); Assert.IsTrue(downloadedMessage.Contains(message)); Assert.AreEqual(1, pop3Server.DeletedMessages.Count); @@ -245,7 +245,7 @@ public void TestDeleteMutliple() messages.Add(message); int port = TestSetup.GetNextFreePort(); - using (var pop3Server = new POP3Server(1, port, messages)) + using (var pop3Server = new Pop3ServerSimulator(1, port, messages)) { pop3Server.StartListen(); @@ -271,7 +271,7 @@ public void TestDeleteMutliple() fa.Delete(); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 3); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 3); Assert.AreEqual(3, pop3Server.DeletedMessages.Count); } @@ -292,7 +292,7 @@ public void TestDeliverToExternalMimeRecipientsDisabled() messages.Add(message); int port = TestSetup.GetNextFreePort(); - using (var pop3Server = new POP3Server(1, port, messages)) + using (var pop3Server = new Pop3ServerSimulator(1, port, messages)) { pop3Server.StartListen(); @@ -326,12 +326,12 @@ public void TestDeliverToExternalMimeRecipientsDisabled() fa.Delete(); - string downloadedMessage1 = POP3ClientSimulator.AssertGetFirstMessageText(account2.Address, "test"); - POP3ClientSimulator.AssertMessageCount(account1.Address, "test", 0); + string downloadedMessage1 = Pop3ClientSimulator.AssertGetFirstMessageText(account2.Address, "test"); + Pop3ClientSimulator.AssertMessageCount(account1.Address, "test", 0); Assert.IsTrue(downloadedMessage1.Contains(message), downloadedMessage1); - POP3ClientSimulator.AssertMessageCount(account2.Address, "test", 0); - POP3ClientSimulator.AssertMessageCount(catchallAccount.Address, "test", 0); + Pop3ClientSimulator.AssertMessageCount(account2.Address, "test", 0); + Pop3ClientSimulator.AssertMessageCount(catchallAccount.Address, "test", 0); } } @@ -350,7 +350,7 @@ public void TestDeliverToExternalMimeRecipientsEnabled() messages.Add(message); int port = TestSetup.GetNextFreePort(); - using (var pop3Server = new POP3Server(1, port, messages)) + using (var pop3Server = new Pop3ServerSimulator(1, port, messages)) { pop3Server.StartListen(); @@ -358,13 +358,13 @@ public void TestDeliverToExternalMimeRecipientsEnabled() deliveryResults["external@dummy-example.com"] = 250; int smtpServerPort = TestSetup.GetNextFreePort(); - using (var smtpServer = new SMTPServerSimulator(1, smtpServerPort)) + using (var smtpServer = new SmtpServerSimulator(1, smtpServerPort)) { smtpServer.AddRecipientResult(deliveryResults); smtpServer.StartListen(); // Add a route so we can connect to localhost. - Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, false); + Route route = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false); route.TreatSecurityAsLocalDomain = true; route.Save(); @@ -396,9 +396,9 @@ public void TestDeliverToExternalMimeRecipientsEnabled() fa.Delete(); - string downloadedMessage1 = POP3ClientSimulator.AssertGetFirstMessageText(account2.Address, "test"); - POP3ClientSimulator.AssertMessageCount(account1.Address, "test", 0); - POP3ClientSimulator.AssertMessageCount(catchallAccount.Address, "test", 0); + string downloadedMessage1 = Pop3ClientSimulator.AssertGetFirstMessageText(account2.Address, "test"); + Pop3ClientSimulator.AssertMessageCount(account1.Address, "test", 0); + Pop3ClientSimulator.AssertMessageCount(catchallAccount.Address, "test", 0); Assert.IsTrue(downloadedMessage1.Contains(message), downloadedMessage1); // Make sure the exernal recipient has received his copy. @@ -428,7 +428,7 @@ public void TestDeliverToExternalMimeRecipientsEnabledRouteAsExternal() messages.Add(message); int port = TestSetup.GetNextFreePort(); - using (var pop3Server = new POP3Server(1, port, messages)) + using (var pop3Server = new Pop3ServerSimulator(1, port, messages)) { pop3Server.StartListen(); @@ -466,7 +466,7 @@ public void TestDeliverToExternalMimeRecipientsEnabledRouteAsExternal() fa.Delete(); - string downloadedMessage1 = POP3ClientSimulator.AssertGetFirstMessageText(recipientAccount1.Address, "test"); + string downloadedMessage1 = Pop3ClientSimulator.AssertGetFirstMessageText(recipientAccount1.Address, "test"); Assert.IsTrue(downloadedMessage1.Contains(message), downloadedMessage1); CustomAsserts.AssertRecipientsInDeliveryQueue(0, false); @@ -487,7 +487,7 @@ public void TestDeliverToMIMERecipients() messages.Add(message); int port = TestSetup.GetNextFreePort(); - using (var pop3Server = new POP3Server(1, port, messages)) + using (var pop3Server = new Pop3ServerSimulator(1, port, messages)) { pop3Server.StartListen(); @@ -520,10 +520,10 @@ public void TestDeliverToMIMERecipients() fa.Delete(); - string downloadedMessage1 = POP3ClientSimulator.AssertGetFirstMessageText(account2.Address, "test"); - string downloadedMessage2 = POP3ClientSimulator.AssertGetFirstMessageText(account3.Address, "test"); - POP3ClientSimulator.AssertMessageCount(account1.Address, "test", 0); - POP3ClientSimulator.AssertMessageCount(catchallAccount.Address, "test", 0); + string downloadedMessage1 = Pop3ClientSimulator.AssertGetFirstMessageText(account2.Address, "test"); + string downloadedMessage2 = Pop3ClientSimulator.AssertGetFirstMessageText(account3.Address, "test"); + Pop3ClientSimulator.AssertMessageCount(account1.Address, "test", 0); + Pop3ClientSimulator.AssertMessageCount(catchallAccount.Address, "test", 0); Assert.IsTrue(downloadedMessage1.Contains(message), downloadedMessage1); Assert.IsTrue(downloadedMessage2.Contains(message), downloadedMessage2); @@ -546,7 +546,7 @@ public void TestServerNotSupportingUIDL() messages.Add(message); int port = TestSetup.GetNextFreePort(); - using (var pop3Server = new POP3Server(1, port, messages)) + using (var pop3Server = new Pop3ServerSimulator(1, port, messages)) { pop3Server.SupportsUIDL = false; pop3Server.StartListen(); @@ -604,7 +604,7 @@ public void TestSpamProtectionDisabled() messages.Add(message); int port = TestSetup.GetNextFreePort(); - using (var pop3Server = new POP3Server(1, port, messages)) + using (var pop3Server = new Pop3ServerSimulator(1, port, messages)) { pop3Server.StartListen(); @@ -630,7 +630,7 @@ public void TestSpamProtectionDisabled() fa.Delete(); - string downloadedMessage = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); + string downloadedMessage = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); Assert.IsFalse(downloadedMessage.Contains("X-hMailServer-Spam: YES")); } @@ -668,7 +668,7 @@ public void TestSpamProtectionNoTagging() messages.Add(message); int port = TestSetup.GetNextFreePort(); - using (var pop3Server = new POP3Server(1, port, messages)) + using (var pop3Server = new Pop3ServerSimulator(1, port, messages)) { pop3Server.StartListen(); @@ -694,7 +694,7 @@ public void TestSpamProtectionNoTagging() fa.Delete(); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1); } } @@ -726,7 +726,7 @@ public void TestSpamProtectionPostTransmission() messages.Add(message); int port = TestSetup.GetNextFreePort(); - using (var pop3Server = new POP3Server(1, port, messages)) + using (var pop3Server = new Pop3ServerSimulator(1, port, messages)) { pop3Server.StartListen(); @@ -752,7 +752,7 @@ public void TestSpamProtectionPostTransmission() fa.Delete(); - string downloadedMessage = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); + string downloadedMessage = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); Assert.IsTrue(downloadedMessage.Contains("X-hMailServer-Spam: YES")); } @@ -784,7 +784,7 @@ public void TestSpamProtectionPreTransmissionHELODelete() messages.Add(message); int port = TestSetup.GetNextFreePort(); - using (var pop3Server = new POP3Server(1, port, messages)) + using (var pop3Server = new Pop3ServerSimulator(1, port, messages)) { pop3Server.StartListen(); @@ -810,7 +810,7 @@ public void TestSpamProtectionPreTransmissionHELODelete() fa.Delete(); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 0); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 0); } } @@ -840,7 +840,7 @@ public void TestSpamProtectionPreTransmissionHELOPass() messages.Add(message); int port = TestSetup.GetNextFreePort(); - using (var pop3Server = new POP3Server(1, port, messages)) + using (var pop3Server = new Pop3ServerSimulator(1, port, messages)) { pop3Server.StartListen(); @@ -866,7 +866,7 @@ public void TestSpamProtectionPreTransmissionHELOPass() fa.Delete(); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1); } } @@ -904,7 +904,7 @@ public void TestSpamProtectionPreTransmissionHELOPassFirst() messages.Add(message); int port = TestSetup.GetNextFreePort(); - using (var pop3Server = new POP3Server(1, port, messages)) + using (var pop3Server = new Pop3ServerSimulator(1, port, messages)) { pop3Server.StartListen(); @@ -930,7 +930,7 @@ public void TestSpamProtectionPreTransmissionHELOPassFirst() fa.Delete(); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1); } } @@ -959,7 +959,7 @@ public void TestSpamProtectionPreTransmissionSPFDelete() messages.Add(message); int port = TestSetup.GetNextFreePort(); - using (var pop3Server = new POP3Server(1, port, messages)) + using (var pop3Server = new Pop3ServerSimulator(1, port, messages)) { pop3Server.StartListen(); @@ -985,7 +985,7 @@ public void TestSpamProtectionPreTransmissionSPFDelete() fa.Delete(); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 0); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 0); } } @@ -1014,7 +1014,7 @@ public void TestSpamProtectionPreTransmissionSPFPass() messages.Add(message); int port = TestSetup.GetNextFreePort(); - using (var pop3Server = new POP3Server(1, port, messages)) + using (var pop3Server = new Pop3ServerSimulator(1, port, messages)) { pop3Server.StartListen(); @@ -1040,7 +1040,7 @@ public void TestSpamProtectionPreTransmissionSPFPass() fa.Delete(); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1); } } @@ -1071,9 +1071,9 @@ public void TestFetchMessagesWithVeryLongHeader() } int port = TestSetup.GetNextFreePort(); - using (var pop3Server = new POP3Server(1, port, messages)) + using (var pop3Server = new Pop3ServerSimulator(1, port, messages)) { - pop3Server.SendBufferMode = POP3Server.BufferMode.SingleBuffer; + pop3Server.SendBufferMode = Pop3ServerSimulator.BufferMode.SingleBuffer; pop3Server.StartListen(); Account account = SingletonProvider.Instance.AddAccount(_domain, "user@test.com", "test"); @@ -1098,8 +1098,8 @@ public void TestFetchMessagesWithVeryLongHeader() fa.Delete(); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 5); - string downloadedMessage = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 5); + string downloadedMessage = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); @@ -1128,9 +1128,9 @@ public void TestFetchMessageWithValidFromAddress() int port = TestSetup.GetNextFreePort(); - using (var pop3Server = new POP3Server(1, port, messages)) + using (var pop3Server = new Pop3ServerSimulator(1, port, messages)) { - pop3Server.SendBufferMode = POP3Server.BufferMode.SingleBuffer; + pop3Server.SendBufferMode = Pop3ServerSimulator.BufferMode.SingleBuffer; pop3Server.StartListen(); Account account = SingletonProvider.Instance.AddAccount(_domain, "user@test.com", "test"); @@ -1155,7 +1155,7 @@ public void TestFetchMessageWithValidFromAddress() fa.Delete(); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1); var log = LogHandler.ReadCurrentDefaultLog(); Assert.IsTrue(log.Contains("Delivering message from A@example.com to user@test.com.")); @@ -1177,9 +1177,9 @@ public void TestFetchMessageWithInvalidFromAddress() int port = TestSetup.GetNextFreePort(); - using (var pop3Server = new POP3Server(1, port, messages)) + using (var pop3Server = new Pop3ServerSimulator(1, port, messages)) { - pop3Server.SendBufferMode = POP3Server.BufferMode.SingleBuffer; + pop3Server.SendBufferMode = Pop3ServerSimulator.BufferMode.SingleBuffer; pop3Server.StartListen(); Account account = SingletonProvider.Instance.AddAccount(_domain, "user@test.com", "test"); @@ -1204,7 +1204,7 @@ public void TestFetchMessageWithInvalidFromAddress() fa.Delete(); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1); var log = LogHandler.ReadCurrentDefaultLog(); Assert.IsTrue(log.Contains("Delivering message from to user@test.com.")); diff --git a/hmailserver/test/RegressionTests/POP3/Fetching/ExternalAccountSslTests.cs b/hmailserver/test/RegressionTests/POP3/Fetching/ExternalAccountSslTests.cs index 4ef9367b0..c549587db 100644 --- a/hmailserver/test/RegressionTests/POP3/Fetching/ExternalAccountSslTests.cs +++ b/hmailserver/test/RegressionTests/POP3/Fetching/ExternalAccountSslTests.cs @@ -30,7 +30,7 @@ public void POP3ServerNotSupportingSSL() messages.Add(message); int port = TestSetup.GetNextFreePort(); - using (var pop3Server = new POP3Server(2, port, messages)) + using (var pop3Server = new Pop3ServerSimulator(2, port, messages)) { pop3Server.DisconnectImmediate = true; pop3Server.StartListen(); @@ -104,7 +104,7 @@ public void POP3ServerSupportingSSL() messages.Add(message); int port = TestSetup.GetNextFreePort(); - using (var pop3Server = new POP3Server(1, port, messages, eConnectionSecurity.eCSTLS)) + using (var pop3Server = new Pop3ServerSimulator(1, port, messages, eConnectionSecurity.eCSTLS)) { pop3Server.SetCertificate(SslSetup.GetCertificate()); pop3Server.StartListen(); @@ -128,7 +128,7 @@ public void POP3ServerSupportingSSL() fa.DownloadNow(); pop3Server.WaitForCompletion(); - POP3ClientSimulator.AssertMessageCount("user@test.com", "test", 1); + Pop3ClientSimulator.AssertMessageCount("user@test.com", "test", 1); fa.Delete(); } @@ -148,7 +148,7 @@ public void POP3ServerNOTSupportingStartTLS_StartTLSRequired() messages.Add(message); int port = TestSetup.GetNextFreePort(); - using (var pop3Server = new POP3Server(1, port, messages, eConnectionSecurity.eCSNone)) + using (var pop3Server = new Pop3ServerSimulator(1, port, messages, eConnectionSecurity.eCSNone)) { pop3Server.SetCertificate(SslSetup.GetCertificate()); pop3Server.StartListen(); @@ -209,7 +209,7 @@ public void POP3ServerNOTSupportingStartTLS_StartTLSOptional() messages.Add(message); int port = TestSetup.GetNextFreePort(); - using (var pop3Server = new POP3Server(1, port, messages, eConnectionSecurity.eCSNone)) + using (var pop3Server = new Pop3ServerSimulator(1, port, messages, eConnectionSecurity.eCSNone)) { pop3Server.SetCertificate(SslSetup.GetCertificate()); pop3Server.StartListen(); @@ -233,7 +233,7 @@ public void POP3ServerNOTSupportingStartTLS_StartTLSOptional() fa.DownloadNow(); pop3Server.WaitForCompletion(); - POP3ClientSimulator.AssertMessageCount("user@test.com", "test", 1); + Pop3ClientSimulator.AssertMessageCount("user@test.com", "test", 1); fa.Delete(); } @@ -253,7 +253,7 @@ public void POP3ServerSupportingStartTLS_StartTLSRequired() messages.Add(message); int port = TestSetup.GetNextFreePort(); - using (var pop3Server = new POP3Server(1, port, messages, eConnectionSecurity.eCSSTARTTLSRequired)) + using (var pop3Server = new Pop3ServerSimulator(1, port, messages, eConnectionSecurity.eCSSTARTTLSRequired)) { pop3Server.SetCertificate(SslSetup.GetCertificate()); pop3Server.StartListen(); @@ -277,7 +277,7 @@ public void POP3ServerSupportingStartTLS_StartTLSRequired() fa.DownloadNow(); pop3Server.WaitForCompletion(); - POP3ClientSimulator.AssertMessageCount("user@test.com", "test", 1); + Pop3ClientSimulator.AssertMessageCount("user@test.com", "test", 1); fa.Delete(); } @@ -297,7 +297,7 @@ public void POP3ServerSupportingStartTLS_StartTLSOptional() messages.Add(message); int port = TestSetup.GetNextFreePort(); - using (var pop3Server = new POP3Server(1, port, messages, eConnectionSecurity.eCSSTARTTLSRequired)) + using (var pop3Server = new Pop3ServerSimulator(1, port, messages, eConnectionSecurity.eCSSTARTTLSRequired)) { pop3Server.SetCertificate(SslSetup.GetCertificate()); pop3Server.StartListen(); @@ -321,7 +321,7 @@ public void POP3ServerSupportingStartTLS_StartTLSOptional() fa.DownloadNow(); pop3Server.WaitForCompletion(); - POP3ClientSimulator.AssertMessageCount("user@test.com", "test", 1); + Pop3ClientSimulator.AssertMessageCount("user@test.com", "test", 1); fa.Delete(); } diff --git a/hmailserver/test/RegressionTests/POP3/Fetching/ServerBehaviors.cs b/hmailserver/test/RegressionTests/POP3/Fetching/ServerBehaviors.cs index 5a460895b..e7e36d4da 100644 --- a/hmailserver/test/RegressionTests/POP3/Fetching/ServerBehaviors.cs +++ b/hmailserver/test/RegressionTests/POP3/Fetching/ServerBehaviors.cs @@ -56,16 +56,16 @@ private FetchAccount CreateFetchAccount() } - private POP3Server CreateServer() + private Pop3ServerSimulator CreateServer() { return CreateServer(_message); } - private POP3Server CreateServer(string message) + private Pop3ServerSimulator CreateServer(string message) { var messages = new List { message }; - return new POP3Server(1, _serverPort, messages); + return new Pop3ServerSimulator(1, _serverPort, messages); } @@ -95,7 +95,7 @@ public void TestDisconnectAfterRetrCommand() fetchAccount.DownloadNow(); pop3Server.WaitForCompletion(); - POP3ClientSimulator.AssertMessageCount(_account.Address, "test", 2); + Pop3ClientSimulator.AssertMessageCount(_account.Address, "test", 2); } [Test] @@ -106,7 +106,7 @@ public void TestSingleBuffer() using (var pop3Server = CreateServer()) { - pop3Server.SendBufferMode = POP3Server.BufferMode.SingleBuffer; + pop3Server.SendBufferMode = Pop3ServerSimulator.BufferMode.SingleBuffer; pop3Server.StartListen(); // Fetch message @@ -119,16 +119,16 @@ public void TestSingleBuffer() // Do it again using (var pop3Server = CreateServer()) { - pop3Server.SendBufferMode = POP3Server.BufferMode.SingleBuffer; + pop3Server.SendBufferMode = Pop3ServerSimulator.BufferMode.SingleBuffer; pop3Server.StartListen(); fetchAccount.DownloadNow(); pop3Server.WaitForCompletion(); LockHelper.WaitForUnlock(fetchAccount); - POP3ClientSimulator.AssertMessageCount(_account.Address, "test", 2); + Pop3ClientSimulator.AssertMessageCount(_account.Address, "test", 2); - string downloadedMessage = POP3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); + string downloadedMessage = Pop3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); Assert.IsTrue(downloadedMessage.Contains(_message)); } } @@ -141,7 +141,7 @@ public void TestMessageAndTerminationInSameBuffer() using (var pop3Server = CreateServer()) { - pop3Server.SendBufferMode = POP3Server.BufferMode.MessageAndTerminatonTogether; + pop3Server.SendBufferMode = Pop3ServerSimulator.BufferMode.MessageAndTerminatonTogether; pop3Server.StartListen(); fetchAccount = CreateFetchAccount(); @@ -156,15 +156,15 @@ public void TestMessageAndTerminationInSameBuffer() // Do it again using (var pop3Server = CreateServer()) { - pop3Server.SendBufferMode = POP3Server.BufferMode.MessageAndTerminatonTogether; + pop3Server.SendBufferMode = Pop3ServerSimulator.BufferMode.MessageAndTerminatonTogether; pop3Server.StartListen(); fetchAccount.DownloadNow(); pop3Server.WaitForCompletion(); LockHelper.WaitForUnlock(fetchAccount); - POP3ClientSimulator.AssertMessageCount(_account.Address, "test", 2); - string downloadedMessage = POP3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); + Pop3ClientSimulator.AssertMessageCount(_account.Address, "test", 2); + string downloadedMessage = Pop3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); Assert.IsTrue(downloadedMessage.Contains(_message)); } } @@ -193,7 +193,7 @@ private void TestMessage(string messageContent) using (var pop3Server = CreateServer(messageContent)) { - pop3Server.SendBufferMode = POP3Server.BufferMode.SingleBuffer; + pop3Server.SendBufferMode = Pop3ServerSimulator.BufferMode.SingleBuffer; pop3Server.StartListen(); fetchAccount = CreateFetchAccount(); @@ -207,15 +207,15 @@ private void TestMessage(string messageContent) // Do it again using (var pop3Server = CreateServer(messageContent)) { - pop3Server.SendBufferMode = POP3Server.BufferMode.MessageAndTerminatonTogether; + pop3Server.SendBufferMode = Pop3ServerSimulator.BufferMode.MessageAndTerminatonTogether; pop3Server.StartListen(); fetchAccount.DownloadNow(); pop3Server.WaitForCompletion(); LockHelper.WaitForUnlock(fetchAccount); - POP3ClientSimulator.AssertMessageCount(_account.Address, "test", 2); - string downloadedMessage = POP3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); + Pop3ClientSimulator.AssertMessageCount(_account.Address, "test", 2); + string downloadedMessage = Pop3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); Assert.IsTrue(downloadedMessage.Contains(messageContent)); } } diff --git a/hmailserver/test/RegressionTests/RegressionTests.csproj b/hmailserver/test/RegressionTests/RegressionTests.csproj index f30ef335d..51017fb88 100644 --- a/hmailserver/test/RegressionTests/RegressionTests.csproj +++ b/hmailserver/test/RegressionTests/RegressionTests.csproj @@ -71,18 +71,19 @@ + - + - + @@ -148,7 +149,7 @@ - + @@ -192,7 +193,7 @@ - + @@ -200,7 +201,7 @@ - + diff --git a/hmailserver/test/RegressionTests/Rules/Rules.cs b/hmailserver/test/RegressionTests/Rules/Rules.cs index d86f68c13..0b40b5649 100644 --- a/hmailserver/test/RegressionTests/Rules/Rules.cs +++ b/hmailserver/test/RegressionTests/Rules/Rules.cs @@ -84,13 +84,13 @@ public void ActionAccountRuleMoveToExistingPublicFolder() // Save the rule in the database oRule.Save(); - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); // Spam folder - Assert.IsTrue(oSMTP.Send("ruletest@test.com", "ruletest@test.com", "SomeString", - "Detta ska hamna i public folder.")); + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "SomeString", + "Detta ska hamna i public folder."); - IMAPClientSimulator.AssertMessageCount("ruletest@test.com", "test", "#public.Share1", 1); + ImapClientSimulator.AssertMessageCount("ruletest@test.com", "test", "#public.Share1", 1); } [Test] @@ -133,13 +133,13 @@ public void ActionAccountRuleMoveToExistingPublicFolderSubStructureWithCreatePer // Save the rule in the database oRule.Save(); - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); // Spam folder - oSMTP.Send("ruletest@test.com", "account1@test.com", "SomeString", + smtpClientSimulator.Send("ruletest@test.com", "account1@test.com", "SomeString", "This should end up in the #public.share1.sub since user lacks right."); - IMAPClientSimulator.AssertMessageCount("account1@test.com", "test", "#public.Share1.Sub", 1); + ImapClientSimulator.AssertMessageCount("account1@test.com", "test", "#public.Share1.Sub", 1); } [Test] @@ -171,13 +171,13 @@ public void ActionAccountRuleMoveToNonExistingPublicFolder() // Save the rule in the database oRule.Save(); - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); // Spam folder - oSMTP.Send("ruletest@test.com", "ruletest@test.com", "SomeString", + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "SomeString", "This should end up in the inbox since user lacks right."); - IMAPClientSimulator.AssertMessageCount("ruletest@test.com", "test", "INBOX", 1); + ImapClientSimulator.AssertMessageCount("ruletest@test.com", "test", "INBOX", 1); } [Test] @@ -205,10 +205,10 @@ public void ActionBindToAddress() oRuleAction.Save(); oRule.Save(); - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); // Spam folder - oSMTP.Send("ruletest@test.com", "knafve@gmail.com", "SomeString", + smtpClientSimulator.Send("ruletest@test.com", "knafve@gmail.com", "SomeString", "This mail should not be delivered - Test ActionBindToAddress."); CustomAsserts.AssertRecipientsInDeliveryQueue(0); @@ -244,15 +244,15 @@ public void ActionDelete() // Save the rule in the database oRule.Save(); - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); // Spam folder - oSMTP.Send("ruletest@test.com", "ruletest@test.com", "TestString", "Test 1"); - oSMTP.Send("ruletest@test.com", "ruletest@test.com", "a", "Test 2"); - oSMTP.Send("ruletest@test.com", "ruletest@test.com", "TestString", "Test 3"); - oSMTP.Send("ruletest@test.com", "ruletest@test.com", "b", "Test 2"); + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "TestString", "Test 1"); + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "a", "Test 2"); + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "TestString", "Test 3"); + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "b", "Test 2"); - IMAPClientSimulator.AssertMessageCount("ruletest@test.com", "test", "Inbox", 2); + ImapClientSimulator.AssertMessageCount("ruletest@test.com", "test", "Inbox", 2); int fileCount = 0; string domainDir = Path.Combine(_application.Settings.Directories.DataDirectory, "test.com"); @@ -304,18 +304,18 @@ public void ActionGlobalMoveToIMAPFolder() // Save the rule in the database oRule.Save(); - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); // Spam folder - oSMTP.Send("ActionGlobalMoveToIMAPFolder@test.com", "ActionGlobalMoveToIMAPFolder@test.com", "SomeString", + smtpClientSimulator.Send("ActionGlobalMoveToIMAPFolder@test.com", "ActionGlobalMoveToIMAPFolder@test.com", "SomeString", "Detta ska inte hamna i mappen Inbox\\NotEquals"); - oSMTP.Send("ActionGlobalMoveToIMAPFolder@test.com", "ActionGlobalMoveToIMAPFolder@test.com", "SomeStringA", + smtpClientSimulator.Send("ActionGlobalMoveToIMAPFolder@test.com", "ActionGlobalMoveToIMAPFolder@test.com", "SomeStringA", "Detta ska hamna i mappen Inbox\\NotEquals"); - oSMTP.Send("ActionGlobalMoveToIMAPFolder@test.com", "ActionGlobalMoveToIMAPFolder@test.com", "somestring", + smtpClientSimulator.Send("ActionGlobalMoveToIMAPFolder@test.com", "ActionGlobalMoveToIMAPFolder@test.com", "somestring", "Detta ska inte hamna i mappen Inbox\\NotEquals"); - IMAPClientSimulator.AssertMessageCount("ActionGlobalMoveToIMAPFolder@test.com", "test", "Inbox.GlobalBox", 1); - IMAPClientSimulator.AssertMessageCount("ActionGlobalMoveToIMAPFolder@test.com", "test", "Inbox", 2); + ImapClientSimulator.AssertMessageCount("ActionGlobalMoveToIMAPFolder@test.com", "test", "Inbox.GlobalBox", 1); + ImapClientSimulator.AssertMessageCount("ActionGlobalMoveToIMAPFolder@test.com", "test", "Inbox", 2); } [Test] @@ -357,12 +357,12 @@ public void ActionGlobalRuleMoveToIMAPFolderPublicFolder() // Save the rule in the database oRule.Save(); - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); // Spam folder - oSMTP.Send("ruletest@test.com", "ruletest@test.com", "SomeString", "Detta ska hamna i public folder."); + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "SomeString", "Detta ska hamna i public folder."); - IMAPClientSimulator.AssertMessageCount("ruletest@test.com", "test", "#public.Share1", 1); + ImapClientSimulator.AssertMessageCount("ruletest@test.com", "test", "#public.Share1", 1); } [Test] @@ -391,11 +391,11 @@ public void ActionGlobalRuleMoveToIMAPFolderPublicFolderNonExistant() // Save the rule in the database oRule.Save(); - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); // Spam folder - Assert.IsTrue(oSMTP.Send("ruletest@test.com", "ruletest@test.com", "SomeString", - "Detta ska hamna i public folder.")); + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "SomeString", + "Detta ska hamna i public folder."); // Wait for the folder to be created. IMAPFolder folder = CustomAsserts.AssertFolderExists(_settings.PublicFolders, "MyFolder"); @@ -407,7 +407,7 @@ public void ActionGlobalRuleMoveToIMAPFolderPublicFolderNonExistant() bool ok = false; try { - IMAPClientSimulator.AssertMessageCount("ruletest@test.com", "test", "#public.MyFolder", 0); + ImapClientSimulator.AssertMessageCount("ruletest@test.com", "test", "#public.MyFolder", 0); } catch (Exception) { @@ -427,7 +427,7 @@ public void ActionGlobalRuleMoveToIMAPFolderPublicFolderNonExistant() // Make sure we can access it now. - IMAPClientSimulator.AssertMessageCount("ruletest@test.com", "test", "#public.MyFolder", 1); + ImapClientSimulator.AssertMessageCount("ruletest@test.com", "test", "#public.MyFolder", 1); } [Test] @@ -456,18 +456,18 @@ public void ActionMoveToIMAPFolder() // Save the rule in the database oRule.Save(); - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); // Spam folder - oSMTP.Send("ruletest@test.com", "ruletest@test.com", "SomeString", + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "SomeString", "Detta ska inte hamna i mappen Inbox\\NotEquals"); - oSMTP.Send("ruletest@test.com", "ruletest@test.com", "SomeStringA", + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "SomeStringA", "Detta ska hamna i mappen Inbox\\NotEquals"); - oSMTP.Send("ruletest@test.com", "ruletest@test.com", "somestring", + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "somestring", "Detta ska inte hamna i mappen Inbox\\NotEquals"); - IMAPClientSimulator.AssertMessageCount("ruletest@test.com", "test", "Inbox.NotEquals", 1); - IMAPClientSimulator.AssertMessageCount("ruletest@test.com", "test", "Inbox", 2); + ImapClientSimulator.AssertMessageCount("ruletest@test.com", "test", "Inbox.NotEquals", 1); + ImapClientSimulator.AssertMessageCount("ruletest@test.com", "test", "Inbox", 2); } [Test] @@ -513,18 +513,18 @@ public void ActionOverrideMoveToIMAPFolder() // Save the rule in the database oAccountRule.Save(); - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); // Spam folder - oSMTP.Send("ruletest@test.com", "ruletest@test.com", "SomeString", + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "SomeString", "Detta ska inte hamna i mappen Inbox.Overriden.Test"); - oSMTP.Send("ruletest@test.com", "ruletest@test.com", "SomeStringA", + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "SomeStringA", "Detta ska hamna i mappen Inbox.Overriden.Test"); - oSMTP.Send("ruletest@test.com", "ruletest@test.com", "somestring", + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "somestring", "Detta ska inte hamna i mappen Inbox.Overriden.Test"); - IMAPClientSimulator.AssertMessageCount("ruletest@test.com", "test", "Inbox.Overriden.Test", 1); - IMAPClientSimulator.AssertMessageCount("ruletest@test.com", "test", "Inbox", 2); + ImapClientSimulator.AssertMessageCount("ruletest@test.com", "test", "Inbox.Overriden.Test", 1); + ImapClientSimulator.AssertMessageCount("ruletest@test.com", "test", "Inbox", 2); } [Test] @@ -536,7 +536,7 @@ public void ActionSendUsingRoute() Account account = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); // Add a route so we can conenct to localhost. - Route route = SMTPClientTests.AddRoutePointingAtLocalhost(5, smtpServerPort, false); + Route route = TestSetup.AddRoutePointingAtLocalhost(5, smtpServerPort, false); // Add a global send-using-route rule Rule oRule = _application.Rules.Add(); @@ -559,12 +559,12 @@ public void ActionSendUsingRoute() oRule.Save(); // Send message and confirm that the route does not affect it. - var smtp = new SMTPClientSimulator(); + var smtp = new SmtpClientSimulator(); var recipients = new List(); recipients.Add("test@test.com"); - if (!smtp.Send("test@test.com", recipients, "Test", "Test message")) - Assert.Fail("Delivery failed"); - string message = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); + smtp.Send("test@test.com", recipients, "Test", "Test message"); + + string message = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); Assert.IsTrue(message.Contains("Test message")); // Send a message and confirm that the rule affects it. @@ -572,7 +572,7 @@ public void ActionSendUsingRoute() deliveryResults["test@nonexistantdomain.com"] = 550; - using (var server = new SMTPServerSimulator(1, smtpServerPort)) + using (var server = new SmtpServerSimulator(1, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.StartListen(); @@ -580,8 +580,8 @@ public void ActionSendUsingRoute() // Send the actual message recipients = new List(); recipients.Add("test@nonexistantdomain.com"); - if (!smtp.Send("test@test.com", recipients, "TestString", "Test message")) - Assert.Fail("Delivery failed"); + smtp.Send("test@test.com", recipients, "TestString", "Test message"); + server.WaitForCompletion(); } @@ -590,7 +590,7 @@ public void ActionSendUsingRoute() CustomAsserts.AssertRecipientsInDeliveryQueue(0); // Download it. - message = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); + message = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); Assert.IsTrue(message.Contains("550")); Assert.IsTrue(message.Contains("test@nonexistantdomain.com")); @@ -623,12 +623,12 @@ public void ActionSetHeaderContents() // Save the rule in the database oRule.Save(); - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); // Spam folder - oSMTP.Send("ruletest@test.com", "ruletest@test.com", "TestString", "Test 1"); + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "TestString", "Test 1"); - string sContents = POP3ClientSimulator.AssertGetFirstMessageText("ruletest@test.com", "test"); + string sContents = Pop3ClientSimulator.AssertGetFirstMessageText("ruletest@test.com", "test"); if (sContents.IndexOf("SomeHeader: SomeValue") <= 0) throw new Exception("Message header not set"); @@ -663,17 +663,17 @@ public void CriteriaContains() // Save the rule in the database oRule.Save(); - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); // Spam folder - oSMTP.Send("ruletest@test.com", "ruletest@test.com", "TestString", + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "TestString", "Detta ska hamna i mappen Inbox\\Wildcard"); - oSMTP.Send("ruletest@test.com", "ruletest@test.com", "TestStri", "Detta ska inte hamna Inbox\\Wildcard"); - oSMTP.Send("ruletest@test.com", "ruletest@test.com", "VaffeTestStringBaffe", + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "TestStri", "Detta ska inte hamna Inbox\\Wildcard"); + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "VaffeTestStringBaffe", "Detta ska hamna i mappen Inbox\\Wildcard"); - IMAPClientSimulator.AssertMessageCount("ruletest@test.com", "test", "Inbox.Wildcard", 2); - IMAPClientSimulator.AssertMessageCount("ruletest@test.com", "test", "Inbox", 1); + ImapClientSimulator.AssertMessageCount("ruletest@test.com", "test", "Inbox.Wildcard", 2); + ImapClientSimulator.AssertMessageCount("ruletest@test.com", "test", "Inbox", 1); Trace.WriteLine(watch.ElapsedMilliseconds); @@ -706,7 +706,7 @@ public void CriteriaContainsHTMLBody() // Save the rule in the database oRule.Save(); - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); string message = "From: Someone " + Environment.NewLine + "Content-Type: text/html; charset=\"Windows-1251\"" + Environment.NewLine + @@ -714,11 +714,11 @@ public void CriteriaContainsHTMLBody() Environment.NewLine + "
MyHTMLBody
" + Environment.NewLine; - oSMTP.SendRaw("someone@example.org", account.Address, message); + smtpClientSimulator.SendRaw("someone@example.org", account.Address, message); // The message should be placed in the Wildcard folder, since the HTML body of the message contains MyHTMLBody. - IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox.Wildcard", 1); - IMAPClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 0); + ImapClientSimulator.AssertMessageCount(account.Address, "test", "Inbox.Wildcard", 1); + ImapClientSimulator.AssertMessageCount(account.Address, "test", "Inbox", 0); } [Test] @@ -747,19 +747,19 @@ public void CriteriaEquals() // Save the rule in the database oRule.Save(); - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); // Spam folder - oSMTP.Send("ruletest@test.com", "ruletest@test.com", "TestString", + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "TestString", "Detta ska hamna i mappen Inbox\\Wildcard"); - oSMTP.Send("ruletest@test.com", "ruletest@test.com", "teststring", "Detta ska hamna Inbox\\Wildcard"); - oSMTP.Send("ruletest@test.com", "ruletest@test.com", "Testar", + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "teststring", "Detta ska hamna Inbox\\Wildcard"); + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "Testar", "Detta ska inte hamna i mappen Inbox\\Wildcard"); - oSMTP.Send("ruletest@test.com", "ruletest@test.com", "teststring vaffe", + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "teststring vaffe", "Detta ska inte hamna i mappen Inbox\\Wildcard"); - IMAPClientSimulator.AssertMessageCount("ruletest@test.com", "test", "Inbox.Wildcard", 2); - IMAPClientSimulator.AssertMessageCount("ruletest@test.com", "test", "Inbox", 2); + ImapClientSimulator.AssertMessageCount("ruletest@test.com", "test", "Inbox.Wildcard", 2); + ImapClientSimulator.AssertMessageCount("ruletest@test.com", "test", "Inbox", 2); } @@ -789,17 +789,17 @@ public void CriteriaGreaterThan() // Save the rule in the database oRule.Save(); - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); // Spam folder - oSMTP.Send("ruletest@test.com", "ruletest@test.com", "0", "Detta ska inte hamna i mappen Inbox"); - oSMTP.Send("ruletest@test.com", "ruletest@test.com", "1", "Detta ska inte hamna i mappen Inbox"); - oSMTP.Send("ruletest@test.com", "ruletest@test.com", "2", "Detta ska inte hamna i mappen Inbox"); - oSMTP.Send("ruletest@test.com", "ruletest@test.com", "3", "Detta ska hamna i mappen Inbox\\GreaterThan"); - oSMTP.Send("ruletest@test.com", "ruletest@test.com", "4", "Detta ska hamna i mappen Inbox\\GreaterThan"); - - IMAPClientSimulator.AssertMessageCount("ruletest@test.com", "test", "Inbox", 3); - IMAPClientSimulator.AssertMessageCount("ruletest@test.com", "test", "Inbox.GreaterThan", 2); + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "0", "Detta ska inte hamna i mappen Inbox"); + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "1", "Detta ska inte hamna i mappen Inbox"); + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "2", "Detta ska inte hamna i mappen Inbox"); + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "3", "Detta ska hamna i mappen Inbox\\GreaterThan"); + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "4", "Detta ska hamna i mappen Inbox\\GreaterThan"); + + ImapClientSimulator.AssertMessageCount("ruletest@test.com", "test", "Inbox", 3); + ImapClientSimulator.AssertMessageCount("ruletest@test.com", "test", "Inbox.GreaterThan", 2); } [Test] @@ -828,16 +828,16 @@ public void CriteriaLessThan() // Save the rule in the database oRule.Save(); - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); // Spam folder - oSMTP.Send("ruletest@test.com", "ruletest@test.com", "0", "Detta ska hamna i mappen Inbox\\LessThan"); - oSMTP.Send("ruletest@test.com", "ruletest@test.com", "2", "Detta ska hamna i mappen Inbox"); - oSMTP.Send("ruletest@test.com", "ruletest@test.com", "3", "Detta ska hamna i mappen Inbox"); - oSMTP.Send("ruletest@test.com", "ruletest@test.com", "4", "Detta ska hamna i mappen Inbox"); + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "0", "Detta ska hamna i mappen Inbox\\LessThan"); + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "2", "Detta ska hamna i mappen Inbox"); + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "3", "Detta ska hamna i mappen Inbox"); + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "4", "Detta ska hamna i mappen Inbox"); - IMAPClientSimulator.AssertMessageCount("ruletest@test.com", "test", "Inbox.LessThan", 1); - IMAPClientSimulator.AssertMessageCount("ruletest@test.com", "test", "Inbox", 3); + ImapClientSimulator.AssertMessageCount("ruletest@test.com", "test", "Inbox.LessThan", 1); + ImapClientSimulator.AssertMessageCount("ruletest@test.com", "test", "Inbox", 3); } [Test] @@ -866,18 +866,18 @@ public void CriteriaNotEquals() // Save the rule in the database oRule.Save(); - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); // Spam folder - oSMTP.Send("ruletest@test.com", "ruletest@test.com", "SomeString", + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "SomeString", "Detta ska inte hamna i mappen Inbox\\NotEquals"); - oSMTP.Send("ruletest@test.com", "ruletest@test.com", "SomeStringA", + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "SomeStringA", "Detta ska hamna i mappen Inbox\\NotEquals"); - oSMTP.Send("ruletest@test.com", "ruletest@test.com", "somestring", + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "somestring", "Detta ska inte hamna i mappen Inbox\\NotEquals"); - IMAPClientSimulator.AssertMessageCount("ruletest@test.com", "test", "Inbox.NotEquals", 1); - IMAPClientSimulator.AssertMessageCount("ruletest@test.com", "test", "Inbox", 2); + ImapClientSimulator.AssertMessageCount("ruletest@test.com", "test", "Inbox.NotEquals", 1); + ImapClientSimulator.AssertMessageCount("ruletest@test.com", "test", "Inbox", 2); } [Test] @@ -906,18 +906,18 @@ public void CriteriaRegEx() // Save the rule in the database oRule.Save(); - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); // Spam folder - oSMTP.Send("ruletest@test.com", "ruletest@test.com", "abc", "Detta ska hamna i mappen Inbox\\Wildcard"); - oSMTP.Send("ruletest@test.com", "ruletest@test.com", "abcdef", "Detta ska hamna i mappen Inbox\\Wildcard"); - oSMTP.Send("ruletest@test.com", "ruletest@test.com", "abcdefghi", + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "abc", "Detta ska hamna i mappen Inbox\\Wildcard"); + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "abcdef", "Detta ska hamna i mappen Inbox\\Wildcard"); + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "abcdefghi", "Detta ska inte hamna i mappen Inbox\\Wildcard"); CustomAsserts.AssertRecipientsInDeliveryQueue(0); - IMAPClientSimulator.AssertMessageCount("ruletest@test.com", "test", "Inbox.RegEx", 2); - IMAPClientSimulator.AssertMessageCount("ruletest@test.com", "test", "Inbox", 1); + ImapClientSimulator.AssertMessageCount("ruletest@test.com", "test", "Inbox.RegEx", 2); + ImapClientSimulator.AssertMessageCount("ruletest@test.com", "test", "Inbox", 1); } [Test] @@ -946,15 +946,15 @@ public void CriteriaWildcardExactMatch() // Save the rule in the database oRule.Save(); - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); // Spam folder - oSMTP.Send("ruletest@test.com", "ruletest@test.com", "Exact wildcard", + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "Exact wildcard", "Detta ska hamna i mappen Inbox\\Wildcard"); - oSMTP.Send("ruletest@test.com", "ruletest@test.com", "Exact wildcard", + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "Exact wildcard", "Detta ska hamna i mappen Inbox\\Wildcard"); - IMAPClientSimulator.AssertMessageCount("ruletest@test.com", "test", "Inbox.Wildcard", 2); + ImapClientSimulator.AssertMessageCount("ruletest@test.com", "test", "Inbox.Wildcard", 2); } [Test] @@ -985,13 +985,13 @@ public void CriteriaWildcardNoCase() // Save the rule in the database oRule.Save(); - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); // Spam folder - oSMTP.Send("CriteriaWildcardNoCase@test.com", "CriteriaWildcardNoCase@test.com", "exact Test match", + smtpClientSimulator.Send("CriteriaWildcardNoCase@test.com", "CriteriaWildcardNoCase@test.com", "exact Test match", "Detta ska hamna i mappen Inbox\\Wildcard"); - IMAPClientSimulator.AssertMessageCount("CriteriaWildcardNoCase@test.com", "test", "Inbox.Wildcard", 1); + ImapClientSimulator.AssertMessageCount("CriteriaWildcardNoCase@test.com", "test", "Inbox.Wildcard", 1); } [Test] @@ -1020,16 +1020,16 @@ public void CriteriaWildcardPartialMatch() // Save the rule in the database oRule.Save(); - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); // Spam folder - oSMTP.Send("ruletest@test.com", "ruletest@test.com", "Exact Test Match", + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "Exact Test Match", "Detta ska hamna i mappen Inbox\\Wildcard"); - oSMTP.Send("ruletest@test.com", "ruletest@test.com", "ExactMatchArInte", + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "ExactMatchArInte", "Detta ska inte hamna Inbox\\Wildcard"); - IMAPClientSimulator.AssertMessageCount("ruletest@test.com", "test", "Inbox.Wildcard", 1); - IMAPClientSimulator.AssertMessageCount("ruletest@test.com", "test", "Inbox", 1); + ImapClientSimulator.AssertMessageCount("ruletest@test.com", "test", "Inbox.Wildcard", 1); + ImapClientSimulator.AssertMessageCount("ruletest@test.com", "test", "Inbox", 1); } [Test] @@ -1073,12 +1073,12 @@ public void MovedToRenamedPublicFolder() // Save the rule in the database oRule.Save(); - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); // Spam folder - oSMTP.Send("ruletest@test.com", "ruletest@test.com", "SomeString", "Detta ska hamna i public folder."); + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "SomeString", "Detta ska hamna i public folder."); - IMAPClientSimulator.AssertMessageCount("ruletest@test.com", "test", "Public.Share1", 1); + ImapClientSimulator.AssertMessageCount("ruletest@test.com", "test", "Public.Share1", 1); } [Test] @@ -1094,29 +1094,29 @@ public void TestBasics() AddCorporateRule(oAccount); AddExactMatchRule(oAccount); - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); // Spam folder - oSMTP.Send("ruletest@test.com", "ruletest@test.com", "**SPAM** INBOX->SPAM", + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "**SPAM** INBOX->SPAM", "Detta ska hamna i mappen Inbox\\Spam"); // Corporate folder - oSMTP.Send("ruletest@test.com", "ruletest@test.com", "**CORPORATE** INBOX->CORPORATE", + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "**CORPORATE** INBOX->CORPORATE", "Detta ska hamna i mappen Inbox\\Corporate"); - oSMTP.Send("ruletest@test.com", "ruletest@test.com", "CORPORATE EXACT MATCH", + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "CORPORATE EXACT MATCH", "Detta ska hamna i mappen Inbox\\Corporate"); // Inbox folder - oSMTP.Send("ruletest@test.com", "ruletest@test.com", "**CORPORATE EXACT MATCH**", + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "**CORPORATE EXACT MATCH**", "Detta ska hamna i mappen Inbox"); - oSMTP.Send("ruletest@test.com", "ruletest@test.com", "INBOX", "Detta ska hamna i mappen Inbox"); - oSMTP.Send("ruletest@test.com", "ruletest@test.com", "INBOX", "Detta ska hamna i mappen Inbox"); - oSMTP.Send("ruletest@test.com", "ruletest@test.com", "INBOX", "Detta ska hamna i mappen Inbox"); + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "INBOX", "Detta ska hamna i mappen Inbox"); + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "INBOX", "Detta ska hamna i mappen Inbox"); + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "INBOX", "Detta ska hamna i mappen Inbox"); - IMAPClientSimulator.AssertMessageCount("ruletest@test.com", "test", "Inbox.Spam", 1); - IMAPClientSimulator.AssertMessageCount("ruletest@test.com", "test", "Inbox.Corporate", 2); - IMAPClientSimulator.AssertMessageCount("ruletest@test.com", "test", "Inbox", 4); + ImapClientSimulator.AssertMessageCount("ruletest@test.com", "test", "Inbox.Spam", 1); + ImapClientSimulator.AssertMessageCount("ruletest@test.com", "test", "Inbox.Corporate", 2); + ImapClientSimulator.AssertMessageCount("ruletest@test.com", "test", "Inbox", 4); // Test move to imap with mail with multiple recipients. @@ -1129,12 +1129,12 @@ public void TestBasics() const string sBody = "Test of sending same email to multiple accounts."; - oSMTP.Send(oAccount1.Address, lstRecipients, "**SPAM** INBOX->SPAM", sBody); + smtpClientSimulator.Send(oAccount1.Address, lstRecipients, "**SPAM** INBOX->SPAM", sBody); - IMAPClientSimulator.AssertMessageCount(oAccount1.Address, "test", "Inbox.Spam", 1); - IMAPClientSimulator.AssertMessageCount(oAccount2.Address, "test", "Inbox", 1); + ImapClientSimulator.AssertMessageCount(oAccount1.Address, "test", "Inbox.Spam", 1); + ImapClientSimulator.AssertMessageCount(oAccount2.Address, "test", "Inbox", 1); - var sim = new IMAPClientSimulator(); + var sim = new ImapClientSimulator(); sim.ConnectAndLogon(oAccount2.Address, "test"); Assert.IsFalse(sim.SelectFolder("Inbox.Spam")); } @@ -1178,15 +1178,15 @@ public void TestCreateCopyAccountRule() // Save the rule in the database oRule.Save(); - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); // Test to send the message to account 1. Make sure a copy is created by this rule. - oSMTP.Send(account1.Address, account1.Address, "Test", "Test message."); + smtpClientSimulator.Send(account1.Address, account1.Address, "Test", "Test message."); CustomAsserts.AssertRecipientsInDeliveryQueue(0, true); - IMAPClientSimulator.AssertMessageCount(account1.Address, "test", "Inbox", 2); + ImapClientSimulator.AssertMessageCount(account1.Address, "test", "Inbox", 2); - string firstTemp = POP3ClientSimulator.AssertGetFirstMessageText(account1.Address, "test"); - string secondTemp = POP3ClientSimulator.AssertGetFirstMessageText(account1.Address, "test"); + string firstTemp = Pop3ClientSimulator.AssertGetFirstMessageText(account1.Address, "test"); + string secondTemp = Pop3ClientSimulator.AssertGetFirstMessageText(account1.Address, "test"); // This is where it gets really ugly. The order of the two deliveries // are not defined. The message created by the rule could be delivered @@ -1248,21 +1248,21 @@ public void TestCreateCopyGlobalRule() // Save the rule in the database oRule.Save(); - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); // Test to send the message to account 1. Make sure a copy is created by this rule. - oSMTP.Send(account1.Address, new List {account1.Address, account2.Address}, "Test", "Test message."); + smtpClientSimulator.Send(account1.Address, new List {account1.Address, account2.Address}, "Test", "Test message."); CustomAsserts.AssertRecipientsInDeliveryQueue(0, true); - IMAPClientSimulator.AssertMessageCount(account1.Address, "test", "Inbox", 2); - IMAPClientSimulator.AssertMessageCount(account2.Address, "test", "Inbox", 2); + ImapClientSimulator.AssertMessageCount(account1.Address, "test", "Inbox", 2); + ImapClientSimulator.AssertMessageCount(account2.Address, "test", "Inbox", 2); /* * The delivery order is not guaranteed. The copied message may be delivered * before the original message. Check both situations. * */ - string first = POP3ClientSimulator.AssertGetFirstMessageText(account1.Address, "test"); - string second = POP3ClientSimulator.AssertGetFirstMessageText(account1.Address, "test"); + string first = Pop3ClientSimulator.AssertGetFirstMessageText(account1.Address, "test"); + string second = Pop3ClientSimulator.AssertGetFirstMessageText(account1.Address, "test"); if (first.Contains("X-hMailServer-LoopCount: 1")) { @@ -1275,8 +1275,8 @@ public void TestCreateCopyGlobalRule() Assert.IsTrue(second.Contains("X-CopyRule: CriteriaTest"), first); } - first = POP3ClientSimulator.AssertGetFirstMessageText(account2.Address, "test"); - second = POP3ClientSimulator.AssertGetFirstMessageText(account2.Address, "test"); + first = Pop3ClientSimulator.AssertGetFirstMessageText(account2.Address, "test"); + second = Pop3ClientSimulator.AssertGetFirstMessageText(account2.Address, "test"); if (first.Contains("X-hMailServer-LoopCount: 1")) { @@ -1330,29 +1330,29 @@ public void TestDeliveryAttempts() deliveryResults["ahem@dummy-example.com"] = 452; int smtpServerPort = TestSetup.GetNextFreePort(); - using (var smtpServer = new SMTPServerSimulator(1, smtpServerPort)) + using (var smtpServer = new SmtpServerSimulator(1, smtpServerPort)) { smtpServer.AddRecipientResult(deliveryResults); smtpServer.StartListen(); // Add a route so we can connect to localhost. - SMTPClientTests.AddRoutePointingAtLocalhost(2, smtpServerPort, false); + TestSetup.AddRoutePointingAtLocalhost(2, smtpServerPort, false); - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); // Test to send the message to account 1. Make sure a copy is created by this rule. - oSMTP.Send(account.Address, new List {"ahem@dummy-example.com"}, "Test", "Test message."); + smtpClientSimulator.Send(account.Address, new List {"ahem@dummy-example.com"}, "Test", "Test message."); smtpServer.WaitForCompletion(); } CustomAsserts.AssertRecipientsInDeliveryQueue(0, true); - string first = POP3ClientSimulator.AssertGetFirstMessageText(adminAccount.Address, "test"); + string first = Pop3ClientSimulator.AssertGetFirstMessageText(adminAccount.Address, "test"); Assert.IsTrue(first.Contains("X-hMailServer-LoopCount: 1"), first); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 0); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 0); } [Test] @@ -1390,15 +1390,15 @@ public void TestForward() // Save the rule in the database oRule.Save(); - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); // Test to send the messge to account 1. - oSMTP.Send(account1.Address, account1.Address, "Test", "Test message."); + smtpClientSimulator.Send(account1.Address, account1.Address, "Test", "Test message."); - IMAPClientSimulator.AssertMessageCount(account1.Address, "test", "Inbox", 1); + ImapClientSimulator.AssertMessageCount(account1.Address, "test", "Inbox", 1); CustomAsserts.AssertRecipientsInDeliveryQueue(0); - IMAPClientSimulator.AssertMessageCount(account3.Address, "test", "Inbox", 1); - IMAPClientSimulator.AssertMessageCount(account2.Address, "test", "Inbox", 1); + ImapClientSimulator.AssertMessageCount(account3.Address, "test", "Inbox", 1); + ImapClientSimulator.AssertMessageCount(account2.Address, "test", "Inbox", 1); } [Test] @@ -1441,13 +1441,13 @@ public void TestMoveToPublicFolderWithoutPermission() // Save the rule in the database oRule.Save(); - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); // Spam folder - oSMTP.Send("ruletest@test.com", "ruletest@test.com", "SomeString", + smtpClientSimulator.Send("ruletest@test.com", "ruletest@test.com", "SomeString", "This should end up in the inbox since user lacks right."); - IMAPClientSimulator.AssertMessageCount("ruletest@test.com", "test", "INBOX", 1); + ImapClientSimulator.AssertMessageCount("ruletest@test.com", "test", "INBOX", 1); } [Test] @@ -1462,7 +1462,7 @@ public void TestRecipientCountInAccountLevelRule() CreatePrintRecipientCountRule(account1.Rules); - SMTPClientSimulator.StaticSend(account1.Address, account1.Address, "SomeString", + SmtpClientSimulator.StaticSend(account1.Address, account1.Address, "SomeString", "Detta ska inte hamna i mappen Inbox.Overriden.Test"); CustomAsserts.AssertRecipientsInDeliveryQueue(0); // This should print a single recipient. @@ -1471,7 +1471,7 @@ public void TestRecipientCountInAccountLevelRule() Assert.IsTrue(eventLogText.Contains("\"1\""), eventLogText); // Send message to two recipients. Recipient should still be one, since it's an account-level rule. - SMTPClientSimulator.StaticSend(account1.Address, new List {account1.Address, account2.Address}, + SmtpClientSimulator.StaticSend(account1.Address, new List {account1.Address, account2.Address}, "SomeString", "Detta ska inte hamna i mappen Inbox.Overriden.Test"); CustomAsserts.AssertRecipientsInDeliveryQueue(0); @@ -1493,7 +1493,7 @@ public void TestRecipientCountInGlobalRule() CreatePrintRecipientCountRule(_application.Rules); - SMTPClientSimulator.StaticSend(account1.Address, account1.Address, "SomeString", + SmtpClientSimulator.StaticSend(account1.Address, account1.Address, "SomeString", "Detta ska inte hamna i mappen Inbox.Overriden.Test"); CustomAsserts.AssertRecipientsInDeliveryQueue(0); // This should print a single recipient. @@ -1503,7 +1503,7 @@ public void TestRecipientCountInGlobalRule() Assert.IsTrue(eventLogText.Contains("\"1\""), eventLogText); // Send message to two recipients. - SMTPClientSimulator.StaticSend(account1.Address, new List {account1.Address, account2.Address}, + SmtpClientSimulator.StaticSend(account1.Address, new List {account1.Address, account2.Address}, "SomeString", "Detta ska inte hamna i mappen Inbox.Overriden.Test"); CustomAsserts.AssertRecipientsInDeliveryQueue(0); @@ -1544,11 +1544,11 @@ public void TestReply() // Save the rule in the database oRule.Save(); - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); // Test to send the message to account 2. - oSMTP.Send(account1.Address, account2.Address, "Test", "Test message."); - IMAPClientSimulator.AssertMessageCount(account2.Address, "test", "Inbox", 1); + smtpClientSimulator.Send(account1.Address, account2.Address, "Test", "Test message."); + ImapClientSimulator.AssertMessageCount(account2.Address, "test", "Inbox", 1); // Make sure a reply is sent back to account 1. CustomAsserts.AssertRecipientsInDeliveryQueue(0); diff --git a/hmailserver/test/RegressionTests/SMTP/Basics.cs b/hmailserver/test/RegressionTests/SMTP/Basics.cs index f33546b23..fa347dc89 100644 --- a/hmailserver/test/RegressionTests/SMTP/Basics.cs +++ b/hmailserver/test/RegressionTests/SMTP/Basics.cs @@ -23,8 +23,8 @@ private static void Send50Messages() { for (int i = 0; i < 50; i++) { - var oSMTP = new SMTPClientSimulator(); - oSMTP.Send("test@test.com", "bigaccount@test.com", "Big account email", "Body av email"); + var smtpClientSimulator = new SmtpClientSimulator(); + smtpClientSimulator.Send("test@test.com", "bigaccount@test.com", "Big account email", "Body av email"); } } @@ -74,8 +74,8 @@ public void BounceMessageShouldContainSubjectAndDate() recipientAccount.Save(); // Make sure that no bounce is sent. - SMTPClientSimulator.StaticSend(senderAccount.Address, recipientAccount.Address, "MySubject", "Test"); - POP3ClientSimulator.AssertGetFirstMessageText(recipientAccount.Address, "test"); + SmtpClientSimulator.StaticSend(senderAccount.Address, recipientAccount.Address, "MySubject", "Test"); + Pop3ClientSimulator.AssertGetFirstMessageText(recipientAccount.Address, "test"); // Build a 2MB string. var builder = new StringBuilder(); @@ -86,15 +86,15 @@ public void BounceMessageShouldContainSubjectAndDate() } string text = builder.ToString(); - SMTPClientSimulator.StaticSend(senderAccount.Address, recipientAccount.Address, "Test subject", text); + SmtpClientSimulator.StaticSend(senderAccount.Address, recipientAccount.Address, "Test subject", text); // Make sure the recipient did not receive it. CustomAsserts.AssertRecipientsInDeliveryQueue(0); - POP3ClientSimulator.AssertMessageCount(recipientAccount.Address, "test", 0); + Pop3ClientSimulator.AssertMessageCount(recipientAccount.Address, "test", 0); CustomAsserts.AssertFilesInUserDirectory(recipientAccount, 0); // Make sure it bounced. - string content = POP3ClientSimulator.AssertGetFirstMessageText(senderAccount.Address, "test"); + string content = Pop3ClientSimulator.AssertGetFirstMessageText(senderAccount.Address, "test"); Assert.IsTrue(content.Contains("Inbox is full")); Assert.IsTrue(content.Contains("Subject: Test subject")); @@ -119,13 +119,13 @@ public void DomainAliasesShouldNotRewriteRecipientList() deliveryResults["test@dummy-example.com"] = 250; int smtpServerPort = TestSetup.GetNextFreePort(); - using (var server = new SMTPServerSimulator(1, smtpServerPort)) + using (var server = new SmtpServerSimulator(1, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.StartListen(); - Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, true, eConnectionSecurity.eCSNone); + Route route = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, true, eConnectionSecurity.eCSNone); // Now send a message from test@test.com to test@otherdomain.com. // Error scenario: @@ -136,12 +136,12 @@ public void DomainAliasesShouldNotRewriteRecipientList() // This should not happen. Otherdomain.com is an alias for test.com, // but we shouldn't actually modify the recipient address just because // of this. - var smtpClient = new SMTPClientSimulator(); - Assert.IsTrue(smtpClient.Send(account.Address, "test@dummy-example.com", "Test", "Test message")); + var smtpClient = new SmtpClientSimulator(); + smtpClient.Send(account.Address, "test@dummy-example.com", "Test", "Test message"); CustomAsserts.AssertRecipientsInDeliveryQueue(0); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 0); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 0); // This should now be processed via the rule -> route -> external server we've set up. server.WaitForCompletion(); @@ -158,7 +158,7 @@ public void MailFromShouldNotUpdatedLastLogonTime() DateTime lastLogonTimeBefore = Convert.ToDateTime(account.LastLogonTime); Thread.Sleep(1000); - SMTPClientSimulator.StaticSend("someone@test.com", "us'er@test.com", "Test", "Test"); + SmtpClientSimulator.StaticSend("someone@test.com", "us'er@test.com", "Test", "Test"); CustomAsserts.AssertRecipientsInDeliveryQueue(0); DateTime lastLogonTimeAfter = @@ -176,8 +176,8 @@ public void TestAntiVirusEnabled() Account account = SingletonProvider.Instance.AddAccount(_domain, "user@test.com", "test"); - SMTPClientSimulator.StaticSend("user@test.com", "user@test.com", "Test", "Test"); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); + SmtpClientSimulator.StaticSend("user@test.com", "user@test.com", "Test", "Test"); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1); Message message = account.IMAPFolders.get_ItemByName("INBOX").Messages[0]; Assert.IsTrue(message.get_Flag(eMessageFlag.eMFVirusScan)); @@ -200,11 +200,11 @@ public void TestAwstatsLog() Account oAccount1 = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); IPAddress localAddress = TestSetup.GetLocalIpAddress(); - var oSMTP = new SMTPClientSimulator(false, 25, localAddress); + var smtpClientSimulator = new SmtpClientSimulator(false, 25, localAddress); // Delivery from external to local. - Assert.IsTrue(oSMTP.Send("test@external.com", "test@test.com", "Mail 1", "Mail 1")); - POP3ClientSimulator.AssertMessageCount("test@test.com", "test", 1); + smtpClientSimulator.Send("test@external.com", "test@test.com", "Mail 1", "Mail 1"); + Pop3ClientSimulator.AssertMessageCount("test@test.com", "test", 1); string contents = TestSetup.ReadExistingTextFile(logging.CurrentAwstatsLog); CustomAsserts.AssertDeleteFile(logging.CurrentAwstatsLog); string expectedString = string.Format("\ttest@external.com\ttest@test.com\t{0}\t127.0.0.1\tSMTP\t?\t250\t", @@ -212,7 +212,7 @@ public void TestAwstatsLog() Assert.IsTrue(contents.Contains(expectedString), contents); // Failed delivery from local to local. - Assert.IsFalse(oSMTP.Send("test@test.com", "test@test.com", "Mail 1", "Mail 1")); + CustomAsserts.Throws(() => smtpClientSimulator.Send("test@test.com", "test@test.com", "Mail 1", "Mail 1")); contents = TestSetup.ReadExistingTextFile(logging.CurrentAwstatsLog); CustomAsserts.AssertDeleteFile(logging.CurrentAwstatsLog); expectedString = string.Format("\ttest@test.com\ttest@test.com\t{0}\t127.0.0.1\tSMTP\t?\t530\t", @@ -239,13 +239,13 @@ public void TestBounceMessageSyntax() string text = builder.ToString(); - SMTPClientSimulator.StaticSend(senderAccount.Address, recipientAccount.Address, "", text); + SmtpClientSimulator.StaticSend(senderAccount.Address, recipientAccount.Address, "", text); // Make sure the recipient did not receive it. CustomAsserts.AssertRecipientsInDeliveryQueue(0); // Check the syntax in the bounce message. - string content = POP3ClientSimulator.AssertGetFirstMessageText(senderAccount.Address, "test"); + string content = Pop3ClientSimulator.AssertGetFirstMessageText(senderAccount.Address, "test"); // The bounce message should contain the MIME-version. Assert.IsTrue(content.Contains("MIME-Version: 1.0")); @@ -268,9 +268,9 @@ public void TestDuplicateMessageIDs() "" + Environment.NewLine + "Test"; - SMTPClientSimulator.StaticSendRaw("test@test.com", "test@test.com", content); + SmtpClientSimulator.StaticSendRaw("test@test.com", "test@test.com", content); - string test = POP3ClientSimulator.AssertGetFirstMessageText("test@test.com", "test"); + string test = Pop3ClientSimulator.AssertGetFirstMessageText("test@test.com", "test"); Assert.IsTrue(test.Contains("Message-Id")); Assert.IsFalse(test.Contains("Message-ID")); @@ -348,40 +348,40 @@ public void TestMailFromSyntaxValidation() { Account account1 = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - var oSMTP = new TcpConnection(); - oSMTP.Connect(25); + var smtpClientSimulator = new TcpConnection(); + smtpClientSimulator.Connect(25); - Assert.IsTrue(oSMTP.Receive().StartsWith("220")); - oSMTP.Send("HELO test\r\n"); - Assert.IsTrue(oSMTP.Receive().StartsWith("250")); + Assert.IsTrue(smtpClientSimulator.Receive().StartsWith("220")); + smtpClientSimulator.Send("HELO test\r\n"); + Assert.IsTrue(smtpClientSimulator.Receive().StartsWith("250")); // A few tests of invalid syntax. - Assert.IsFalse(oSMTP.SendAndReceive("MAIL FROM: \r\n").StartsWith("250")); - Assert.IsFalse(oSMTP.SendAndReceive("MAIL FROM: < test@test.com \r\n").StartsWith("250")); - Assert.IsFalse(oSMTP.SendAndReceive("MAIL FROM: < \r\n").StartsWith("250")); - Assert.IsFalse(oSMTP.SendAndReceive("MAIL FROM: > \r\n").StartsWith("250")); - Assert.IsFalse(oSMTP.SendAndReceive("MAIL FROM: \r\n").StartsWith("250")); - Assert.IsFalse(oSMTP.SendAndReceive("MAIL FROM sdsdfs@sdsdf.csd\r\n").StartsWith("250")); + Assert.IsFalse(smtpClientSimulator.SendAndReceive("MAIL FROM: \r\n").StartsWith("250")); + Assert.IsFalse(smtpClientSimulator.SendAndReceive("MAIL FROM: < test@test.com \r\n").StartsWith("250")); + Assert.IsFalse(smtpClientSimulator.SendAndReceive("MAIL FROM: < \r\n").StartsWith("250")); + Assert.IsFalse(smtpClientSimulator.SendAndReceive("MAIL FROM: > \r\n").StartsWith("250")); + Assert.IsFalse(smtpClientSimulator.SendAndReceive("MAIL FROM: \r\n").StartsWith("250")); + Assert.IsFalse(smtpClientSimulator.SendAndReceive("MAIL FROM sdsdfs@sdsdf.csd\r\n").StartsWith("250")); // Valid syntax, < and > - Assert.IsTrue(oSMTP.SendAndReceive("MAIL FROM: \r\n").StartsWith("250")); - Assert.IsTrue(oSMTP.SendAndReceive("RSET\r\n").StartsWith("250")); + Assert.IsTrue(smtpClientSimulator.SendAndReceive("MAIL FROM: \r\n").StartsWith("250")); + Assert.IsTrue(smtpClientSimulator.SendAndReceive("RSET\r\n").StartsWith("250")); - Assert.IsTrue(oSMTP.SendAndReceive("MAIL FROM: test@test.com\r\n").StartsWith("250")); - Assert.IsTrue(oSMTP.SendAndReceive("RSET\r\n").StartsWith("250")); + Assert.IsTrue(smtpClientSimulator.SendAndReceive("MAIL FROM: test@test.com\r\n").StartsWith("250")); + Assert.IsTrue(smtpClientSimulator.SendAndReceive("RSET\r\n").StartsWith("250")); - Assert.IsTrue(oSMTP.SendAndReceive("MAIL FROM: test@test.com \r\n").StartsWith("250")); - Assert.IsTrue(oSMTP.SendAndReceive("RSET\r\n").StartsWith("250")); + Assert.IsTrue(smtpClientSimulator.SendAndReceive("MAIL FROM: test@test.com \r\n").StartsWith("250")); + Assert.IsTrue(smtpClientSimulator.SendAndReceive("RSET\r\n").StartsWith("250")); - Assert.IsTrue(oSMTP.SendAndReceive("MAIL FROM:test@test.com\r\n").StartsWith("250")); - Assert.IsTrue(oSMTP.SendAndReceive("RSET\r\n").StartsWith("250")); + Assert.IsTrue(smtpClientSimulator.SendAndReceive("MAIL FROM:test@test.com\r\n").StartsWith("250")); + Assert.IsTrue(smtpClientSimulator.SendAndReceive("RSET\r\n").StartsWith("250")); - Assert.IsTrue(oSMTP.SendAndReceive("MAIL FROM:\r\n").StartsWith("250")); - Assert.IsTrue(oSMTP.SendAndReceive("RSET\r\n").StartsWith("250")); + Assert.IsTrue(smtpClientSimulator.SendAndReceive("MAIL FROM:\r\n").StartsWith("250")); + Assert.IsTrue(smtpClientSimulator.SendAndReceive("RSET\r\n").StartsWith("250")); - oSMTP.Disconnect(); + smtpClientSimulator.Disconnect(); } [Test] @@ -397,8 +397,8 @@ public void TestMaxSizeLimitation() recipientAccount.Save(); // Make sure that no bounce is sent. - SMTPClientSimulator.StaticSend(senderAccount.Address, recipientAccount.Address, "MySubject", "Test"); - POP3ClientSimulator.AssertGetFirstMessageText(recipientAccount.Address, "test"); + SmtpClientSimulator.StaticSend(senderAccount.Address, recipientAccount.Address, "MySubject", "Test"); + Pop3ClientSimulator.AssertGetFirstMessageText(recipientAccount.Address, "test"); // Build a 2MB string. var builder = new StringBuilder(); @@ -409,15 +409,15 @@ public void TestMaxSizeLimitation() } string text = builder.ToString(); - SMTPClientSimulator.StaticSend(senderAccount.Address, recipientAccount.Address, "MySubject", text); + SmtpClientSimulator.StaticSend(senderAccount.Address, recipientAccount.Address, "MySubject", text); // Make sure the recipient did not receive it. CustomAsserts.AssertRecipientsInDeliveryQueue(0); - POP3ClientSimulator.AssertMessageCount(recipientAccount.Address, "test", 0); + Pop3ClientSimulator.AssertMessageCount(recipientAccount.Address, "test", 0); CustomAsserts.AssertFilesInUserDirectory(recipientAccount, 0); // Make sure it bounced. - string content = POP3ClientSimulator.AssertGetFirstMessageText(senderAccount.Address, "test"); + string content = Pop3ClientSimulator.AssertGetFirstMessageText(senderAccount.Address, "test"); Assert.IsTrue(content.Contains("Inbox is full")); } @@ -434,10 +434,10 @@ public void TestMaxSizeLimitationMultipleSmallMessages() recipientAccount.Save(); // Make sure we can send several messages. - Assert.IsTrue(SMTPClientSimulator.StaticSend(senderAccount.Address, recipientAccount.Address, "Test", "Test")); - Assert.IsTrue(SMTPClientSimulator.StaticSend(senderAccount.Address, recipientAccount.Address, "Test", "Test")); + SmtpClientSimulator.StaticSend(senderAccount.Address, recipientAccount.Address, "Test", "Test"); + SmtpClientSimulator.StaticSend(senderAccount.Address, recipientAccount.Address, "Test", "Test"); - POP3ClientSimulator.AssertMessageCount(recipientAccount.Address, "test", 2); + Pop3ClientSimulator.AssertMessageCount(recipientAccount.Address, "test", 2); } [Test] @@ -448,7 +448,7 @@ public void TestMediumVolume() SingletonProvider.Instance.AddAccount(_domain, "bigaccount@test.com", "test"); - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); var oThreads = new ArrayList(); @@ -466,7 +466,7 @@ public void TestMediumVolume() oThread.Join(); } - IMAPClientSimulator.AssertMessageCount("bigaccount@test.com", "test", "Inbox", 250); + ImapClientSimulator.AssertMessageCount("bigaccount@test.com", "test", "Inbox", 250); } [Test] @@ -479,21 +479,21 @@ public void TestMultipleHostsLimitMXHosts() deliveryResults["user1@dummy-example.com"] = 250; int smtpServerPort = TestSetup.GetNextFreePort(); - using (var server = new SMTPServerSimulator(1, smtpServerPort)) + using (var server = new SmtpServerSimulator(1, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.StartListen(); // Add a route so we can connect to localhost. - Route route = SMTPClientTests.AddRoutePointingAtLocalhostMultipleHosts(2, smtpServerPort); + Route route = TestSetup.AddRoutePointingAtLocalhostMultipleHosts(2, smtpServerPort); // Send message to this route. - var smtp = new SMTPClientSimulator(); + var smtp = new SmtpClientSimulator(); var recipients = new List(); recipients.Add("user1@dummy-example.com"); - Assert.IsTrue(SMTPClientSimulator.StaticSend("test@test.com", "user1@dummy-example.com", "Test", "Test")); + SmtpClientSimulator.StaticSend("test@test.com", "user1@dummy-example.com", "Test", "Test"); // Wait for the client to disconnect. server.WaitForCompletion(); @@ -512,8 +512,8 @@ public void TestPostmasterAddressIsAlias() Alias alias = SingletonProvider.Instance.AddAlias(_domain, "alias@test.com", "test@test.com"); Account account = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - Assert.IsTrue(SMTPClientSimulator.StaticSend("someone@example.com", "someone@test.com", "Test", "Test")); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); + SmtpClientSimulator.StaticSend("someone@example.com", "someone@test.com", "Test", "Test"); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1); } [Test] @@ -523,7 +523,7 @@ public void TestPostmasterAddressIsAliasButAliasMissing() _domain.Save(); Account account = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - Assert.IsFalse(SMTPClientSimulator.StaticSend("someone@example.com", "someone@test.com", "Test", "Test")); + CustomAsserts.Throws(() => SmtpClientSimulator.StaticSend("someone@example.com", "someone@test.com", "Test", "Test")); } [Test] @@ -535,9 +535,9 @@ public void TestPostmasterInternalSender() SingletonProvider.Instance.AddAccount(_domain, "sender@test.com", "test"); Account account = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - Assert.IsTrue(SMTPClientSimulator.StaticSend("sender@test.com", "someone@test.com", "Test", "Test")); + SmtpClientSimulator.StaticSend("sender@test.com", "someone@test.com", "Test", "Test"); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1); } [Test] @@ -552,9 +552,9 @@ public void TestPostmasterOnSecondDomain() Account account = SingletonProvider.Instance.AddAccount(otherDomain, "test@otherDomain.com", "test"); - Assert.IsTrue(SMTPClientSimulator.StaticSend("sender@test.com", "someone@test.com", "Test", "Test")); + SmtpClientSimulator.StaticSend("sender@test.com", "someone@test.com", "Test", "Test"); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1); } [Test] @@ -572,9 +572,9 @@ public void TestPostmasterOnSecondDomainWithDomainAlias() Account account = SingletonProvider.Instance.AddAccount(otherDomain, "test@otherDomain.com", "test"); - Assert.IsTrue(SMTPClientSimulator.StaticSend("sender@test.com", "someone@test.com", "Test", "Test")); + SmtpClientSimulator.StaticSend("sender@test.com", "someone@test.com", "Test", "Test"); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1); } [Test] @@ -587,7 +587,7 @@ public void TestPostmasterRecipientExternal() SingletonProvider.Instance.AddAccount(_domain, "sender@test.com", "test"); Account account = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - Assert.IsFalse(SMTPClientSimulator.StaticSend("sender@example.com", "someone@example.com", "Test", "Test")); + CustomAsserts.Throws(() => SmtpClientSimulator.StaticSend("sender@example.com", "someone@example.com", "Test", "Test")); } [Test] @@ -604,9 +604,9 @@ public void TestPostmasterToPostmasterOnOtherDomain() Account account = SingletonProvider.Instance.AddAccount(otherDomain, "account@otherDomain.com", "test"); - Assert.IsTrue(SMTPClientSimulator.StaticSend("sender@test.com", "someone@test.com", "Test", "Test")); + SmtpClientSimulator.StaticSend("sender@test.com", "someone@test.com", "Test", "Test"); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1); } [Test] @@ -616,24 +616,24 @@ public void TestRcptToSyntax() { Account account1 = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - var oSMTP = new TcpConnection(); - oSMTP.Connect(25); + var smtpClientSimulator = new TcpConnection(); + smtpClientSimulator.Connect(25); - Assert.IsTrue(oSMTP.Receive().StartsWith("220")); - oSMTP.Send("HELO test\r\n"); - Assert.IsTrue(oSMTP.Receive().StartsWith("250")); + Assert.IsTrue(smtpClientSimulator.Receive().StartsWith("220")); + smtpClientSimulator.Send("HELO test\r\n"); + Assert.IsTrue(smtpClientSimulator.Receive().StartsWith("250")); // A few tests of invalid syntax. - Assert.IsTrue(oSMTP.SendAndReceive("MAIL FROM: \r\n").StartsWith("250")); - Assert.IsFalse(oSMTP.SendAndReceive("RCPT TO: test@test.com>\r\n").StartsWith("250")); - Assert.IsFalse(oSMTP.SendAndReceive("RCPT TO: \r\n").StartsWith("250")); + Assert.IsFalse(smtpClientSimulator.SendAndReceive("RCPT TO: test@test.com>\r\n").StartsWith("250")); + Assert.IsFalse(smtpClientSimulator.SendAndReceive("RCPT TO: \r\n").StartsWith("250")); - Assert.IsTrue(oSMTP.SendAndReceive("RCPT TO: test@test.com\r\n").StartsWith("250")); + Assert.IsTrue(smtpClientSimulator.SendAndReceive("RCPT TO: \r\n").StartsWith("250")); + Assert.IsTrue(smtpClientSimulator.SendAndReceive("RCPT TO: test@test.com\r\n").StartsWith("250")); - oSMTP.Disconnect(); + smtpClientSimulator.Disconnect(); } [Test] @@ -650,19 +650,19 @@ public void TestSameRecipientMultipleTimes() Account account1 = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - var oSMTP = new TcpConnection(); - oSMTP.Connect(25); - Assert.IsTrue(oSMTP.Receive().StartsWith("220")); - oSMTP.Send("HELO test\r\n"); - Assert.IsTrue(oSMTP.Receive().StartsWith("250")); - oSMTP.Send("MAIL FROM: test@test.com\r\n"); - Assert.IsTrue(oSMTP.Receive().StartsWith("250")); - oSMTP.Send("RCPT TO: knafve@gmail.com\r\n"); - Assert.IsTrue(oSMTP.Receive().StartsWith("250")); - oSMTP.Send("RCPT TO: knafve@gmail.com\r\n"); - Assert.IsTrue(oSMTP.Receive().StartsWith("250")); + var smtpClientSimulator = new TcpConnection(); + smtpClientSimulator.Connect(25); + Assert.IsTrue(smtpClientSimulator.Receive().StartsWith("220")); + smtpClientSimulator.Send("HELO test\r\n"); + Assert.IsTrue(smtpClientSimulator.Receive().StartsWith("250")); + smtpClientSimulator.Send("MAIL FROM: test@test.com\r\n"); + Assert.IsTrue(smtpClientSimulator.Receive().StartsWith("250")); + smtpClientSimulator.Send("RCPT TO: knafve@gmail.com\r\n"); + Assert.IsTrue(smtpClientSimulator.Receive().StartsWith("250")); + smtpClientSimulator.Send("RCPT TO: knafve@gmail.com\r\n"); + Assert.IsTrue(smtpClientSimulator.Receive().StartsWith("250")); - oSMTP.Disconnect(); + smtpClientSimulator.Disconnect(); } [Test] @@ -684,16 +684,16 @@ public void TestSendExternalToExternalPermitted() deliveryResults["test2@dummy-example.com"] = 250; int smtpServerPort = TestSetup.GetNextFreePort(); - using (var server = new SMTPServerSimulator(1, smtpServerPort)) + using (var server = new SmtpServerSimulator(1, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.StartListen(); - Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, false, eConnectionSecurity.eCSNone); + Route route = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false, eConnectionSecurity.eCSNone); - var oSMTP = new SMTPClientSimulator(); - Assert.IsTrue(oSMTP.Send("test@sdag532sdfagdsa12fsdafdsa1.com", - "test2@dummy-example.com", "Mail 1", "Test message")); + var smtpClientSimulator = new SmtpClientSimulator(); + smtpClientSimulator.Send("test@sdag532sdfagdsa12fsdafdsa1.com", + "test2@dummy-example.com", "Mail 1", "Test message"); // This should now be processed via the rule -> route -> external server we've set up. @@ -707,8 +707,8 @@ public void TestSendExternalToExternalPermitted() public void TestSendToAddressWithQuote() { Account account = SingletonProvider.Instance.AddAccount(_domain, "us'er@test.com", "test"); - SMTPClientSimulator.StaticSend("someone@test.com", "us'er@test.com", "Test", "Test"); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); + SmtpClientSimulator.StaticSend("someone@test.com", "us'er@test.com", "Test", "Test"); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1); } [Test] @@ -719,7 +719,7 @@ public void TestSendToMultipleAccounts() Account oAccount2 = SingletonProvider.Instance.AddAccount(_domain, "multi2@test.com", "test"); Account oAccount3 = SingletonProvider.Instance.AddAccount(_domain, "multi3@test.com", "test"); - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); var lstRecipients = new List(); lstRecipients.Add("multi1@test.com"); @@ -728,19 +728,19 @@ public void TestSendToMultipleAccounts() string sBody = "Test of sending same email to multiple accounts."; - oSMTP.Send(oAccount1.Address, lstRecipients, "Multi test", sBody); + smtpClientSimulator.Send(oAccount1.Address, lstRecipients, "Multi test", sBody); - var oPOP3 = new POP3ClientSimulator(); + var pop3ClientSimulator = new Pop3ClientSimulator(); - string sMessageData = POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); + string sMessageData = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); if (sMessageData.IndexOf(sBody) < 0) throw new Exception("E-mail not found"); - sMessageData = POP3ClientSimulator.AssertGetFirstMessageText(oAccount2.Address, "test"); + sMessageData = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount2.Address, "test"); if (sMessageData.IndexOf(sBody) < 0) throw new Exception("E-mail not found"); - sMessageData = POP3ClientSimulator.AssertGetFirstMessageText(oAccount3.Address, "test"); + sMessageData = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount3.Address, "test"); if (sMessageData.IndexOf(sBody) < 0) throw new Exception("E-mail not found"); } @@ -752,8 +752,8 @@ public void TestSendToPostmasterAddress() _domain.Save(); Account account = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - Assert.IsTrue(SMTPClientSimulator.StaticSend("someone@example.com", "someone@test.com", "Test", "Test")); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); + SmtpClientSimulator.StaticSend("someone@example.com", "someone@test.com", "Test", "Test"); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1); } @@ -768,9 +768,9 @@ public void TestSendToPostmasterAddressDomainAlias() _domain.Save(); Account account = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - Assert.IsTrue(SMTPClientSimulator.StaticSend("someone@example.com", "someone@test.com", "Test", "Test")); + SmtpClientSimulator.StaticSend("someone@example.com", "someone@test.com", "Test", "Test"); - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1); } [Test] @@ -792,8 +792,8 @@ public void TestTempErrorIfDiskFull() string result = ""; - var sim = new SMTPClientSimulator(); - sim.Send(senderAccount.Address, recipientAccount.Address, "MySubject", "Test", out result); + var sim = new SmtpClientSimulator(); + CustomAsserts.Throws( () => sim.Send(senderAccount.Address, recipientAccount.Address, "MySubject", "Test", out result)); Assert.IsTrue(result.StartsWith("4"), "Expected temporary error, but was: " + result); @@ -932,13 +932,13 @@ public void TestValidEmailAddress() string text = builder.ToString(); - SMTPClientSimulator.StaticSend(senderAccount.Address, recipientAccount.Address, "", text); + SmtpClientSimulator.StaticSend(senderAccount.Address, recipientAccount.Address, "", text); // Make sure the recipient did not receive it. CustomAsserts.AssertRecipientsInDeliveryQueue(0); // Check the syntax in the bounce message. - string content = POP3ClientSimulator.AssertGetFirstMessageText(senderAccount.Address, "test"); + string content = Pop3ClientSimulator.AssertGetFirstMessageText(senderAccount.Address, "test"); // The bounce message should contain the MIME-version. Assert.IsTrue(content.Contains("MIME-Version: 1.0")); @@ -953,7 +953,7 @@ public void TestWelcomeMessage() Application application = SingletonProvider.Instance.GetApp(); _settings.WelcomeSMTP = "HOWDYHO"; - var oSimulator = new SMTPClientSimulator(); + var oSimulator = new SmtpClientSimulator(); string sWelcomeMessage = oSimulator.GetWelcomeMessage(); @@ -973,7 +973,7 @@ public void SmtpRelayShouldConsolidateRecipients() deliveryResults["user4@test4.com"] = 250; int smtpServerPort = TestSetup.GetNextFreePort(); - using (var server = new SMTPServerSimulator(1, smtpServerPort)) + using (var server = new SmtpServerSimulator(1, smtpServerPort)) { _application.Settings.SMTPRelayer = "localhost"; _application.Settings.SMTPRelayerPort = smtpServerPort; @@ -981,7 +981,7 @@ public void SmtpRelayShouldConsolidateRecipients() server.AddRecipientResult(deliveryResults); server.StartListen(); - var smtpClient = new SMTPClientSimulator(); + var smtpClient = new SmtpClientSimulator(); var recipients = new List() { @@ -992,7 +992,7 @@ public void SmtpRelayShouldConsolidateRecipients() }; Account senderAccount = SingletonProvider.Instance.AddAccount(_domain, "sender@test.com", "test"); - Assert.IsTrue(smtpClient.Send(senderAccount.Address, recipients, "Test", "Test message")); + smtpClient.Send(senderAccount.Address, recipients, "Test", "Test message"); CustomAsserts.AssertRecipientsInDeliveryQueue(0); server.WaitForCompletion(); diff --git a/hmailserver/test/RegressionTests/SMTP/BlockedAttachmentTests.cs b/hmailserver/test/RegressionTests/SMTP/BlockedAttachmentTests.cs index f1286d955..583d94272 100644 --- a/hmailserver/test/RegressionTests/SMTP/BlockedAttachmentTests.cs +++ b/hmailserver/test/RegressionTests/SMTP/BlockedAttachmentTests.cs @@ -72,9 +72,9 @@ public void TestAttachmentRemoval() "\r\n" + "--------------050908050500020808050006--\r\n"; - SMTPClientSimulator.StaticSendRaw("test@test.com", "test@test.com", messageText); + SmtpClientSimulator.StaticSendRaw("test@test.com", "test@test.com", messageText); - IMAPClientSimulator.AssertMessageCount("test@test.com", "test", "Inbox", 1); + ImapClientSimulator.AssertMessageCount("test@test.com", "test", "Inbox", 1); Message message = CustomAsserts.AssertRetrieveFirstMessage(_account.IMAPFolders.get_ItemByName("INBOX")); Assert.AreEqual(1, message.Attachments.Count); @@ -122,7 +122,7 @@ public void TestSingleBlockedAttachment() } // Check that the message exists - string message = POP3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); + string message = Pop3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); Assert.IsTrue(message.Contains(string.Format("The attachment {0} was blocked for delivery by the e-mail server.", attachmentName))); } @@ -164,7 +164,7 @@ public void TestTwoBlockedAttachments() } // Check that the message exists - string message = POP3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); + string message = Pop3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); Assert.IsTrue(message.Contains(string.Format("The attachment {0} was blocked for delivery by the e-mail server.", attachment1Name))); Assert.IsTrue(message.Contains(string.Format("The attachment {0} was blocked for delivery by the e-mail server.", attachment2Name))); @@ -204,7 +204,7 @@ public void TestBlockedAttachmentWithUnicodeInName() string expectedNewAttachmentName = attachmentName + ".txt"; - IMAPClientSimulator.AssertMessageCount("test@test.com", "test", "Inbox", 1); + ImapClientSimulator.AssertMessageCount("test@test.com", "test", "Inbox", 1); Message message = CustomAsserts.AssertRetrieveFirstMessage(_account.IMAPFolders.get_ItemByName("INBOX")); Assert.AreEqual(1, message.Attachments.Count); diff --git a/hmailserver/test/RegressionTests/SMTP/DistributionLists.cs b/hmailserver/test/RegressionTests/SMTP/DistributionLists.cs index d5cb4f377..f3dbadb94 100644 --- a/hmailserver/test/RegressionTests/SMTP/DistributionLists.cs +++ b/hmailserver/test/RegressionTests/SMTP/DistributionLists.cs @@ -4,6 +4,7 @@ using System.Text; using System.Threading; using NUnit.Framework; +using RegressionTests.Infrastructure; using RegressionTests.Shared; using hMailServer; @@ -15,11 +16,7 @@ public class DistributionLists : TestFixtureBase [Test] public void TestDistributionListAnnouncementFromDomainAlias() { - var oIMAP = new IMAPClientSimulator(); - var oSMTP = new SMTPClientSimulator(); - - Application application = SingletonProvider.Instance.GetApp(); - + var smtpClientSimulator = new SmtpClientSimulator(); // // TEST LIST SECURITY IN COMBINATION WITH DOMAIN NAME ALIASES @@ -38,15 +35,15 @@ public void TestDistributionListAnnouncementFromDomainAlias() oList3.Save(); // THIS MESSAGE SHOULD FAIL - Assert.IsFalse(oSMTP.Send("test@test.com", "list@test.com", "Mail 1", "Mail 1")); + CustomAsserts.Throws(()=> smtpClientSimulator.Send("test@test.com", "list@test.com", "Mail 1", "Mail 1")); DomainAlias oDA = _domain.DomainAliases.Add(); oDA.AliasName = "dummy-example.com"; oDA.Save(); // THIS MESSAGE SHOULD SUCCEED - Assert.IsTrue(oSMTP.Send("test@dummy-example.com", "list@dummy-example.com", "Mail 1", "Mail 1")); - IMAPClientSimulator.AssertMessageCount("test@dummy-example.com", "test", "Inbox", 1); + smtpClientSimulator.Send("test@dummy-example.com", "list@dummy-example.com", "Mail 1", "Mail 1"); + ImapClientSimulator.AssertMessageCount("test@dummy-example.com", "test", "Inbox", 1); } [Test] @@ -66,11 +63,11 @@ public void TestDistributionListPointingAtItself() SingletonProvider.Instance.AddAccount(_domain, "recipient3@test.com", "test"); SingletonProvider.Instance.AddAccount(_domain, "recipient4@test.com", "test"); - Assert.IsTrue(SMTPClientSimulator.StaticSend("test@test.com", "list1@test.com", "Mail 1", "Mail 1")); + SmtpClientSimulator.StaticSend("test@test.com", "list1@test.com", "Mail 1", "Mail 1"); - IMAPClientSimulator.AssertMessageCount("recipient1@test.com", "test", "Inbox", 1); - IMAPClientSimulator.AssertMessageCount("recipient2@test.com", "test", "Inbox", 1); - IMAPClientSimulator.AssertMessageCount("recipient4@test.com", "test", "Inbox", 1); + ImapClientSimulator.AssertMessageCount("recipient1@test.com", "test", "Inbox", 1); + ImapClientSimulator.AssertMessageCount("recipient2@test.com", "test", "Inbox", 1); + ImapClientSimulator.AssertMessageCount("recipient4@test.com", "test", "Inbox", 1); } [Test] @@ -117,11 +114,11 @@ public void TestDistributionListModePublic() list.RequireSMTPAuth = false; list.Save(); - var smtpClient = new SMTPClientSimulator(); - Assert.IsTrue(smtpClient.Send("test@test.com", list.Address, "Mail 1", "Mail 1")); + var smtpClient = new SmtpClientSimulator(); + smtpClient.Send("test@test.com", list.Address, "Mail 1", "Mail 1"); foreach (var recipient in recipients) - IMAPClientSimulator.AssertMessageCount(recipient, "test", "Inbox", 1); + ImapClientSimulator.AssertMessageCount(recipient, "test", "Inbox", 1); } @@ -147,12 +144,12 @@ public void TestDistributionListModeAnnouncer() list.RequireSMTPAuth = false; list.Save(); - var smtpClient = new SMTPClientSimulator(); - Assert.IsFalse(smtpClient.Send("test@test.com", list.Address, "Mail 1", "Mail 1")); - Assert.IsTrue(smtpClient.Send(announcer.Address, list.Address, "Mail 1", "Mail 1")); + var smtpClient = new SmtpClientSimulator(); + CustomAsserts.Throws(() => smtpClient.Send("test@test.com", list.Address, "Mail 1", "Mail 1")); + smtpClient.Send(announcer.Address, list.Address, "Mail 1", "Mail 1"); foreach (var recipient in recipients) - IMAPClientSimulator.AssertMessageCount(recipient, "test", "Inbox", 1); + ImapClientSimulator.AssertMessageCount(recipient, "test", "Inbox", 1); } [Test] @@ -177,20 +174,20 @@ public void TestDistributionListModeMembers() list.RequireSMTPAuth = false; list.Save(); - var smtpClient = new SMTPClientSimulator(); - Assert.IsFalse(smtpClient.Send("test@test.com", list.Address, "Mail 1", "Mail 1")); - Assert.IsFalse(smtpClient.Send(announcer.Address, list.Address, "Mail 1", "Mail 1")); - Assert.IsTrue(smtpClient.Send(recipients[0], list.Address, "Mail 1", "Mail 1")); + var smtpClient = new SmtpClientSimulator(); + CustomAsserts.Throws(() => smtpClient.Send("test@test.com", list.Address, "Mail 1", "Mail 1")); + CustomAsserts.Throws(() => smtpClient.Send(announcer.Address, list.Address, "Mail 1", "Mail 1")); + smtpClient.Send(recipients[0], list.Address, "Mail 1", "Mail 1"); foreach (var recipient in recipients) - IMAPClientSimulator.AssertMessageCount(recipient, "test", "Inbox", 1); + ImapClientSimulator.AssertMessageCount(recipient, "test", "Inbox", 1); } [Test] public void TestDistributionListsMembershipDomainAliases() { - var oIMAP = new IMAPClientSimulator(); - var oSMTP = new SMTPClientSimulator(); + var oIMAP = new ImapClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); Application application = SingletonProvider.Instance.GetApp(); @@ -218,7 +215,7 @@ public void TestDistributionListsMembershipDomainAliases() oList3.Save(); // THIS MESSAGE SHOULD FAIL - Membership required, unknown sender domain - Assert.IsFalse(oSMTP.Send("account1@dummy-example.com", "list@test.com", "Mail 1", "Mail 1")); + CustomAsserts.Throws(() => smtpClientSimulator.Send("account1@dummy-example.com", "list@test.com", "Mail 1", "Mail 1")); oList3.Delete(); @@ -233,10 +230,10 @@ public void TestDistributionListsMembershipDomainAliases() oList3.Mode = eDistributionListMode.eLMMembership; oList3.Save(); - Assert.IsTrue(oSMTP.Send("account1@dummy-example.com", "list@test.com", "Mail 1", "Mail 1")); + smtpClientSimulator.Send("account1@dummy-example.com", "list@test.com", "Mail 1", "Mail 1"); - IMAPClientSimulator.AssertMessageCount("account1@test.com", "test", "Inbox", 1); - IMAPClientSimulator.AssertMessageCount("account2@test.com", "test", "Inbox", 1); + ImapClientSimulator.AssertMessageCount("account1@test.com", "test", "Inbox", 1); + ImapClientSimulator.AssertMessageCount("account2@test.com", "test", "Inbox", 1); } @@ -288,13 +285,13 @@ public void TestListContainingLists() "outsider2@test.com" }; - var smtpClient = new SMTPClientSimulator(); - Assert.IsTrue(smtpClient.Send(test.Address, recipients, "test" , "test")); + var smtpClient = new SmtpClientSimulator(); + smtpClient.Send(test.Address, recipients, "test" , "test"); - IMAPClientSimulator.AssertMessageCount("acc2@test.com", "test", "Inbox", 1); // Member in list - IMAPClientSimulator.AssertMessageCount("acc3@test.com", "test", "Inbox", 1); // Member in list - IMAPClientSimulator.AssertMessageCount("outsider1@test.com", "test", "Inbox", 1); // Included in To list - IMAPClientSimulator.AssertMessageCount("outsider2@test.com", "test", "Inbox", 1); // Included in To list + ImapClientSimulator.AssertMessageCount("acc2@test.com", "test", "Inbox", 1); // Member in list + ImapClientSimulator.AssertMessageCount("acc3@test.com", "test", "Inbox", 1); // Member in list + ImapClientSimulator.AssertMessageCount("outsider1@test.com", "test", "Inbox", 1); // Included in To list + ImapClientSimulator.AssertMessageCount("outsider2@test.com", "test", "Inbox", 1); // Included in To list } } } diff --git a/hmailserver/test/RegressionTests/SMTP/ReceivedHeaders.cs b/hmailserver/test/RegressionTests/SMTP/ReceivedHeaders.cs index 7b4e14fa9..d28fcd228 100644 --- a/hmailserver/test/RegressionTests/SMTP/ReceivedHeaders.cs +++ b/hmailserver/test/RegressionTests/SMTP/ReceivedHeaders.cs @@ -34,10 +34,10 @@ public void TestESMTPAInHeader() { string errorMessage; - var client = new SMTPClientSimulator(); + var client = new SmtpClientSimulator(); client.Send(false, _account.Address, "test", _account.Address, _account.Address, "Test", "Test", out errorMessage); - var message = POP3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); + var message = Pop3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); Assert.IsTrue(message.Contains("ESMTPA\r\n")); } @@ -46,12 +46,12 @@ public void TestESMTPAInHeader() [Description("Header should contain ESMTPS if STARTTLS is used.")] public void TestESMTPSInHeader() { - var smtpClientSimulator = new SMTPClientSimulator(false, 25002); + var smtpClientSimulator = new SmtpClientSimulator(false, 25002); string errorMessage; smtpClientSimulator.Send(true, string.Empty, string.Empty, _account.Address, _account.Address, "Test", "test", out errorMessage); - var message = POP3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); + var message = Pop3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); Assert.IsTrue(message.Contains("ESMTPS\r\n")); } @@ -61,13 +61,13 @@ public void TestESMTPSAInHeader() { try { - var smtpClientSimulator = new SMTPClientSimulator(false, 25002); + var smtpClientSimulator = new SmtpClientSimulator(false, 25002); string errorMessage; smtpClientSimulator.Send(true, _account.Address, "test", _account.Address, _account.Address, "Test", "test", out errorMessage); - var message = POP3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); + var message = Pop3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); Assert.IsTrue(message.Contains("ESMTPSA\r\n")); } catch (Exception e) @@ -82,13 +82,13 @@ public void TestCipherInfoInReceivedHeader() { try { - var smtpClientSimulator = new SMTPClientSimulator(false, 25002); + var smtpClientSimulator = new SmtpClientSimulator(false, 25002); string errorMessage; smtpClientSimulator.Send(true, _account.Address, "test", _account.Address, _account.Address, "Test", "test", out errorMessage); - var message = POP3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); + var message = Pop3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); Assert.IsTrue(message.Contains("version=TLS")); Assert.IsTrue(message.Contains("cipher=")); Assert.IsTrue(message.Contains("bits=")); @@ -105,13 +105,13 @@ public void TestMissingCipherInfoInReceivedHeader() { try { - var smtpClientSimulator = new SMTPClientSimulator(false, 25); + var smtpClientSimulator = new SmtpClientSimulator(false, 25); string errorMessage; smtpClientSimulator.Send(false, _account.Address, "test", _account.Address, _account.Address, "Test", "test", out errorMessage); - var message = POP3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); + var message = Pop3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); Assert.IsFalse(message.Contains("cipher\r\n")); } catch (Exception e) diff --git a/hmailserver/test/RegressionTests/SMTP/Routes.cs b/hmailserver/test/RegressionTests/SMTP/Routes.cs index f614e7e26..5517eaf35 100644 --- a/hmailserver/test/RegressionTests/SMTP/Routes.cs +++ b/hmailserver/test/RegressionTests/SMTP/Routes.cs @@ -20,7 +20,7 @@ public void SendMessageToAliasForwardToRoute() deliveryResults["user@test.com"] = 250; int smtpServerPort = TestSetup.GetNextFreePort(); - using (var server = new SMTPServerSimulator(1, smtpServerPort)) + using (var server = new SmtpServerSimulator(1, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.StartListen(); @@ -44,8 +44,8 @@ public void SendMessageToAliasForwardToRoute() SingletonProvider.Instance.AddAlias(_domain, "users@test.com", "user@test.com"); - var smtpClient = new SMTPClientSimulator(); - Assert.IsTrue(smtpClient.Send("example@example.com", "users@test.com", "Test", "Test message")); + var smtpClient = new SmtpClientSimulator(); + smtpClient.Send("example@example.com", "users@test.com", "Test", "Test message"); CustomAsserts.AssertRecipientsInDeliveryQueue(0); server.WaitForCompletion(); @@ -68,7 +68,7 @@ public void RoutesShouldHaveHigherPrioThanSMTPRelay() _application.Settings.SMTPRelayer = "example.com"; int smtpServerPort = TestSetup.GetNextFreePort(); - using (var server = new SMTPServerSimulator(1, smtpServerPort)) + using (var server = new SmtpServerSimulator(1, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.StartListen(); @@ -92,8 +92,8 @@ public void RoutesShouldHaveHigherPrioThanSMTPRelay() SingletonProvider.Instance.AddAlias(_domain, "users@test.com", "user@test.com"); - var smtpClient = new SMTPClientSimulator(); - Assert.IsTrue(smtpClient.Send("example@example.com", "users@test.com", "Test", "Test message")); + var smtpClient = new SmtpClientSimulator(); + smtpClient.Send("example@example.com", "users@test.com", "Test", "Test message"); CustomAsserts.AssertRecipientsInDeliveryQueue(0); server.WaitForCompletion(); @@ -114,7 +114,7 @@ public void RoutesShouldConsolidateRecipients() deliveryResults["user4@test.com"] = 250; int smtpServerPort = TestSetup.GetNextFreePort(); - using (var server = new SMTPServerSimulator(1, smtpServerPort)) + using (var server = new SmtpServerSimulator(1, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.StartListen(); @@ -131,7 +131,7 @@ public void RoutesShouldConsolidateRecipients() route.AllAddresses = true; route.Save(); - var smtpClient = new SMTPClientSimulator(); + var smtpClient = new SmtpClientSimulator(); var recipients = new List() { @@ -141,7 +141,7 @@ public void RoutesShouldConsolidateRecipients() "user4@test.com" }; - Assert.IsTrue(smtpClient.Send("example@example.com", recipients, "Test", "Test message")); + smtpClient.Send("example@example.com", recipients, "Test", "Test message"); CustomAsserts.AssertRecipientsInDeliveryQueue(0); server.WaitForCompletion(); @@ -159,7 +159,7 @@ public void RoutesShouldSupportWildcardDomain() deliveryResults["user@stuff.example.com"] = 250; int smtpServerPort = TestSetup.GetNextFreePort(); - using (var server = new SMTPServerSimulator(1, smtpServerPort)) + using (var server = new SmtpServerSimulator(1, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.StartListen(); @@ -181,8 +181,8 @@ public void RoutesShouldSupportWildcardDomain() routeAddress.Address = "user@" + _domain.Name; routeAddress.Save(); - var smtpClient = new SMTPClientSimulator(); - Assert.IsTrue(smtpClient.Send("example@example.com", "user@stuff.example.com", "Test", "Test message")); + var smtpClient = new SmtpClientSimulator(); + smtpClient.Send("example@example.com", "user@stuff.example.com", "Test", "Test message"); CustomAsserts.AssertRecipientsInDeliveryQueue(0); server.WaitForCompletion(); @@ -207,10 +207,10 @@ public void RecipientNotInListShouldReturnError() route.AllAddresses = false; // only to recipients in list. route.Save(); - var smtpClient = new SMTPClientSimulator(); + var smtpClient = new SmtpClientSimulator(); - string resultMessage; - Assert.IsFalse(smtpClient.Send("example@example.com", "user1@test.com", "Test", "Test message", out resultMessage)); + string resultMessage = ""; + CustomAsserts.Throws(() => smtpClient.Send("example@example.com", "user1@test.com", "Test", "Test message", out resultMessage)); Assert.AreEqual("550 Recipient not in route list.", resultMessage); } @@ -222,18 +222,18 @@ public void ShouldBePossibleToSendToRouteWithTargetIPAddress() deliveryResults["test@dummy-example.com"] = 250; int smtpServerPort = TestSetup.GetNextFreePort(); - using (var server = new SMTPServerSimulator(1, smtpServerPort)) + using (var server = new SmtpServerSimulator(1, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.StartListen(); - Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, true, eConnectionSecurity.eCSNone); + Route route = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, true, eConnectionSecurity.eCSNone); route.TargetSMTPHost = "127.0.0.1"; route.Save(); - var smtpSimulator = new SMTPClientSimulator(); - Assert.IsTrue(smtpSimulator.Send("test@test.com", - "test@dummy-example.com", "Mail 1", "Test message")); + var smtpSimulator = new SmtpClientSimulator(); + smtpSimulator.Send("test@test.com", + "test@dummy-example.com", "Mail 1", "Test message"); // This should now be processed via the rule -> route -> external server we've set up. diff --git a/hmailserver/test/RegressionTests/SMTP/SMTPClientStartTLSTests.cs b/hmailserver/test/RegressionTests/SMTP/SMTPClientStartTLSTests.cs index f97b42e70..28809c7f5 100644 --- a/hmailserver/test/RegressionTests/SMTP/SMTPClientStartTLSTests.cs +++ b/hmailserver/test/RegressionTests/SMTP/SMTPClientStartTLSTests.cs @@ -28,17 +28,16 @@ public void UseStartTlsIfEnabledAndAvailable() deliveryResults["test@dummy-example.com"] = 250; int smtpServerPort = TestSetup.GetNextFreePort(); - using (var server = new SMTPServerSimulator(1, smtpServerPort, eConnectionSecurity.eCSSTARTTLSOptional)) + using (var server = new SmtpServerSimulator(1, smtpServerPort, eConnectionSecurity.eCSSTARTTLSOptional)) { server.AddRecipientResult(deliveryResults); server.StartListen(); - Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, false, eConnectionSecurity.eCSSTARTTLSOptional); + Route route = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false, eConnectionSecurity.eCSSTARTTLSOptional); // Send message to this route. - var smtp = new SMTPClientSimulator(); - if (!smtp.Send("test@test.com", "test@dummy-example.com", "Test", "Test message")) - Assert.Fail("Delivery failed"); + var smtp = new SmtpClientSimulator(); + smtp.Send("test@test.com", "test@dummy-example.com", "Test", "Test message"); // Wait for the client to disconnect. server.WaitForCompletion(); @@ -59,17 +58,16 @@ public void DoNotUseStartTlsIfEnabledButNotAvailable() deliveryResults["test@dummy-example.com"] = 250; int smtpServerPort = TestSetup.GetNextFreePort(); - using (var server = new SMTPServerSimulator(1, smtpServerPort, eConnectionSecurity.eCSNone)) + using (var server = new SmtpServerSimulator(1, smtpServerPort, eConnectionSecurity.eCSNone)) { server.AddRecipientResult(deliveryResults); server.StartListen(); - Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, false, eConnectionSecurity.eCSSTARTTLSOptional); + Route route = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false, eConnectionSecurity.eCSSTARTTLSOptional); // Send message to this route. - var smtp = new SMTPClientSimulator(); - if (!smtp.Send("test@test.com", "test@dummy-example.com", "Test", "Test message")) - Assert.Fail("Delivery failed"); + var smtp = new SmtpClientSimulator(); + smtp.Send("test@test.com", "test@dummy-example.com", "Test", "Test message"); // Wait for the client to disconnect. server.WaitForCompletion(); @@ -90,17 +88,17 @@ public void DoNotUseStartTlsIfNotEnabledButAvailable() deliveryResults["test@dummy-example.com"] = 250; int smtpServerPort = TestSetup.GetNextFreePort(); - using (var server = new SMTPServerSimulator(1, smtpServerPort, eConnectionSecurity.eCSSTARTTLSOptional)) + using (var server = new SmtpServerSimulator(1, smtpServerPort, eConnectionSecurity.eCSSTARTTLSOptional)) { server.AddRecipientResult(deliveryResults); server.StartListen(); - Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, false, eConnectionSecurity.eCSNone); + Route route = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false, eConnectionSecurity.eCSNone); // Send message to this route. - var smtp = new SMTPClientSimulator(); - if (!smtp.Send("test@test.com", "test@dummy-example.com", "Test", "Test message")) - Assert.Fail("Delivery failed"); + var smtp = new SmtpClientSimulator(); + smtp.Send("test@test.com", "test@dummy-example.com", "Test", "Test message"); + // Wait for the client to disconnect. server.WaitForCompletion(); @@ -121,17 +119,16 @@ public void DoNotUseStartTlsIfNotEnabledAndNotAvailable() deliveryResults["test@dummy-example.com"] = 250; int smtpServerPort = TestSetup.GetNextFreePort(); - using (var server = new SMTPServerSimulator(1, smtpServerPort, eConnectionSecurity.eCSNone)) + using (var server = new SmtpServerSimulator(1, smtpServerPort, eConnectionSecurity.eCSNone)) { server.AddRecipientResult(deliveryResults); server.StartListen(); - Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, false, eConnectionSecurity.eCSNone); + Route route = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false, eConnectionSecurity.eCSNone); // Send message to this route. - var smtp = new SMTPClientSimulator(); - if (!smtp.Send("test@test.com", "test@dummy-example.com", "Test", "Test message")) - Assert.Fail("Delivery failed"); + var smtp = new SmtpClientSimulator(); + smtp.Send("test@test.com", "test@dummy-example.com", "Test", "Test message"); // Wait for the client to disconnect. server.WaitForCompletion(); @@ -157,19 +154,18 @@ public void TestDelivertoServerNotSupportingEHLOOptionalConnectionSecurity() }; int smtpServerPort = TestSetup.GetNextFreePort(); - using (var server = new SMTPServerSimulator(1, smtpServerPort)) + using (var server = new SmtpServerSimulator(1, smtpServerPort)) { server.ServerSupportsEhlo = false; server.AddRecipientResult(deliveryResults); server.StartListen(); // Add a route so we can conenct to localhost. - SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, false, eConnectionSecurity.eCSSTARTTLSOptional); + TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false, eConnectionSecurity.eCSSTARTTLSOptional); // Send message to this route. - if (!SMTPClientSimulator.StaticSend("test@test.com", "user1@dummy-example.com", "Test", "Test message")) - Assert.Fail("Delivery failed"); + SmtpClientSimulator.StaticSend("test@test.com", "user1@dummy-example.com", "Test", "Test message"); // Wait for the client to disconnect. server.WaitForCompletion(); @@ -191,26 +187,25 @@ public void TestDeliverToServerNotSupportingEHLORequiredConnectionSecurity() }; int smtpServerPort = TestSetup.GetNextFreePort(); - using (var server = new SMTPServerSimulator(1, smtpServerPort)) + using (var server = new SmtpServerSimulator(1, smtpServerPort)) { server.ServerSupportsEhlo = false; server.AddRecipientResult(deliveryResults); server.StartListen(); // Add a route so we can conenct to localhost. - SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, false, eConnectionSecurity.eCSSTARTTLSRequired); + TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false, eConnectionSecurity.eCSSTARTTLSRequired); // Send message to this route. - if (!SMTPClientSimulator.StaticSend("test@test.com", "user1@dummy-example.com", "Test", "Test message")) - Assert.Fail("Delivery failed"); + SmtpClientSimulator.StaticSend("test@test.com", "user1@dummy-example.com", "Test", "Test message"); // Wait for the client to disconnect. server.WaitForCompletion(); CustomAsserts.AssertRecipientsInDeliveryQueue(0, true); - var msg = POP3ClientSimulator.AssertGetFirstMessageText("test@test.com", "test"); + var msg = Pop3ClientSimulator.AssertGetFirstMessageText("test@test.com", "test"); Assert.IsTrue(msg.Contains("Server does not support EHLO command.")); } } diff --git a/hmailserver/test/RegressionTests/SMTP/SMTPClientTests.cs b/hmailserver/test/RegressionTests/SMTP/SMTPClientTests.cs index 7fccc14b8..c0c4df26e 100644 --- a/hmailserver/test/RegressionTests/SMTP/SMTPClientTests.cs +++ b/hmailserver/test/RegressionTests/SMTP/SMTPClientTests.cs @@ -30,44 +30,6 @@ public class SMTPClientTests : TestFixtureBase private Status _status; private Account _account; - internal static Route AddRoutePointingAtLocalhost(int numberOfTries, int port, bool treatSecurityAsLocal, eConnectionSecurity connectionSecurity) - { - // Add a route pointing at localhost - Settings oSettings = SingletonProvider.Instance.GetApp().Settings; - - Route route = oSettings.Routes.Add(); - route.DomainName = "dummy-example.com"; - route.TargetSMTPHost = "localhost"; - route.TargetSMTPPort = port; - route.NumberOfTries = numberOfTries; - route.MinutesBetweenTry = 5; - route.TreatRecipientAsLocalDomain = treatSecurityAsLocal; - route.TreatSenderAsLocalDomain = treatSecurityAsLocal; - route.ConnectionSecurity = connectionSecurity; - route.Save(); - - return route; - } - - internal static Route AddRoutePointingAtLocalhost(int numberOfTries, int port, bool treatSecurityAsLocal) - { - return AddRoutePointingAtLocalhost(numberOfTries, port, treatSecurityAsLocal, eConnectionSecurity.eCSNone); - } - - public static Route AddRoutePointingAtLocalhostMultipleHosts(int numberOfTries, int port) - { - // Add a route pointing at localhost - Route route = AddRoutePointingAtLocalhost(numberOfTries, port, false); - route.DomainName = "dummy-example.com"; - route.TargetSMTPHost = "localhost|localhost"; - route.TargetSMTPPort = port; - route.NumberOfTries = numberOfTries; - route.MinutesBetweenTry = 5; - route.Save(); - - return route; - } - [Test] [Description("Make sure that the bounce message doesn't include a SMTP auth password")] public void TestAuthFailurePasswordInBounce() @@ -79,30 +41,30 @@ public void TestAuthFailurePasswordInBounce() deliveryResults["test@dummy-example.com"] = 250; int smtpServerPort = TestSetup.GetNextFreePort(); - using (var server = new SMTPServerSimulator(1, smtpServerPort)) + using (var server = new SmtpServerSimulator(1, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.SimulatedError = SimulatedErrorType.ForceAuthenticationFailure; server.StartListen(); // Add a route so we can connect to localhost. - Route route = AddRoutePointingAtLocalhost(5, smtpServerPort, false); + Route route = TestSetup.AddRoutePointingAtLocalhost(5, smtpServerPort, false); route.RelayerRequiresAuth = true; route.RelayerAuthUsername = "user@example.com"; route.SetRelayerAuthPassword("MySecretPassword"); // Send message to this route. - var smtp = new SMTPClientSimulator(); + var smtp = new SmtpClientSimulator(); var recipients = new List(); recipients.Add("test@dummy-example.com"); - Assert.IsTrue(smtp.Send("test@test.com", recipients, "Test", "Test message")); + smtp.Send("test@test.com", recipients, "Test", "Test message"); // Wait for the client to disconnect. server.WaitForCompletion(); CustomAsserts.AssertRecipientsInDeliveryQueue(0); - string messageText = POP3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); + string messageText = Pop3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); Assert.IsFalse(messageText.Contains("MySecretPassword")); Assert.IsTrue(messageText.Contains("")); @@ -118,10 +80,10 @@ public void TestDeliverToMyselfOnLocalPort() Assert.AreEqual(0, _status.UndeliveredMessages.Length); // Add a route so we can conenct to localhost. - AddRoutePointingAtLocalhost(1, 25, false); + TestSetup.AddRoutePointingAtLocalhost(1, 25, false); // Send message to this route. - SMTPClientSimulator.StaticSend("test@test.com", "test@dummy-example.com", "subject", "body"); + SmtpClientSimulator.StaticSend("test@test.com", "test@dummy-example.com", "subject", "body"); for (int i = 0; i < 40; i++) { @@ -135,7 +97,7 @@ public void TestDeliverToMyselfOnLocalPort() // Wait for the bounce message to be delivered. CustomAsserts.AssertRecipientsInDeliveryQueue(0, true); - string message = POP3ClientSimulator.AssertGetFirstMessageText("test@test.com", "test"); + string message = Pop3ClientSimulator.AssertGetFirstMessageText("test@test.com", "test"); Assert.IsTrue(message.Contains("this would mean connecting to myself.")); } @@ -165,16 +127,16 @@ public void TestDeliverToMyselfOnLocalPortAfterChangedLocalPort() deliveryResults["user@dummy-example.com"] = 250; int smtpServerPort = TestSetup.GetNextFreePort(); - using (var server = new SMTPServerSimulator(1, smtpServerPort)) + using (var server = new SmtpServerSimulator(1, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.StartListen(); // Add a route so we can connect to localhost. - AddRoutePointingAtLocalhost(5, smtpServerPort, false); + TestSetup.AddRoutePointingAtLocalhost(5, smtpServerPort, false); // Send message to this route. - var sim = new SMTPClientSimulator(false, 11000); + var sim = new SmtpClientSimulator(false, 11000); sim.Send("test@test.com", "user@dummy-example.com", "Test", "Test message"); @@ -202,7 +164,7 @@ public void TestDeliverySuccess250Recipients() deliveryResults["user" + i.ToString() + "@dummy-example.com"] = 250; int smtpServerPort = TestSetup.GetNextFreePort(); - using (var server = new SMTPServerSimulator(3, smtpServerPort)) + using (var server = new SmtpServerSimulator(3, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.AddRecipientResult(deliveryResults); @@ -210,16 +172,16 @@ public void TestDeliverySuccess250Recipients() server.StartListen(); // Add a route so we can connect to localhost. - AddRoutePointingAtLocalhost(5, smtpServerPort, false); + TestSetup.AddRoutePointingAtLocalhost(5, smtpServerPort, false); // Send message to this route. - var smtp = new SMTPClientSimulator(); + var smtp = new SmtpClientSimulator(); var recipients = new List(); for (int i = 0; i < 250; i++) recipients.Add("user" + i.ToString() + "@dummy-example.com"); - Assert.IsTrue(smtp.Send("test@test.com", recipients, "Test", "Test message")); + smtp.Send("test@test.com", recipients, "Test", "Test message"); // Wait for the client to disconnect. server.WaitForCompletion(); @@ -242,23 +204,22 @@ public void TestDeliverySuccess50Recipients() deliveryResults["user" + i.ToString() + "@dummy-example.com"] = 250; int smtpServerPort = TestSetup.GetNextFreePort(); - using (var server = new SMTPServerSimulator(1, smtpServerPort)) + using (var server = new SmtpServerSimulator(1, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.StartListen(); // Add a route so we can conenct to localhost. - AddRoutePointingAtLocalhost(5, smtpServerPort, false); + TestSetup.AddRoutePointingAtLocalhost(5, smtpServerPort, false); // Send message to this route. - var smtp = new SMTPClientSimulator(); + var smtp = new SmtpClientSimulator(); var recipients = new List(); for (int i = 0; i < 50; i++) recipients.Add("user" + i.ToString() + "@dummy-example.com"); - if (!smtp.Send("test@test.com", recipients, "Test", "Test message")) - Assert.Fail("Delivery failed"); + smtp.Send("test@test.com", recipients, "Test", "Test message"); // Wait for the client to disconnect. server.WaitForCompletion(); @@ -283,20 +244,20 @@ public void TestDeliverySuccessDisconnectAfterMessageAccept() deliveryResults["test@dummy-example.com"] = 250; int smtpServerPort = TestSetup.GetNextFreePort(); - using (var server = new SMTPServerSimulator(1, smtpServerPort)) + using (var server = new SmtpServerSimulator(1, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.StartListen(); server.SimulatedError = SimulatedErrorType.DisconnectAfterMessageAccept; // Add a route so we can connect to localhost. - AddRoutePointingAtLocalhost(5, smtpServerPort, false); + TestSetup.AddRoutePointingAtLocalhost(5, smtpServerPort, false); // Send message to this route. - var smtp = new SMTPClientSimulator(); + var smtp = new SmtpClientSimulator(); var recipients = new List(); recipients.Add("test@dummy-example.com"); - Assert.IsTrue(smtp.Send("test@test.com", recipients, "Test", "DisconnectAfterAcceptBeforeQuit")); + smtp.Send("test@test.com", recipients, "Test", "DisconnectAfterAcceptBeforeQuit"); // Wait for the client to disconnect. server.WaitForCompletion(); @@ -317,19 +278,19 @@ public void TestDeliverySuccessSingleRecipient() deliveryResults["test@dummy-example.com"] = 250; int smtpServerPort = TestSetup.GetNextFreePort(); - using (var server = new SMTPServerSimulator(1, smtpServerPort)) + using (var server = new SmtpServerSimulator(1, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.StartListen(); // Add a route so we can connect to localhost. - AddRoutePointingAtLocalhost(5, smtpServerPort, false); + TestSetup.AddRoutePointingAtLocalhost(5, smtpServerPort, false); // Send message to this route. - var smtp = new SMTPClientSimulator(); + var smtp = new SmtpClientSimulator(); var recipients = new List(); recipients.Add("test@dummy-example.com"); - Assert.IsTrue(smtp.Send("test@test.com", recipients, "Test", "Test message")); + smtp.Send("test@test.com", recipients, "Test", "Test message"); // Wait for the client to disconnect. server.WaitForCompletion(); @@ -352,21 +313,21 @@ public void TestLargeMessageSuccess() deliveryResults["test@dummy-example.com"] = 250; int smtpServerPort = TestSetup.GetNextFreePort(); - using (var server = new SMTPServerSimulator(1, smtpServerPort)) + using (var server = new SmtpServerSimulator(1, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.StartListen(); // Add a route so we can connect to localhost. - AddRoutePointingAtLocalhost(5, smtpServerPort, false); + TestSetup.AddRoutePointingAtLocalhost(5, smtpServerPort, false); // Send message to this route. var messageBody = TestSetup.CreateLargeDummyMailBody(); - var smtp = new SMTPClientSimulator(); + var smtp = new SmtpClientSimulator(); var recipients = new List(); recipients.Add("test@dummy-example.com"); - Assert.IsTrue(smtp.Send("test@test.com", recipients, "Test", messageBody)); + smtp.Send("test@test.com", recipients, "Test", messageBody); // Wait for the client to disconnect. server.WaitForCompletion(); @@ -390,20 +351,20 @@ public void TestDeliverySuccessSingleRecipientMissingQuitResponse() deliveryResults["test@dummy-example.com"] = 250; int smtpServerPort = TestSetup.GetNextFreePort(); - using (var server = new SMTPServerSimulator(1, smtpServerPort)) + using (var server = new SmtpServerSimulator(1, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.StartListen(); server.SimulatedError = SimulatedErrorType.DisconnectWithoutReplyOnQuit; // Add a route so we can connect to localhost. - AddRoutePointingAtLocalhost(5, smtpServerPort, false); + TestSetup.AddRoutePointingAtLocalhost(5, smtpServerPort, false); // Send message to this route. - var smtp = new SMTPClientSimulator(); + var smtp = new SmtpClientSimulator(); var recipients = new List(); recipients.Add("test@dummy-example.com"); - Assert.IsTrue(smtp.Send("test@test.com", recipients, "Test", "DeliverySuccessNoQuitResponse")); + smtp.Send("test@test.com", recipients, "Test", "DeliverySuccessNoQuitResponse"); // Wait for the client to disconnect. server.WaitForCompletion(); @@ -425,27 +386,27 @@ public void TestErrorOnMailFrom() deliveryResults["test@dummy-example.com"] = 250; int smtpServerPort = TestSetup.GetNextFreePort(); - using (var server = new SMTPServerSimulator(1, smtpServerPort)) + using (var server = new SmtpServerSimulator(1, smtpServerPort)) { server.MailFromResult = 561; server.AddRecipientResult(deliveryResults); server.StartListen(); // Add a route so we can conenct to localhost. - AddRoutePointingAtLocalhost(5, smtpServerPort, false); + TestSetup.AddRoutePointingAtLocalhost(5, smtpServerPort, false); // Send message to this route. - var smtp = new SMTPClientSimulator(); + var smtp = new SmtpClientSimulator(); var recipients = new List(); recipients.Add("test@dummy-example.com"); - Assert.IsTrue(smtp.Send("test@test.com", recipients, "Test", "Test message")); + smtp.Send("test@test.com", recipients, "Test", "Test message"); // Wait for the client to disconnect. server.WaitForCompletion(); CustomAsserts.AssertRecipientsInDeliveryQueue(0); - string bounceMessage = POP3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); + string bounceMessage = Pop3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); Assert.IsTrue(bounceMessage.Contains("MAIL FROM:")); Assert.IsTrue(bounceMessage.Contains("Remote server replied: 561")); @@ -465,20 +426,20 @@ public void TestFailureAfterConnect() deliveryResults["test@dummy-example.com"] = 250; int smtpServerPort = TestSetup.GetNextFreePort(); - using (var server = new SMTPServerSimulator(1, smtpServerPort)) + using (var server = new SmtpServerSimulator(1, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.SimulatedError = SimulatedErrorType.DisconnectAfterSessionStart; server.StartListen(); // Add a route so we can connect to localhost. - AddRoutePointingAtLocalhost(1, smtpServerPort, false); + TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false); // Send message to this route. - var smtp = new SMTPClientSimulator(); + var smtp = new SmtpClientSimulator(); var recipients = new List(); recipients.Add("test@dummy-example.com"); - Assert.IsTrue(smtp.Send(_account.Address, recipients, "Test", "Test message")); + smtp.Send(_account.Address, recipients, "Test", "Test message"); // Wait for the client to disconnect. server.WaitForCompletion(); @@ -486,7 +447,7 @@ public void TestFailureAfterConnect() // Force the message to be bounced. CustomAsserts.AssertRecipientsInDeliveryQueue(0, true); - string bounce = POP3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); + string bounce = Pop3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); Assert.IsTrue(bounce.Contains("test@dummy-example.com")); Assert.IsTrue(bounce.Contains("Remote server closed connection.")); @@ -508,20 +469,20 @@ public void TestFailureAfterDelivery() deliveryResults["test@dummy-example.com"] = 250; int smtpServerPort = TestSetup.GetNextFreePort(); - using (var server = new SMTPServerSimulator(1, smtpServerPort)) + using (var server = new SmtpServerSimulator(1, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.QuitResult = 421; server.StartListen(); // Add a route so we can connect to localhost. - AddRoutePointingAtLocalhost(5, smtpServerPort, false); + TestSetup.AddRoutePointingAtLocalhost(5, smtpServerPort, false); // Send message to this route. - var smtp = new SMTPClientSimulator(); + var smtp = new SmtpClientSimulator(); var recipients = new List(); recipients.Add("test@dummy-example.com"); - Assert.IsTrue(smtp.Send("test@test.com", recipients, "Test", "test of error after accepted delivery")); + smtp.Send("test@test.com", recipients, "Test", "test of error after accepted delivery"); // Wait for the client to disconnect. server.WaitForCompletion(); @@ -545,20 +506,20 @@ public void TestFailureAfterDeliveryStarted() deliveryResults["test@dummy-example.com"] = 250; int smtpServerPort = TestSetup.GetNextFreePort(); - using (var server = new SMTPServerSimulator(1, smtpServerPort)) + using (var server = new SmtpServerSimulator(1, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.SimulatedError = SimulatedErrorType.DisconnectAfterDeliveryStarted; server.StartListen(); // Add a route so we can connect to localhost. - AddRoutePointingAtLocalhost(1, smtpServerPort, false); + TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false); // Send message to this route. - var smtp = new SMTPClientSimulator(); + var smtp = new SmtpClientSimulator(); var recipients = new List(); recipients.Add("test@dummy-example.com"); - Assert.IsTrue(smtp.Send(_account.Address, recipients, "Test", "Test message")); + smtp.Send(_account.Address, recipients, "Test", "Test message"); // Wait for the client to disconnect. server.WaitForCompletion(); @@ -566,7 +527,7 @@ public void TestFailureAfterDeliveryStarted() // Force the message to be bounced. CustomAsserts.AssertRecipientsInDeliveryQueue(0, true); - string bounce = POP3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); + string bounce = Pop3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); Assert.IsTrue(bounce.Contains("test@dummy-example.com")); Assert.IsTrue(bounce.Contains("Remote server closed connection.")); @@ -587,20 +548,20 @@ public void TestFailureAfterReceivedHelloBanner() deliveryResults["test@dummy-example.com"] = 250; int smtpServerPort = TestSetup.GetNextFreePort(); - using (var server = new SMTPServerSimulator(1, smtpServerPort)) + using (var server = new SmtpServerSimulator(1, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.SimulatedError = SimulatedErrorType.DisconnectAfterSessionStart; server.StartListen(); // Add a route so we can connect to localhost. - AddRoutePointingAtLocalhost(1, smtpServerPort, false); + TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false); // Send message to this route. - var smtp = new SMTPClientSimulator(); + var smtp = new SmtpClientSimulator(); var recipients = new List(); recipients.Add("test@dummy-example.com"); - Assert.IsTrue(smtp.Send(_account.Address, recipients, "Test", "Test message")); + smtp.Send(_account.Address, recipients, "Test", "Test message"); // Wait for the client to disconnect. server.WaitForCompletion(); @@ -608,7 +569,7 @@ public void TestFailureAfterReceivedHelloBanner() // Force the message to be bounced. CustomAsserts.AssertRecipientsInDeliveryQueue(0, true); - string bounce = POP3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); + string bounce = Pop3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); Assert.IsTrue(bounce.Contains("test@dummy-example.com")); Assert.IsTrue(bounce.Contains("Remote server closed connection.")); @@ -631,19 +592,19 @@ public void TestFatalDeliveryFailure() deliveryResults["test@dummy-example.com"] = 550; int smtpServerPort = TestSetup.GetNextFreePort(); - using (var server = new SMTPServerSimulator(1, smtpServerPort)) + using (var server = new SmtpServerSimulator(1, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.StartListen(); // Add a route so we can conenct to localhost. - AddRoutePointingAtLocalhost(0, smtpServerPort, false); + TestSetup.AddRoutePointingAtLocalhost(0, smtpServerPort, false); // Send message to this route. - var smtp = new SMTPClientSimulator(); + var smtp = new SmtpClientSimulator(); var recipients = new List(); recipients.Add("test@dummy-example.com"); - Assert.IsTrue(smtp.Send("test@test.com", recipients, "Test", "Test message")); + smtp.Send("test@test.com", recipients, "Test", "Test message"); string undeliveredMessages = _status.UndeliveredMessages; @@ -663,7 +624,7 @@ public void TestFatalDeliveryFailure() CustomAsserts.AssertRecipientsInDeliveryQueue(0, true); - string bounceMessage = POP3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); + string bounceMessage = Pop3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); Assert.IsTrue(bounceMessage.Contains("Remote server (127.0.0.1) issued an error.")); Assert.IsTrue(bounceMessage.Contains("550 test@dummy-example.com")); @@ -691,7 +652,7 @@ public void TestMultipleHostsHalfDeliveryOnFirstPermanentOnSecond() deliveryResultsSecond["user3@dummy-example.com"] = 500; int smtpServerPort = TestSetup.GetNextFreePort(); - using (var server = new SMTPServerSimulator(2, smtpServerPort)) + using (var server = new SmtpServerSimulator(2, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.AddRecipientResult(deliveryResultsSecond); @@ -699,17 +660,17 @@ public void TestMultipleHostsHalfDeliveryOnFirstPermanentOnSecond() // Add a route so we can connect to localhost. - AddRoutePointingAtLocalhostMultipleHosts(1, smtpServerPort); + TestSetup.AddRoutePointingAtLocalhostMultipleHosts(1, smtpServerPort); // Send message to this route. - var smtp = new SMTPClientSimulator(); + var smtp = new SmtpClientSimulator(); var recipients = new List(); recipients.Add("user1@dummy-example.com"); recipients.Add("user2@dummy-example.com"); recipients.Add("user3@dummy-example.com"); - Assert.IsTrue(smtp.Send("test@test.com", recipients, "Test", "Accepted message")); + smtp.Send("test@test.com", recipients, "Test", "Accepted message"); // Wait for the client to disconnect. server.WaitForCompletion(); @@ -717,7 +678,7 @@ public void TestMultipleHostsHalfDeliveryOnFirstPermanentOnSecond() // Trigger a sending of the bounce message. CustomAsserts.AssertRecipientsInDeliveryQueue(0, true); - string bounceMessage = POP3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); + string bounceMessage = Pop3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); Assert.IsFalse(bounceMessage.Contains("RCPT TO:")); Assert.IsFalse(bounceMessage.Contains("RCPT TO:")); @@ -738,25 +699,25 @@ public void TestMultipleHostsTemporaryFailure() deliveryResults["user3@dummy-example.com"] = 499; int smtpServerPort = TestSetup.GetNextFreePort(); - using (var server = new SMTPServerSimulator(2, smtpServerPort)) + using (var server = new SmtpServerSimulator(2, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.AddRecipientResult(deliveryResults); server.StartListen(); // Add a route so we can connect to localhost. - Route route = AddRoutePointingAtLocalhostMultipleHosts(2, smtpServerPort); + Route route = TestSetup.AddRoutePointingAtLocalhostMultipleHosts(2, smtpServerPort); // Send message to this route. - var smtp = new SMTPClientSimulator(); + var smtp = new SmtpClientSimulator(); var recipients = new List(); recipients.Add("user1@dummy-example.com"); recipients.Add("user2@dummy-example.com"); recipients.Add("user3@dummy-example.com"); - if (!smtp.Send("test@test.com", recipients, "Test", "Test message")) - Assert.Fail("Delivery failed"); + smtp.Send("test@test.com", recipients, "Test", "Test message"); + // Wait for the client to disconnect. server.WaitForCompletion(); @@ -770,7 +731,7 @@ public void TestMultipleHostsTemporaryFailure() Assert.AreEqual(-1, _status.UndeliveredMessages.IndexOf("user2@dummy-example.com")); Assert.AreNotEqual(-1, _status.UndeliveredMessages.IndexOf("user3@dummy-example.com")); - using (var server = new SMTPServerSimulator(2, smtpServerPort)) + using (var server = new SmtpServerSimulator(2, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.AddRecipientResult(deliveryResults); @@ -780,7 +741,7 @@ public void TestMultipleHostsTemporaryFailure() server.WaitForCompletion(); - string bounceMessage = POP3ClientSimulator.AssertGetFirstMessageText("test@test.com", "test"); + string bounceMessage = Pop3ClientSimulator.AssertGetFirstMessageText("test@test.com", "test"); Assert.IsFalse(bounceMessage.Contains("user1@dummy-example.com")); Assert.IsFalse(bounceMessage.Contains("user2@dummy-example.com")); @@ -807,7 +768,7 @@ public void TestMultipleHostsTemporaryFailureDeliveryOnSecondServer() deliveryResultsSecond["user3@dummy-example.com"] = 250; int smtpServerPort = TestSetup.GetNextFreePort(); - using (var server = new SMTPServerSimulator(2, smtpServerPort)) + using (var server = new SmtpServerSimulator(2, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.AddRecipientResult(deliveryResultsSecond); @@ -815,18 +776,19 @@ public void TestMultipleHostsTemporaryFailureDeliveryOnSecondServer() // Add a route so we can connect to localhost. - AddRoutePointingAtLocalhostMultipleHosts(2, smtpServerPort); + TestSetup.AddRoutePointingAtLocalhostMultipleHosts(2, smtpServerPort); // Send message to this route. - var smtp = new SMTPClientSimulator(); + var smtp = new SmtpClientSimulator(); var recipients = new List(); recipients.Add("user1@dummy-example.com"); recipients.Add("user2@dummy-example.com"); recipients.Add("user3@dummy-example.com"); - if (!smtp.Send("test@test.com", recipients, "Test", "Accepted message")) - Assert.Fail("Delivery failed"); + smtp.Send("test@test.com", recipients, "Test", "Accepted message"); + + // Wait for the client to disconnect. server.WaitForCompletion(); @@ -850,24 +812,23 @@ public void TestPartialTemporaryErrorFailure() deliveryResults["user3@dummy-example.com"] = 400; int smtpServerPort = TestSetup.GetNextFreePort(); - using (var server = new SMTPServerSimulator(1, smtpServerPort)) + using (var server = new SmtpServerSimulator(1, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.StartListen(); // Add a route so we can connect to localhost. - AddRoutePointingAtLocalhost(2, smtpServerPort, false); + TestSetup.AddRoutePointingAtLocalhost(2, smtpServerPort, false); // Send message to this route. - var smtp = new SMTPClientSimulator(); + var smtp = new SmtpClientSimulator(); var recipients = new List(); recipients.Add("user1@dummy-example.com"); recipients.Add("user2@dummy-example.com"); recipients.Add("user3@dummy-example.com"); - if (!smtp.Send("test@test.com", recipients, "Test", "Test message")) - Assert.Fail("Delivery failed"); + smtp.Send("test@test.com", recipients, "Test", "Test message"); // Wait for the client to disconnect. server.WaitForCompletion(); @@ -883,7 +844,7 @@ public void TestPartialTemporaryErrorFailure() } // Attempt to deliver the message again. - using (var server = new SMTPServerSimulator(1, smtpServerPort)) + using (var server = new SmtpServerSimulator(1, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.StartListen(); @@ -892,7 +853,7 @@ public void TestPartialTemporaryErrorFailure() // CustomAsserts.AssertRecipientsInDeliveryQueue(0); - string bounceMessage = POP3ClientSimulator.AssertGetFirstMessageText("test@test.com", "test"); + string bounceMessage = Pop3ClientSimulator.AssertGetFirstMessageText("test@test.com", "test"); Assert.IsTrue(bounceMessage.Contains("400 user3@dummy-example.com")); Assert.IsTrue(bounceMessage.Contains("Tried 2 time(s)")); @@ -911,19 +872,19 @@ public void TestPermanentFailure() deliveryResults["test@dummy-example.com"] = 542; int smtpServerPort = TestSetup.GetNextFreePort(); - using (var server = new SMTPServerSimulator(1, smtpServerPort)) + using (var server = new SmtpServerSimulator(1, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.StartListen(); // Add a route so we can connect to localhost. - AddRoutePointingAtLocalhost(5, smtpServerPort, false); + TestSetup.AddRoutePointingAtLocalhost(5, smtpServerPort, false); // Send message to this route. - var smtp = new SMTPClientSimulator(); + var smtp = new SmtpClientSimulator(); var recipients = new List(); recipients.Add("test@dummy-example.com"); - Assert.IsTrue(smtp.Send("test@test.com", recipients, "Test", "Test message")); + smtp.Send("test@test.com", recipients, "Test", "Test message"); // Wait for the client to disconnect. server.WaitForCompletion(); @@ -933,7 +894,7 @@ public void TestPermanentFailure() CustomAsserts.AssertRecipientsInDeliveryQueue(0); - string bounce = POP3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); + string bounce = Pop3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); Assert.IsTrue(bounce.Contains("Remote server replied: 542 test@dummy-example.com")); } @@ -950,7 +911,7 @@ public void TestSMTPClientTimeout() deliveryResults["test@dummy-example.com"] = 250; int smtpServerPort = TestSetup.GetNextFreePort(); - using (var server = new SMTPServerSimulator(1, smtpServerPort)) + using (var server = new SmtpServerSimulator(1, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.SimulatedError = SimulatedErrorType.Sleep15MinutesAfterSessionStart; @@ -958,16 +919,16 @@ public void TestSMTPClientTimeout() server.StartListen(); // Add a route so we can connect to localhost. - Route route = AddRoutePointingAtLocalhost(5, smtpServerPort, false); + Route route = TestSetup.AddRoutePointingAtLocalhost(5, smtpServerPort, false); route.RelayerRequiresAuth = true; route.RelayerAuthUsername = "user@example.com"; route.SetRelayerAuthPassword("MySecretPassword"); // Send message to this route. - var smtp = new SMTPClientSimulator(); + var smtp = new SmtpClientSimulator(); var recipients = new List(); recipients.Add("test@dummy-example.com"); - Assert.IsTrue(smtp.Send("test@test.com", recipients, "Test", "Test message")); + smtp.Send("test@test.com", recipients, "Test", "Test message"); // Wait for the client to disconnect. server.WaitForCompletion(); @@ -985,19 +946,19 @@ public void TestTemporaryFailure() deliveryResults["test@dummy-example.com"] = 452; int smtpServerPort = TestSetup.GetNextFreePort(); - using (var server = new SMTPServerSimulator(1, smtpServerPort)) + using (var server = new SmtpServerSimulator(1, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.StartListen(); // Add a route so we can connect to localhost. - AddRoutePointingAtLocalhost(2, smtpServerPort, false); + TestSetup.AddRoutePointingAtLocalhost(2, smtpServerPort, false); // Send message to this route. - var smtp = new SMTPClientSimulator(); + var smtp = new SmtpClientSimulator(); var recipients = new List(); recipients.Add("test@dummy-example.com"); - Assert.IsTrue(smtp.Send("test@test.com", recipients, "Test", "Test message")); + smtp.Send("test@test.com", recipients, "Test", "Test message"); // Wait for the client to disconnect. server.WaitForCompletion(); @@ -1005,7 +966,7 @@ public void TestTemporaryFailure() Assert.AreNotEqual(0, _status.UndeliveredMessages.Length); } - using (var server = new SMTPServerSimulator(1, smtpServerPort))// Start to listen again. + using (var server = new SmtpServerSimulator(1, smtpServerPort))// Start to listen again. { server.AddRecipientResult(deliveryResults); server.StartListen(); @@ -1020,7 +981,7 @@ public void TestTemporaryFailure() } // Now the message has bounced. - string message = POP3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); + string message = Pop3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); Assert.IsTrue(message.Contains("452 test@dummy-example.com")); Assert.IsTrue(message.Contains("Tried 2 time(s)")); @@ -1037,19 +998,17 @@ public void TestDeliverToServerNotSupportingEHLO() }; int smtpServerPort = TestSetup.GetNextFreePort(); - using (var server = new SMTPServerSimulator(1, smtpServerPort)) + using (var server = new SmtpServerSimulator(1, smtpServerPort)) { server.ServerSupportsEhlo = false; server.AddRecipientResult(deliveryResults); server.StartListen(); // Add a route so we can conenct to localhost. - SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, false, eConnectionSecurity.eCSNone); + TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false, eConnectionSecurity.eCSNone); - // Send message to this route. - - if (!SMTPClientSimulator.StaticSend("test@test.com", "user1@dummy-example.com", "Test", "Test message")) - Assert.Fail("Delivery failed"); + + SmtpClientSimulator.StaticSend("test@test.com", "user1@dummy-example.com", "Test", "Test message"); // Wait for the client to disconnect. server.WaitForCompletion(); @@ -1071,26 +1030,26 @@ public void TestDeliverToServerNotSupportingHELO() }; int smtpServerPort = TestSetup.GetNextFreePort(); - using (var server = new SMTPServerSimulator(1, smtpServerPort)) + using (var server = new SmtpServerSimulator(1, smtpServerPort)) { server.ServerSupportsHelo = false; server.AddRecipientResult(deliveryResults); server.StartListen(); // Add a route so we can conenct to localhost. - SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, false, eConnectionSecurity.eCSNone); + TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false, eConnectionSecurity.eCSNone); // Send message to this route. - if (!SMTPClientSimulator.StaticSend("test@test.com", "user1@dummy-example.com", "Test", "Test message")) - Assert.Fail("Delivery failed"); + SmtpClientSimulator.StaticSend("test@test.com", "user1@dummy-example.com", "Test", "Test message"); + // Wait for the client to disconnect. server.WaitForCompletion(); CustomAsserts.AssertRecipientsInDeliveryQueue(0, true); - var msg = POP3ClientSimulator.AssertGetFirstMessageText("test@test.com", "test"); + var msg = Pop3ClientSimulator.AssertGetFirstMessageText("test@test.com", "test"); Assert.IsTrue(msg.Contains("Remote server replied: 550 Command HELO not recognized.")); } } diff --git a/hmailserver/test/RegressionTests/SMTP/Signatures.cs b/hmailserver/test/RegressionTests/SMTP/Signatures.cs index f01e120af..992553a10 100644 --- a/hmailserver/test/RegressionTests/SMTP/Signatures.cs +++ b/hmailserver/test/RegressionTests/SMTP/Signatures.cs @@ -33,10 +33,10 @@ public void TestAccountSignatureMacro() _account.SignaturePlainText = "Regards %User.FirstName% %User.Lastname%"; _account.Save(); - SMTPClientSimulator.StaticSend(_account.Address, _account.Address, "Test of signature, 2", + SmtpClientSimulator.StaticSend(_account.Address, _account.Address, "Test of signature, 2", "Test of signature - Body"); - string sMessageData = POP3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); + string sMessageData = Pop3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); Assert.IsTrue(sMessageData.Contains("Regards Martin Knafve")); } @@ -47,7 +47,7 @@ public void TestAccountSignatureMacro() [Test] public void TestDomainSignature() { - var oPOP3 = new POP3ClientSimulator(); + var pop3ClientSimulator = new Pop3ClientSimulator(); _domain.SignatureEnabled = true; _domain.AddSignaturesToLocalMail = true; @@ -59,10 +59,10 @@ public void TestDomainSignature() oAccount1.Save(); - var oSMTP = new SMTPClientSimulator(); - oSMTP.Send(oAccount1.Address, oAccount1.Address, "Test of signature, 1", "Test of signature - Body"); + var smtpClientSimulator = new SmtpClientSimulator(); + smtpClientSimulator.Send(oAccount1.Address, oAccount1.Address, "Test of signature, 1", "Test of signature - Body"); - string sMessageContents = POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); + string sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); if (sMessageContents.IndexOf("PlainTextSignature") <= 0) throw new Exception("Did not find signature"); @@ -71,9 +71,9 @@ public void TestDomainSignature() _domain.SignaturePlainText = "DomainSignature"; _domain.SignatureMethod = eDomainSignatureMethod.eSMAppendToAccountSignature; _domain.Save(); - oSMTP.Send(oAccount1.Address, oAccount1.Address, "Test of signature, 1", "Test of signature - Body"); + smtpClientSimulator.Send(oAccount1.Address, oAccount1.Address, "Test of signature, 1", "Test of signature - Body"); - sMessageContents = POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); + sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); if (sMessageContents.IndexOf("PlainTextSignature") <= 0 || sMessageContents.IndexOf("DomainSignature") <= 0) throw new Exception("Did not find signature"); @@ -83,9 +83,9 @@ public void TestDomainSignature() _domain.SignaturePlainText = "DomainSignature"; _domain.SignatureMethod = eDomainSignatureMethod.eSMOverwriteAccountSignature; _domain.Save(); - oSMTP.Send(oAccount1.Address, oAccount1.Address, "Test of signature, 1", "Test of signature - Body"); + smtpClientSimulator.Send(oAccount1.Address, oAccount1.Address, "Test of signature, 1", "Test of signature - Body"); - sMessageContents = POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); + sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); if (sMessageContents.IndexOf("PlainTextSignature") >= 0 || sMessageContents.IndexOf("DomainSignature") <= 0) throw new Exception("Did not find signature"); @@ -95,9 +95,9 @@ public void TestDomainSignature() _domain.SignaturePlainText = "DomainSignature"; _domain.SignatureMethod = eDomainSignatureMethod.eSMSetIfNotSpecifiedInAccount; _domain.Save(); - oSMTP.Send(oAccount1.Address, oAccount1.Address, "Test of signature, 1", "Test of signature - Body"); + smtpClientSimulator.Send(oAccount1.Address, oAccount1.Address, "Test of signature, 1", "Test of signature - Body"); - sMessageContents = POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); + sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); if (sMessageContents.IndexOf("DomainSignature") >= 0) throw new Exception("Found incorrect signature."); @@ -109,9 +109,9 @@ public void TestDomainSignature() oAccount1.SignaturePlainText = ""; oAccount1.Save(); - oSMTP.Send(oAccount1.Address, oAccount1.Address, "Test of signature, 1", "Test of signature - Body"); + smtpClientSimulator.Send(oAccount1.Address, oAccount1.Address, "Test of signature, 1", "Test of signature - Body"); - sMessageContents = POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); + sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); if (sMessageContents.IndexOf("DomainSignature") <= 0) throw new Exception("Found incorrect signature."); @@ -120,18 +120,18 @@ public void TestDomainSignature() _domain.Save(); oAccount1.SignaturePlainText = "PlainTextSignature"; oAccount1.Save(); - oSMTP.Send(oAccount1.Address, oAccount1.Address, "Test of signature, 1", "Test of signature - Body"); + smtpClientSimulator.Send(oAccount1.Address, oAccount1.Address, "Test of signature, 1", "Test of signature - Body"); - sMessageContents = POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); + sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); if (sMessageContents.IndexOf("PlainTextSignature") > 0) throw new Exception("Found incorrect signature."); _domain.AddSignaturesToLocalMail = true; _domain.Save(); - oSMTP.Send(oAccount1.Address, oAccount1.Address, "Test of signature, 1", "Test of signature - Body"); + smtpClientSimulator.Send(oAccount1.Address, oAccount1.Address, "Test of signature, 1", "Test of signature - Body"); - sMessageContents = POP3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); + sMessageContents = Pop3ClientSimulator.AssertGetFirstMessageText(oAccount1.Address, "test"); if (sMessageContents.IndexOf("PlainTextSignature") <= 0) throw new Exception("Found incorrect signature."); } @@ -149,10 +149,10 @@ public void TestDomainSignatureMacro() _account.PersonLastName = "Knafve"; _account.Save(); - SMTPClientSimulator.StaticSend(_account.Address, _account.Address, "Test of signature, 2", + SmtpClientSimulator.StaticSend(_account.Address, _account.Address, "Test of signature, 2", "Test of signature - Body"); - string sMessageData = POP3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); + string sMessageData = Pop3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); Assert.IsTrue(sMessageData.Contains("Regards Knafve, Martin")); } @@ -164,20 +164,20 @@ public void TestSignature() _domain.AddSignaturesToLocalMail = true; _account.SignatureEnabled = true; - var oSMTP = new SMTPClientSimulator(); - oSMTP.Send(_account.Address, _account.Address, "Test of signature, 1", "Test of signature - Body"); + var smtpClientSimulator = new SmtpClientSimulator(); + smtpClientSimulator.Send(_account.Address, _account.Address, "Test of signature, 1", "Test of signature - Body"); - string sMessageData = POP3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); + string sMessageData = Pop3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); if (sMessageData.IndexOf("PlainTextSignature") > 0) throw new Exception("Found exception which should not be there"); _account.SignaturePlainText = "PlainTextSignature"; _account.Save(); - oSMTP.Send(_account.Address, _account.Address, "Test of signature, 2", "Test of signature - Body"); + smtpClientSimulator.Send(_account.Address, _account.Address, "Test of signature, 2", "Test of signature - Body"); - sMessageData = POP3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); + sMessageData = Pop3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); if (sMessageData.IndexOf("PlainTextSignature") < 0) throw new Exception("Did not find expected signature"); @@ -186,8 +186,8 @@ public void TestSignature() _account.SignatureEnabled = false; _account.Save(); - oSMTP.Send(_account.Address, _account.Address, "Test of signature, 2", "Test of signature - Body"); - sMessageData = POP3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); + smtpClientSimulator.Send(_account.Address, _account.Address, "Test of signature, 2", "Test of signature - Body"); + sMessageData = Pop3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); if (sMessageData.IndexOf("PlainTextSignature") > 0) throw new Exception("Found signature even though there shouldn't be any"); @@ -206,10 +206,10 @@ public void TestSignatureExternalDomain() Account account = SingletonProvider.Instance.AddAccount(_domain, "recipient@test.com", "test"); - var oSMTP = new SMTPClientSimulator(); - oSMTP.Send("nonexistant@dummy-example.com", account.Address, "SignatureTest", "SignaturerTestBody"); + var smtpClientSimulator = new SmtpClientSimulator(); + smtpClientSimulator.Send("nonexistant@dummy-example.com", account.Address, "SignatureTest", "SignaturerTestBody"); - string messageData = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); + string messageData = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); Assert.IsFalse(messageData.Contains(_domain.SignaturePlainText)); } @@ -228,10 +228,10 @@ public void TestSignatureLocalDomainNonExistantAccount() Account account = SingletonProvider.Instance.AddAccount(_domain, "recipient@test.com", "test"); - var oSMTP = new SMTPClientSimulator(); - oSMTP.Send("nonexistant@" + _domain.Name, account.Address, "SignatureTest", "SignaturerTestBody"); + var smtpClientSimulator = new SmtpClientSimulator(); + smtpClientSimulator.Send("nonexistant@" + _domain.Name, account.Address, "SignatureTest", "SignaturerTestBody"); - string messageData = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); + string messageData = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); Assert.IsTrue(messageData.Contains(_domain.SignaturePlainText)); } @@ -251,10 +251,10 @@ public void TestSignatureMacroLocalDomainNonExistantAccount() Account account = SingletonProvider.Instance.AddAccount(_domain, "recipient@test.com", "test"); account.PersonFirstName = "Martin"; - var oSMTP = new SMTPClientSimulator(); - oSMTP.Send("nonexistant@" + _domain.Name, account.Address, "SignatureTest", "SignaturerTestBody"); + var smtpClientSimulator = new SmtpClientSimulator(); + smtpClientSimulator.Send("nonexistant@" + _domain.Name, account.Address, "SignatureTest", "SignaturerTestBody"); - string messageData = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); + string messageData = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); Assert.IsTrue(messageData.Contains("%User.FirstName%")); } @@ -358,7 +358,7 @@ private Message SendMessageWithSignature(string plainTextSignature, string htmlS _account.SignatureHTML = htmlSignature; _account.Save(); - SMTPClientSimulator.StaticSendRaw(_account.Address, _account.Address, message); + SmtpClientSimulator.StaticSendRaw(_account.Address, _account.Address, message); return CustomAsserts.AssertGetFirstMessage(_account, "Inbox"); diff --git a/hmailserver/test/RegressionTests/SSL/SmtpDeliverySslTests.cs b/hmailserver/test/RegressionTests/SSL/SmtpDeliverySslTests.cs index b3066d5a5..952127dca 100644 --- a/hmailserver/test/RegressionTests/SSL/SmtpDeliverySslTests.cs +++ b/hmailserver/test/RegressionTests/SSL/SmtpDeliverySslTests.cs @@ -21,16 +21,16 @@ public void SmtpServerSupportingSSL() deliveryResults["test@dummy-example.com"] = 250; int smtpServerPort = TestSetup.GetNextFreePort(); - using (var server = new SMTPServerSimulator(1, smtpServerPort, eConnectionSecurity.eCSTLS)) + using (var server = new SmtpServerSimulator(1, smtpServerPort, eConnectionSecurity.eCSTLS)) { server.SetCertificate(SslSetup.GetCertificate()); server.AddRecipientResult(deliveryResults); server.StartListen(); - Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, true, eConnectionSecurity.eCSTLS); + Route route = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, true, eConnectionSecurity.eCSTLS); - var smtpClient = new SMTPClientSimulator(); - Assert.IsTrue(smtpClient.Send(account.Address, "test@dummy-example.com", "Test", "Test message")); + var smtpClient = new SmtpClientSimulator(); + smtpClient.Send(account.Address, "test@dummy-example.com", "Test", "Test message"); CustomAsserts.AssertRecipientsInDeliveryQueue(0); @@ -51,16 +51,16 @@ public void SmtpServerSupportingStartTls_StartTlsRequired() deliveryResults["test@dummy-example.com"] = 250; int smtpServerPort = TestSetup.GetNextFreePort(); - using (var smtpServer = new SMTPServerSimulator(1, smtpServerPort, eConnectionSecurity.eCSSTARTTLSRequired)) + using (var smtpServer = new SmtpServerSimulator(1, smtpServerPort, eConnectionSecurity.eCSSTARTTLSRequired)) { smtpServer.SetCertificate(SslSetup.GetCertificate()); smtpServer.AddRecipientResult(deliveryResults); smtpServer.StartListen(); - Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, true, eConnectionSecurity.eCSSTARTTLSRequired); + Route route = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, true, eConnectionSecurity.eCSSTARTTLSRequired); - var smtpClient = new SMTPClientSimulator(); - Assert.IsTrue(smtpClient.Send(account.Address, "test@dummy-example.com", "Test", "Test message")); + var smtpClient = new SmtpClientSimulator(); + smtpClient.Send(account.Address, "test@dummy-example.com", "Test", "Test message"); CustomAsserts.AssertRecipientsInDeliveryQueue(0); @@ -80,16 +80,16 @@ public void SmtpServerSupportingStartTls_StartTlsOptional() deliveryResults["test@dummy-example.com"] = 250; int smtpServerPort = TestSetup.GetNextFreePort(); - using (var server = new SMTPServerSimulator(1, smtpServerPort, eConnectionSecurity.eCSSTARTTLSRequired)) + using (var server = new SmtpServerSimulator(1, smtpServerPort, eConnectionSecurity.eCSSTARTTLSRequired)) { server.SetCertificate(SslSetup.GetCertificate()); server.AddRecipientResult(deliveryResults); server.StartListen(); - Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, true, eConnectionSecurity.eCSSTARTTLSOptional); + Route route = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, true, eConnectionSecurity.eCSSTARTTLSOptional); - var smtpClient = new SMTPClientSimulator(); - Assert.IsTrue(smtpClient.Send(account.Address, "test@dummy-example.com", "Test", "Test message")); + var smtpClient = new SmtpClientSimulator(); + smtpClient.Send(account.Address, "test@dummy-example.com", "Test", "Test message"); CustomAsserts.AssertRecipientsInDeliveryQueue(0); @@ -109,23 +109,23 @@ public void SmtpServerNOTSupportingStartTls_StartTlsRequired() deliveryResults["test@dummy-example.com"] = 250; int smtpServerPort = TestSetup.GetNextFreePort(); - using (var server = new SMTPServerSimulator(1, smtpServerPort, eConnectionSecurity.eCSNone)) + using (var server = new SmtpServerSimulator(1, smtpServerPort, eConnectionSecurity.eCSNone)) { server.SetCertificate(SslSetup.GetCertificate()); server.AddRecipientResult(deliveryResults); server.StartListen(); - Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, true, eConnectionSecurity.eCSSTARTTLSRequired); + Route route = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, true, eConnectionSecurity.eCSSTARTTLSRequired); - var smtpClient = new SMTPClientSimulator(); - Assert.IsTrue(smtpClient.Send(account.Address, "test@dummy-example.com", "Test", "Test message")); + var smtpClient = new SmtpClientSimulator(); + smtpClient.Send(account.Address, "test@dummy-example.com", "Test", "Test message"); CustomAsserts.AssertRecipientsInDeliveryQueue(0); // This should now be processed via the rule -> route -> external server we've set up. server.WaitForCompletion(); - var msg = POP3ClientSimulator.AssertGetFirstMessageText("sender@test.com", "test"); + var msg = Pop3ClientSimulator.AssertGetFirstMessageText("sender@test.com", "test"); Assert.IsTrue(msg.Contains("Server does not support STARTTLS")); } @@ -141,16 +141,16 @@ public void SmtpServerNOTSupportingStartTls_StartTlsOptional() deliveryResults["test@dummy-example.com"] = 250; int smtpServerPort = TestSetup.GetNextFreePort(); - using (var server = new SMTPServerSimulator(1, smtpServerPort, eConnectionSecurity.eCSNone)) + using (var server = new SmtpServerSimulator(1, smtpServerPort, eConnectionSecurity.eCSNone)) { server.SetCertificate(SslSetup.GetCertificate()); server.AddRecipientResult(deliveryResults); server.StartListen(); - Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, true, eConnectionSecurity.eCSSTARTTLSOptional); + Route route = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, true, eConnectionSecurity.eCSSTARTTLSOptional); - var smtpClient = new SMTPClientSimulator(); - Assert.IsTrue(smtpClient.Send(account.Address, "test@dummy-example.com", "Test", "Test message")); + var smtpClient = new SmtpClientSimulator(); + smtpClient.Send(account.Address, "test@dummy-example.com", "Test", "Test message"); CustomAsserts.AssertRecipientsInDeliveryQueue(0); diff --git a/hmailserver/test/RegressionTests/SSL/SslServerTests.cs b/hmailserver/test/RegressionTests/SSL/SslServerTests.cs index 27ac9ed4a..4501d998f 100644 --- a/hmailserver/test/RegressionTests/SSL/SslServerTests.cs +++ b/hmailserver/test/RegressionTests/SSL/SslServerTests.cs @@ -63,7 +63,7 @@ public void TestIMAPServer() { try { - var imapSim = new IMAPClientSimulator(true, 14301); + var imapSim = new ImapClientSimulator(true, 14301); imapSim.ConnectAndLogon(account.Address, "test"); Assert.IsTrue(imapSim.SelectFolder("Inbox"), "SelectInbox"); imapSim.CreateFolder("Test"); @@ -86,15 +86,15 @@ public void TestPOP3Server() { Account account = SingletonProvider.Instance.AddAccount(_domain, "pop3-ssl@test.com", "test"); - var smtpSim = new SMTPClientSimulator(); - Assert.IsTrue(smtpSim.Send("test@test.com", account.Address, "Test", "MyBody")); + var smtpSim = new SmtpClientSimulator(); + smtpSim.Send("test@test.com", account.Address, "Test", "MyBody"); for (int i = 0; i < 10; i++) { try { - POP3ClientSimulator.AssertMessageCount(account.Address, "test", 1); - var pop3Sim = new POP3ClientSimulator(true, 11001); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", 1); + var pop3Sim = new Pop3ClientSimulator(true, 11001); string text = pop3Sim.GetFirstMessageText(account.Address, "test"); Assert.IsTrue(text.Contains("MyBody")); @@ -123,8 +123,8 @@ public void TestSMTPServer() { try { - var smtpSim = new SMTPClientSimulator(true, 25001); - Assert.IsTrue(smtpSim.Send("test@test.com", account.Address, "Test", "MyBody")); + var smtpSim = new SmtpClientSimulator(true, 25001); + smtpSim.Send("test@test.com", account.Address, "Test", "MyBody"); break; } @@ -135,8 +135,8 @@ public void TestSMTPServer() } } - POP3ClientSimulator.AssertMessageCount(account.Address, "test", i + 1); - var pop3Sim = new POP3ClientSimulator(false, 110); + Pop3ClientSimulator.AssertMessageCount(account.Address, "test", i + 1); + var pop3Sim = new Pop3ClientSimulator(false, 110); string text = pop3Sim.GetFirstMessageText(account.Address, "test"); Assert.IsTrue(text.Contains("MyBody")); } diff --git a/hmailserver/test/RegressionTests/SSL/SslTlsVersionTests.cs b/hmailserver/test/RegressionTests/SSL/SslTlsVersionTests.cs index 9440711eb..47058f3f5 100644 --- a/hmailserver/test/RegressionTests/SSL/SslTlsVersionTests.cs +++ b/hmailserver/test/RegressionTests/SSL/SslTlsVersionTests.cs @@ -38,7 +38,7 @@ private void SetSslVersions(bool sslv3, bool tlsv10, bool tlsv11, bool tlsv12) public void SslV2ShouldBeDisabled() { SetSslVersions(true, true, true, true); - var smtpClientSimulator = new SMTPClientSimulator(true, SslProtocols.Ssl2, 25001, null); + var smtpClientSimulator = new SmtpClientSimulator(true, SslProtocols.Ssl2, 25001, null); try { @@ -62,14 +62,14 @@ public void SslV2ShouldBeDisabled() public void ItShouldBePossibleToEnableSslV3() { SetSslVersions(true, false, false, false); - var smtpClientSimulator = new SMTPClientSimulator(true, SslProtocols.Ssl3, 25001, null); + var smtpClientSimulator = new SmtpClientSimulator(true, SslProtocols.Ssl3, 25001, null); string errorMessage; - Assert.IsTrue(smtpClientSimulator.Send(false, _account.Address, "test", _account.Address, _account.Address, "Test", "test", out errorMessage)); + smtpClientSimulator.Send(false, _account.Address, "test", _account.Address, _account.Address, "Test", "test", out errorMessage); - var message = POP3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); + var message = Pop3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); Assert.IsTrue(message.Contains("version=SSLv3"), message); } @@ -78,7 +78,7 @@ public void ItShouldBePossibleToEnableSslV3() public void ItShouldBePossibleToDisableSslV3() { SetSslVersions(false, true, true, true); - var smtpClientSimulator = new SMTPClientSimulator(true, SslProtocols.Ssl3, 25001, null); + var smtpClientSimulator = new SmtpClientSimulator(true, SslProtocols.Ssl3, 25001, null); try { @@ -104,12 +104,12 @@ public void ItShouldBePossibleToDisableSslV3() public void WhenSSL3IsDisabledTLSShouldWork() { SetSslVersions(false, true, true, true); - var smtpClientSimulator = new SMTPClientSimulator(true, SslProtocols.Tls, 25001, null); + var smtpClientSimulator = new SmtpClientSimulator(true, SslProtocols.Tls, 25001, null); string errorMessage; - Assert.IsTrue(smtpClientSimulator.Send(false, _account.Address, "test", _account.Address, _account.Address, "Test", "test", out errorMessage)); + smtpClientSimulator.Send(false, _account.Address, "test", _account.Address, _account.Address, "Test", "test", out errorMessage); - var message = POP3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); + var message = Pop3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); Assert.IsTrue(message.Contains("version=TLSv1"), message); } diff --git a/hmailserver/test/RegressionTests/SSL/StartTls/ImapServerTests.cs b/hmailserver/test/RegressionTests/SSL/StartTls/ImapServerTests.cs index 812784ec6..1ec95cd91 100644 --- a/hmailserver/test/RegressionTests/SSL/StartTls/ImapServerTests.cs +++ b/hmailserver/test/RegressionTests/SSL/StartTls/ImapServerTests.cs @@ -29,7 +29,7 @@ class ImapServerTests : TestFixtureBase [Test] public void IfStartTlsNotEnabledStartTlsShouldNotBeShownInEhloResponse() { - var imapSimulator = new IMAPClientSimulator(false, 143); + var imapSimulator = new ImapClientSimulator(false, 143); imapSimulator.Connect(); var data = imapSimulator.GetCapabilities(); @@ -39,7 +39,7 @@ public void IfStartTlsNotEnabledStartTlsShouldNotBeShownInEhloResponse() [Test] public void IfStartTlsIsEnabledStartTlsShouldBeShownInEhloResponse() { - var imapSimulator = new IMAPClientSimulator(false, 14302); + var imapSimulator = new ImapClientSimulator(false, 14302); imapSimulator.Connect(); var data = imapSimulator.GetCapabilities(); @@ -49,7 +49,7 @@ public void IfStartTlsIsEnabledStartTlsShouldBeShownInEhloResponse() [Test] public void StlsCommandShouldSwithToTls() { - var imapSimulator = new IMAPClientSimulator(false, 14302); + var imapSimulator = new ImapClientSimulator(false, 14302); imapSimulator.Connect(); var data = imapSimulator.GetCapabilities(); imapSimulator.SendSingleCommand("A01 STARTTLS"); @@ -64,7 +64,7 @@ public void StlsCommandShouldSwithToTls() [Test] public void IfStlsRequiredLogonShouldSucceedIfStls() { - var imapSimulator = new IMAPClientSimulator(false, 14303); + var imapSimulator = new ImapClientSimulator(false, 14303); imapSimulator.Connect(); imapSimulator.SendSingleCommand("A01 STARTTLS"); imapSimulator.Handshake(); @@ -78,7 +78,7 @@ public void IfStlsRequiredLogonShouldSucceedIfStls() [Test] public void IfStlsRequiredLogonShouldFailIfNoStls() { - var imapSimulator = new IMAPClientSimulator(false, 14303); + var imapSimulator = new ImapClientSimulator(false, 14303); imapSimulator.Connect(); string errorMessage; @@ -94,7 +94,7 @@ public void IfStlsOptionalButSslRequiredByIpRangeForAuthThenAuthShouldFail() range.RequireSSLTLSForAuth = true; range.Save(); - var imapSimulator = new IMAPClientSimulator(false, 14302); + var imapSimulator = new ImapClientSimulator(false, 14302); imapSimulator.Connect(); string errorMessage; diff --git a/hmailserver/test/RegressionTests/SSL/StartTls/Pop3ServerTests.cs b/hmailserver/test/RegressionTests/SSL/StartTls/Pop3ServerTests.cs index 080c4214a..a844e99e4 100644 --- a/hmailserver/test/RegressionTests/SSL/StartTls/Pop3ServerTests.cs +++ b/hmailserver/test/RegressionTests/SSL/StartTls/Pop3ServerTests.cs @@ -30,7 +30,7 @@ public class Pop3ServerTests : TestFixtureBase [Test] public void IfStartTlsNotEnabledStartTlsShouldNotBeShownInEhloResponse() { - var pop3Simulator = new POP3ClientSimulator(false, 110); + var pop3Simulator = new Pop3ClientSimulator(false, 110); pop3Simulator.Connect(); string banner; @@ -44,7 +44,7 @@ public void IfStartTlsNotEnabledStartTlsShouldNotBeShownInEhloResponse() [Test] public void IfStartTlsIsEnabledStartTlsShouldBeShownInEhloResponse() { - var pop3Simulator = new POP3ClientSimulator(false, 11002); + var pop3Simulator = new Pop3ClientSimulator(false, 11002); pop3Simulator.Connect(); string banner; @@ -58,7 +58,7 @@ public void IfStartTlsIsEnabledStartTlsShouldBeShownInEhloResponse() [Test] public void StlsCommandShouldSwithToTls() { - var pop3Simulator = new POP3ClientSimulator(false, 11002); + var pop3Simulator = new Pop3ClientSimulator(false, 11002); pop3Simulator.Connect(); string banner; pop3Simulator.ReceiveBanner(out banner); @@ -73,7 +73,7 @@ public void StlsCommandShouldSwithToTls() [Test] public void IfStlsRequiredLogonShouldSucceedIfStls() { - var pop3Simulator = new POP3ClientSimulator(false, 11003); + var pop3Simulator = new Pop3ClientSimulator(false, 11003); pop3Simulator.Connect(); string banner; pop3Simulator.ReceiveBanner(out banner); @@ -88,7 +88,7 @@ public void IfStlsRequiredLogonShouldSucceedIfStls() [Test] public void IfStlsRequiredLogonShouldFailIfNoStls() { - var pop3Simulator = new POP3ClientSimulator(false, 11003); + var pop3Simulator = new Pop3ClientSimulator(false, 11003); pop3Simulator.Connect(); string banner; pop3Simulator.ReceiveBanner(out banner); @@ -105,7 +105,7 @@ public void IfStlsOptionalButSslRequiredByIpRangeForAuthThenAuthShouldFail() range.RequireSSLTLSForAuth = true; range.Save(); - var pop3Simulator = new POP3ClientSimulator(false, 11002); + var pop3Simulator = new Pop3ClientSimulator(false, 11002); pop3Simulator.Connect(); string banner; pop3Simulator.ReceiveBanner(out banner); diff --git a/hmailserver/test/RegressionTests/Security/AutoBan.cs b/hmailserver/test/RegressionTests/Security/AutoBan.cs index ca820f061..8e3e052fc 100644 --- a/hmailserver/test/RegressionTests/Security/AutoBan.cs +++ b/hmailserver/test/RegressionTests/Security/AutoBan.cs @@ -32,7 +32,7 @@ public void TestDisabled() Account account = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - var sim = new POP3ClientSimulator(); + var sim = new Pop3ClientSimulator(); Assert.IsTrue(sim.ConnectAndLogon(account.Address, "test")); sim.Disconnect(); @@ -63,7 +63,7 @@ public void TestIMAPLogonFailure() Account account = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - var sim = new IMAPClientSimulator(); + var sim = new ImapClientSimulator(); Assert.IsTrue(sim.ConnectAndLogon(account.Address, "test")); sim.Disconnect(); @@ -102,7 +102,7 @@ public void TestIPRangeName() Account account = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - var sim = new POP3ClientSimulator(); + var sim = new Pop3ClientSimulator(); Assert.IsTrue(sim.ConnectAndLogon(account.Address, "test")); sim.Disconnect(); @@ -138,7 +138,7 @@ public void TestPOP3LogonFailure() Account account = SingletonProvider.Instance.AddAccount(_domain, "te'st@test.com", "test"); - var sim = new POP3ClientSimulator(TestSetup.GetLocalIpAddress(), false, 110); + var sim = new Pop3ClientSimulator(TestSetup.GetLocalIpAddress(), false, 110); Assert.IsTrue(sim.ConnectAndLogon(account.Address, "test")); sim.Disconnect(); @@ -174,11 +174,11 @@ public void TestSMTPLogonFailure() Account account = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - var sim = new SMTPClientSimulator(); + var sim = new SmtpClientSimulator(); //test@test.com / test string errorMessage; - Assert.IsTrue(sim.ConnectAndLogon("dGVzdEB0ZXN0LmNvbQ==", "dGVzdA==", out errorMessage)); + sim.ConnectAndLogon("dGVzdEB0ZXN0LmNvbQ==", "dGVzdA==", out errorMessage); sim.Disconnect(); // confirm that we can retrieve welcome message. @@ -187,7 +187,7 @@ public void TestSMTPLogonFailure() // fail to log on 3 times. for (int i = 0; i < 2; i++) { - Assert.IsFalse(sim.ConnectAndLogon("dGVzdEB0ZXN0LmNvbQ==", "Vaffe==", out errorMessage)); + CustomAsserts.Throws(() => sim.ConnectAndLogon("dGVzdEB0ZXN0LmNvbQ==", "Vaffe==", out errorMessage)); sim.Disconnect(); if (i == 2) diff --git a/hmailserver/test/RegressionTests/Security/Basics.cs b/hmailserver/test/RegressionTests/Security/Basics.cs index 0d3b40d2f..a1f6c1f16 100644 --- a/hmailserver/test/RegressionTests/Security/Basics.cs +++ b/hmailserver/test/RegressionTests/Security/Basics.cs @@ -1,6 +1,8 @@ // Copyright (c) 2010 Martin Knafve / hMailServer.com. // http://www.hmailserver.com +using System; +using System.Security.Authentication; using NUnit.Framework; using RegressionTests.Infrastructure; using RegressionTests.Shared; @@ -17,16 +19,16 @@ public void TestEmptyPassword() Account account1 = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", ""); string message; - var sim = new POP3ClientSimulator(); + var sim = new Pop3ClientSimulator(); Assert.IsFalse(sim.ConnectAndLogon(account1.Address, "", out message)); - var simIMAP = new IMAPClientSimulator(); + var simIMAP = new ImapClientSimulator(); Assert.IsFalse(simIMAP.ConnectAndLogon(account1.Address, "", out message)); Assert.AreEqual("A01 NO Invalid user name or password.\r\n", message); - var simSMTP = new SMTPClientSimulator(); - Assert.IsFalse(simSMTP.ConnectAndLogon("dGVzdEB0ZXN0LmNvbQ==", "", out message)); + var simSMTP = new SmtpClientSimulator(); + CustomAsserts.Throws(() => simSMTP.ConnectAndLogon("dGVzdEB0ZXN0LmNvbQ==", "", out message)); Assert.AreEqual("535 Authentication failed. Restarting authentication process.\r\n", message); } } diff --git a/hmailserver/test/RegressionTests/Security/PasswordMasking.cs b/hmailserver/test/RegressionTests/Security/PasswordMasking.cs index 547caa70d..93a366cca 100644 --- a/hmailserver/test/RegressionTests/Security/PasswordMasking.cs +++ b/hmailserver/test/RegressionTests/Security/PasswordMasking.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Security.Authentication; using System.Text; using System.Threading; using NUnit.Framework; @@ -104,7 +105,7 @@ internal Route AddRoutePointingAtLocalhostWithAuth(int numberOfTries, int port) [Test] public void TestIMAPServerLiteral() { - var sim = new IMAPClientSimulator(); + var sim = new ImapClientSimulator(); sim.Connect(); Assert.IsTrue(sim.Send("a01 login " + GetUsername() + " {4}").StartsWith("+")); sim.Send(GetPassword()); @@ -114,7 +115,7 @@ public void TestIMAPServerLiteral() [Test] public void TestIMAPServerLiteral2() { - var sim = new IMAPClientSimulator(); + var sim = new ImapClientSimulator(); sim.Connect(); Assert.IsTrue(sim.Send("a01 login {" + GetUsername().Length.ToString() + "} {4}").StartsWith("+")); Assert.IsTrue(sim.Send(GetUsername() + " {" + GetPassword().Length.ToString() + "}").StartsWith("+")); @@ -125,7 +126,7 @@ public void TestIMAPServerLiteral2() [Test] public void TestIMAPServerNormal() { - var sim = new IMAPClientSimulator(); + var sim = new ImapClientSimulator(); sim.ConnectAndLogon(GetUsername(), GetPassword()); EnsureNoPassword(); } @@ -144,7 +145,7 @@ public void TestPOP3Client() messages.Add(message); int port = TestSetup.GetNextFreePort(); - using (var pop3Server = new POP3Server(1, port, messages)) + using (var pop3Server = new Pop3ServerSimulator(1, port, messages)) { pop3Server.StartListen(); @@ -168,7 +169,7 @@ public void TestPOP3Client() fa.Delete(); - string downloadedMessage = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); + string downloadedMessage = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); Assert.IsTrue(downloadedMessage.Contains(message)); EnsureNoPassword(); @@ -178,7 +179,7 @@ public void TestPOP3Client() [Test] public void TestPOP3Server() { - var sim = new POP3ClientSimulator(); + var sim = new Pop3ClientSimulator(); sim.ConnectAndLogon(GetUsername(), GetPassword()); EnsureNoPassword(); } @@ -196,7 +197,7 @@ public void TestSMTPClient() int smtpServerPort = TestSetup.GetNextFreePort(); - using (var server = new SMTPServerSimulator(1, smtpServerPort)) + using (var server = new SmtpServerSimulator(1, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.StartListen(); @@ -205,8 +206,8 @@ public void TestSMTPClient() AddRoutePointingAtLocalhostWithAuth(0, smtpServerPort); // Send message to this route. - var smtp = new SMTPClientSimulator(); - Assert.IsTrue(smtp.Send("test@test.com", "test@dummy-example.com", "Test", "Test message")); + var smtp = new SmtpClientSimulator(); + smtp.Send("test@test.com", "test@dummy-example.com", "Test", "Test message"); CustomAsserts.AssertRecipientsInDeliveryQueue(0); @@ -224,9 +225,11 @@ public void TestSMTPClient() [Test] public void TestSMTPServerAuthLogin() { - var sim = new SMTPClientSimulator(); + var sim = new SmtpClientSimulator(); string errorMsg; - sim.ConnectAndLogon(GetUsername(), GetPassword(), out errorMsg); + + CustomAsserts.Throws(() => sim.ConnectAndLogon(GetUsername(), GetPassword(), out errorMsg)); + EnsureNoPassword(); } diff --git a/hmailserver/test/RegressionTests/Security/SMTPAuthentication.cs b/hmailserver/test/RegressionTests/Security/SMTPAuthentication.cs index 67d65bd9d..2f82eff59 100644 --- a/hmailserver/test/RegressionTests/Security/SMTPAuthentication.cs +++ b/hmailserver/test/RegressionTests/Security/SMTPAuthentication.cs @@ -1,6 +1,7 @@ // Copyright (c) 2010 Martin Knafve / hMailServer.com. // http://www.hmailserver.com +using System; using System.Collections.Generic; using NUnit.Framework; using RegressionTests.Infrastructure; @@ -43,14 +44,14 @@ public void TestBlockingDeliveries() Account account1 = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); - string result1, result2, result3, result4; + string result1 = "", result2 = "", result3 = "", result4 = ""; - Assert.IsFalse(oSMTP.Send(account1.Address, account1.Address, "Mail 1", "Mail 1", out result1)); - Assert.IsFalse(oSMTP.Send(account1.Address, "externaladdress@gmail.com", "Mail 1", "Mail 1", out result2)); - Assert.IsFalse(oSMTP.Send("externaladdress@gmail.com", account1.Address, "Mail 1", "Mail 1", out result3)); - Assert.IsFalse(oSMTP.Send("externaladdress@gmail.com", "externaladdress@gmail.com", "Mail 1", "Mail 1", + CustomAsserts.Throws(() => smtpClientSimulator.Send(account1.Address, account1.Address, "Mail 1", "Mail 1", out result1)); + CustomAsserts.Throws(() => smtpClientSimulator.Send(account1.Address, "externaladdress@gmail.com", "Mail 1", "Mail 1", out result2)); + CustomAsserts.Throws(() => smtpClientSimulator.Send("externaladdress@gmail.com", account1.Address, "Mail 1", "Mail 1", out result3)); + CustomAsserts.Throws(() => smtpClientSimulator.Send("externaladdress@gmail.com", "externaladdress@gmail.com", "Mail 1", "Mail 1", out result4)); Assert.IsTrue(result1.Contains("550 Delivery is not allowed to this address.")); @@ -68,9 +69,9 @@ public void TestSMTPAuthExternalToExternal() range.RequireSMTPAuthExternalToExternal = true; range.Save(); - var oSMTP = new SMTPClientSimulator(); - string result; - Assert.IsFalse(oSMTP.Send("externaladdress@example.com", "someexternaladdress@example.com", "Mail 1", + var smtpClientSimulator = new SmtpClientSimulator(); + string result = ""; + CustomAsserts.Throws(() => smtpClientSimulator.Send("externaladdress@example.com", "someexternaladdress@example.com", "Mail 1", "Mail 1", out result)); Assert.IsTrue(result.Contains("SMTP authentication is required.")); @@ -78,7 +79,7 @@ public void TestSMTPAuthExternalToExternal() range.AllowDeliveryFromRemoteToRemote = false; range.Save(); - Assert.IsFalse(oSMTP.Send("externaladdress@example.com", "someexternaladdress@example.com", "Mail 1", + CustomAsserts.Throws(() => smtpClientSimulator.Send("externaladdress@example.com", "someexternaladdress@example.com", "Mail 1", "Mail 1", out result)); Assert.IsTrue(result.Contains("550 Delivery is not allowed to this address.")); } @@ -94,13 +95,13 @@ public void TestSMTPAuthExternalToLocal() Account account1 = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - var oSMTP = new SMTPClientSimulator(); - Assert.IsFalse(oSMTP.Send("someexternaladdress@example.com", account1.Address, "Mail 1", "Mail 1")); + var smtpClientSimulator = new SmtpClientSimulator(); + CustomAsserts.Throws(() => smtpClientSimulator.Send("someexternaladdress@example.com", account1.Address, "Mail 1", "Mail 1")); range.RequireSMTPAuthExternalToLocal = false; range.Save(); - Assert.IsTrue(oSMTP.Send("someexternaladdress@example.com", account1.Address, "Mail 1", "Mail 1")); + smtpClientSimulator.Send("someexternaladdress@example.com", account1.Address, "Mail 1", "Mail 1"); CustomAsserts.AssertRecipientsInDeliveryQueue(0); } @@ -116,7 +117,7 @@ public void TestSMTPAuthExternalToRouteConfiguredAsLocal() range.Save(); int smtpServerPort = TestSetup.GetNextFreePort(); - Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, false); + Route route = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false); route.TreatRecipientAsLocalDomain = true; route.TreatSenderAsLocalDomain = true; route.Save(); @@ -126,14 +127,14 @@ public void TestSMTPAuthExternalToRouteConfiguredAsLocal() deliveryResults["dummy@dummy-example.com"] = 250; - using (var server = new SMTPServerSimulator(1, smtpServerPort)) + using (var server = new SmtpServerSimulator(1, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.StartListen(); // Make sure we can't send to this route without using smtp auth. - var oSMTP = new SMTPClientSimulator(); - Assert.IsTrue(oSMTP.Send("someexternaladdress@example.com", "dummy@dummy-example.com", "Mail 1", "Mail 1")); + var smtpClientSimulator = new SmtpClientSimulator(); + smtpClientSimulator.Send("someexternaladdress@example.com", "dummy@dummy-example.com", "Mail 1", "Mail 1"); server.WaitForCompletion(); @@ -152,9 +153,9 @@ public void TestSMTPAuthLocalToExternal() Account account1 = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - var oSMTP = new SMTPClientSimulator(); - string result; - Assert.IsFalse(oSMTP.Send(account1.Address, "someexternaladdress@example.com", "Mail 1", "Mail 1", + var smtpClientSimulator = new SmtpClientSimulator(); + string result = ""; + CustomAsserts.Throws(() => smtpClientSimulator.Send(account1.Address, "someexternaladdress@example.com", "Mail 1", "Mail 1", out result)); Assert.IsTrue(result.Contains("SMTP authentication is required")); } @@ -170,15 +171,15 @@ public void TestSMTPAuthLocalToLocal() Account account1 = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - var oSMTP = new SMTPClientSimulator(); - string result; - Assert.IsFalse(oSMTP.Send(account1.Address, account1.Address, "Mail 1", "Mail 1", out result)); + var smtpClientSimulator = new SmtpClientSimulator(); + string result = ""; + CustomAsserts.Throws(() => smtpClientSimulator.Send(account1.Address, account1.Address, "Mail 1", "Mail 1", out result)); Assert.IsTrue(result.Contains("SMTP authentication is required.")); range.RequireSMTPAuthLocalToLocal = false; range.Save(); - Assert.IsTrue(oSMTP.Send(account1.Address, account1.Address, "Mail 1", "Mail 1", out result)); + smtpClientSimulator.Send(account1.Address, account1.Address, "Mail 1", "Mail 1", out result); CustomAsserts.AssertRecipientsInDeliveryQueue(0); } @@ -189,7 +190,7 @@ public void TestSMTPAuthLocalToLocal() public void TestSenderAsExternalDomainSendToLocalAccountFail() { int smtpServerPort = TestSetup.GetNextFreePort(); - Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, false); + Route route = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false); route.TreatSenderAsLocalDomain = false; route.Save(); @@ -200,9 +201,9 @@ public void TestSenderAsExternalDomainSendToLocalAccountFail() Account account1 = SingletonProvider.Instance.AddAccount(_domain, "sales@test.com", "test"); - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); string result; - Assert.IsFalse(oSMTP.Send("someone@dummy-example.com", account1.Address, "Mail 1", "Mail 1", out result)); + CustomAsserts.Throws(() => smtpClientSimulator.Send("someone@dummy-example.com", account1.Address, "Mail 1", "Mail 1", out result)); } [Test] @@ -212,7 +213,7 @@ public void TestSenderAsExternalDomainSendToLocalAccountFail() public void TestSenderAsExternalDomainSendToLocalAccountPass() { int smtpServerPort = TestSetup.GetNextFreePort(); - Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, false); + Route route = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false); route.TreatSenderAsLocalDomain = false; route.Save(); @@ -223,11 +224,11 @@ public void TestSenderAsExternalDomainSendToLocalAccountPass() Account account1 = SingletonProvider.Instance.AddAccount(_domain, "sales@test.com", "test"); - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); string result; - Assert.IsTrue(oSMTP.Send("someone@dummy-example.com", account1.Address, "Mail 1", "Mail 1", out result)); + smtpClientSimulator.Send("someone@dummy-example.com", account1.Address, "Mail 1", "Mail 1", out result); - string text = POP3ClientSimulator.AssertGetFirstMessageText(account1.Address, "test"); + string text = Pop3ClientSimulator.AssertGetFirstMessageText(account1.Address, "test"); Assert.IsTrue(text.Contains("Mail 1")); } @@ -238,7 +239,7 @@ public void TestSenderAsExternalDomainSendToLocalAccountPass() public void TestSenderAsLocalDomainSendToExternal() { int smtpServerPort = TestSetup.GetNextFreePort(); - Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, false); + Route route = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false); route.TreatSenderAsLocalDomain = true; route.Save(); @@ -247,9 +248,9 @@ public void TestSenderAsLocalDomainSendToExternal() range.RequireSMTPAuthLocalToExternal = true; range.Save(); - var oSMTP = new SMTPClientSimulator(); - string result; - Assert.IsFalse(oSMTP.Send("someone@dummy-example.com", "test@example.com", "Mail 1", "Mail 1", out result)); + var smtpClientSimulator = new SmtpClientSimulator(); + string result = ""; + CustomAsserts.Throws(() => smtpClientSimulator.Send("someone@dummy-example.com", "test@example.com", "Mail 1", "Mail 1", out result)); Assert.IsTrue(result.Contains("530 SMTP authentication is required.")); } @@ -260,7 +261,7 @@ public void TestSenderAsLocalDomainSendToExternal() public void TestSenderAsLocalDomainSendToLocalAccount() { int smtpServerPort = TestSetup.GetNextFreePort(); - Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, false); + Route route = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false); route.TreatSenderAsLocalDomain = true; route.Save(); @@ -271,9 +272,9 @@ public void TestSenderAsLocalDomainSendToLocalAccount() Account account1 = SingletonProvider.Instance.AddAccount(_domain, "sales@test.com", "test"); - var oSMTP = new SMTPClientSimulator(); - string result; - Assert.IsFalse(oSMTP.Send("someone@dummy-example.com", account1.Address, "Mail 1", "Mail 1", out result)); + var smtpClientSimulator = new SmtpClientSimulator(); + string result = ""; + CustomAsserts.Throws(() => smtpClientSimulator.Send("someone@dummy-example.com", account1.Address, "Mail 1", "Mail 1", out result)); Assert.IsTrue(result.Contains("530 SMTP authentication is required.")); } @@ -284,7 +285,7 @@ public void TestSenderAsLocalDomainSendToLocalAccount() public void TestSenderAsLocalDomainSendToLocalAccountPass() { int smtpServerPort = TestSetup.GetNextFreePort(); - Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, false); + Route route = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false); route.TreatSenderAsLocalDomain = true; route.Save(); @@ -295,11 +296,11 @@ public void TestSenderAsLocalDomainSendToLocalAccountPass() Account account1 = SingletonProvider.Instance.AddAccount(_domain, "sales@test.com", "test"); - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); string result; - Assert.IsTrue(oSMTP.Send("someone@dummy-example.com", account1.Address, "Mail 1", "Mail 1", out result)); + smtpClientSimulator.Send("someone@dummy-example.com", account1.Address, "Mail 1", "Mail 1", out result); - string text = POP3ClientSimulator.AssertGetFirstMessageText(account1.Address, "test"); + string text = Pop3ClientSimulator.AssertGetFirstMessageText(account1.Address, "test"); Assert.IsTrue(text.Contains("Mail 1")); } @@ -309,7 +310,7 @@ public void TestSenderAsLocalDomainSendToLocalAccountPass() public void TestUseCase3DeliveryFromExternalUserToPrimaryViaBackup() { int smtpServerPort = TestSetup.GetNextFreePort(); - Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, false); + Route route = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false); route.TreatRecipientAsLocalDomain = true; route.TreatSenderAsLocalDomain = false; route.Save(); @@ -317,14 +318,14 @@ public void TestUseCase3DeliveryFromExternalUserToPrimaryViaBackup() var deliveryResults = new Dictionary(); deliveryResults["test@dummy-example.com"] = 250; - using (var server = new SMTPServerSimulator(1, smtpServerPort)) + using (var server = new SmtpServerSimulator(1, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.StartListen(); - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); string result; - Assert.IsTrue(oSMTP.Send("someone@example.com", "test@dummy-example.com", "Mail 1", "Mail 1", out result)); + smtpClientSimulator.Send("someone@example.com", "test@dummy-example.com", "Mail 1", "Mail 1", out result); server.WaitForCompletion(); @@ -338,18 +339,18 @@ public void TestUseCase3DeliveryFromExternalUserToPrimaryViaBackup() public void TestUseCaseDeliveryFromPrimaryMXToBackupMX() { int smtpServerPort = TestSetup.GetNextFreePort(); - Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, false); + Route route = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false); route.TreatRecipientAsLocalDomain = true; route.TreatSenderAsLocalDomain = false; route.Save(); Account account1 = SingletonProvider.Instance.AddAccount(_domain, "sales@test.com", "test"); - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); string result; - Assert.IsTrue(oSMTP.Send("someone@dummy-example.com", account1.Address, "Mail 1", "Mail 1", out result)); + smtpClientSimulator.Send("someone@dummy-example.com", account1.Address, "Mail 1", "Mail 1", out result); - string text = POP3ClientSimulator.AssertGetFirstMessageText(account1.Address, "test"); + string text = Pop3ClientSimulator.AssertGetFirstMessageText(account1.Address, "test"); Assert.IsTrue(text.Contains("Mail 1")); } @@ -360,7 +361,7 @@ public void TestUseCaseDeliveryFromPrimaryMXToBackupMX() public void TestUseCaseDeliveryToLocalRoute() { int smtpServerPort = TestSetup.GetNextFreePort(); - Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, false); + Route route = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false); route.TreatRecipientAsLocalDomain = true; route.TreatSenderAsLocalDomain = false; route.Save(); @@ -368,15 +369,15 @@ public void TestUseCaseDeliveryToLocalRoute() var deliveryResults = new Dictionary(); deliveryResults["test@dummy-example.com"] = 250; - using (var server = new SMTPServerSimulator(1, smtpServerPort)) + using (var server = new SmtpServerSimulator(1, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.StartListen(); - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); string result; - Assert.IsTrue(oSMTP.Send("someone@dummy-example.com", "test@dummy-example.com", "Mail 1", "Mail 1", - out result)); + smtpClientSimulator.Send("someone@dummy-example.com", "test@dummy-example.com", "Mail 1", "Mail 1", + out result); server.WaitForCompletion(); @@ -392,13 +393,13 @@ public void TestUseCaseDeliveryToLocalRoute() public void TreatRecipientAsExternalDomain() { int smtpServerPort = TestSetup.GetNextFreePort(); - Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, false); + Route route = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false); route.TreatRecipientAsLocalDomain = false; route.Save(); - var oSMTP = new SMTPClientSimulator(); - string result; - Assert.IsFalse(oSMTP.Send("someone@example.com", "test@dummy-example.com", "Mail 1", "Mail 1", out result)); + var smtpClientSimulator = new SmtpClientSimulator(); + string result = ""; + CustomAsserts.Throws(() => smtpClientSimulator.Send("someone@example.com", "test@dummy-example.com", "Mail 1", "Mail 1", out result)); Assert.IsTrue(result.Contains("530 SMTP authentication is required.")); } @@ -410,7 +411,7 @@ public void TreatRecipientAsExternalDomain() public void TreatRecipientAsExternalDomainPermitted() { int smtpServerPort = TestSetup.GetNextFreePort(); - Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, false); + Route route = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false); route.TreatRecipientAsLocalDomain = false; route.Save(); @@ -423,14 +424,14 @@ public void TreatRecipientAsExternalDomainPermitted() var deliveryResults = new Dictionary(); deliveryResults["test@dummy-example.com"] = 250; - using (var server = new SMTPServerSimulator(1, smtpServerPort)) + using (var server = new SmtpServerSimulator(1, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.StartListen(); - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); string result; - Assert.IsTrue(oSMTP.Send("someone@example.com", "test@dummy-example.com", "Mail 1", "Mail 1", out result)); + smtpClientSimulator.Send("someone@example.com", "test@dummy-example.com", "Mail 1", "Mail 1", out result); server.WaitForCompletion(); @@ -445,21 +446,21 @@ public void TreatRecipientAsExternalDomainPermitted() public void TreatRecipientAsLocalDomain() { int smtpServerPort = TestSetup.GetNextFreePort(); - Route route = SMTPClientTests.AddRoutePointingAtLocalhost(1, smtpServerPort, false); + Route route = TestSetup.AddRoutePointingAtLocalhost(1, smtpServerPort, false); route.TreatRecipientAsLocalDomain = true; route.Save(); var deliveryResults = new Dictionary(); deliveryResults["test@dummy-example.com"] = 250; - using (var server = new SMTPServerSimulator(1, smtpServerPort)) + using (var server = new SmtpServerSimulator(1, smtpServerPort)) { server.AddRecipientResult(deliveryResults); server.StartListen(); - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); string result; - Assert.IsTrue(oSMTP.Send("someone@example.com", "test@dummy-example.com", "Mail 1", "Mail 1", out result)); + smtpClientSimulator.Send("someone@example.com", "test@dummy-example.com", "Mail 1", "Mail 1", out result); server.WaitForCompletion(); diff --git a/hmailserver/test/RegressionTests/Shared/DeliveryFailedException.cs b/hmailserver/test/RegressionTests/Shared/DeliveryFailedException.cs new file mode 100644 index 000000000..0dfec5287 --- /dev/null +++ b/hmailserver/test/RegressionTests/Shared/DeliveryFailedException.cs @@ -0,0 +1,13 @@ +using System; + +namespace RegressionTests.Shared +{ + public class DeliveryFailedException : Exception + { + public DeliveryFailedException(string message) : + base(message) + { + + } + } +} diff --git a/hmailserver/test/RegressionTests/Shared/IMAPClientSimulator.cs b/hmailserver/test/RegressionTests/Shared/IMAPClientSimulator.cs index e1905d180..77a450243 100644 --- a/hmailserver/test/RegressionTests/Shared/IMAPClientSimulator.cs +++ b/hmailserver/test/RegressionTests/Shared/IMAPClientSimulator.cs @@ -13,17 +13,17 @@ namespace RegressionTests.Shared /// /// Summary description for IMAPClientSimulator. /// - public class IMAPClientSimulator + public class ImapClientSimulator { private readonly int _port = 143; private readonly TcpConnection _tcpConnection; - public IMAPClientSimulator() + public ImapClientSimulator() { _tcpConnection = new TcpConnection(); } - public IMAPClientSimulator(string username, string password, string mailbox) + public ImapClientSimulator(string username, string password, string mailbox) { _tcpConnection = new TcpConnection(); @@ -31,7 +31,7 @@ public IMAPClientSimulator(string username, string password, string mailbox) Assert.IsTrue(SelectFolder(mailbox)); } - public IMAPClientSimulator(bool useSSL, int port) + public ImapClientSimulator(bool useSSL, int port) { _tcpConnection = new TcpConnection(useSSL); _port = port; @@ -647,7 +647,7 @@ public static void AssertMessageCount(string accountName, string accountPassword CustomAsserts.AssertRecipientsInDeliveryQueue(0); } - var oIMAP = new IMAPClientSimulator(); + var oIMAP = new ImapClientSimulator(); Assert.IsTrue(oIMAP.ConnectAndLogon(accountName, accountPassword)); if (expectedCount != 0) diff --git a/hmailserver/test/RegressionTests/Shared/POP3ClientSimulator.cs b/hmailserver/test/RegressionTests/Shared/POP3ClientSimulator.cs index 47689457c..67557af72 100644 --- a/hmailserver/test/RegressionTests/Shared/POP3ClientSimulator.cs +++ b/hmailserver/test/RegressionTests/Shared/POP3ClientSimulator.cs @@ -11,25 +11,25 @@ namespace RegressionTests.Shared /// /// Summary description for POP3ClientSimulator. /// - public class POP3ClientSimulator + public class Pop3ClientSimulator { private readonly IPAddress _ipaddress; private readonly int _port = 110; private readonly TcpConnection _tcpConnection; - public POP3ClientSimulator() + public Pop3ClientSimulator() { _tcpConnection = new TcpConnection(); } - public POP3ClientSimulator(IPAddress ipaddress, bool useSSL, int port) + public Pop3ClientSimulator(IPAddress ipaddress, bool useSSL, int port) { _tcpConnection = new TcpConnection(useSSL); _port = port; _ipaddress = ipaddress; } - public POP3ClientSimulator(bool useSSL, int port) : + public Pop3ClientSimulator(bool useSSL, int port) : this(null, useSSL, port) { } @@ -331,9 +331,9 @@ public static void AssertMessageCount(string accountName, string accountPassword int actualCount = 0; while (timeout > 0) { - var oPOP3 = new POP3ClientSimulator(); + var pop3ClientSimulator = new Pop3ClientSimulator(); - actualCount = oPOP3.GetMessageCount(accountName, accountPassword); + actualCount = pop3ClientSimulator.GetMessageCount(accountName, accountPassword); if (actualCount == expectedCount) return; @@ -354,7 +354,7 @@ public static void AssertMessageCount(string accountName, string accountPassword public static string AssertGetFirstMessageText(string accountName, string accountPassword) { // Wait for the message to appear. - var pop3 = new POP3ClientSimulator(); + var pop3 = new Pop3ClientSimulator(); for (int i = 0; i < 5000; i++) { if (pop3.GetMessageCount(accountName, accountPassword) > 0) diff --git a/hmailserver/test/RegressionTests/Shared/POP3Server.cs b/hmailserver/test/RegressionTests/Shared/Pop3ServerSimulator.cs similarity index 94% rename from hmailserver/test/RegressionTests/Shared/POP3Server.cs rename to hmailserver/test/RegressionTests/Shared/Pop3ServerSimulator.cs index 41a6bbf82..6b43d6fdc 100644 --- a/hmailserver/test/RegressionTests/Shared/POP3Server.cs +++ b/hmailserver/test/RegressionTests/Shared/Pop3ServerSimulator.cs @@ -9,7 +9,7 @@ namespace RegressionTests.Shared { - internal class POP3Server : TcpServer + internal class Pop3ServerSimulator : TcpServer { private readonly List _messages; private bool _disconnectImmediate; @@ -22,13 +22,13 @@ public enum BufferMode } - public POP3Server(int maxNumberOfConnections, int port, List messages) : + public Pop3ServerSimulator(int maxNumberOfConnections, int port, List messages) : this(maxNumberOfConnections, port, messages, eConnectionSecurity.eCSNone) { } - public POP3Server(int maxNumberOfConnections, int port, List messages, eConnectionSecurity connectionSecurity) : + public Pop3ServerSimulator(int maxNumberOfConnections, int port, List messages, eConnectionSecurity connectionSecurity) : base(maxNumberOfConnections, port, connectionSecurity) { _messages = messages; diff --git a/hmailserver/test/RegressionTests/Shared/SMTPClientSimulator.cs b/hmailserver/test/RegressionTests/Shared/SMTPClientSimulator.cs index 4d11ad6aa..fb9ee1faa 100644 --- a/hmailserver/test/RegressionTests/Shared/SMTPClientSimulator.cs +++ b/hmailserver/test/RegressionTests/Shared/SMTPClientSimulator.cs @@ -13,29 +13,29 @@ namespace RegressionTests.Shared /// /// Summary description for SMTPSimulator. /// - public class SMTPClientSimulator + public class SmtpClientSimulator { private readonly IPAddress _ipaddress; private readonly int _port = 25; private readonly TcpConnection _tcpConnection; - public SMTPClientSimulator() : + public SmtpClientSimulator() : this(false, 25) { } - public SMTPClientSimulator(bool useSSL, int port) : + public SmtpClientSimulator(bool useSSL, int port) : this(useSSL, port, null) { } - public SMTPClientSimulator(bool useSSL, int port, IPAddress ipaddress) : + public SmtpClientSimulator(bool useSSL, int port, IPAddress ipaddress) : this(useSSL, SslProtocols.Default, port, ipaddress) { } - public SMTPClientSimulator(bool useSSL, SslProtocols sslProtocols, int port, IPAddress ipaddress) + public SmtpClientSimulator(bool useSSL, SslProtocols sslProtocols, int port, IPAddress ipaddress) { _tcpConnection = new TcpConnection(useSSL, sslProtocols); _port = port; @@ -43,18 +43,16 @@ public SMTPClientSimulator(bool useSSL, SslProtocols sslProtocols, int port, IPA } - public bool ConnectAndLogon(string base64Username, string base64Password, out string errorMessage) + public void ConnectAndLogon(string base64Username, string base64Password, out string errorMessage) { _tcpConnection.Connect(_port); errorMessage = Receive(); if (!errorMessage.StartsWith("220")) - return false; - - if (!Logon(base64Username, base64Password, out errorMessage)) - return false; + throw new AuthenticationException("Error when connecting: " + errorMessage); - return true; + if (!Logon(base64Username, base64Password, out errorMessage)) + throw new AuthenticationException("Logon failed: " + errorMessage); } private bool Logon(string base64Username, string base64Password, out string errorMessage) @@ -75,6 +73,7 @@ private bool Logon(string base64Username, string base64Password, out string erro errorMessage = SendAndReceive(base64Password + "\r\n"); if (!errorMessage.StartsWith("235")) return false; + return true; } @@ -103,10 +102,12 @@ public string GetWelcomeMessage() return sData; } - public bool Send(string sFrom, List lstRecipients, string sSubject, string sBody) + public void Send(string sFrom, List lstRecipients, string sSubject, string sBody) { if (!_tcpConnection.Connect(_ipaddress, _port)) - return false; + { + throw new DeliveryFailedException("Failed to connect to server"); + } // Receive welcome message. string sData = _tcpConnection.Receive(); @@ -125,7 +126,7 @@ public bool Send(string sFrom, List lstRecipients, string sSubject, stri sData = _tcpConnection.Receive(); if (!sData.StartsWith("250")) - return false; + throw new DeliveryFailedException("Unexpected response from server: " + sData); if (sCommaSeparatedRecipients.Length > 0) sCommaSeparatedRecipients += ", "; @@ -157,7 +158,7 @@ public bool Send(string sFrom, List lstRecipients, string sSubject, stri // Wait for OK. sData = _tcpConnection.Receive(); if (sData.Substring(0, 3) != "250") - return false; + throw new DeliveryFailedException("Unexpected response from server: " + sData); // Quit again _tcpConnection.Send("QUIT\r\n"); @@ -166,22 +167,22 @@ public bool Send(string sFrom, List lstRecipients, string sSubject, stri _tcpConnection.Disconnect(); - return true; + } - public bool Send(string sFrom, string sTo, string sSubject, string sBody) + public void Send(string sFrom, string sTo, string sSubject, string sBody) { string result = ""; - return Send(false, "", "", sFrom, sTo, sSubject, sBody, out result); + Send(false, "", "", sFrom, sTo, sSubject, sBody, out result); } - public bool Send(string sFrom, string sTo, string sSubject, string sBody, out string result) + public void Send(string sFrom, string sTo, string sSubject, string sBody, out string result) { - return Send(false, "", "", sFrom, sTo, sSubject, sBody, out result); + Send(false, "", "", sFrom, sTo, sSubject, sBody, out result); } - public bool Send(bool useStartTls, string username, string password, string sFrom, string sTo, string sSubject, string sBody, out string errorMessage) + public void Send(bool useStartTls, string username, string password, string sFrom, string sTo, string sSubject, string sBody, out string errorMessage) { string sData; @@ -195,7 +196,7 @@ public bool Send(bool useStartTls, string username, string password, string sFro var capabilities1 = SendAndReceive("EHLO example.com\r\n"); if (!capabilities1.Contains("STARTTLS")) - throw new Exception("Server does not support STARTTLS."); + throw new DeliveryFailedException("Server does not support STARTTLS."); SendAndReceive("STARTTLS\r\n"); @@ -205,7 +206,7 @@ public bool Send(bool useStartTls, string username, string password, string sFro if (!string.IsNullOrEmpty(username)) { if (!Logon(EncodeBase64(username), EncodeBase64(password), out errorMessage)) - return false; + throw new DeliveryFailedException("Login failed: " + errorMessage); } _tcpConnection.Send("HELO example.com\r\n"); @@ -220,12 +221,18 @@ public bool Send(bool useStartTls, string username, string password, string sFro if (sData.StartsWith("2") == false) { errorMessage = TrimNewlline(sData); - return false; + throw new DeliveryFailedException("Unexpected response from server: " + errorMessage); } // Select inbox _tcpConnection.Send("DATA\r\n"); - _tcpConnection.Receive(); + sData = _tcpConnection.Receive(); + if (sData.Substring(0, 3) != "354") + { + errorMessage = TrimNewlline(sData); + throw new DeliveryFailedException("Unexpected response from server: " + errorMessage); + } + _tcpConnection.Send("From: " + sFrom + "\r\n"); _tcpConnection.Send("To: " + sTo + "\r\n"); @@ -245,7 +252,7 @@ public bool Send(bool useStartTls, string username, string password, string sFro if (sData.Substring(0, 3) != "250") { errorMessage = TrimNewlline(sData); - return false; + throw new DeliveryFailedException("Unexpected response from server: " + errorMessage); } // Quit again @@ -255,7 +262,6 @@ public bool Send(bool useStartTls, string username, string password, string sFro _tcpConnection.Disconnect(); errorMessage = ""; - return true; } private string TrimNewlline(string input) @@ -263,10 +269,10 @@ private string TrimNewlline(string input) return input.TrimEnd('\r', '\n'); } - public bool SendRaw(string sFrom, string sTo, string text) + public void SendRaw(string sFrom, string sTo, string text) { if (!_tcpConnection.Connect(_port)) - return false; + throw new DeliveryFailedException("Unable to connect."); // Receive welcome message. string sData = _tcpConnection.Receive(); @@ -281,7 +287,7 @@ public bool SendRaw(string sFrom, string sTo, string text) _tcpConnection.Send("RCPT TO:<" + sTo + ">\r\n"); sData = _tcpConnection.Receive(); if (sData.StartsWith("2") == false) - return false; + throw new DeliveryFailedException("Unexpected response from server: " + sData); // Send the message. _tcpConnection.Send("DATA\r\n"); @@ -297,7 +303,7 @@ public bool SendRaw(string sFrom, string sTo, string text) bool success = sData.Substring(0, 3) == "250"; if (!success) - return false; + throw new DeliveryFailedException("Unexpected response from server: " + sData); // Quit again _tcpConnection.Send("QUIT\r\n"); @@ -305,28 +311,27 @@ public bool SendRaw(string sFrom, string sTo, string text) _tcpConnection.Disconnect(); - return success; } - public static bool StaticSend(string sFrom, List lstRecipients, string sSubject, string sBody) + public static void StaticSend(string sFrom, List lstRecipients, string sSubject, string sBody) { - var oSimulator = new SMTPClientSimulator(); - return oSimulator.Send(sFrom, lstRecipients, sSubject, sBody); + var oSimulator = new SmtpClientSimulator(); + oSimulator.Send(sFrom, lstRecipients, sSubject, sBody); } - public static bool StaticSendRaw(string sFrom, string recipient, string sBody) + public static void StaticSendRaw(string sFrom, string recipient, string sBody) { - var oSimulator = new SMTPClientSimulator(); - return oSimulator.SendRaw(sFrom, recipient, sBody); + var oSimulator = new SmtpClientSimulator(); + oSimulator.SendRaw(sFrom, recipient, sBody); } - public static bool StaticSend(string sFrom, string recipient, string sSubject, string sBody) + public static void StaticSend(string sFrom, string recipient, string sSubject, string sBody) { var messageRecipients = new List(); messageRecipients.Add(recipient); - var oSimulator = new SMTPClientSimulator(); - return oSimulator.Send(sFrom, messageRecipients, sSubject, sBody); + var oSimulator = new SmtpClientSimulator(); + oSimulator.Send(sFrom, messageRecipients, sSubject, sBody); } private string EncodeBase64(string s) diff --git a/hmailserver/test/RegressionTests/Shared/SMTPServerSimulator.cs b/hmailserver/test/RegressionTests/Shared/SMTPServerSimulator.cs index 9a1cc9663..2947f8f40 100644 --- a/hmailserver/test/RegressionTests/Shared/SMTPServerSimulator.cs +++ b/hmailserver/test/RegressionTests/Shared/SMTPServerSimulator.cs @@ -23,7 +23,7 @@ internal enum SimulatedErrorType DisconnectAfterMessageAccept } - internal class SMTPServerSimulator : TcpServer + internal class SmtpServerSimulator : TcpServer { private readonly List> _recipientResults; private Dictionary _currentRecipientResult; @@ -41,7 +41,7 @@ internal class SMTPServerSimulator : TcpServer public bool ServerSupportsHelo { get; set; } - public SMTPServerSimulator(int maxNumberOfConnections, int port, eConnectionSecurity connectionSecurity) : + public SmtpServerSimulator(int maxNumberOfConnections, int port, eConnectionSecurity connectionSecurity) : base(maxNumberOfConnections, port, connectionSecurity) { _recipientResults = new List>(); @@ -49,7 +49,7 @@ public SMTPServerSimulator(int maxNumberOfConnections, int port, eConnectionSecu ServerSupportsHelo = true; } - public SMTPServerSimulator(int maxNumberOfConnections, int port) : + public SmtpServerSimulator(int maxNumberOfConnections, int port) : this(maxNumberOfConnections, port, eConnectionSecurity.eCSNone) { diff --git a/hmailserver/test/RegressionTests/Shared/TestSetup.cs b/hmailserver/test/RegressionTests/Shared/TestSetup.cs index c1296f81c..3ad46555c 100644 --- a/hmailserver/test/RegressionTests/Shared/TestSetup.cs +++ b/hmailserver/test/RegressionTests/Shared/TestSetup.cs @@ -20,7 +20,7 @@ namespace RegressionTests.Shared { - internal class TestSetup + public class TestSetup { private Application application; private Settings _settings; @@ -689,5 +689,45 @@ public static int GetNextFreePort() _freePort++; return _freePort; } + + + internal static Route AddRoutePointingAtLocalhost(int numberOfTries, int port, bool treatSecurityAsLocal, eConnectionSecurity connectionSecurity) + { + // Add a route pointing at localhost + Settings oSettings = SingletonProvider.Instance.GetApp().Settings; + + Route route = oSettings.Routes.Add(); + route.DomainName = "dummy-example.com"; + route.TargetSMTPHost = "localhost"; + route.TargetSMTPPort = port; + route.NumberOfTries = numberOfTries; + route.MinutesBetweenTry = 5; + route.TreatRecipientAsLocalDomain = treatSecurityAsLocal; + route.TreatSenderAsLocalDomain = treatSecurityAsLocal; + route.ConnectionSecurity = connectionSecurity; + route.Save(); + + return route; + } + + internal static Route AddRoutePointingAtLocalhost(int numberOfTries, int port, bool treatSecurityAsLocal) + { + return AddRoutePointingAtLocalhost(numberOfTries, port, treatSecurityAsLocal, eConnectionSecurity.eCSNone); + } + + public static Route AddRoutePointingAtLocalhostMultipleHosts(int numberOfTries, int port) + { + // Add a route pointing at localhost + Route route = AddRoutePointingAtLocalhost(numberOfTries, port, false); + route.DomainName = "dummy-example.com"; + route.TargetSMTPHost = "localhost|localhost"; + route.TargetSMTPPort = port; + route.NumberOfTries = numberOfTries; + route.MinutesBetweenTry = 5; + route.Save(); + + return route; + } + } } \ No newline at end of file diff --git a/hmailserver/test/RegressionTests/Stress/ContentStressTest.cs b/hmailserver/test/RegressionTests/Stress/ContentStressTest.cs index ceefc7910..17bb09f9a 100644 --- a/hmailserver/test/RegressionTests/Stress/ContentStressTest.cs +++ b/hmailserver/test/RegressionTests/Stress/ContentStressTest.cs @@ -6,6 +6,7 @@ using System.Net.Sockets; using System.Text; using NUnit.Framework; +using RegressionTests.Infrastructure; using RegressionTests.Shared; using hMailServer; @@ -24,8 +25,8 @@ public void TestLongLineInData() sb.Append("1234567890"); } - var sim = new SMTPClientSimulator(); - Assert.IsFalse(sim.SendRaw("test@test.com", "test@test.com", sb.ToString())); + var sim = new SmtpClientSimulator(); + CustomAsserts.Throws(() => sim.SendRaw("test@test.com", "test@test.com", sb.ToString())); } @@ -264,12 +265,12 @@ public void TestOverlappingBoundaryNames() // Save the rule in the database oRule.Save(); - var oSMTP = new SMTPClientSimulator(); + var smtpClientSimulator = new SmtpClientSimulator(); // Spam folder - oSMTP.SendRaw("mimetest@test.com", "mimetest@test.com", content); + smtpClientSimulator.SendRaw("mimetest@test.com", "mimetest@test.com", content); - string sContents = POP3ClientSimulator.AssertGetFirstMessageText("mimetest@test.com", "test"); + string sContents = Pop3ClientSimulator.AssertGetFirstMessageText("mimetest@test.com", "test"); Assert.IsTrue(sContents.IndexOf("SomeHeader: SomeValue") > 0); Assert.IsTrue(sContents.IndexOf("------=_NextPart_000_000D_01C97C94.33D5E670.ALT--") > 0); diff --git a/hmailserver/test/RegressionTests/Stress/StabilitySanityTests.cs b/hmailserver/test/RegressionTests/Stress/StabilitySanityTests.cs index ce8f3872b..5e66b3e6f 100644 --- a/hmailserver/test/RegressionTests/Stress/StabilitySanityTests.cs +++ b/hmailserver/test/RegressionTests/Stress/StabilitySanityTests.cs @@ -21,7 +21,7 @@ public void TestDeletionOfMessageInDeletedFolder() Application application = SingletonProvider.Instance.GetApp(); string deletedMessageText = _settings.ServerMessages.get_ItemByName("MESSAGE_FILE_MISSING").Text; Account account = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody"); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody"); IMAPFolder inbox = account.IMAPFolders.get_ItemByName("Inbox"); CustomAsserts.AssertFolderMessageCount(inbox, 1); @@ -113,7 +113,7 @@ public void TestRetrievalOfDeletedMessage() Account account = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody"); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody"); IMAPFolder inbox = account.IMAPFolders.get_ItemByName("Inbox"); @@ -124,7 +124,7 @@ public void TestRetrievalOfDeletedMessage() File.Delete(message.Filename); - string text = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); + string text = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); Assert.IsTrue(text.Contains(deletedMessageText.Replace("%MACRO_FILE%", message.Filename))); CustomAsserts.AssertReportedError("Message retrieval failed because message file"); @@ -138,7 +138,7 @@ public void TestRetrievalOfMessageInDeletedFolder() Account account = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody"); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody"); IMAPFolder inbox = account.IMAPFolders.get_ItemByName("Inbox"); @@ -151,7 +151,7 @@ public void TestRetrievalOfMessageInDeletedFolder() DirectoryInfo parent = dir.Parent.Parent.Parent; parent.Delete(true); - string text = POP3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); + string text = Pop3ClientSimulator.AssertGetFirstMessageText(account.Address, "test"); Assert.IsTrue(text.Contains(deletedMessageText.Replace("%MACRO_FILE%", message.Filename))); CustomAsserts.AssertReportedError("Message retrieval failed because message file"); } @@ -165,7 +165,7 @@ public void TestRetrievalOfMessageInDeletedFolderUsingIMAP() Account account = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); - SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody"); + SmtpClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody"); IMAPFolder inbox = account.IMAPFolders.get_ItemByName("Inbox"); @@ -178,7 +178,7 @@ public void TestRetrievalOfMessageInDeletedFolderUsingIMAP() DirectoryInfo parent = dir.Parent.Parent.Parent; parent.Delete(true); - var sim = new IMAPClientSimulator(); + var sim = new ImapClientSimulator(); sim.ConnectAndLogon(account.Address, "test"); sim.SelectFolder("INBOX"); string result = sim.Fetch("1 BODY[1]"); diff --git a/hmailserver/test/StressTest/DKIM.cs b/hmailserver/test/StressTest/DKIM.cs index e279089d5..eb2f3106a 100644 --- a/hmailserver/test/StressTest/DKIM.cs +++ b/hmailserver/test/StressTest/DKIM.cs @@ -92,18 +92,19 @@ public void TestDKIMUnsupported() public void TestDKIMBadSignature() { hMailServer.AntiSpam antiSpam = _application.Settings.AntiSpam; - - string folder = Path.GetFullPath("../../../TestData/DKIM/PermFail"); - string path = Path.Combine(Environment.CurrentDirectory, folder); - string[] files = Directory.GetFiles(path); - - foreach (string file in files) - { - DeleteCurrentLog(); - hMailServer.eDKIMResult result = antiSpam.DKIMVerify(file); - Assert.AreEqual(hMailServer.eDKIMResult.eDKPermFail, result, file); - Assert.IsFalse(VerifyLoadSuccess()); - } + + + string folder = Path.GetFullPath("../../../TestData/DKIM/PermFail"); + string path = Path.Combine(Environment.CurrentDirectory, folder); + string[] files = Directory.GetFiles(path); + + foreach (string file in files) + { + DeleteCurrentLog(); + hMailServer.eDKIMResult result = antiSpam.DKIMVerify(file); + Assert.AreEqual(hMailServer.eDKIMResult.eDKPermFail, result, file); + Assert.IsFalse(VerifyLoadSuccess()); + } } [Test] diff --git a/hmailserver/test/StressTest/IMAP.cs b/hmailserver/test/StressTest/IMAP.cs index 211dd4b50..3bcf856c2 100644 --- a/hmailserver/test/StressTest/IMAP.cs +++ b/hmailserver/test/StressTest/IMAP.cs @@ -20,7 +20,7 @@ public class IMAP : TestFixtureBase [Test] public void TestLongIMAPCommand() { - IMAPClientSimulator sim = ConnectAndLogon(); + ImapClientSimulator sim = ConnectAndLogon(); // build a large string. StringBuilder sb = new StringBuilder(); @@ -40,9 +40,9 @@ public void TestLongIMAPCommand() } - private static IMAPClientSimulator ConnectAndLogon() + private static ImapClientSimulator ConnectAndLogon() { - IMAPClientSimulator sim = new IMAPClientSimulator(); + ImapClientSimulator sim = new ImapClientSimulator(); sim.ConnectAndLogon("test@test.com", "test"); return sim; } diff --git a/hmailserver/test/StressTest/POP3.cs b/hmailserver/test/StressTest/POP3.cs index 83f79348e..b28577134 100644 --- a/hmailserver/test/StressTest/POP3.cs +++ b/hmailserver/test/StressTest/POP3.cs @@ -24,7 +24,7 @@ public void TestPOP3DownloadOfLargeMessage() { Send100MBMessage(); - POP3ClientSimulator.AssertMessageCount("test@test.com", "test", 1); + Pop3ClientSimulator.AssertMessageCount("test@test.com", "test", 1); TcpConnection socket = new TcpConnection(); socket.Connect(110); @@ -126,7 +126,7 @@ public void Send100MBMessage() result = socket.Receive(); socket.Disconnect(); - POP3ClientSimulator.AssertMessageCount(_domain.Accounts[0].Address, "test", 1); + Pop3ClientSimulator.AssertMessageCount(_domain.Accounts[0].Address, "test", 1); } } } diff --git a/hmailserver/test/StressTest/SMTP.cs b/hmailserver/test/StressTest/SMTP.cs index 313b5d5e7..2230106c8 100644 --- a/hmailserver/test/StressTest/SMTP.cs +++ b/hmailserver/test/StressTest/SMTP.cs @@ -48,7 +48,7 @@ public void TestLargeDistributionList() var sw = new Stopwatch(); sw.Start(); - SMTPClientSimulator.StaticSend("test@test.com", "list@test.com", "Test", "Test message"); + SmtpClientSimulator.StaticSend("test@test.com", "list@test.com", "Test", "Test message"); sw.Stop(); Console.WriteLine("Elapsed time: " + sw.Elapsed.TotalSeconds); @@ -103,7 +103,7 @@ public void TestSendToManyRecipients() var sw = new Stopwatch(); sw.Start(); - SMTPClientSimulator.StaticSend("test@test.com", recipients, "Test", "Test message"); + SmtpClientSimulator.StaticSend("test@test.com", recipients, "Test", "Test message"); sw.Stop(); Console.WriteLine("Elapsed time: " + sw.Elapsed.TotalSeconds); @@ -181,7 +181,7 @@ public void TestSend200KMessages() for (int i = 1; i <= numberOfMessages; i++) { - Assert.IsTrue(SMTPClientSimulator.StaticSend("test@test.com", "test@test.com", "Test", "Test message")); + SmtpClientSimulator.StaticSend("test@test.com", "test@test.com", "Test", "Test message"); if (i % 100 == 0) { @@ -351,7 +351,7 @@ public void TestLongSMTPDataSessionIncludingNewline() socket.Receive(); socket.Disconnect(); - POP3ClientSimulator.AssertMessageCount(_domain.Accounts[0].Address, "test", 1); + Pop3ClientSimulator.AssertMessageCount(_domain.Accounts[0].Address, "test", 1); } diff --git a/hmailserver/test/StressTest/SpamAssassin.cs b/hmailserver/test/StressTest/SpamAssassin.cs index 798dd1a0d..1f6c4d27f 100644 --- a/hmailserver/test/StressTest/SpamAssassin.cs +++ b/hmailserver/test/StressTest/SpamAssassin.cs @@ -38,14 +38,14 @@ public void SingleThread() { for (int i = 0; i < 15; i++) { - SMTPClientSimulator.StaticSend("test@test.com", "test@test.com", "test", "test"); + SmtpClientSimulator.StaticSend("test@test.com", "test@test.com", "test", "test"); } - POP3ClientSimulator.AssertMessageCount(_account.Address, "test", 15); + Pop3ClientSimulator.AssertMessageCount(_account.Address, "test", 15); for (int i = 0; i < 15; i++) { - string content = POP3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); + string content = Pop3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); Assert.IsTrue(content.Contains("X-Spam-Status"), content); } @@ -74,11 +74,11 @@ public void MultiThread() t.Join(); } - POP3ClientSimulator.AssertMessageCount(_account.Address, "test", totalMessageCount); + Pop3ClientSimulator.AssertMessageCount(_account.Address, "test", totalMessageCount); for (int i = 0; i < totalMessageCount; i++) { - string content = POP3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); + string content = Pop3ClientSimulator.AssertGetFirstMessageText(_account.Address, "test"); Assert.IsTrue(content.Contains("X-Spam-Status"), content); } @@ -88,7 +88,7 @@ private void SendMessageThread() { for (int message = 0; message < _threadedMessageCount; message++) { - SMTPClientSimulator.StaticSend("test@test.com", "test@test.com", "test", "test"); + SmtpClientSimulator.StaticSend("test@test.com", "test@test.com", "test", "test"); } } diff --git a/hmailserver/test/StressTest/StressTest.csproj b/hmailserver/test/StressTest/StressTest.csproj index 70988505d..a672e9c1d 100644 --- a/hmailserver/test/StressTest/StressTest.csproj +++ b/hmailserver/test/StressTest/StressTest.csproj @@ -60,39 +60,6 @@ - - External\CustomAsserts.cs - - - External\LogHandler.cs - - - External\RetryHelper.cs - - - External\IMAPClientSimulator.cs - - - External\POP3ClientSimulator.cs - - - External\SingletonProvider.cs - - - External\SMTPClientSimulator.cs - - - External\TcpConnection.cs - - - External\TestFixtureBase.cs - - - External\TestSetup.cs - - - External\TestTracer.cs - @@ -117,6 +84,10 @@ {CBDEF4D1-5545-4693-B6DF-17D6EDE484CF} hMailServer.Test.Infrastructure + + {8f691179-0851-4a25-ac78-3548dd0514fa} + RegressionTests + + \ No newline at end of file diff --git a/hmailserver/test/hMailServer.PerformanceTests/hMailServer.PerformanceTests.sln b/hmailserver/test/hMailServer.PerformanceTests/hMailServer.PerformanceTests.sln new file mode 100644 index 000000000..fa585860d --- /dev/null +++ b/hmailserver/test/hMailServer.PerformanceTests/hMailServer.PerformanceTests.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.30723.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "hMailServer.PerformanceTests", "hMailServer.PerformanceTests\hMailServer.PerformanceTests.csproj", "{B9678F32-2E33-49E3-B385-D60790A77B82}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RegressionTests", "..\RegressionTests\RegressionTests.csproj", "{8F691179-0851-4A25-AC78-3548DD0514FA}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B9678F32-2E33-49E3-B385-D60790A77B82}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B9678F32-2E33-49E3-B385-D60790A77B82}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B9678F32-2E33-49E3-B385-D60790A77B82}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B9678F32-2E33-49E3-B385-D60790A77B82}.Release|Any CPU.Build.0 = Release|Any CPU + {8F691179-0851-4A25-AC78-3548DD0514FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8F691179-0851-4A25-AC78-3548DD0514FA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8F691179-0851-4A25-AC78-3548DD0514FA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8F691179-0851-4A25-AC78-3548DD0514FA}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/hmailserver/test/hMailServer.PerformanceTests/hMailServer.PerformanceTests/AverageMailSending.cs b/hmailserver/test/hMailServer.PerformanceTests/hMailServer.PerformanceTests/AverageMailSending.cs new file mode 100644 index 000000000..5fba0dd48 --- /dev/null +++ b/hmailserver/test/hMailServer.PerformanceTests/hMailServer.PerformanceTests/AverageMailSending.cs @@ -0,0 +1,129 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Net.Mail; +using System.Text; +using System.Threading.Tasks; +using NUnit.Framework; +using RegressionTests.Infrastructure; +using RegressionTests.Shared; + +namespace hMailServer.PerformanceTests +{ + [TestFixture] + public class AverageMailSending : TestFixtureBase + { + private hMailServer.Account _account; + + [SetUp] + public new void SetUp() + { + _account = SingletonProvider.Instance.AddAccount(_domain, "test@test.com", "test"); + } + + [Test] + public void Send1000MessagesOn5Threads() + { + SendMessagesInParallell(5, 1000); + } + + [Test] + public void Send1000MessagesOn10Threads() + { + SendMessagesInParallell(10, 1000); + } + + [Test] + public void Send10000MessagesOn5Threads() + { + SendMessagesInParallell(5, 10000); + } + + + private void SendMessagesInParallell(int threadCount, int messagesPerThread) + { + var actions = new List(); + + for (int i = 0; i < threadCount; i++) + { + actions.Add(new Action(() => SendMessages(messagesPerThread))); + } + + var parallellOptions = new ParallelOptions() + { + MaxDegreeOfParallelism = actions.Count + }; + + MeasureTime( + () => + { + Parallel.Invoke(parallellOptions, actions.ToArray()); + + WaitForMessageCount(TimeSpan.FromMinutes(5), threadCount*messagesPerThread); + }); + } + + private void WaitForMessageCount(TimeSpan timeout, int expectedMessageCount) + { + RetryHelper.TryAction(timeout, () => + { + var pop3ClientSimulator = new POP3ClientSimulator(); + int count = pop3ClientSimulator.GetMessageCount("test@test.com", "test"); + + Assert.AreEqual(expectedMessageCount, count); + }); + } + + private MailMessage CreateMailMessage() + { + // body is 75kb, which according to some represents the average email size. + + var body = new StringBuilder(); + + for (int i = 0; i < 1024; i++) + { + body.AppendLine(new string('a', 75)); + } + + var mailMessage = new MailMessage() + { + From = new MailAddress("test@test.com"), + Subject = Guid.NewGuid().ToString(), + Body = body.ToString() + }; + + mailMessage.To.Add(new MailAddress("test@test.com")); + + return mailMessage; + } + + private void SendMessages(int count) + { + var mailMessage = CreateMailMessage(); + for (int i = 0; i < count; i++) + { + using (var client = new SmtpClient()) + { + // send mail synchronously. + client.Host = "127.0.0.1"; + client.SendMailAsync(mailMessage).Wait(); + } + + } + } + + private void MeasureTime(Action action) + { + // stopwatch isn't exact, but exact enough for this type of measurement. + var stopwatch = new Stopwatch(); + stopwatch.Start(); + + action(); + + stopwatch.Stop(); + + Console.WriteLine("{0};{1};{2};{3}", _application.Version, TestContext.CurrentContext.Test.FullName, DateTime.UtcNow.ToString("yyyyMMdd HH:mm:ss"), stopwatch.Elapsed); + } + + } +} diff --git a/hmailserver/test/hMailServer.PerformanceTests/hMailServer.PerformanceTests/Properties/AssemblyInfo.cs b/hmailserver/test/hMailServer.PerformanceTests/hMailServer.PerformanceTests/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..c8d24a588 --- /dev/null +++ b/hmailserver/test/hMailServer.PerformanceTests/hMailServer.PerformanceTests/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("hMailServer.PerformanceTests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("hMailServer.PerformanceTests")] +[assembly: AssemblyCopyright("Copyright © 2014")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("4af75fa6-3998-4d6c-a0b8-1b63507f966b")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/hmailserver/test/hMailServer.PerformanceTests/hMailServer.PerformanceTests/TestPerformanceInfo.cs b/hmailserver/test/hMailServer.PerformanceTests/hMailServer.PerformanceTests/TestPerformanceInfo.cs new file mode 100644 index 000000000..4330179b5 --- /dev/null +++ b/hmailserver/test/hMailServer.PerformanceTests/hMailServer.PerformanceTests/TestPerformanceInfo.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace hMailServer.PerformanceTests +{ + public static class TestPerformanceInfo + { + public static Dictionary Timings = new Dictionary(); + } +} diff --git a/hmailserver/test/hMailServer.PerformanceTests/hMailServer.PerformanceTests/hMailServer.PerformanceTests.csproj b/hmailserver/test/hMailServer.PerformanceTests/hMailServer.PerformanceTests/hMailServer.PerformanceTests.csproj new file mode 100644 index 000000000..d09d04c3a --- /dev/null +++ b/hmailserver/test/hMailServer.PerformanceTests/hMailServer.PerformanceTests/hMailServer.PerformanceTests.csproj @@ -0,0 +1,76 @@ + + + + + Debug + AnyCPU + {B9678F32-2E33-49E3-B385-D60790A77B82} + Library + Properties + hMailServer.PerformanceTests + hMailServer.PerformanceTests + v4.5 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + x86 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + x86 + + + + ..\..\..\..\libraries\nunit-2.6.3\nunit.framework.dll + + + + + + + + + + + + + + + + + {DB241B59-A1B1-4C59-98FC-8D101A2995F2} + 1 + 0 + 0 + tlbimp + False + False + + + + + {8f691179-0851-4a25-ac78-3548dd0514fa} + RegressionTests + + + + + \ No newline at end of file