private void Bind()
 {
     lock (this.m_pParent)
     {
         this.m_pParent.TCP_Client.TcpStream.WriteLine("GetVirtualServers");
         string text = this.m_pParent.ReadLine();
         if (!text.ToUpper().StartsWith("+OK"))
         {
             throw new Exception(text);
         }
         int num = Convert.ToInt32(text.Split(new char[]
         {
             ' '
         }, 2)[1]);
         MemoryStream memoryStream = new MemoryStream();
         this.m_pParent.TCP_Client.TcpStream.ReadFixedCount(memoryStream, num);
         DataSet dataSet = Utils.DecompressDataSet(memoryStream);
         if (dataSet.Tables.Contains("Servers"))
         {
             foreach (DataRow dataRow in dataSet.Tables["Servers"].Rows)
             {
                 this.m_pVirtualServers.Add(new VirtualServer(this.m_pParent, this, dataRow["ID"].ToString(), ConvertEx.ToBoolean(dataRow["Enabled"], true), dataRow["Name"].ToString(), dataRow["API_assembly"].ToString(), dataRow["API_class"].ToString(), dataRow["API_initstring"].ToString()));
             }
         }
     }
 }
 private void Bind()
 {
     lock (this.m_pVirtualServer.Server.LockSynchronizer)
     {
         this.m_pVirtualServer.Server.TCP_Client.TcpStream.WriteLine("GetUsersDefaultFolders " + this.m_pVirtualServer.VirtualServerID);
         string text = this.m_pVirtualServer.Server.ReadLine();
         if (!text.ToUpper().StartsWith("+OK"))
         {
             throw new Exception(text);
         }
         int num = Convert.ToInt32(text.Split(new char[]
         {
             ' '
         }, 2)[1]);
         MemoryStream memoryStream = new MemoryStream();
         this.m_pVirtualServer.Server.TCP_Client.TcpStream.ReadFixedCount(memoryStream, (long)num);
         DataSet dataSet = Utils.DecompressDataSet(memoryStream);
         if (dataSet.Tables.Contains("UsersDefaultFolders"))
         {
             foreach (DataRow dataRow in dataSet.Tables["UsersDefaultFolders"].Rows)
             {
                 this.m_pFolders.Add(new UsersDefaultFolder(this, dataRow["FolderName"].ToString(), ConvertEx.ToBoolean(dataRow["Permanent"])));
             }
         }
     }
 }
