public void TestFixtureSetUp() { SingletonProvider<Utilities>.Instance.Authenticate(); _application = SingletonProvider<Utilities>.Instance.GetApp(); _settings = _application.Settings; }
public new void SetUp() { Utilities.AssertSpamAssassinIsRunning(); // Enable spam assassin application = SingletonProvider<Utilities>.Instance.GetApp(); hMailServer.AntiSpam antiSpam = _settings.AntiSpam; ; account = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); // Disallow incorrect line endings. antiSpam.SpamMarkThreshold = 1; antiSpam.SpamDeleteThreshold = 10000; antiSpam.AddHeaderReason = true; antiSpam.AddHeaderSpam = true; antiSpam.PrependSubject = true; antiSpam.PrependSubjectText = "ThisIsSpam"; // Enable SpamAssassin antiSpam.SpamAssassinEnabled = true; antiSpam.SpamAssassinHost = "localhost"; antiSpam.SpamAssassinPort = 783; antiSpam.SpamAssassinMergeScore = false; antiSpam.SpamAssassinScore = 5; }
public void TestDomainAdminAccessOtherDomain() { hMailServer.Account account = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); account.AdminLevel = hMailServer.eAdminLevel.hAdminLevelDomainAdmin; account.Save(); SingletonProvider<Utilities>.Instance.AddDomain("example.com"); hMailServer.Application newApplication = new hMailServer.Application(); newApplication.Authenticate("*****@*****.**", "test"); Assert.AreEqual(1, newApplication.Domains.Count); hMailServer.Domains domains = SingletonProvider<Utilities>.Instance.GetApp().Domains; Assert.AreEqual(2, domains.Count); try { hMailServer.Domain secondDomain = newApplication.Domains.get_ItemByName("example.com"); Assert.Fail(); } catch (COMException ex) { Assert.IsTrue(ex.Message.Contains("Invalid index.")); } }
public void LoadData() { _application = APICreator.Application; labelVersion.Text = string.Format("{0} ({1})", _application.Version, _application.VersionArchitecture); ShowStatistics(); hMailServer.Database database = _application.Database; labelServerType.Text = InternalNames.GetDatabaseServerTypeName(database.DatabaseType); if (database.ServerName.Length > 0) labelServerHost.Text = database.ServerName; else labelServerHost.Text = "-"; if (database.DatabaseName.Length > 0 && database.DatabaseType != eDBtype.hDBTypeMSSQLCE) labelName.Text = database.DatabaseName; else labelName.Text = "-"; labelDBVersion.Text = database.CurrentVersion.ToString(); Marshal.ReleaseComObject(database); hMailServer.Settings settings = _application.Settings; _logging = settings.Logging; Marshal.ReleaseComObject(settings); DisplayServerState(); DisplayWarnings(); }
public formMain(hMailServer.Application application) { InitializeComponent(); _application = application; _databaseType = null; }
public ucProgress() { InitializeComponent(); _application = Globals.GetApp(); _utilities = _application.Utilities; _domains = _application.Domains; _counter = 0; }
public void TestDomainAdminAccessSettings() { hMailServer.Account account = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); account.AdminLevel = hMailServer.eAdminLevel.hAdminLevelDomainAdmin; account.Save(); hMailServer.Application newApplication = new hMailServer.Application(); newApplication.Authenticate("*****@*****.**", "test"); hMailServer.Settings settings = newApplication.Settings; }
static void Main() { CommandLineParser.Parse(); _application = new hMailServer.Application(); if (_application.Database.DatabaseExists) UpgradeDatabase(); else CreateDatabase(); }
public void TestDomainAdminAccessDatabase() { hMailServer.Account account = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); account.AdminLevel = hMailServer.eAdminLevel.hAdminLevelDomainAdmin; account.Save(); hMailServer.Application newApplication = new hMailServer.Application(); newApplication.Authenticate("*****@*****.**", "test"); hMailServer.Database database = newApplication.Database; database.ExecuteSQL("select"); }
public void TestCriteriaMatching() { hMailServer.Application app = SingletonProvider <Utilities> .Instance.GetApp(); hMailServer.Utilities utilities = app.Utilities; Assert.IsTrue(utilities.CriteriaMatch("Test", hMailServer.eRuleMatchType.eMTEquals, "Test")); Assert.IsFalse(utilities.CriteriaMatch("Testa", hMailServer.eRuleMatchType.eMTEquals, "Test")); Assert.IsTrue(utilities.CriteriaMatch("Test*", hMailServer.eRuleMatchType.eMTWildcard, "Testar!")); Assert.IsFalse(utilities.CriteriaMatch("Test*", hMailServer.eRuleMatchType.eMTWildcard, "Tesb")); }
public void NormalUserShouldNotBeAbleToAddDomain() { hMailServer.Domain domain = SingletonProvider <Utilities> .Instance.AddTestDomain(); // Create an account with normal privileges. hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(domain, "*****@*****.**", "test"); hMailServer.Application newApp = new hMailServer.Application(); hMailServer.Account authenticated = newApp.Authenticate(account.Address, "test"); Assert.IsNotNull(authenticated); // This should throw an exception. hMailServer.Domain newDomain = newApp.Domains.Add(); }
public void TestLanguages() { hMailServer.Application application = SingletonProvider <Utilities> .Instance.GetApp(); hMailServer.Language oLanguageSwedish = application.GlobalObjects.Languages.get_ItemByName("swedish"); hMailServer.Language oLanguageEnglish = application.GlobalObjects.Languages.get_ItemByName("english"); string sSWE = oLanguageSwedish.get_String("File"); string sENG = oLanguageEnglish.get_String("File"); Assert.AreEqual(sENG, "File"); Assert.AreNotEqual(sSWE, sENG); Assert.AreNotEqual(sSWE, ""); }
public void NormalUserShouldNotBeAbleToAddDomain() { hMailServer.Domain domain = SingletonProvider<Utilities>.Instance.AddTestDomain(); // Create an account with normal privileges. hMailServer.Account account = SingletonProvider<Utilities>.Instance.AddAccount(domain, "*****@*****.**", "test"); hMailServer.Application newApp = new hMailServer.Application(); hMailServer.Account authenticated = newApp.Authenticate(account.Address, "test"); Assert.IsNotNull(authenticated); // This should throw an exception. hMailServer.Domain newDomain = newApp.Domains.Add(); }
public void TestOnAcceptMessageVBScript() { hMailServer.Application application = SingletonProvider <Utilities> .Instance.GetApp(); string eventLogFile = _settings.Logging.CurrentEventLog; if (File.Exists(eventLogFile)) { File.Delete(eventLogFile); } // First set up a script string script = @"Sub OnAcceptMessage(oClient, oMessage) oMessage.HeaderValue(""X-SpamResult"") = ""TEST"" oMessage.Save() EventLog.Write(""Port: "" & oClient.Port) EventLog.Write(""Address: "" & oClient.IPAddress) EventLog.Write(""Username: "" & oClient.Username) End Sub"; hMailServer.Scripting scripting = _settings.Scripting; string file = scripting.CurrentScriptFile; Utilities.WriteFile(file, script); scripting.Enabled = true; scripting.Reload(); // Add an account and send a message to it. hMailServer.Account oAccount1 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); SMTPClientSimulator.StaticSend(oAccount1.Address, oAccount1.Address, "Test", "SampleBody"); // Check that the message exists string message = POP3Simulator.AssertGetFirstMessageText(oAccount1.Address, "test"); Assert.IsNotEmpty(message); Assert.Less(0, message.IndexOf("X-SpamResult: TEST")); // Check that the message exists message = Utilities.ReadExistingTextFile(eventLogFile); Assert.IsNotEmpty(message); Assert.IsTrue(message.Contains("Port: 25")); Assert.IsTrue(message.Contains("Address: 127")); Assert.IsTrue(message.Contains("Username: \"")); // Should be empty, Username isn't available at this time. }
public void TestMaxSizeNoLimit() { hMailServer.Application application = SingletonProvider <Utilities> .Instance.GetApp(); // Create a test account // Fetch the default domain ; hMailServer.Account oAccount1 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); // Disallow incorrect line endings. _antiSpam.SpamMarkThreshold = 1; _antiSpam.SpamDeleteThreshold = 100; _antiSpam.AddHeaderReason = true; _antiSpam.AddHeaderSpam = true; _antiSpam.PrependSubject = true; _antiSpam.PrependSubjectText = "ThisIsSpam"; _antiSpam.MaximumMessageSize = 0; // Enable SURBL. hMailServer.SURBLServer oSURBLServer = _antiSpam.SURBLServers[0]; oSURBLServer.Active = true; oSURBLServer.Score = 5; oSURBLServer.Save(); // Send a messages to this account. SMTPClientSimulator oSMTP = new SMTPClientSimulator(); StringBuilder sb = new StringBuilder(); int iterations = ((40 * 1024) / 100) + 1; for (int i = 0; i < iterations; i++) { sb.Append("1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\r\n"); } Assert.IsTrue(oSMTP.Send("*****@*****.**", "*****@*****.**", "SURBL-No-Match", "This is a test message with a SURBL url: -> http://surbl-org-permanent-test-point.com/ <-\r\n" + sb.ToString())); string sMessageContents = POP3Simulator.AssertGetFirstMessageText(oAccount1.Address, "test"); if (!sMessageContents.Contains("X-hMailServer-Spam") || !sMessageContents.Contains("X-hMailServer-Reason") || !sMessageContents.Contains("ThisIsSpam")) { throw new Exception("Spam message not detected as spam."); } oSURBLServer.Active = false; oSURBLServer.Save(); }
public formMain(hMailServer.Application app, string serverHost) { InitializeComponent(); application = app; _serverHost = serverHost; currentlySelectedNode = null; _language = "English"; LoadWindowSettings(); _language = Strings.LoadLanguage(_language); Strings.Localize(this); }
public void TestDuplicateRoutes() { hMailServer.Application app = SingletonProvider <Utilities> .Instance.GetApp(); hMailServer.Routes routes = app.Settings.Routes; hMailServer.Route route = routes.Add(); route.DomainName = "test.com"; route.Save(); hMailServer.Route route2 = routes.Add(); route2.DomainName = "test.com"; route2.Save(); }
static internal void AskRestartServer() { if (MessageBox.Show(Strings.Localize("hMailServer needs to be restarted for the changes to take effect.") + Environment.NewLine + Strings.Localize("Do you want to restart hMailServer now?"), EnumStrings.hMailServerAdministrator, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { using (new WaitCursor()) { hMailServer.Application application = APICreator.Application; application.Stop(); application.Start(); MessageBox.Show(Strings.Localize("The hMailServer server has been restarted."), EnumStrings.hMailServerAdministrator, MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
private void buttonDefault_Click(object sender, EventArgs e) { if (MessageBox.Show(Strings.Localize("This operation will change the configuration of the TCP/IP ports to their default values. Are you sure you want to do this?"), EnumStrings.hMailServerAdministrator, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { hMailServer.Application app = APICreator.Application; hMailServer.TCPIPPorts tcpIPPorts = APICreator.TCPIPPortsSettings; tcpIPPorts.SetDefault(); Marshal.ReleaseComObject(tcpIPPorts); LoadList(); Instances.MainForm.RefreshCurrentNode(null); } }
public bool SaveData() { hMailServer.Application app = APICreator.Application; hMailServer.Settings settings = app.Settings; settings.SslCipherList = textSslCipherList.Text; Marshal.ReleaseComObject(settings); Utility.AskRestartServer(); DirtyChecker.SetClean(this); return(true); }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); CommandLineParser.Parse(); hMailServer.Application application = new hMailServer.Application(); if (!Authenticator.AuthenticateUser(application)) return; Globals.SetApp(application); Application.Run(new formMain()); }
public HMailService(string host, string username, string password, string domain, string counterServer, string counterDatabase, string counterUsername, string counterPassword, int counterPort) { _Host = host; _Username = username; _Password = password; _Domain = domain; _CounterServer = counterServer; _CounterDatabase = counterDatabase; _CounterUsername = counterUsername; _CounterPassword = counterPassword; _CounterPort = counterPort; _App = InitApp(); }
public void Run() { hMailServer.Application applicaiton = new hMailServer.Application(); applicaiton.Authenticate("Administrator", "testar"); // Run DNS query tests. TestDNSQueries test = new TestDNSQueries(applicaiton); test.Prepare(); int iMemoryUsageBefore = Utilities.GetMemoryUsage(); test.Run(); int iMemoryUsageAfter = Utilities.GetMemoryUsage(); int iBytesDiff = iMemoryUsageAfter - iMemoryUsageBefore; if (iBytesDiff > test.MaxIncrease) throw new Exception("Memory leak found: " + iBytesDiff.ToString() + " bytes leaked"); }
public void LoadData() { hMailServer.Application app = APICreator.Application; hMailServer.Settings settings = app.Settings; checkVerifyRemoteServerSslCertificate.Checked = settings.VerifyRemoteSslCertificate; textSslCipherList.Text = settings.SslCipherList; checkTlsVersion10.Checked = settings.TlsVersion10Enabled; checkTlsVersion11.Checked = settings.TlsVersion11Enabled; checkTlsVersion12.Checked = settings.TlsVersion12Enabled; checkTlsVersion13.Checked = settings.TlsVersion13Enabled; Marshal.ReleaseComObject(settings); }
static void Main() { CommandLineParser.Parse(); _application = new hMailServer.Application(); if (_application.Database.DatabaseExists) { UpgradeDatabase(); } else { CreateDatabase(); } }
public void TestMetaDataSortSubjectGreek() { hMailServer.Application application = SingletonProvider <Utilities> .Instance.GetApp(); hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "meta'*****@*****.**", "test"); // disable... SendMessage("Test Σ", "Body", "", ""); IMAPSimulator.AssertMessageCount(account.Address, "test", "Inbox", 1); // pos: 18 SendMessage("Test Α", "Body", "", ""); IMAPSimulator.AssertMessageCount(account.Address, "test", "Inbox", 2); // pos: 1 SendMessage("Test Δ", "Body", "", ""); IMAPSimulator.AssertMessageCount(account.Address, "test", "Inbox", 3); // pos: 4 SendMessage("Test β", "Body", "", ""); IMAPSimulator.AssertMessageCount(account.Address, "test", "Inbox", 4); // pos: 2 SendMessage("Test κ", "Body", "", ""); IMAPSimulator.AssertMessageCount(account.Address, "test", "Inbox", 5); // pos: 10 SendMessage("Test Ψ", "Body", "", ""); IMAPSimulator.AssertMessageCount(account.Address, "test", "Inbox", 6); // pos: 23 AssertAllMessagesIndexed(); IMAPSimulator sim = new IMAPSimulator(account.Address, "test", "Inbox"); string result = sim.Sort("(SUBJECT) UTF-8 ALL"); Assert.AreEqual("2 4 3 5 1 6", result); // Disable the indexing functionality _indexing.Enabled = false; _indexing.Clear(); // Make sure the sort order is the same. string resultAfter = sim.Sort("(SUBJECT) UTF-8 ALL"); Assert.AreEqual(result, resultAfter); }
public void TestSearchUID() { hMailServer.Application application = SingletonProvider <Utilities> .Instance.GetApp(); ; hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); // Send a message to this account. SMTPClientSimulator oSMTP = new SMTPClientSimulator(); for (int i = 0; i < 3; i++) { oSMTP.Send("*****@*****.**", "*****@*****.**", "Test1", "This is a test of IMAP Search"); } IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 3); // There should be 3 UID's, 1,2,3 or similar. No skips in the middle fo them. IMAPSimulator oSimulator = new IMAPSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon("*****@*****.**", "test"); Assert.IsTrue(oSimulator.SelectFolder("INBOX")); string result = oSimulator.SendSingleCommand("* UID SEARCH UID 1:*"); // Potentially, the response is multiline. (UID RESPONSE and an OK line). We only want the first line... result = result.Substring(0, result.IndexOf("\r\n")); string [] tokens = Microsoft.VisualBasic.Strings.Split(result, " ", -1, Microsoft.VisualBasic.CompareMethod.Text); List <int> uids = new List <int>(); foreach (string token in tokens) { int temp; if (Int32.TryParse(token, out temp)) { uids.Add(temp); } } Assert.AreEqual(3, uids.Count, result); Assert.AreEqual(1, uids[0]); Assert.AreEqual(2, uids[1]); Assert.AreEqual(3, uids[2]); }
private bool IsAuthHMail(hMailServer.Application hApp) { string hAdministrator = txtHAdmin.Text; string hPassword = txtHPassword.Text; hMailServer.Account authenticated = hApp.Authenticate(hAdministrator, hPassword); if (authenticated != null) { return(true); } txtLog.AppendText("hAdministrator или hPassword неправильный!" + Environment.NewLine); return(false); }
public void TestImproperDisconnect() { hMailServer.Application application = SingletonProvider <Utilities> .Instance.GetApp(); hMailServer.Account oAccount = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); int iCount = application.Status.get_SessionCount(hMailServer.eSessionType.eSTPOP3); POP3Simulator oPOP3 = new POP3Simulator(); oPOP3.Connect(110); AssertSessionCount(hMailServer.eSessionType.eSTPOP3, iCount + 1); oPOP3.Disconnect(); // Disconnect without sending quit AssertSessionCount(hMailServer.eSessionType.eSTPOP3, iCount); }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); CommandLineParser.Parse(); hMailServer.Application application = new hMailServer.Application(); if (!Authenticator.AuthenticateUser(application)) { return; } Globals.SetApp(application); Application.Run(new formMain()); }
public ucScripts() { InitializeComponent(); DirtyChecker.SubscribeToChange(this, OnContentChanged); new TabOrderManager(this).SetTabOrder(TabOrderManager.TabScheme.AcrossFirst); comboLanguage.AddItem("VBScript", "VBScript"); comboLanguage.AddItem("JScript", "JScript"); hMailServer.Application app = APICreator.Application; hMailServer.Settings settings = app.Settings; _scriptingSettings = app.Settings.Scripting; Marshal.ReleaseComObject(settings); }
private hMailServer.Application GetApp() { hMailServer.Application application = new hMailServer.Application(); hMailServer.Account account = application.Authenticate("Administrator", ""); if (account != null) return application; account = application.Authenticate("Administrator", "testar"); if (account != null) return application; MessageBox.Show("Authentication failed", "Database password"); return null; }
public void TestHeloSpamTest() { hMailServer.Application application = SingletonProvider <Utilities> .Instance.GetApp(); hMailServer.Account oAccount1 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); // Disallow incorrect line endings. _antiSpam.SpamDeleteThreshold = 100; _antiSpam.CheckHostInHelo = true; _antiSpam.CheckHostInHeloScore = 125; // Send a messages to this account. SMTPClientSimulator oSMTP = new SMTPClientSimulator(); Assert.IsFalse(oSMTP.Send("*****@*****.**", "*****@*****.**", "SURBL-Match", "Test")); }
public void TestFormatVariations() { hMailServer.Application application = SingletonProvider <Utilities> .Instance.GetApp(); hMailServer.WhiteListAddresses obAddresses = _antiSpam.WhiteListAddresses; hMailServer.WhiteListAddress obAddress = obAddresses.Add(); string address = @"A%B/C\[email protected]"; obAddress.EmailAddress = address; Assert.AreEqual(address, obAddress.EmailAddress); address = @"\%%%__\[email protected]"; obAddress.EmailAddress = address; Assert.AreEqual(address, obAddress.EmailAddress); }
private void formDatabasePassword_Load(object sender, EventArgs e) { // Locate hMailServer.ini RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\hMailServer"); string installDir = key.GetValue("InstallLocation") as string; string binDir = Path.Combine(installDir, "Bin"); string iniFile = Path.Combine(binDir, "hMailServer.ini"); // Read the database password. string encryptedPassword = IniReadValue(iniFile, "Database", "password"); hMailServer.Application app = GetApp(); string decryptedPassword = app.Utilities.BlowfishDecrypt(encryptedPassword); textPassword.Text = decryptedPassword; }
public void TestRetrieveMessageID() { hMailServer.Application app = SingletonProvider <Utilities> .Instance.GetApp(); hMailServer.Utilities utilities = app.Utilities; // Add an account and send a message to it. hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "SampleBody"); POP3Simulator.AssertMessageCount(account.Address, "test", 1); hMailServer.Message message = account.IMAPFolders.get_ItemByName("INBOX").Messages[0]; Assert.AreEqual(message.ID, utilities.RetrieveMessageID(message.Filename)); Assert.AreEqual(0, utilities.RetrieveMessageID(@"C:\some\nonexistant\file")); }
public void TestSPFWithDebugLogging() { hMailServer.Application application = SingletonProvider <Utilities> .Instance.GetApp(); string debugLog = _settings.Logging.CurrentDefaultLog; Utilities.AssertDeleteFile(debugLog); // Create a test account // Fetch the default domain ; hMailServer.Account oAccount1 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); // Disallow incorrect line endings. _antiSpam.SpamMarkThreshold = 1; _antiSpam.SpamDeleteThreshold = 100; _antiSpam.AddHeaderReason = true; _antiSpam.AddHeaderSpam = true; _antiSpam.PrependSubject = true; _antiSpam.PrependSubjectText = "ThisIsSpam"; // Enable SPF _antiSpam.UseSPF = true; _antiSpam.UseSPFScore = 12; // Send a messages to this account. SMTPClientSimulator oSMTP = new SMTPClientSimulator(); oSMTP.Send("*****@*****.**", oAccount1.Address, "SPF test", "This is a test message."); string sMessageContents = POP3Simulator.AssertGetFirstMessageText(oAccount1.Address, "test"); if (!sMessageContents.Contains("X-hMailServer-Spam")) { throw new Exception("Spam message not detected as spam"); } // Check that it has been logged. string contents = Utilities.ReadExistingTextFile(debugLog); Assert.IsTrue(contents.Contains("Total spam score: 12")); Assert.IsTrue(contents.Contains("Spam test: SpamTestSPF, Score: 12")); Utilities.AssertDeleteFile(debugLog); }
public static hMailServer.Application Create(string hostName) { try { Type obj = Type.GetTypeFromProgID("hMailServer.Application", hostName); hMailServer.Application app = (hMailServer.Application)Activator.CreateInstance(obj); application = app; return(app); } catch (Exception e) { MessageBox.Show(e.Message, EnumStrings.hMailServerAdministrator); } return(null); }
public ucSelectDomain() { InitializeComponent(); hMailServer.Application application = Globals.GetApp(); hMailServer.Domains domains = application.Domains; for (int i = 0; i < domains.Count; i++) { hMailServer.Domain domain = domains[i]; listViewDomains.Items.Add(domain.Name); Marshal.ReleaseComObject(domain); } Marshal.ReleaseComObject(domains); }
public void TestSearchOR() { hMailServer.Application application = SingletonProvider <Utilities> .Instance.GetApp(); ; hMailServer.Account oAccount = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); // Send a message to this account. SMTPClientSimulator oSMTP = new SMTPClientSimulator(); oSMTP.Send("*****@*****.**", "*****@*****.**", "Search test", "This is a test of IMAP Search"); IMAPSimulator.AssertMessageCount("*****@*****.**", "test", "INBOX", 1); IMAPSimulator oSimulator = new IMAPSimulator(); string sWelcomeMessage = oSimulator.Connect(); oSimulator.Logon("*****@*****.**", "test"); Assert.IsTrue(oSimulator.SelectFolder("INBOX")); if (oSimulator.Search("OR SINCE 28-May-2001 ON 28-May-2001 ALL") != "1") { throw new Exception("ERROR - Search or flag failed"); } if (oSimulator.Search("OR SINCE 28-May-2012 ON 28-May-2012 ALL") != "") { throw new Exception("ERROR - Search or flag failed"); } string formattedToday = DateTime.Now.ToString("dd-MMM-yyyy", System.Globalization.CultureInfo.InvariantCulture).ToUpper(); if (oSimulator.Search("OR SINCE 28-May-2017 ON " + formattedToday + " ALL") != "1") { throw new Exception("ERROR - Search or flag failed"); } string formatted2001 = new DateTime(2001, 01, 01).ToString("dd-MMM-yyyy").ToUpper(); if (oSimulator.Search("OR SINCE 28-May-2008 ON " + formatted2001 + " ALL") != "1") { throw new Exception("ERROR - Search or flag failed"); } }
public bool SaveData() { if (_representedObject == null) { hMailServer.TCPIPPorts tcpIPPorts = APICreator.TCPIPPortsSettings; _representedObject = tcpIPPorts.Add(); Marshal.ReleaseComObject(tcpIPPorts); } _representedObject.Address = textIPAddress.Text; _representedObject.PortNumber = textTCPIPPort.Number; _representedObject.UseSSL = checkEnableSSL.Checked; _representedObject.Protocol = (hMailServer.eSessionType)comboProtocol.SelectedValue; if (comboSSLCertificate.SelectedValue == null) { _representedObject.SSLCertificateID = 0; } else { _representedObject.SSLCertificateID = (int)comboSSLCertificate.SelectedValue; } _representedObject.Save(); DirtyChecker.SetClean(this); Utility.RefreshNode(InternalNames.GetPortName(_representedObject)); if (MessageBox.Show(Strings.Localize("hMailServer needs to be restarted for the changes to take effect.") + Environment.NewLine + Strings.Localize("Do you want to restart hMailServer now?"), EnumStrings.hMailServerAdministrator, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { using (new WaitCursor()) { hMailServer.Application application = APICreator.Application; application.Stop(); application.Start(); MessageBox.Show(Strings.Localize("The hMailServer server has been restarted."), EnumStrings.hMailServerAdministrator, MessageBoxButtons.OK, MessageBoxIcon.Information); } } return(true); }
public void DomainAdminShouldBeAbleToSaveDomain() { hMailServer.Domain domain = SingletonProvider<Utilities>.Instance.AddTestDomain(); // Create an account with normal privileges. hMailServer.Account account = SingletonProvider<Utilities>.Instance.AddAccount(domain, "*****@*****.**", "test"); account.AdminLevel = hMailServer.eAdminLevel.hAdminLevelDomainAdmin; account.Save(); hMailServer.Application newApp = new hMailServer.Application(); hMailServer.Account authenticated = newApp.Authenticate(account.Address, "test"); Assert.IsNotNull(authenticated); Assert.AreEqual(1, newApp.Domains.Count); // Retrieve our domain. hMailServer.Domain newDomain = newApp.Domains[0]; newDomain.Save(); }
public void TestSPF() { hMailServer.Application application = SingletonProvider <Utilities> .Instance.GetApp(); // Create a test account // Fetch the default domain ; hMailServer.Account oAccount1 = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); // Disallow incorrect line endings. _antiSpam.SpamMarkThreshold = 1; _antiSpam.SpamDeleteThreshold = 100; _antiSpam.AddHeaderReason = true; _antiSpam.AddHeaderSpam = true; _antiSpam.PrependSubject = true; _antiSpam.PrependSubjectText = "ThisIsSpam"; // Enable SPF _antiSpam.UseSPF = true; _antiSpam.UseSPFScore = 5; // Send a messages to this account. SMTPClientSimulator oSMTP = new SMTPClientSimulator(); oSMTP.Send("*****@*****.**", oAccount1.Address, "SPF test", "This is a test message."); string sMessageContents = POP3Simulator.AssertGetFirstMessageText(oAccount1.Address, "test"); if (!sMessageContents.Contains("X-hMailServer-Spam")) { throw new Exception("Spam message not detected as spam"); } _antiSpam.UseSPF = false; oSMTP.Send("*****@*****.**", oAccount1.Address, "SPF test", "This is a test message."); sMessageContents = POP3Simulator.AssertGetFirstMessageText(oAccount1.Address, "test"); if (sMessageContents.Contains("X-hMailServer-Spam")) { throw new Exception("Non-spam message detected as spam"); } }
public void TestDNSBlackList() { hMailServer.DNSBlackLists dnsBlackLists = SingletonProvider <Utilities> .Instance.GetApp().Settings.AntiSpam.DNSBlackLists; hMailServer.DNSBlackList dnsBlackList = dnsBlackLists.Add(); dnsBlackList.DNSHost = "zen.spamhaus.org"; dnsBlackList.RejectMessage = "srv1"; dnsBlackList.Score = 5; dnsBlackList.Active = true; dnsBlackList.Save(); dnsBlackList = dnsBlackLists.Add(); dnsBlackList.DNSHost = "bl.spamcop.net"; dnsBlackList.RejectMessage = "srv2"; dnsBlackList.Score = 5; dnsBlackList.Active = false; dnsBlackList.Save(); dnsBlackList = dnsBlackLists.Add(); dnsBlackList.DNSHost = "dnsbl.njabl.org"; dnsBlackList.RejectMessage = "srv3"; dnsBlackList.Score = 5; dnsBlackList.Active = true; dnsBlackList.Save(); hMailServer.Application application = SingletonProvider <Utilities> .Instance.GetApp(); _antiSpam.SpamMarkThreshold = 1; _antiSpam.SpamDeleteThreshold = 100; hMailServer.Account account = SingletonProvider <Utilities> .Instance.AddAccount(_domain, "*****@*****.**", "test"); Utilities.DeleteCurrentDefaultLog(); SMTPClientSimulator.StaticSend(account.Address, account.Address, "Test", "TestBody"); POP3Simulator.AssertGetFirstMessageText(account.Address, "test"); string result = Utilities.ReadCurrentDefaultLog(); Assert.IsTrue(result.Contains(".zen.spamhaus.org, 0 addresses found: (none), Match: False"), result); Assert.IsTrue(result.Contains(".dnsbl.njabl.org, 0 addresses found: (none), Match: False"), result); Assert.IsFalse(result.Contains(".bl.spamcop.net, 0 addresses found:"), result); }
public void TestNormalUserAccessOtherAccount() { hMailServer.Account account = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); account.AdminLevel = hMailServer.eAdminLevel.hAdminLevelNormal; account.Save(); hMailServer.Account secondAccount = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); secondAccount.AdminLevel = hMailServer.eAdminLevel.hAdminLevelNormal; secondAccount.Save(); hMailServer.Application newApplication = new hMailServer.Application(); newApplication.Authenticate("*****@*****.**", "test"); Assert.AreEqual(1, newApplication.Domains.Count); Assert.AreEqual(1, newApplication.Domains[0].Accounts.Count); hMailServer.Account myAccount = newApplication.Domains[0].Accounts.get_ItemByAddress("*****@*****.**"); try { hMailServer.Account otherAccount = newApplication.Domains[0].Accounts.get_ItemByAddress("*****@*****.**"); Assert.Fail(); } catch (COMException ex) { Assert.IsTrue(ex.Message.Contains("Invalid index.")); } hMailServer.Domains domains = SingletonProvider<Utilities>.Instance.GetApp().Domains; Assert.AreEqual(2, domains[0].Accounts.Count); }
public static void EditUserEmailPassword(Config config, string email, string password) { try { // If Email Server is enabled if (config.EmailConfig.Enabled) { var app = new hMailServer.Application(); app.Connect(); app.Authenticate(config.EmailConfig.Username, config.EmailConfig.Password); var domain = app.Domains.ItemByName[config.EmailConfig.Domain]; var account = domain.Accounts.ItemByAddress[email]; account.Password = password; account.Save(); } } catch (Exception ex) { throw new Exception("Unable to edit email account password.", ex); } }
public static List<string> GetInactiveAccounts(Config config, TeknikEntities db, int maxDays) { List<string> foundUsers = new List<string>(); List<User> curUsers = db.Users.ToList(); foreach (User user in curUsers) { // If the username is reserved, don't worry about it if (UserHelper.UsernameReserved(config, user.Username)) { continue; } #region Inactivity Finding DateTime lastActivity = UserHelper.GetLastAccountActivity(db, config, user); TimeSpan inactiveTime = DateTime.Now.Subtract(lastActivity); // If older than max days, check their current usage if (inactiveTime >= new TimeSpan(maxDays, 0, 0, 0, 0)) { // Check the user's usage of the service. bool noData = true; // Any blog comments? var blogCom = db.BlogComments.Where(c => c.UserId == user.UserId); noData &= !(blogCom != null && blogCom.Any()); // Any blog posts? var blogPosts = db.BlogPosts.Where(p => p.Blog.UserId == user.UserId); noData &= !(blogPosts != null && blogPosts.Any()); // Any podcast comments? var podCom = db.PodcastComments.Where(p => p.UserId == user.UserId); noData &= !(podCom != null && podCom.Any()); // Any email? if (config.EmailConfig.Enabled) { var app = new hMailServer.Application(); app.Connect(); app.Authenticate(config.EmailConfig.Username, config.EmailConfig.Password); try { var domain = app.Domains.ItemByName[config.EmailConfig.Domain]; var account = domain.Accounts.ItemByAddress[UserHelper.GetUserEmailAddress(config, user.Username)]; noData &= ((account.Messages.Count == 0) && ((int)account.Size == 0)); } catch { } } // Any git repos? if (config.GitConfig.Enabled) { string email = UserHelper.GetUserEmailAddress(config, user.Username); // We need to check the actual git database MysqlDatabase mySQL = new MysqlDatabase(config.GitConfig.Database); string sql = @"SELECT * FROM gogs.repository LEFT JOIN gogs.action ON gogs.user.id = gogs.action.act_user_id WHERE gogs.user.login_name = {0}"; var results = mySQL.Query(sql, new object[] { email }); noData &= !(results != null && results.Any()); } if (noData) { // They have no data, so safe to delete them. foundUsers.Add(user.Username); } continue; } #endregion } return foundUsers; }
public static hMailServer.Application Create(string hostName) { try { Type obj = Type.GetTypeFromProgID("hMailServer.Application", hostName); hMailServer.Application app = (hMailServer.Application) Activator.CreateInstance(obj); application = app; return app; } catch (COMException comException) { if (comException.ErrorCode == -2147023174) { MessageBox.Show("Unable to connect to the specified server.", EnumStrings.hMailServerAdministrator); } else { MessageBox.Show(comException.Message, EnumStrings.hMailServerAdministrator); } } catch (Exception e) { MessageBox.Show(e.Message, EnumStrings.hMailServerAdministrator); } return null; }
private bool Connect(Server server) { try { application = APICreator.Create(server.hostName); if (application == null) return false; if (application.Database.RequiresUpgrade) { string message = string.Format("Your database is not up to date and needs to be upgraded." + Environment.NewLine + "Please run DBUpdater.exe to update the datatabase." + Environment.NewLine + Environment.NewLine + "Current database version: {0}" + Environment.NewLine + "Required database version: {1}", application.Database.CurrentVersion, application.Database.RequiredVersion); MessageBox.Show(message, EnumStrings.hMailServerAdministrator, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return false; } if (APICreator.Authenticate(application, server)) { DialogResult = DialogResult.OK; _serverName = server.hostName; return true; } return false; } catch (Exception ex) { MessageBox.Show(ex.Message, EnumStrings.hMailServerAdministrator, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return false; } }
public static void SetApp(hMailServer.Application application) { _application = application; }
private bool Connect() { // Should we save the currently viewed? if (!AskSaveChanges()) { treeNodes.SelectedNode = currentlySelectedNode; return false; } // Connect formConnect connectDlg = new formConnect(); if (connectDlg.ShowDialog() != DialogResult.OK) return false; application = connectDlg.Application; _serverHost = connectDlg.Server; Initialize(); return true; }
public static void DeleteUserEmail(Config config, string email) { try { // If Email Server is enabled if (config.EmailConfig.Enabled) { var app = new hMailServer.Application(); app.Connect(); app.Authenticate(config.EmailConfig.Username, config.EmailConfig.Password); var domain = app.Domains.ItemByName[config.EmailConfig.Domain]; var account = domain.Accounts.ItemByAddress[email]; if (account != null) { account.Delete(); } } } catch (Exception ex) { throw new Exception("Unable to delete email account.", ex); } }
public void TestNormalUserAccessBackupManager() { hMailServer.Account account = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "*****@*****.**", "test"); account.AdminLevel = hMailServer.eAdminLevel.hAdminLevelNormal; account.Save(); hMailServer.Application newApplication = new hMailServer.Application(); newApplication.Authenticate("*****@*****.**", "test"); hMailServer.BackupManager backupManager = newApplication.BackupManager; }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); string databaseOldErrorMessage = "The database is too old for this version of hMailServer."; try { CommandLineParser.Parse(); hMailServer.Application application = new hMailServer.Application(); try { application.Connect(); } catch (Exception ex) { if (!ex.Message.Contains(databaseOldErrorMessage)) throw ex; } int from = application.Database.CurrentVersion; int to = application.Database.RequiredVersion; if (from == to) { if (!CommandLineParser.ContainsArgument("/SilentIfOk") && !CommandLineParser.IsSilent()) MessageBox.Show("Your hMailServer database is already up to date.", "hMailServer Administrator"); return; } if (!Authenticator.AuthenticateUser(application)) return; formMain main = new formMain(application); if (!main.LoadSettings()) return; if (!main.CreateUpgradePath()) return; if (CommandLineParser.IsSilent()) { // Silently perform the upgrade main.DoUpgrade(); return; } // Do it the default way. Application.Run(main); } catch (Exception ex) { MessageBox.Show(ex.Message + Environment.NewLine + Environment.NewLine + "Please check the hMailServer error log for further details.", "hMailServer Administrator", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void LoadData() { hMailServer.Application app = APICreator.Application; _application = app; if (_domain == null) return; textDomainName.Text = _domain.Name; textCatchAllAddress.Text = _domain.Postmaster; checkAddSignaturesToReplies.Checked = _domain.AddSignaturesToReplies; checkAddSignaturesToLocalMail.Checked = _domain.AddSignaturesToLocalMail; checkSignatureEnabled.Checked = _domain.SignatureEnabled; checkEnabled.Checked = _domain.Active; switch (_domain.SignatureMethod) { case eDomainSignatureMethod.eSMAppendToAccountSignature: radioSMAppendToAccountSignature.Checked = true; break; case eDomainSignatureMethod.eSMOverwriteAccountSignature: radioSMOverwriteAccountSignature.Checked = true; break; case eDomainSignatureMethod.eSMSetIfNotSpecifiedInAccount: radioSMSetIfNotSpecifiedInAccount.Checked = true; break; } textMaxSize.Number = _domain.MaxSize; textAllocatedSize.Number64 = _domain.AllocatedSize; textMaxMessageSize.Number = _domain.MaxMessageSize; textMaxAccountSize.Number = _domain.MaxAccountSize; textMaxNumberOfAccounts.Number = _domain.MaxNumberOfAccounts; textMaxNumberOfAliases.Number = _domain.MaxNumberOfAliases; textMaxNumberOfDistributionLists.Number = _domain.MaxNumberOfDistributionLists; checkMaxNumberOfAccountsEnabled.Checked = _domain.MaxNumberOfAccountsEnabled; checkMaxNumberOfAliasesEnabled.Checked = _domain.MaxNumberOfAliasesEnabled; checkMaxNumberOfDistributionListsEnabled.Checked = _domain.MaxNumberOfDistributionListsEnabled; textPlainTextSignature.Text = _domain.SignaturePlainText; textHTMLSignature.Text = _domain.SignatureHTML; checkUsePlusAddressing.Checked = _domain.PlusAddressingEnabled; comboPlusAddressingCharacter.Text = _domain.PlusAddressingCharacter; checkGreyListingEnabled.Checked = _domain.AntiSpamEnableGreylisting; checkDKIMSignEnabled.Checked = _domain.DKIMSignEnabled; textDKIMPrivateKeyFile.Text = _domain.DKIMPrivateKeyFile; textDKIMSelector.Text = _domain.DKIMSelector; switch (_domain.DKIMHeaderCanonicalizationMethod) { case eDKIMCanonicalizationMethod.eCanonicalizationRelaxed: radioDKIMHeaderMethodRelaxed.Checked = true; break; case eDKIMCanonicalizationMethod.eCanonicalizationSimple: radioDKIMHeaderMethodSimple.Checked = true; break; } switch (_domain.DKIMBodyCanonicalizationMethod) { case eDKIMCanonicalizationMethod.eCanonicalizationRelaxed: radioDKIMBodyMethodRelaxed.Checked = true; break; case eDKIMCanonicalizationMethod.eCanonicalizationSimple: radioDKIMBodyMethodSimple.Checked = true; break; } switch (_domain.DKIMSigningAlgorithm) { case eDKIMAlgorithm.eSHA1: radioDKIMSigningAlgorithmSHA1.Checked = true; break; case eDKIMAlgorithm.eSHA256: radioDKIMSigningAlgorithmSHA256.Checked = true; break; } ListDomainAliases(); }
public static List<string> GetOrphanedEmail(Config config, TeknikEntities db) { List<string> foundEmail = new List<string>(); if (config.EmailConfig.Enabled) { List<User> curUsers = db.Users.ToList(); // Connect to hmailserver COM var app = new hMailServer.Application(); app.Connect(); app.Authenticate(config.EmailConfig.Username, config.EmailConfig.Password); var domain = app.Domains.ItemByName[config.EmailConfig.Domain]; var accounts = domain.Accounts; for (int i = 0; i < accounts.Count; i++) { var account = accounts[i]; bool userExists = curUsers.Exists(u => UserHelper.GetUserEmailAddress(config, u.Username) == account.Address); bool isReserved = UserHelper.GetReservedUsernames(config).Exists(r => UserHelper.GetUserEmailAddress(config, r).ToLower() == account.Address.ToLower()); if (!userExists && !isReserved) { foundEmail.Add(account.Address); } } } return foundEmail; }
public static void AddUserEmail(Config config, string email, string password) { try { // If Email Server is enabled if (config.EmailConfig.Enabled) { // Connect to hmailserver COM var app = new hMailServer.Application(); app.Connect(); app.Authenticate(config.EmailConfig.Username, config.EmailConfig.Password); var domain = app.Domains.ItemByName[config.EmailConfig.Domain]; var newAccount = domain.Accounts.Add(); newAccount.Address = email; newAccount.Password = password; newAccount.Active = true; newAccount.MaxSize = config.EmailConfig.MaxSize; newAccount.Save(); } } catch (Exception ex) { throw new Exception("Unable to add email.", ex); } }
public TestDNSQueries(hMailServer.Application app) { application = app; utilities = app.Utilities; }
public static DateTime UserEmailLastActive(Config config, string email) { DateTime lastActive = new DateTime(1900, 1, 1); if (config.EmailConfig.Enabled) { var app = new hMailServer.Application(); app.Connect(); app.Authenticate(config.EmailConfig.Username, config.EmailConfig.Password); try { var domain = app.Domains.ItemByName[config.EmailConfig.Domain]; var account = domain.Accounts.ItemByAddress[email]; DateTime lastEmail = (DateTime)account.LastLogonTime; if (lastActive < lastEmail) lastActive = lastEmail; } catch { } } return lastActive; }