public UsersDefaultFolder Add(string folderName, bool permanent)
        {
            if (folderName.IndexOfAny(new char[]
            {
                '\\',
                '/'
            }) > -1)
            {
                throw new Exception("Folders with path not allowed !");
            }
            Guid.NewGuid().ToString();
            this.m_pVirtualServer.Server.TCP_Client.TcpStream.WriteLine(string.Concat(new object[]
            {
                "AddUsersDefaultFolder ",
                this.m_pVirtualServer.VirtualServerID,
                " ",
                TextUtils.QuoteString(folderName),
                " ",
                permanent
            }));
            string text = this.m_pVirtualServer.Server.ReadLine();

            if (!text.ToUpper().StartsWith("+OK"))
            {
                throw new Exception(text);
            }
            UsersDefaultFolder usersDefaultFolder = new UsersDefaultFolder(this, folderName, permanent);

            this.m_pFolders.Add(usersDefaultFolder);
            return(usersDefaultFolder);
        }
        public void Remove(UsersDefaultFolder folder)
        {
            if (folder.FolderName.ToLower() == "inbox")
            {
                throw new Exception("Inbox is permanent system folder and can't be deleted ! '");
            }
            Guid.NewGuid().ToString();
            this.m_pVirtualServer.Server.TCP_Client.TcpStream.WriteLine("DeleteUsersDefaultFolder " + this.m_pVirtualServer.VirtualServerID + " " + TextUtils.QuoteString(folder.FolderName));
            string text = this.m_pVirtualServer.Server.ReadLine();

            if (!text.ToUpper().StartsWith("+OK"))
            {
                throw new Exception(text);
            }
            this.m_pFolders.Remove(folder);
        }