예제 #3
0
        public void Restore(Stream stream, RestoreFlags_enum restoreFlags)
        {
            DataSet dataSet = new DataSet();

            dataSet.ReadXml(stream);
            if (dataSet.Tables.Contains("Settings"))
            {
                this.SystemSettings.LoadSettings(dataSet);
                this.SystemSettings.Commit();
            }
            if (dataSet.Tables.Contains("Domains"))
            {
                foreach (DataRow dataRow in dataSet.Tables["Domains"].Rows)
                {
                    if (this.Domains.Contains(dataRow["DomainName"].ToString()))
                    {
                        if ((restoreFlags & RestoreFlags_enum.Replace) != (RestoreFlags_enum)0)
                        {
                        }
                    }
                    else if ((restoreFlags & RestoreFlags_enum.Add) != (RestoreFlags_enum)0)
                    {
                        this.Domains.Add(dataRow["DomainName"].ToString(), dataRow["Description"].ToString());
                    }
                }
            }
            if (dataSet.Tables.Contains("Users"))
            {
                foreach (DataRow dataRow2 in dataSet.Tables["Users"].Rows)
                {
                    User user = null;
                    bool flag = false;
                    if (this.Users.Contains(dataRow2["UserName"].ToString()))
                    {
                        if ((restoreFlags & RestoreFlags_enum.Replace) != (RestoreFlags_enum)0)
                        {
                            user                    = this.Users.GetUserByName(dataRow2["UserName"].ToString());
                            user.UserName           = dataRow2["UserName"].ToString();
                            user.FullName           = dataRow2["FullName"].ToString();
                            user.Password           = dataRow2["Password"].ToString();
                            user.Description        = dataRow2["Description"].ToString();
                            user.MaximumMailboxSize = ConvertEx.ToInt32(dataRow2["Mailbox_Size"]);
                            user.Enabled            = ConvertEx.ToBoolean(dataRow2["Enabled"]);
                            user.Permissions        = (UserPermissions)ConvertEx.ToInt32(dataRow2["Permissions"]);
                            user.Commit();
                            string[] array = user.EmailAddresses.ToArray();
                            for (int i = 0; i < array.Length; i++)
                            {
                                string emailAddress = array[i];
                                user.EmailAddresses.Remove(emailAddress);
                            }
                            UserRemoteServer[] array2 = user.RemoteServers.ToArray();
                            for (int j = 0; j < array2.Length; j++)
                            {
                                UserRemoteServer remoteServer = array2[j];
                                user.RemoteServers.Remove(remoteServer);
                            }
                            UserMessageRule[] array3 = user.MessageRules.ToArray();
                            for (int k = 0; k < array3.Length; k++)
                            {
                                UserMessageRule rule = array3[k];
                                user.MessageRules.Remove(rule);
                            }
                            flag = true;
                        }
                    }
                    else if ((restoreFlags & RestoreFlags_enum.Add) != (RestoreFlags_enum)0)
                    {
                        user = this.Users.Add(dataRow2["UserName"].ToString(), dataRow2["FullName"].ToString(), dataRow2["Password"].ToString(), dataRow2["Description"].ToString(), ConvertEx.ToInt32(dataRow2["Mailbox_Size"]), ConvertEx.ToBoolean(dataRow2["Enabled"]), (UserPermissions)ConvertEx.ToInt32(dataRow2["Permissions"]));
                        flag = true;
                    }
                    if (flag)
                    {
                        if (dataSet.Tables.Contains("User_EmailAddresses"))
                        {
                            foreach (DataRowView dataRowView in new DataView(dataSet.Tables["User_EmailAddresses"])
                            {
                                RowFilter = "UserID='" + dataRow2["UserID"].ToString() + "'"
                            })
                            {
                                user.EmailAddresses.Add(dataRowView["EmailAddress"].ToString());
                            }
                        }
                        if (dataSet.Tables.Contains("User_RemoteServers"))
                        {
                            foreach (DataRowView dataRowView2 in new DataView(dataSet.Tables["User_RemoteServers"])
                            {
                                RowFilter = "UserID='" + dataRow2["UserID"].ToString() + "'"
                            })
                            {
                                user.RemoteServers.Add(dataRowView2["Description"].ToString(), dataRowView2["RemoteServer"].ToString(), ConvertEx.ToInt32(dataRowView2["RemotePort"]), ConvertEx.ToBoolean(dataRowView2["UseSSL"]), dataRowView2["RemoteUserName"].ToString(), dataRowView2["RemotePassword"].ToString(), ConvertEx.ToBoolean(dataRowView2["Enabled"]));
                            }
                        }
                        if (dataSet.Tables.Contains("User_MessageRules"))
                        {
                            foreach (DataRowView dataRowView3 in new DataView(dataSet.Tables["User_MessageRules"])
                            {
                                RowFilter = "UserID='" + dataRow2["UserID"].ToString() + "'"
                            })
                            {
                                UserMessageRule userMessageRule = user.MessageRules.Add(ConvertEx.ToBoolean(dataRowView3["Enabled"]), dataRowView3["Description"].ToString(), dataRowView3["MatchExpression"].ToString(), (GlobalMessageRule_CheckNextRule)ConvertEx.ToInt32(dataRowView3["CheckNextRuleIf"]));
                                if (dataSet.Tables.Contains("User_MessageRuleActions"))
                                {
                                    foreach (DataRowView dataRowView4 in new DataView(dataSet.Tables["User_MessageRuleActions"])
                                    {
                                        RowFilter = string.Concat(new string[]
                                        {
                                            "UserID='",
                                            dataRow2["UserID"].ToString(),
                                            "' AND RuleID='",
                                            dataRowView3["RuleID"].ToString(),
                                            "'"
                                        })
                                    })
                                    {
                                        userMessageRule.Actions.Add(dataRowView4["ActionID"].ToString(), dataRowView4["Description"].ToString(), (UserMessageRuleActionType)Convert.ToInt32(dataRowView4["ActionType"]), Convert.FromBase64String(dataRowView4["ActionData"].ToString()), true);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (dataSet.Tables.Contains("Groups"))
            {
                foreach (DataRow dataRow3 in dataSet.Tables["Groups"].Rows)
                {
                    bool flag2 = false;
                    if (this.Groups.Contains(dataRow3["GroupName"].ToString()) && (restoreFlags & RestoreFlags_enum.Replace) != (RestoreFlags_enum)0)
                    {
                        this.Groups.Remove(this.Groups.GetGroupByName(dataRow3["GroupName"].ToString()));
                        flag2 = true;
                    }
                    if (!this.Groups.Contains(dataRow3["GroupName"].ToString()) && (flag2 || (restoreFlags & RestoreFlags_enum.Add) != (RestoreFlags_enum)0))
                    {
                        Group group = this.Groups.Add(dataRow3["GroupName"].ToString(), dataRow3["Description"].ToString(), ConvertEx.ToBoolean(dataRow3["Enabled"]));
                        if (dataSet.Tables.Contains("Group_Members"))
                        {
                            foreach (DataRowView dataRowView5 in new DataView(dataSet.Tables["Group_Members"])
                            {
                                RowFilter = "GroupID='" + dataRow3["GroupID"].ToString() + "'"
                            })
                            {
                                group.Members.Add(dataRowView5["UserOrGroup"].ToString());
                            }
                        }
                    }
                }
            }
            if (dataSet.Tables.Contains("MailingLists"))
            {
                foreach (DataRow dataRow4 in dataSet.Tables["MailingLists"].Rows)
                {
                    bool flag3 = false;
                    if (this.MailingLists.Contains(dataRow4["MailingListName"].ToString()) && (restoreFlags & RestoreFlags_enum.Replace) != (RestoreFlags_enum)0)
                    {
                        this.MailingLists.Remove(this.MailingLists.GetMailingListByName(dataRow4["MailingListName"].ToString()));
                        flag3 = true;
                    }
                    if (!this.MailingLists.Contains(dataRow4["MailingListName"].ToString()) && (flag3 || (restoreFlags & RestoreFlags_enum.Add) != (RestoreFlags_enum)0))
                    {
                        MailingList mailingList = this.MailingLists.Add(dataRow4["MailingListName"].ToString(), dataRow4["Description"].ToString(), ConvertEx.ToBoolean(dataRow4["Enabled"]));
                        if (dataSet.Tables.Contains("MailingList_Members"))
                        {
                            foreach (DataRowView dataRowView6 in new DataView(dataSet.Tables["MailingList_Members"])
                            {
                                RowFilter = "MailingListID='" + dataRow4["MailingListID"].ToString() + "'"
                            })
                            {
                                mailingList.Members.Add(dataRowView6["Address"].ToString());
                            }
                        }
                        if (dataSet.Tables.Contains("MailingList_ACL"))
                        {
                            foreach (DataRowView dataRowView7 in new DataView(dataSet.Tables["MailingList_ACL"])
                            {
                                RowFilter = "MailingListID='" + dataRow4["MailingListID"].ToString() + "'"
                            })
                            {
                                mailingList.ACL.Add(dataRowView7["UserOrGroup"].ToString());
                            }
                        }
                    }
                }
            }
            if (dataSet.Tables.Contains("Routing"))
            {
                foreach (DataRow dataRow5 in dataSet.Tables["Routing"].Rows)
                {
                    bool flag4 = false;
                    if (this.Routes.ContainsPattern(dataRow5["Pattern"].ToString()) && (restoreFlags & RestoreFlags_enum.Replace) != (RestoreFlags_enum)0)
                    {
                        this.Routes.Remove(this.Routes.GetRouteByPattern(dataRow5["Pattern"].ToString()));
                        flag4 = true;
                    }
                    if (!this.Routes.ContainsPattern(dataRow5["Pattern"].ToString()) && (flag4 || (restoreFlags & RestoreFlags_enum.Add) != (RestoreFlags_enum)0))
                    {
                        RouteAction     routeAction_enum = (RouteAction)Convert.ToInt32(dataRow5["Action"]);
                        RouteActionBase action           = null;
                        if (routeAction_enum == RouteAction.RouteToEmail)
                        {
                            action = new RouteAction_RouteToEmail(Convert.FromBase64String(dataRow5["ActionData"].ToString()));
                        }
                        else if (routeAction_enum == RouteAction.RouteToHost)
                        {
                            action = new RouteAction_RouteToHost(Convert.FromBase64String(dataRow5["ActionData"].ToString()));
                        }
                        else if (routeAction_enum == RouteAction.RouteToMailbox)
                        {
                            action = new RouteAction_RouteToMailbox(Convert.FromBase64String(dataRow5["ActionData"].ToString()));
                        }
                        this.Routes.Add(dataRow5["Description"].ToString(), dataRow5["Pattern"].ToString(), ConvertEx.ToBoolean(dataRow5["Enabled"]), action);
                    }
                }
            }
            if (dataSet.Tables.Contains("GlobalMessageRules"))
            {
                IEnumerator enumerator;
                if ((restoreFlags & RestoreFlags_enum.Replace) != (RestoreFlags_enum)0)
                {
                    enumerator = this.GlobalMessageRules.GetEnumerator();
                    try
                    {
                        while (enumerator.MoveNext())
                        {
                            GlobalMessageRule rule2 = (GlobalMessageRule)enumerator.Current;
                            this.GlobalMessageRules.Remove(rule2);
                        }
                    }
                    finally
                    {
                        IDisposable disposable = enumerator as IDisposable;
                        if (disposable != null)
                        {
                            disposable.Dispose();
                        }
                    }
                }
                DataView dataView = new DataView(dataSet.Tables["GlobalMessageRules"]);
                enumerator = dataView.GetEnumerator();
                try
                {
                    while (enumerator.MoveNext())
                    {
                        DataRowView       dataRowView8      = (DataRowView)enumerator.Current;
                        GlobalMessageRule globalMessageRule = this.GlobalMessageRules.Add(ConvertEx.ToBoolean(dataRowView8["Enabled"]), dataRowView8["Description"].ToString(), dataRowView8["MatchExpression"].ToString(), (GlobalMessageRule_CheckNextRule)ConvertEx.ToInt32(dataRowView8["CheckNextRuleIf"]));
                        if (dataSet.Tables.Contains("GlobalMessageRuleActions"))
                        {
                            foreach (DataRowView dataRowView9 in new DataView(dataSet.Tables["GlobalMessageRuleActions"])
                            {
                                RowFilter = "RuleID='" + dataRowView8["RuleID"].ToString() + "'"
                            })
                            {
                                globalMessageRule.Actions.Add(dataRowView9["ActionID"].ToString(), dataRowView9["Description"].ToString(), (GlobalMessageRuleActionType)Convert.ToInt32(dataRowView9["ActionType"]), Convert.FromBase64String(dataRowView9["ActionData"].ToString()), true);
                            }
                        }
                    }
                }
                finally
                {
                    IDisposable disposable = enumerator as IDisposable;
                    if (disposable != null)
                    {
                        disposable.Dispose();
                    }
                }
            }
            if (dataSet.Tables.Contains("IP_Security"))
            {
                IPSecurity[] array4 = this.IpSecurity.ToArray();
                for (int i = 0; i < array4.Length; i++)
                {
                    IPSecurity entry = array4[i];
                    this.IpSecurity.Remove(entry);
                }
                foreach (DataRow dataRow6 in dataSet.Tables["IP_Security"].Rows)
                {
                    this.IpSecurity.Add(ConvertEx.ToBoolean(dataRow6["Enabled"]), dataRow6["Description"].ToString(), (ServiceKind)ConvertEx.ToInt32(dataRow6["Service"]), (IPSecurityAction)ConvertEx.ToInt32(dataRow6["Action"]), IPAddress.Parse(dataRow6["StartIP"].ToString()), IPAddress.Parse(dataRow6["EndIP"].ToString()));
                }
            }
            if (dataSet.Tables.Contains("Filters"))
            {
                Filter[] array5 = this.Filters.ToArray();
                for (int i = 0; i < array5.Length; i++)
                {
                    Filter filter = array5[i];
                    this.Filters.Remove(filter);
                }
                foreach (DataRow dataRow7 in dataSet.Tables["Filters"].Rows)
                {
                    this.Filters.Add(ConvertEx.ToBoolean(dataRow7["Enabled"]), dataRow7["Description"].ToString(), dataRow7["Assembly"].ToString(), dataRow7["ClassName"].ToString());
                }
            }
            if (dataSet.Tables.Contains("UsersDefaultFolders"))
            {
                foreach (DataRow dataRow8 in dataSet.Tables["UsersDefaultFolders"].Rows)
                {
                    if (this.UsersDefaultFolders.Contains(dataRow8["FolderName"].ToString()))
                    {
                        if ((restoreFlags & RestoreFlags_enum.Replace) != (RestoreFlags_enum)0)
                        {
                            this.UsersDefaultFolders.Remove(this.UsersDefaultFolders.GetFolderByName(dataRow8["FolderName"].ToString()));
                            this.UsersDefaultFolders.Add(dataRow8["FolderName"].ToString(), ConvertEx.ToBoolean(dataRow8["Permanent"]));
                        }
                    }
                    else if ((restoreFlags & RestoreFlags_enum.Add) != (RestoreFlags_enum)0)
                    {
                        this.UsersDefaultFolders.Add(dataRow8["FolderName"].ToString(), ConvertEx.ToBoolean(dataRow8["Permanent"]));
                    }
                }
            }
        }