public wfrm_User_General(ServerAPI serverAPI,string domainID)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //

            try
            {
                m_ServerAPI = serverAPI;

                DataView dvDomains = m_ServerAPI.GetDomainList();
                foreach(DataRowView vDr in dvDomains){
                    m_pDomains.Items.Add(vDr["DomainName"].ToString(),vDr["DomainID"].ToString());
                }

                if(m_pDomains.Items.Count > 0){
                    m_pDomains.SelectedIndex = 0;
                }
                if(domainID != "ALL"){
                    m_pDomains.SelectItemByTag(domainID);
                }
            }
            catch(Exception x)
            {
                wfrm_Error frm = new wfrm_Error(x,new System.Diagnostics.StackTrace());
                frm.ShowDialog(this);
            }
        }
        /// <summary>
        /// Edit constructor.
        /// </summary>
        /// <param name="serverAPI"></param>
        /// <param name="dr"></param>
        public wfrm_Route(ServerAPI serverAPI,DataRow dr)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
            m_ServerAPI = serverAPI;

            m_pRouteType.Items.Add("Route to mailbox","mailbox");
            m_pRouteType.Items.Add("Route to remote address","remoteaddress");
            m_pRouteType.SelectedIndex = 0;

            foreach(DataRowView drV in serverAPI.GetDomainList()){
                m_pDomains.Items.Add(drV["DomainName"].ToString(),drV["DomainID"].ToString());
            }

            if(dr != null){
                string mailbox = dr["Mailbox"].ToString();
                if(mailbox.ToUpper().StartsWith("REMOTE:")){
                    mailbox = mailbox.Substring(7);
                    m_pRouteType.SelectItemByTag("remoteaddress");
                }

                m_pDomains.SelectItemByTag(dr["DomainID"].ToString());
                m_pPattern.Text     = dr["Pattern"].ToString();
                m_pRouteTo.Text     = mailbox;
                m_pDescription.Text = dr["Description"].ToString();
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="serverAPI"></param>
        public wfrm_System_Frame(ServerAPI serverAPI)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //

            try
            {
                m_ServerAPI = serverAPI;

                dsSettings = m_ServerAPI.GetSettings();
                dsSettings.AcceptChanges();
            }
            catch(Exception x){
                wfrm_Error frm = new wfrm_Error(x,new System.Diagnostics.StackTrace());
                frm.ShowDialog(this);
            }

            InitTab();
        }
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="serverAPI"></param>
        /// <param name="frame"></param>
        public wfrm_Domains(ServerAPI serverAPI,WFrame frame)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //

            try
            {
                m_ServerAPI = serverAPI;

                //---- Toolbar stuff
                frame.Frame_ToolBar = wToolBar1;

                InitGrid();

                m_Dv = serverAPI.GetDomainList();
                grid.DataSource = m_Dv;

                UpdateButtons();
            }
            catch(Exception x)
            {
                wfrm_Error frm = new wfrm_Error(x,new System.Diagnostics.StackTrace());
                frm.ShowDialog(this);
            }
        }
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="serverAPI"></param>
        public wfrm_Aliases(ServerAPI serverAPI,WFrame frame)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //

            try
            {
                m_ServerAPI = serverAPI;

                //---- Toolbar stuff
                frame.Frame_ToolBar = wToolBar1;

                InitGrid();

                RefreshForm();
            }
            catch(Exception x)
            {
                wfrm_Error frm = new wfrm_Error(x,new System.Diagnostics.StackTrace());
                frm.ShowDialog(this);
            }
        }
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="serverAPI"></param>
        public wfrm_Server(ServerAPI serverAPI)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
            m_ServerAPI = serverAPI;
        }
        public wfrm_User_Pop3Rem(ServerAPI serverAPI,string userName)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //

            InitGrid();

            ds = serverAPI.GetUserRemotePop3Servers(userName);
            grid.DataSource = ds.Tables["RemotePop3Servers"].DefaultView;
        }
        /// <summary>
        /// Filters message.
        /// </summary>
        /// <param name="messageStream">Message stream which to filter.</param>
        /// <param name="filteredStream">Filtered stream.</param>
        /// <param name="sender">Senders email address.</param>
        /// <param name="recipients">Recipients email addresses.</param>
        /// <param name="api">Access to server API.</param>
        public FilterResult Filter(MemoryStream messageStream,out MemoryStream filteredStream,string sender,string[] recipients,ServerAPI api)
        {
            filteredStream = null;

            // Store message to tmp file
            string mailStorePath = api.GetSettings().Tables["Settings"].Rows[0]["MailRoot"].ToString();

            if(!Directory.Exists(mailStorePath + "tmpScan")){
                Directory.CreateDirectory(mailStorePath + "tmpScan");
            }

            string file = mailStorePath + "tmpScan\\" + Guid.NewGuid().ToString() + ".eml";
            using(FileStream fs = File.Create(file)){
                messageStream.WriteTo(fs);
            }

            // Execute virus program to scan tmp message
            // #FileName - place holder is replaced with file
            DataSet ds = new DataSet();
            DataTable dt = ds.Tables.Add("Settings");
            dt.Columns.Add("Program");
            dt.Columns.Add("Arguments");
            ds.ReadXml(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\lsVirusFilter_db.xml");

            string virusSoft     = ds.Tables["Settings"].Rows[0]["Program"].ToString();
            string virusSoftArgs = ds.Tables["Settings"].Rows[0]["Arguments"].ToString().Replace("#FileName",file);

            System.Diagnostics.ProcessStartInfo sInf = new System.Diagnostics.ProcessStartInfo(virusSoft,virusSoftArgs);
            sInf.CreateNoWindow  = true;
            System.Diagnostics.Process p = System.Diagnostics.Process.Start(sInf);
            if(p != null){
                p.WaitForExit(100000);
            }

            // Return scanned message and delete tmp file
            using(FileStream fs = File.OpenRead(file)){
                byte[] data = new byte[fs.Length];
                fs.Read(data,0,data.Length);

                filteredStream = new MemoryStream(data);
            }

            File.Delete(file);

            return FilterResult.Store;
        }
        /// <summary>
        /// Adds mailserver to treeview.
        /// </summary>
        internal void AddMailServer(string name,string webServicesUrl,string userName,string password)
        {
            TreeNode node_Server = new TreeNode(name,1,1);

            ServerAPI api = null;
            // Local server connection
            if(node_Server.Text == "[local]"){
                api = new ServerAPI(Application.StartupPath + "\\Settings\\");
            }
            // Remote server connection.
            else{
                api = new ServerAPI(Application.StartupPath + "\\Settings\\",webServicesUrl,userName,password);
            }

            node_Server.Tag = new NodeData(NodeType.Server,api);
            m_pTreeView.Nodes[0].Nodes.Add(node_Server);

                TreeNode node_Sys = new TreeNode("System",2,2);
                node_Sys.Tag = new NodeData(NodeType.System,api);
                node_Server.Nodes.Add(node_Sys);

                TreeNode node_Domains = new TreeNode("Domains",3,3);
                node_Domains.Tag = new NodeData(NodeType.Domains,api);
                node_Server.Nodes.Add(node_Domains);

                TreeNode node_Users = new TreeNode("Users",4,4);
                node_Users.Tag = new NodeData(NodeType.Users,api);
                node_Server.Nodes.Add(node_Users);

                TreeNode node_Aliases = new TreeNode("Aliases",5,5);
                node_Aliases.Tag = new NodeData(NodeType.Aliases,api);
                node_Server.Nodes.Add(node_Aliases);

                TreeNode node_Routing = new TreeNode("Routing",6,6);
                node_Routing.Tag = new NodeData(NodeType.Routing,api);
                node_Server.Nodes.Add(node_Routing);

                TreeNode node_Security = new TreeNode("Security",7,7);
                node_Security.Tag = new NodeData(NodeType.Security,api);
                node_Server.Nodes.Add(node_Security);

                TreeNode node_Filters = new TreeNode("Filters",8,8);
                node_Filters.Tag = new NodeData(NodeType.Filters,api);
                node_Server.Nodes.Add(node_Filters);
        }
        public wfrm_Filter(ServerAPI serverAPI,DataRow dr)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
            if(dr != null){
                m_pDescription.Text = dr["Description"].ToString();
                m_pAssembly.Text    = dr["Assembly"].ToString();
                m_pClass.Text       = dr["ClassName"].ToString();
                m_pCost.DecValue    = Convert.ToDecimal(dr["Cost"]);
                m_pEnabled.Checked  = Convert.ToBoolean(dr["Enabled"]);
            }
        }
        public wfrm_User_Frame(ServerAPI serverAPI,DataRow dr)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
            m_ServerAPI = serverAPI;

            m_wfrm_User_General = new wfrm_User_General(serverAPI,dr);
            m_wfrm_User_Pop3Rem = new wfrm_User_Pop3Rem(serverAPI,dr["UserName"].ToString());

            wTab1.AddTab(m_wfrm_User_General, "General");
            wTab1.AddTab(m_wfrm_User_Pop3Rem, "Pop3 remote accounts");
            wTab1.SelectFirstTab();
        }
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="serverAPI"></param>
        /// <param name="frame"></param>
        public wfrm_Routing(ServerAPI serverAPI,WFrame frame)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
            m_ServerAPI = serverAPI;

            //---- Toolbar stuff
            frame.Frame_ToolBar = wToolBar1;

            InitGrid();

            RefreshForm();
        }
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="serverAPI"></param>
        /// <param name="frame"></param>
        public wfrm_Filters(ServerAPI serverAPI,WFrame frame)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
            m_ServerAPI = serverAPI;

            //---- Toolbar stuff
            frame.Frame_ToolBar = wToolBar1;

            InitGrid();

            m_DV = serverAPI.GetFilterList();
            grid.DataSource = m_DV;
        }
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="serverAPI"></param>
        public wfrm_Domain(ServerAPI serverAPI)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //

            try
            {
                m_ServerAPI = serverAPI;
            }
            catch(Exception x)
            {
                wfrm_Error frm = new wfrm_Error(x,new System.Diagnostics.StackTrace());
                frm.ShowDialog(this);
            }
        }
        public wfrm_User_Frame(ServerAPI serverAPI,string domainID)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
            m_ServerAPI = serverAPI;

            m_wfrm_User_General = new wfrm_User_General(serverAPI,domainID);
            m_wfrm_User_Pop3Rem = new wfrm_User_Pop3Rem(serverAPI,"xxxx_afafaftwwt_sgs"); // set dummy username

            wTab1.AddTab(m_wfrm_User_General, "General");
            wTab1.AddTab(m_wfrm_User_Pop3Rem, "Pop3 remote accounts");
            wTab1.SelectFirstTab();

            m_New = true;
        }
 public DataSet AddUser(string fullName,string userName,string password,string Description,string emails,string domainID,int mailboxSize,bool enabled,bool allowRelay,byte[] remPop3Accounts)
 {
     ServerAPI api = new ServerAPI(m_SettingsPath);
     return api.AddUser(fullName,userName,password,Description,emails,domainID,mailboxSize,enabled,allowRelay,remPop3Accounts).Table.DataSet;
 }
 public DataSet AddSecurityEntry(string Description,string protocol,string type,string action,string content,long startIP,long endIP)
 {
     ServerAPI api = new ServerAPI(m_SettingsPath);
     return api.AddSecurityEntry(Description,protocol,type,action,content,startIP,endIP).Table.DataSet;
 }
 public DataSet AddRoute(string pattern,string mailbox,string Description,string domainID)
 {
     ServerAPI api = new ServerAPI(m_SettingsPath);
     return api.AddRoute(pattern,mailbox,Description,domainID).Table.DataSet;
 }
 public DataSet AddFilter(string description,string assembly,string className,int cost,bool enabled)
 {
     ServerAPI api = new ServerAPI(m_SettingsPath);
     return api.AddFilter(description,assembly,className,cost,enabled).Table.DataSet;
 }
 public DataSet AddDomain(string domainName,string Description)
 {
     ServerAPI api = new ServerAPI(m_SettingsPath);
     return api.AddDomain(domainName,Description).Table.DataSet;
 }
 public DataSet AddAlias(string aliasName,string Description,string AliasMembers,string domainID,bool isPublic)
 {
     ServerAPI api = new ServerAPI(m_SettingsPath);
     return api.AddAlias(aliasName,Description,AliasMembers,domainID,isPublic).Table.DataSet;
 }
 public void DeleteDomain(string domainID)
 {
     ServerAPI api = new ServerAPI(m_SettingsPath);
     api.DeleteDomain(domainID);
 }
 public byte[] CreateBackUp()
 {
     ServerAPI api = new ServerAPI(m_SettingsPath);
     return api.CreateBackUp();
 }
 public void UpdateFilter(string filterID,string description,string assembly,string className,int cost,bool enabled)
 {
     ServerAPI api = new ServerAPI(m_SettingsPath);
     api.UpdateFilter(filterID,description,assembly,className,cost,enabled);
 }
 public void DeleteAlias(string aliasID)
 {
     ServerAPI api = new ServerAPI(m_SettingsPath);
     api.DeleteAlias(aliasID);
 }
 public void UpdateSettings(DataSet dsSettings)
 {
     ServerAPI api = new ServerAPI(m_SettingsPath);
     api.UpdateSettings(dsSettings);
 }
 public void UpdateRoute(string routeID,string pattern,string mailbox,string Description,string domainID)
 {
     ServerAPI api = new ServerAPI(m_SettingsPath);
     api.UpdateRoute(routeID,pattern,mailbox,Description,domainID);
 }
 public void UpdateUser(string userID,string fullName,string password,string Description,string emails,string domainID,int mailboxSize,bool enabled,bool allowRelay,byte[] remPop3Accounts)
 {
     ServerAPI api = new ServerAPI(m_SettingsPath);
     api.UpdateUser(userID,fullName,password,Description,emails,domainID,mailboxSize,enabled,allowRelay,remPop3Accounts);
 }
        public wfrm_User_General(ServerAPI serverAPI,DataRow dr)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //

            try
            {
                m_ServerAPI = serverAPI;
                drUser      = dr;

                m_pFullName.Text      = dr["FullName"].ToString();
                m_pLogOnName.Text     = dr["UserName"].ToString();
                m_pPassword.Text      = dr["Password"].ToString();
                m_pDescription.Text   = dr["Description"].ToString();
                m_pMailboxSize.Text   = dr["Mailbox_Size"].ToString();
                m_pEnabled.Checked    = Convert.ToBoolean(dr["Enabled"]);
                m_pAllowRelay.Checked = Convert.ToBoolean(dr["AllowRelay"]);

                string[] addresses = dr["Emails"].ToString().Split(new char[]{';'});
                foreach(string adr in addresses){
                    m_pAddresses.Items.Add(adr);
                }

                DataView dvDomains = m_ServerAPI.GetDomainList();
                foreach(DataRowView vDr in dvDomains){
                    m_pDomains.Items.Add(vDr["DomainName"].ToString(),vDr["DomainID"].ToString());
                }

                if(m_pAddresses.Items.Count > 0){
                    m_pDomains.SelectItemByTag(dr["DomainID"].ToString());
                    m_pDomains.Enabled = false;
                }
            }
            catch(Exception x)
            {
                wfrm_Error frm = new wfrm_Error(x,new System.Diagnostics.StackTrace());
                frm.ShowDialog(this);
            }
        }
 public void UpdateSecurityEntry(string securityID,string Description,string protocol,string type,string action,string content,long startIP,long endIP)
 {
     ServerAPI api = new ServerAPI(m_SettingsPath);
     api.UpdateSecurityEntry(securityID,Description,protocol,type,action,content,startIP,endIP);
 }