Example #1
0
        public void TestDomainAdminAccessOtherDomain()
        {
            hMailServer.Account account = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "[email protected]", "test");
            account.AdminLevel = hMailServer.eAdminLevel.hAdminLevelDomainAdmin;
            account.Save();

            SingletonProvider<Utilities>.Instance.AddDomain("example.com");

            hMailServer.Application newApplication = new hMailServer.Application();
            newApplication.Authenticate("[email protected]", "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."));
            }
        }
Example #2
0
        public formMain(hMailServer.Application application)
        {
            InitializeComponent();

             _application = application;
             _databaseType = null;
        }
Example #3
0
        public void TestFixtureSetUp()
        {
            SingletonProvider<Utilities>.Instance.Authenticate();

             _application = SingletonProvider<Utilities>.Instance.GetApp();
             _settings = _application.Settings;
        }
Example #4
0
        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 new void SetUp()
        {
            Utilities.AssertSpamAssassinIsRunning();

            // Enable spam assassin
            application = SingletonProvider<Utilities>.Instance.GetApp();
            hMailServer.AntiSpam antiSpam = _settings.AntiSpam;
            ;
            account = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "[email protected]", "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;
        }
Example #6
0
        public ucProgress()
        {
            InitializeComponent();

             _application = Globals.GetApp();
             _utilities = _application.Utilities;
             _domains = _application.Domains;
             _counter = 0;
        }
Example #7
0
        public void TestDomainAdminAccessSettings()
        {
            hMailServer.Account account = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "[email protected]", "test");
            account.AdminLevel = hMailServer.eAdminLevel.hAdminLevelDomainAdmin;
            account.Save();

            hMailServer.Application newApplication = new hMailServer.Application();
            newApplication.Authenticate("[email protected]", "test");
            hMailServer.Settings settings = newApplication.Settings;
        }
Example #8
0
        static void Main()
        {
            CommandLineParser.Parse();

             _application = new hMailServer.Application();

             if (_application.Database.DatabaseExists)
            UpgradeDatabase();
             else
            CreateDatabase();
        }
Example #9
0
        public void TestDomainAdminAccessDatabase()
        {
            hMailServer.Account account = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "[email protected]", "test");
            account.AdminLevel = hMailServer.eAdminLevel.hAdminLevelDomainAdmin;
            account.Save();

            hMailServer.Application newApplication = new hMailServer.Application();
            newApplication.Authenticate("[email protected]", "test");
            hMailServer.Database database = newApplication.Database;
            database.ExecuteSQL("select");
        }
Example #10
0
        public void NormalUserShouldNotBeAbleToAddDomain()
        {
            hMailServer.Domain domain = SingletonProvider<Utilities>.Instance.AddTestDomain();

             // Create an account with normal privileges.
             hMailServer.Account account = SingletonProvider<Utilities>.Instance.AddAccount(domain, "[email protected]", "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();
        }
Example #11
0
        public formMain(hMailServer.Application app, string serverHost)
        {
            InitializeComponent();

            application = app;
            _serverHost = serverHost;
            currentlySelectedNode = null;

            _language = "English";

            LoadWindowSettings();

            _language = Strings.LoadLanguage(_language);
            Strings.Localize(this);
        }
Example #12
0
        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());
        }
Example #13
0
        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");
        }
Example #14
0
        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;
        }
Example #15
0
        public void DomainAdminShouldBeAbleToSaveDomain()
        {
            hMailServer.Domain domain = SingletonProvider<Utilities>.Instance.AddTestDomain();

             // Create an account with normal privileges.
             hMailServer.Account account = SingletonProvider<Utilities>.Instance.AddAccount(domain, "[email protected]", "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();
        }
Example #16
0
        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;
             }
        }
Example #17
0
        public void TestNormalUserAccessBackupManager()
        {
            hMailServer.Account account = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "[email protected]", "test");
            account.AdminLevel = hMailServer.eAdminLevel.hAdminLevelNormal;
            account.Save();

            hMailServer.Application newApplication = new hMailServer.Application();
            newApplication.Authenticate("[email protected]", "test");
            hMailServer.BackupManager backupManager = newApplication.BackupManager;
        }
Example #18
0
        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();
        }
Example #19
0
 public static void SetApp(hMailServer.Application application)
 {
    _application = application;
 }
Example #20
0
 public TestDNSQueries(hMailServer.Application app)
 {
     application = app;
     utilities = app.Utilities;
 }
Example #21
0
        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);
             }
        }
Example #22
0
 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);
     }
 }
Example #23
0
        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;
        }
Example #24
0
        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;
        }
Example #25
0
        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;
        }
Example #26
0
        public void TestNormalUserAccessOtherAccount()
        {
            hMailServer.Account account = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "[email protected]", "test");
            account.AdminLevel = hMailServer.eAdminLevel.hAdminLevelNormal;
            account.Save();

            hMailServer.Account secondAccount = SingletonProvider<Utilities>.Instance.AddAccount(_domain, "[email protected]", "test");
            secondAccount.AdminLevel = hMailServer.eAdminLevel.hAdminLevelNormal;
            secondAccount.Save();

            hMailServer.Application newApplication = new hMailServer.Application();
            newApplication.Authenticate("[email protected]", "test");
            Assert.AreEqual(1, newApplication.Domains.Count);
            Assert.AreEqual(1, newApplication.Domains[0].Accounts.Count);

            hMailServer.Account myAccount = newApplication.Domains[0].Accounts.get_ItemByAddress("[email protected]");

            try
            {
                hMailServer.Account otherAccount = newApplication.Domains[0].Accounts.get_ItemByAddress("[email protected]");

                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);
        }
Example #27
0
 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);
     }
 }
Example #28
0
        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;
        }
Example #29
0
        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);
            }
        }
Example #30
0
        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;
        }