Ejemplo n.º 3
0
        public void Backup(Stream stream)
        {
            DataSet dataSet = new DataSet("dsVirtualServerBackup");

            dataSet.Merge(this.SystemSettings.ToDataSet());
            dataSet.Tables.Add("Domains");
            dataSet.Tables["Domains"].Columns.Add("DomainID");
            dataSet.Tables["Domains"].Columns.Add("DomainName");
            dataSet.Tables["Domains"].Columns.Add("Description");
            foreach (Domain domain in this.Domains)
            {
                DataRow dataRow = dataSet.Tables["Domains"].NewRow();
                dataRow["DomainID"]    = domain.DomainID;
                dataRow["DomainName"]  = domain.DomainName;
                dataRow["Description"] = domain.Description;
                dataSet.Tables["Domains"].Rows.Add(dataRow);
            }
            dataSet.Tables.Add("Users");
            dataSet.Tables["Users"].Columns.Add("UserID");
            dataSet.Tables["Users"].Columns.Add("FullName");
            dataSet.Tables["Users"].Columns.Add("UserName");
            dataSet.Tables["Users"].Columns.Add("Password");
            dataSet.Tables["Users"].Columns.Add("Description");
            dataSet.Tables["Users"].Columns.Add("Mailbox_Size");
            dataSet.Tables["Users"].Columns.Add("Enabled");
            dataSet.Tables["Users"].Columns.Add("Permissions");
            foreach (User user in this.Users)
            {
                DataRow dataRow2 = dataSet.Tables["Users"].NewRow();
                dataRow2["UserID"]       = user.UserID;
                dataRow2["FullName"]     = user.FullName;
                dataRow2["UserName"]     = user.UserName;
                dataRow2["Password"]     = user.Password;
                dataRow2["Description"]  = user.Description;
                dataRow2["Mailbox_Size"] = user.MaximumMailboxSize;
                dataRow2["Enabled"]      = user.Enabled;
                dataRow2["Permissions"]  = (int)user.Permissions;
                dataSet.Tables["Users"].Rows.Add(dataRow2);
            }
            dataSet.Tables.Add("User_EmailAddresses");
            dataSet.Tables["User_EmailAddresses"].Columns.Add("UserID");
            dataSet.Tables["User_EmailAddresses"].Columns.Add("EmailAddress");
            foreach (User user2 in this.Users)
            {
                foreach (string value in user2.EmailAddresses)
                {
                    DataRow dataRow3 = dataSet.Tables["User_EmailAddresses"].NewRow();
                    dataRow3["UserID"]       = user2.UserID;
                    dataRow3["EmailAddress"] = value;
                    dataSet.Tables["User_EmailAddresses"].Rows.Add(dataRow3);
                }
            }
            dataSet.Tables.Add("User_RemoteServers");
            dataSet.Tables["User_RemoteServers"].Columns.Add("UserID");
            dataSet.Tables["User_RemoteServers"].Columns.Add("ServerID");
            dataSet.Tables["User_RemoteServers"].Columns.Add("Description");
            dataSet.Tables["User_RemoteServers"].Columns.Add("RemoteServer");
            dataSet.Tables["User_RemoteServers"].Columns.Add("RemotePort");
            dataSet.Tables["User_RemoteServers"].Columns.Add("RemoteUserName");
            dataSet.Tables["User_RemoteServers"].Columns.Add("RemotePassword");
            dataSet.Tables["User_RemoteServers"].Columns.Add("UseSSL");
            dataSet.Tables["User_RemoteServers"].Columns.Add("Enabled");
            foreach (User user3 in this.Users)
            {
                foreach (UserRemoteServer userRemoteServer in user3.RemoteServers)
                {
                    DataRow dataRow4 = dataSet.Tables["User_RemoteServers"].NewRow();
                    dataRow4["UserID"]         = user3.UserID;
                    dataRow4["ServerID"]       = userRemoteServer.ID;
                    dataRow4["Description"]    = userRemoteServer.Description;
                    dataRow4["RemoteServer"]   = userRemoteServer.Host;
                    dataRow4["RemotePort"]     = userRemoteServer.Port;
                    dataRow4["RemoteUserName"] = userRemoteServer.UserName;
                    dataRow4["RemotePassword"] = userRemoteServer.Password;
                    dataRow4["UseSSL"]         = userRemoteServer.SSL;
                    dataRow4["Enabled"]        = userRemoteServer.Enabled;
                    dataSet.Tables["User_RemoteServers"].Rows.Add(dataRow4);
                }
            }
            dataSet.Tables.Add("User_MessageRules");
            dataSet.Tables["User_MessageRules"].Columns.Add("UserID");
            dataSet.Tables["User_MessageRules"].Columns.Add("RuleID");
            dataSet.Tables["User_MessageRules"].Columns.Add("Enabled");
            dataSet.Tables["User_MessageRules"].Columns.Add("CheckNextRuleIf");
            dataSet.Tables["User_MessageRules"].Columns.Add("Description");
            dataSet.Tables["User_MessageRules"].Columns.Add("MatchExpression");
            foreach (User user4 in this.Users)
            {
                foreach (UserMessageRule userMessageRule in user4.MessageRules)
                {
                    DataRow dataRow5 = dataSet.Tables["User_MessageRules"].NewRow();
                    dataRow5["UserID"]          = user4.UserID;
                    dataRow5["RuleID"]          = userMessageRule.ID;
                    dataRow5["Enabled"]         = userMessageRule.Enabled;
                    dataRow5["CheckNextRuleIf"] = (int)userMessageRule.CheckNextRule;
                    dataRow5["Description"]     = userMessageRule.Description;
                    dataRow5["MatchExpression"] = userMessageRule.MatchExpression;
                    dataSet.Tables["User_MessageRules"].Rows.Add(dataRow5);
                }
            }
            dataSet.Tables.Add("User_MessageRuleActions");
            dataSet.Tables["User_MessageRuleActions"].Columns.Add("UserID");
            dataSet.Tables["User_MessageRuleActions"].Columns.Add("RuleID");
            dataSet.Tables["User_MessageRuleActions"].Columns.Add("ActionID");
            dataSet.Tables["User_MessageRuleActions"].Columns.Add("Description");
            dataSet.Tables["User_MessageRuleActions"].Columns.Add("ActionType");
            dataSet.Tables["User_MessageRuleActions"].Columns.Add("ActionData", typeof(byte[]));
            IEnumerator enumerator;

            foreach (User user5 in this.Users)
            {
                enumerator = user5.MessageRules.GetEnumerator();
                try
                {
                    while (enumerator.MoveNext())
                    {
                        UserMessageRule userMessageRule2 = (UserMessageRule)enumerator.Current;
                        foreach (UserMessageRuleActionBase userMessageRuleActionBase in userMessageRule2.Actions)
                        {
                            DataRow dataRow6 = dataSet.Tables["User_MessageRuleActions"].NewRow();
                            dataRow6["UserID"]      = user5.UserID;
                            dataRow6["RuleID"]      = userMessageRule2.ID;
                            dataRow6["ActionID"]    = userMessageRuleActionBase.ID;
                            dataRow6["Description"] = userMessageRuleActionBase.Description;
                            dataRow6["ActionType"]  = (int)userMessageRuleActionBase.ActionType;
                            dataRow6["ActionData"]  = userMessageRuleActionBase.Serialize();
                            dataSet.Tables["User_MessageRuleActions"].Rows.Add(dataRow6);
                        }
                    }
                }
                finally
                {
                    IDisposable disposable = enumerator as IDisposable;
                    if (disposable != null)
                    {
                        disposable.Dispose();
                    }
                }
            }
            dataSet.Tables.Add("Groups");
            dataSet.Tables["Groups"].Columns.Add("GroupID");
            dataSet.Tables["Groups"].Columns.Add("GroupName");
            dataSet.Tables["Groups"].Columns.Add("Description");
            dataSet.Tables["Groups"].Columns.Add("Enabled");
            enumerator = this.Groups.GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    Group   group    = (Group)enumerator.Current;
                    DataRow dataRow7 = dataSet.Tables["Groups"].NewRow();
                    dataRow7["GroupID"]     = group.GroupID;
                    dataRow7["GroupName"]   = group.GroupName;
                    dataRow7["Description"] = group.Description;
                    dataRow7["Enabled"]     = group.Enabled;
                    dataSet.Tables["Groups"].Rows.Add(dataRow7);
                }
            }
            finally
            {
                IDisposable disposable = enumerator as IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
            dataSet.Tables.Add("Group_Members");
            dataSet.Tables["Group_Members"].Columns.Add("GroupID");
            dataSet.Tables["Group_Members"].Columns.Add("UserOrGroup");
            enumerator = this.Groups.GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    Group group2 = (Group)enumerator.Current;
                    foreach (string value2 in group2.Members)
                    {
                        DataRow dataRow8 = dataSet.Tables["Group_Members"].NewRow();
                        dataRow8["GroupID"]     = group2.GroupID;
                        dataRow8["UserOrGroup"] = value2;
                        dataSet.Tables["Group_Members"].Rows.Add(dataRow8);
                    }
                }
            }
            finally
            {
                IDisposable disposable = enumerator as IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
            dataSet.Tables.Add("MailingLists");
            dataSet.Tables["MailingLists"].Columns.Add("MailingListID");
            dataSet.Tables["MailingLists"].Columns.Add("MailingListName");
            dataSet.Tables["MailingLists"].Columns.Add("Description");
            dataSet.Tables["MailingLists"].Columns.Add("Enabled");
            enumerator = this.MailingLists.GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    MailingList mailingList = (MailingList)enumerator.Current;
                    DataRow     dataRow9    = dataSet.Tables["MailingLists"].NewRow();
                    dataRow9["MailingListID"]   = mailingList.ID;
                    dataRow9["MailingListName"] = mailingList.Name;
                    dataRow9["Description"]     = mailingList.Description;
                    dataRow9["Enabled"]         = mailingList.Enabled;
                    dataSet.Tables["MailingLists"].Rows.Add(dataRow9);
                }
            }
            finally
            {
                IDisposable disposable = enumerator as IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
            dataSet.Tables.Add("MailingList_Members");
            dataSet.Tables["MailingList_Members"].Columns.Add("MailingListID");
            dataSet.Tables["MailingList_Members"].Columns.Add("Address");
            enumerator = this.MailingLists.GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    MailingList mailingList2 = (MailingList)enumerator.Current;
                    foreach (string value3 in mailingList2.Members)
                    {
                        DataRow dataRow10 = dataSet.Tables["MailingList_Members"].NewRow();
                        dataRow10["MailingListID"] = mailingList2.ID;
                        dataRow10["Address"]       = value3;
                        dataSet.Tables["MailingList_Members"].Rows.Add(dataRow10);
                    }
                }
            }
            finally
            {
                IDisposable disposable = enumerator as IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
            dataSet.Tables.Add("MailingList_ACL");
            dataSet.Tables["MailingList_ACL"].Columns.Add("MailingListID");
            dataSet.Tables["MailingList_ACL"].Columns.Add("UserOrGroup");
            enumerator = this.MailingLists.GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    MailingList mailingList3 = (MailingList)enumerator.Current;
                    foreach (string value4 in mailingList3.ACL)
                    {
                        DataRow dataRow11 = dataSet.Tables["MailingList_ACL"].NewRow();
                        dataRow11["MailingListID"] = mailingList3.ID;
                        dataRow11["UserOrGroup"]   = value4;
                        dataSet.Tables["MailingList_ACL"].Rows.Add(dataRow11);
                    }
                }
            }
            finally
            {
                IDisposable disposable = enumerator as IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
            dataSet.Tables.Add("Routing");
            dataSet.Tables["Routing"].Columns.Add("RouteID");
            dataSet.Tables["Routing"].Columns.Add("Enabled");
            dataSet.Tables["Routing"].Columns.Add("Description");
            dataSet.Tables["Routing"].Columns.Add("Pattern");
            dataSet.Tables["Routing"].Columns.Add("Action");
            dataSet.Tables["Routing"].Columns.Add("ActionData", typeof(byte[]));
            enumerator = this.Routes.GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    Route   route     = (Route)enumerator.Current;
                    DataRow dataRow12 = dataSet.Tables["Routing"].NewRow();
                    dataRow12["RouteID"]     = route.ID;
                    dataRow12["Enabled"]     = route.Enabled;
                    dataRow12["Description"] = route.Description;
                    dataRow12["Pattern"]     = route.Pattern;
                    dataRow12["Action"]      = (int)route.Action.ActionType;
                    dataRow12["ActionData"]  = route.Action.Serialize();
                    dataSet.Tables["Routing"].Rows.Add(dataRow12);
                }
            }
            finally
            {
                IDisposable disposable = enumerator as IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
            dataSet.Tables.Add("GlobalMessageRules");
            dataSet.Tables["GlobalMessageRules"].Columns.Add("RuleID");
            dataSet.Tables["GlobalMessageRules"].Columns.Add("Enabled");
            dataSet.Tables["GlobalMessageRules"].Columns.Add("CheckNextRuleIf");
            dataSet.Tables["GlobalMessageRules"].Columns.Add("Description");
            dataSet.Tables["GlobalMessageRules"].Columns.Add("MatchExpression");
            enumerator = this.GlobalMessageRules.GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    GlobalMessageRule globalMessageRule = (GlobalMessageRule)enumerator.Current;
                    DataRow           dataRow13         = dataSet.Tables["GlobalMessageRules"].NewRow();
                    dataRow13["RuleID"]          = globalMessageRule.ID;
                    dataRow13["Enabled"]         = globalMessageRule.Enabled;
                    dataRow13["CheckNextRuleIf"] = (int)globalMessageRule.CheckNextRule;
                    dataRow13["Description"]     = globalMessageRule.Description;
                    dataRow13["MatchExpression"] = globalMessageRule.MatchExpression;
                    dataSet.Tables["GlobalMessageRules"].Rows.Add(dataRow13);
                }
            }
            finally
            {
                IDisposable disposable = enumerator as IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
            dataSet.Tables.Add("GlobalMessageRuleActions");
            dataSet.Tables["GlobalMessageRuleActions"].Columns.Add("RuleID");
            dataSet.Tables["GlobalMessageRuleActions"].Columns.Add("ActionID");
            dataSet.Tables["GlobalMessageRuleActions"].Columns.Add("Description");
            dataSet.Tables["GlobalMessageRuleActions"].Columns.Add("ActionType");
            dataSet.Tables["GlobalMessageRuleActions"].Columns.Add("ActionData", typeof(byte[]));
            enumerator = this.GlobalMessageRules.GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    GlobalMessageRule globalMessageRule2 = (GlobalMessageRule)enumerator.Current;
                    foreach (GlobalMessageRuleActionBase globalMessageRuleActionBase in globalMessageRule2.Actions)
                    {
                        DataRow dataRow14 = dataSet.Tables["GlobalMessageRuleActions"].NewRow();
                        dataRow14["RuleID"]      = globalMessageRule2.ID;
                        dataRow14["ActionID"]    = globalMessageRuleActionBase.ID;
                        dataRow14["Description"] = globalMessageRuleActionBase.Description;
                        dataRow14["ActionType"]  = (int)globalMessageRuleActionBase.ActionType;
                        dataRow14["ActionData"]  = globalMessageRuleActionBase.Serialize();
                        dataSet.Tables["GlobalMessageRuleActions"].Rows.Add(dataRow14);
                    }
                }
            }
            finally
            {
                IDisposable disposable = enumerator as IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
            dataSet.Tables.Add("IP_Security");
            dataSet.Tables["IP_Security"].Columns.Add("ID");
            dataSet.Tables["IP_Security"].Columns.Add("Enabled");
            dataSet.Tables["IP_Security"].Columns.Add("Description");
            dataSet.Tables["IP_Security"].Columns.Add("Service");
            dataSet.Tables["IP_Security"].Columns.Add("Action");
            dataSet.Tables["IP_Security"].Columns.Add("StartIP");
            dataSet.Tables["IP_Security"].Columns.Add("EndIP");
            enumerator = this.IpSecurity.GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    IPSecurity iPSecurity = (IPSecurity)enumerator.Current;
                    DataRow    dataRow15  = dataSet.Tables["IP_Security"].NewRow();
                    dataRow15["ID"]          = iPSecurity.ID;
                    dataRow15["Enabled"]     = iPSecurity.Enabled;
                    dataRow15["Description"] = iPSecurity.Description;
                    dataRow15["Service"]     = (int)iPSecurity.Service;
                    dataRow15["Action"]      = (int)iPSecurity.Action;
                    dataRow15["StartIP"]     = iPSecurity.StartIP;
                    dataRow15["EndIP"]       = iPSecurity.EndIP;
                    dataSet.Tables["IP_Security"].Rows.Add(dataRow15);
                }
            }
            finally
            {
                IDisposable disposable = enumerator as IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
            dataSet.Tables.Add("Filters");
            dataSet.Tables["Filters"].Columns.Add("FilterID");
            dataSet.Tables["Filters"].Columns.Add("Assembly");
            dataSet.Tables["Filters"].Columns.Add("ClassName");
            dataSet.Tables["Filters"].Columns.Add("Enabled");
            dataSet.Tables["Filters"].Columns.Add("Description");
            enumerator = this.Filters.GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    Filter  filter    = (Filter)enumerator.Current;
                    DataRow dataRow16 = dataSet.Tables["Filters"].NewRow();
                    dataRow16["FilterID"]    = filter.ID;
                    dataRow16["Assembly"]    = filter.AssemblyName;
                    dataRow16["ClassName"]   = filter.Class;
                    dataRow16["Enabled"]     = filter.Enabled;
                    dataRow16["Description"] = filter.Description;
                    dataSet.Tables["Filters"].Rows.Add(dataRow16);
                }
            }
            finally
            {
                IDisposable disposable = enumerator as IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
            dataSet.Tables.Add("UsersDefaultFolders");
            dataSet.Tables["UsersDefaultFolders"].Columns.Add("FolderName");
            dataSet.Tables["UsersDefaultFolders"].Columns.Add("Permanent");
            enumerator = this.UsersDefaultFolders.GetEnumerator();
            try
            {
                while (enumerator.MoveNext())
                {
                    UsersDefaultFolder usersDefaultFolder = (UsersDefaultFolder)enumerator.Current;
                    DataRow            dataRow17          = dataSet.Tables["UsersDefaultFolders"].NewRow();
                    dataRow17["FolderName"] = usersDefaultFolder.FolderName;
                    dataRow17["Permanent"]  = usersDefaultFolder.Permanent;
                    dataSet.Tables["UsersDefaultFolders"].Rows.Add(dataRow17);
                }
            }
            finally
            {
                IDisposable disposable = enumerator as IDisposable;
                if (disposable != null)
                {
                    disposable.Dispose();
                }
            }
            dataSet.WriteXml(stream);
        }