MailServer_Service.cs
上传用户:horngjaan
上传日期:2009-12-12
资源大小:2882k
文件大小:27k
- using System;
- using System.IO;
- using System.Collections;
- using System.ComponentModel;
- using System.Data;
- using System.Diagnostics;
- using System.ServiceProcess;
- using System.Threading;
- using LumiSoft.MailServer;
- namespace LumiSoft.MailServer
- {
- /// <summary>
- /// Mail server service.
- /// </summary>
- public class MailServer : System.ServiceProcess.ServiceBase
- {
- private LumiSoft.MailServer.POP3.POP3_Server POP3_Server;
- private LumiSoft.MailServer.SMTP.SMTP_Server SMTP_Server;
- private System.Timers.Timer timer1;
- private System.ComponentModel.IContainer components;
- private static ServerAPI m_pAPI = null;
- private DataSet dsSettings = null;
- internal string m_SartUpPath = ""; // Path where (this)service relies.
- internal string m_PostmasterUName = ""; // Holds postmaster UserName.
- internal string m_PostmasterPwd = ""; // Holds postmaster Password.
- private DB_Type m_DB_Type = DB_Type.XML;
- internal string m_connStr = ""; // Sql connection string to Mail DB.
- private DateTime m_SettingsDate; // Holds server Settings.xml date.
- private DateTime m_UsersDate; // Holds server Users.xml date.
- private DateTime m_AliasesDate; // Holds server Aliases.xml date.
- private DateTime m_RoutingDate; // Holds server Routing.xml date.
- private DateTime m_DomainsDate; // Holds server Domains.xml date.
- private DateTime m_SecurityDate; // Holds server Secuirty.xml date.
- private DateTime m_RelayTime;
- private DateTime m_RelayRetryTime;
- /// <summary>
- /// Default constructor.
- /// </summary>
- public MailServer()
- {
- // This call is required by the Windows.Forms Component Designer.
- InitializeComponent();
- // TODO: Add any initialization after the InitComponent call
- }
- #region static Main
- // The main entry point for the process
- static void Main()
- {
- System.ServiceProcess.ServiceBase[] ServicesToRun;
-
- // More than one user Service may run within the same process. To add
- // another service to this process, change the following line to
- // create a second service object. For example,
- //
- // ServicesToRun = New System.ServiceProcess.ServiceBase[] {new Service1(), new MySecondUserService()};
- //
- ServicesToRun = new System.ServiceProcess.ServiceBase[] { new MailServer() };
- System.ServiceProcess.ServiceBase.Run(ServicesToRun);
- }
- #endregion
- #region Designer Generated code
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
- {
- this.components = new System.ComponentModel.Container();
- this.POP3_Server = new LumiSoft.MailServer.POP3.POP3_Server(this.components);
- this.timer1 = new System.Timers.Timer();
- this.SMTP_Server = new LumiSoft.MailServer.SMTP.SMTP_Server(this.components);
- ((System.ComponentModel.ISupportInitialize)(this.timer1)).BeginInit();
- //
- // POP3_Server
- //
- this.POP3_Server.CommandIdleTimeOut = 60000;
- this.POP3_Server.LogCommands = false;
- this.POP3_Server.SessionIdleTimeOut = 80000;
- this.POP3_Server.GetTopLines += new LumiSoft.MailServer.POP3.GetTopLinesHandler(this.POP3_Server_GetTopLines);
- this.POP3_Server.GetMailEvent += new LumiSoft.MailServer.POP3.GetMessageHandler(this.pop3_Server_GetMailEvent);
- this.POP3_Server.DeleteMessageEvent += new LumiSoft.MailServer.POP3.DeleteMessageHandler(this.pop3_Server_DeleteMessageEvent);
- this.POP3_Server.SysError += new LumiSoft.MailServer.ErrorEventHandler(this.OnServer_SysError);
- this.POP3_Server.AuthUser += new LumiSoft.MailServer.AuthUserEventHandler(this.Server_AuthenticateUser);
- this.POP3_Server.GetMessgesList += new LumiSoft.MailServer.POP3.GetMessagesInfoHandler(this.pop3_Server_GetMessgesList);
- this.POP3_Server.SessionLog += new LumiSoft.MailServer.LogEventHandler(this.POP3_Server_SessionLog);
- this.POP3_Server.ValidateIPAddress += new LumiSoft.MailServer.ValidateIPHandler(this.POP3_Server_ValidateIPAddress);
- //
- // timer1
- //
- this.timer1.Interval = 15000;
- this.timer1.Elapsed += new System.Timers.ElapsedEventHandler(this.timer1_Elapsed);
- //
- // SMTP_Server
- //
- this.SMTP_Server.CommandIdleTimeOut = 60000;
- this.SMTP_Server.LogCommands = false;
- this.SMTP_Server.MaxBadCommands = 8;
- this.SMTP_Server.MaxMessageSize = 1000000;
- this.SMTP_Server.MaxRecipients = 100;
- this.SMTP_Server.SessionIdleTimeOut = 80000;
- this.SMTP_Server.AuthUser += new LumiSoft.MailServer.AuthUserEventHandler(this.Server_AuthenticateUser);
- this.SMTP_Server.SessionLog += new LumiSoft.MailServer.LogEventHandler(this.SMTP_Server_SessionLog);
- this.SMTP_Server.ValidateMailFrom += new LumiSoft.MailServer.SMTP.ValidateMailFromHandler(this.smtp_Server_ValidateSender);
- this.SMTP_Server.SysError += new LumiSoft.MailServer.ErrorEventHandler(this.OnServer_SysError);
- this.SMTP_Server.NewMailEvent += new LumiSoft.MailServer.SMTP.NewMailEventHandler(this.smtp_Server_NewMailEvent);
- this.SMTP_Server.ValidateMailTo += new LumiSoft.MailServer.SMTP.ValidateMailToHandler(this.smtp_Server_ValidateRecipient);
- this.SMTP_Server.ValidateMailboxSize += new LumiSoft.MailServer.SMTP.ValidateMailboxSize(this.SMTP_Server_ValidateMailBoxSize);
- this.SMTP_Server.ValidateIPAddress += new LumiSoft.MailServer.ValidateIPHandler(this.SMTP_Server_ValidateIPAddress);
- //
- // MailServer
- //
- this.ServiceName = "Service1";
- ((System.ComponentModel.ISupportInitialize)(this.timer1)).EndInit();
- }
- #endregion
- #region function Dispose
- /// <summary>
- /// Clean up any resources being used.
- /// </summary>
- protected override void Dispose( bool disposing )
- {
- if( disposing )
- {
- if (components != null)
- {
- components.Dispose();
- }
- }
- base.Dispose( disposing );
- }
- #endregion
- #region function OnStart
- /// <summary>
- /// Set things in motion so your service can do its work.
- /// </summary>
- protected override void OnStart(string[] args)
- {
- try
- {
- string filePath = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
- m_SartUpPath = filePath.Substring(0,filePath.LastIndexOf('\')) + "\";
- Error.ErrorFilePath = m_SartUpPath;
-
- LoadSettings();
- m_pAPI = new ServerAPI(m_SartUpPath + "Settings\",MailStore.MailStorePath,m_connStr,m_DB_Type);
- // If don't use sql, load Users and Domains from xml
- if(m_DB_Type == DB_Type.XML){
- LoadLocalDomains();
- LoadLocalUsers();
- LoadLocalAliases();
- LoadRoutes();
- LoadLocalSecurity();
- }
-
- // Start Servers
- SMTP_Server.Enabled = true;
- POP3_Server.Enabled = true;
- timer1.Enabled = true;
- m_RelayTime = DateTime.Today;
- m_RelayRetryTime = DateTime.Today;
- // Logging stuff
- SCore.WriteLog(m_SartUpPath + "Logs\Server\server.log","//---- Server started " + DateTime.Now);
- }
- catch(Exception x)
- {
- Error.DumpError(x,new System.Diagnostics.StackTrace());
- }
- }
- #endregion
- #region function OnStop
-
- /// <summary>
- /// Stop this service.
- /// </summary>
- protected override void OnStop()
- {
- SMTP_Server.Enabled = false;
- POP3_Server.Enabled = false;
- timer1.Enabled = false;
- // Logging stuff
- SCore.WriteLog(m_SartUpPath + "Logs\Server\server.log","//---- Server stopped " + DateTime.Now);
- }
- #endregion
- #region SMTP Events
- //------ SMTP Events -----------------------//
- #region function SMTP_Server_ValidateIPAddress
- private void SMTP_Server_ValidateIPAddress(object sender, LumiSoft.MailServer.ValidateIP_EventArgs e)
- {
- try
- {
- string IP = Ip_to_longStr(e.ConnectedIP);
- e.Validated = m_pAPI.IsSmtpAccessAllowed(IP);
- }
- catch(Exception x)
- {
- e.Validated = false;
- Error.DumpError(x,new System.Diagnostics.StackTrace());
- }
- }
- #endregion
- #region function smtp_Server_ValidateSender
- private void smtp_Server_ValidateSender(object sender, LumiSoft.MailServer.SMTP.ValidateSender_EventArgs e)
- {
- e.Validated = true;
- }
- #endregion
- #region function smtp_Server_ValidateRecipient
- private void smtp_Server_ValidateRecipient(object sender, LumiSoft.MailServer.SMTP.ValidateRecipient_EventArgs e)
- {
- try
- {
- e.Validated = false;
- string mailTo = e.MailTo;
- mailTo = mailTo.Replace("%",""); //remove '%'
- mailTo = mailTo.Replace("!",""); //remove '!'
- mailTo = mailTo.Replace("[",""); //remove '['
- mailTo = mailTo.Replace("]",""); //remove ']'
- //1) is local domain or relay needed
- //2) can map email address to mailbox
- //3) [is alias. NOTE: only authenticated user can access alias !]
- //4) if matches any routing pattern
- // check e-domain, if it's local.
- if(m_pAPI.DomainExists(mailTo)){
- if(m_pAPI.MapUser(mailTo) == null){
- // Check if alias. NOTE: only authenticated user can access alias !
- if(e.Authenticated && m_pAPI.GetAliasMembers(mailTo) != null){
- e.Validated = true;
- }
- // At least check if matches any routing pattern.
- else if(m_pAPI.GetMailboxFromPattern(mailTo) != null){
- e.Validated = true;
- }
- }
- else{
- e.Validated = true;
- }
- }
- else{
- e.LocalRecipient = false;
-
- // This isn't domain what we want.
- // 1)If user Authenticated, allow relay.
- // 2)Check if relay is allowed for this ip.
- if(e.Authenticated || IsRelayAllowed(e.ConnectedIP)){
- e.Validated = true;
- }
- }
- }
- catch(Exception x)
- {
- Error.DumpError(x,new System.Diagnostics.StackTrace());
- }
- }
- #endregion
- #region function SMTP_Server_ValidateMailBoxSize
- private void SMTP_Server_ValidateMailBoxSize(object sender, LumiSoft.MailServer.SMTP.ValidateMailboxSize_EventArgs e)
- {
- e.IsValid = false;
- try
- {
- // If relay or alias address, don't check size
- if(!m_pAPI.DomainExists(e.eAddress) || m_pAPI.GetAliasMembers(e.eAddress) != null){
- e.IsValid = true;
- return;
- }
- //--------------------------------//
- string user = m_pAPI.MapUser(e.eAddress);
- if(user == null){
- user = m_pAPI.GetMailboxFromPattern(e.eAddress);
- }
- if(user != null){
- e.IsValid = !m_pAPI.ValidateMailboxSize(user);
- }
- }
- catch(Exception x)
- {
- Error.DumpError(x,new System.Diagnostics.StackTrace());
- }
- }
- #endregion
- #region function smtp_Server_NewMailEvent
- private void smtp_Server_NewMailEvent(object sender, LumiSoft.MailServer.SMTP.NewMail_EventArgs e)
- {
- try
- {
- Hashtable forward_pathList = new Hashtable();
- //--------------------------------------------------------------//
- // Construct new forward-path list.(because of aliases)
- foreach(string forward_path in e.MailTo){
- string emailAddress = Core.ParseEmailFromPath(forward_path);
- string[] aliasMembers = m_pAPI.GetAliasMembers(emailAddress);
- if(aliasMembers != null){
- foreach(string member in aliasMembers){
- if(!forward_pathList.Contains(member)){
- forward_pathList.Add(member,member);
- }
- }
- }
- else{
- if(!forward_pathList.Contains(emailAddress)){
- forward_pathList.Add(emailAddress,forward_path);
- }
- }
- }
- //------------------------------------------------------------//
-
- // Store individual msg for each Recipient
- foreach(string forward_path in forward_pathList.Values){
- string eAddress = Core.ParseEmailFromPath(forward_path);
- string mailbox = m_pAPI.MapUser(eAddress);
- bool relay = false;
-
- // if not valid mailbox
- if(mailbox == null){
- // check e-domain, if it's local.
- if(m_pAPI.DomainExists(eAddress)){
- // Check if eAddress matches routing pattern
- mailbox = m_pAPI.GetMailboxFromPattern(eAddress);
- // If there isn't valid mailbox, some error has happened.
- // (One known reason is when user,alias,routing is deleted between RCPT and DATA)
- // Forward message to postmaster.
- if(mailbox == null){
- mailbox = "postmaster";
- }
- }
- // This isn't domain what we want, relay message.
- else{
- relay = true;
- }
- }
- // stores mail
- MailStore.StoreMessage(mailbox,e.MessageStream,forward_path,e.MailFrom,relay);
- }
- }
- catch(Exception x)
- {
- Error.DumpError(x,new System.Diagnostics.StackTrace());
- }
- }
- #endregion
- #region function SMTP_Server_SessionLog
- private void SMTP_Server_SessionLog(object sender, LumiSoft.MailServer.Log_EventArgs e)
- {
- DateTime today = DateTime.Today;
- string fileName = "smtpCmds_" + today.Year.ToString() + "_" + today.Month.ToString() + "_" + today.Day.ToString() + ".log";
- SCore.WriteLog(m_SartUpPath + "Logs\SMTP\" + fileName,e.LogText);
- }
- #endregion
- //------ End of SMTP Events ----------------//
- #endregion
- #region POP3 Events
- //------ POP3 Events ----------------------//
- #region function POP3_Server_ValidateIPAddress
- private void POP3_Server_ValidateIPAddress(object sender, LumiSoft.MailServer.ValidateIP_EventArgs e)
- {
- try
- {
- string IP = Ip_to_longStr(e.ConnectedIP);
- e.Validated = m_pAPI.IsPop3AccessAllowed(IP);
- }
- catch(Exception x)
- {
- e.Validated = false;
- Error.DumpError(x,new System.Diagnostics.StackTrace());
- }
- }
- #endregion
-
- #region function pop3_Server_GetMessgesList
- private void pop3_Server_GetMessgesList(object sender, LumiSoft.MailServer.POP3.GetMessagesInfo_EventArgs e)
- {
- try
- {
- string userName = e.UserName;
- // If postmaster, mailbox name is always 'postmaster'.
- if(m_PostmasterUName == e.UserName){
- userName = "postmaster";
- }
- MailStore.GetMessageList(userName,e);
- }
- catch(Exception x)
- {
- Error.DumpError(x,new System.Diagnostics.StackTrace());
- }
- }
- #endregion
- #region function pop3_Server_GetMailEvent
- private void pop3_Server_GetMailEvent(object sender, LumiSoft.MailServer.POP3.GetMessage_EventArgs e)
- {
- try
- {
- string mailbox = e.UserName;
- string msgFile = e.MessageID;
- // If postmaster, mailbox name is always 'postmaster'.
- if(m_PostmasterUName == e.UserName){
- mailbox = "postmaster";
- }
- e.Message = MailStore.GetMessage(mailbox,msgFile);
- }
- catch(Exception x)
- {
- Error.DumpError(x,new System.Diagnostics.StackTrace());
- }
- }
- #endregion
- #region function pop3_Server_DeleteMessageEvent
- private void pop3_Server_DeleteMessageEvent(object sender, LumiSoft.MailServer.POP3.DeleteMessage_EventArgs e)
- {
- try
- {
- string mailbox = e.UserName;
- string msgFile = e.MessageID;
- MailStore.DeleteMessage(mailbox,msgFile);
- }
- catch(Exception x)
- {
- Error.DumpError(x,new System.Diagnostics.StackTrace());
- }
- }
- #endregion
- #region function POP3_Server_GetTopLines
- private void POP3_Server_GetTopLines(object sender, LumiSoft.MailServer.POP3.GetTopLines_Eventargs e)
- {
- try
- {
- e.LinesData = m_pAPI.GetMessageTopLines(e.Mailbox,e.MessageID,e.Lines);
- }
- catch(Exception x)
- {
- Error.DumpError(x,new System.Diagnostics.StackTrace());
- }
- }
- #endregion
- #region function POP3_Server_SessionLog
- private void POP3_Server_SessionLog(object sender, LumiSoft.MailServer.Log_EventArgs e)
- {
- DateTime today = DateTime.Today;
- string fileName = "pop3Cmds_" + today.Year.ToString() + "_" + today.Month.ToString() + "_" + today.Day.ToString() + ".log";
- SCore.WriteLog(m_SartUpPath + "Logs\POP3\" + fileName,e.LogText);
- }
- #endregion
- //------ End of POP3 Events ---------------//
-
- #endregion
- #region Common Events
- #region function Server_AuthenticateUser
- private void Server_AuthenticateUser(object sender, LumiSoft.MailServer.AuthUser_EventArgs e)
- {
- try
- {
- e.Validated = m_pAPI.AuthUser(e.UserName,e.PasswData,e.AuthData,e.AuthType);
- }
- catch(Exception x)
- {
- e.Validated = false;
- Error.DumpError(x,new System.Diagnostics.StackTrace());
- }
- }
- #endregion
- #region function OnServer_SysError
- private void OnServer_SysError(object sender,LumiSoft.MailServer.Error_EventArgs e)
- {
- Error.DumpError(e.Exception,e.StackTrace);
- }
- #endregion
- #endregion
-
- #region function IsRelayAllowed
- /// <summary>
- /// Checks if relaying is allowed to specified IP.
- /// </summary>
- /// <param name="ipAddress"></param>
- /// <returns></returns>
- private bool IsRelayAllowed(string ipAddress)
- {
- try
- {
- string IP = Ip_to_longStr(ipAddress);
- return m_pAPI.IsRelayAllowed(IP);
- }
- catch(Exception x)
- {
- Error.DumpError(x,new System.Diagnostics.StackTrace());
- }
- return false;
- }
- #endregion
-
- #region Service Timer
-
- private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
- {
- try
- {
- //------------ local settings --------------------------------------------------------------//
- DateTime dateSettings = File.GetLastWriteTime(m_SartUpPath + "\Settings\Settings.xml");
- if(DateTime.Compare(dateSettings,m_SettingsDate) != 0){
- LoadSettings();
- }
- if(m_DB_Type == DB_Type.XML){
- DateTime dateUsers = File.GetLastWriteTime(m_SartUpPath + "\Settings\Users.xml");
- DateTime dateAliases = File.GetLastWriteTime(m_SartUpPath + "\Settings\Aliases.xml");
- DateTime dateDomains = File.GetLastWriteTime(m_SartUpPath + "\Settings\Domains.xml");
- DateTime dateRouting = File.GetLastWriteTime(m_SartUpPath + "\Settings\Routing.xml");
- DateTime dateSecurity = File.GetLastWriteTime(m_SartUpPath + "\Settings\Security.xml");
-
- if(DateTime.Compare(dateDomains,m_DomainsDate) != 0){
- LoadLocalDomains();
- }
- if(DateTime.Compare(dateUsers,m_UsersDate) != 0){
- LoadLocalUsers();
- }
- if(DateTime.Compare(dateAliases,m_AliasesDate) != 0){
- LoadLocalAliases();
- }
- if(DateTime.Compare(dateRouting,m_RoutingDate) != 0){
- LoadRoutes();
- }
- if(DateTime.Compare(dateSecurity,m_SecurityDate) != 0){
- LoadLocalSecurity();
- }
- }
- //------------------------------------------------------------------------------------------//
- //---- Relay stuff ----------------------------------------------------------------------------//
- if(DateTime.Now.CompareTo(m_RelayTime.AddSeconds(Relay.RelayInterval)) >= 0 && !Relay.IsDelivering){
- Relay relay = new Relay(this);
- // Create New Thread for Mail Delivery handling
- ThreadStart tStart = new ThreadStart(relay.Deliver);
- Thread tr = new Thread(tStart);
- tr.Priority = ThreadPriority.Lowest;
- tr.Start();
- m_RelayTime = DateTime.Now;
- }
-
- if(DateTime.Now.CompareTo(m_RelayRetryTime.AddSeconds(Relay.RelayRetryInterval)) >= 0 && !Relay.IsDeliveringRetry){
- Relay relay = new Relay(this);
- // Create New Thread for Mail Delivery handling
- ThreadStart tStart = new ThreadStart(relay.DeliverRetry);
- Thread tr = new Thread(tStart);
- tr.Priority = ThreadPriority.Lowest;
- tr.Start();
- m_RelayRetryTime = DateTime.Now;
- }
- //----------------------------------------------------------------------------------------------//
-
- }
- catch(Exception x)
- {
- Error.DumpError(x,new System.Diagnostics.StackTrace());
- }
- }
- #endregion
- #region Local settings loading stuff
- #region function LoadSettings
- private void LoadSettings()
- {
- try
- {
- lock(this){
- dsSettings = new DataSet();
- dsSettings.ReadXml(m_SartUpPath + "\Settings\Settings.xml");
- m_SettingsDate = File.GetLastWriteTime(m_SartUpPath + "\Settings\Settings.xml");
- DataRow dr = dsSettings.Tables["Settings"].Rows[0];
- m_connStr = dr["ConnectionString"].ToString();
- m_DB_Type = (DB_Type)Enum.Parse(typeof(DB_Type),dr["DataBaseType"].ToString());
- string mailStorePath = dr["MailRoot"].ToString();
- if(!mailStorePath.EndsWith("\")){
- mailStorePath += "\";
- }
- if(mailStorePath.Length < 3){
- mailStorePath = m_SartUpPath + "MailStore\";
- }
- MailStore.MailStorePath = mailStorePath;
- //------- SMTP Settings ---------------------------------------------//
- SMTP_Server.IpAddress = dr["SMTP_IPAddress"].ToString();
- SMTP_Server.Port = Convert.ToInt32(dr["SMTP_Port"]);
- SMTP_Server.Threads = Convert.ToInt32(dr["SMTP_Threads"]);
- SMTP_Server.SessionIdleTimeOut = Convert.ToInt32(dr["SMTP_SessionIdleTimeOut"]) * 1000; // Seconds to milliseconds
- SMTP_Server.CommandIdleTimeOut = Convert.ToInt32(dr["SMTP_CommandIdleTimeOut"]) * 1000; // Seconds to milliseconds
- SMTP_Server.MaxMessageSize = Convert.ToInt32(dr["MaxMessageSize"]) * 1000000; // Mb to byte.
- SMTP_Server.MaxRecipients = Convert.ToInt32(dr["MaxRecipients"]);
- SMTP_Server.MaxBadCommands = Convert.ToInt32(dr["SMTP_MaxBadCommands"]);
- m_PostmasterUName = dr["PostMasterUserName"].ToString();
- m_PostmasterPwd = dr["PostMasterPassword"].ToString();
- //-------------------------------------------------------------------//
- //------- POP3 Settings -------------------------------------//
- POP3_Server.IpAddress = dr["POP3_IPAddress"].ToString();
- POP3_Server.Port = Convert.ToInt32(dr["POP3_Port"]);
- POP3_Server.Threads = Convert.ToInt32(dr["POP3_Threads"]);
- POP3_Server.SessionIdleTimeOut = Convert.ToInt32(dr["POP3_SessionIdleTimeOut"]) * 1000; // Seconds to milliseconds
- POP3_Server.CommandIdleTimeOut = Convert.ToInt32(dr["POP3_CommandIdleTimeOut"]) * 1000; // Seconds to milliseconds
- POP3_Server.MaxBadCommands = Convert.ToInt32(dr["POP3_MaxBadCommands"]);
- //-----------------------------------------------------------//
-
- //------- Delivery ------------------------------------------//
- Relay.SmartHost = dr["SmartHost"].ToString();
- Relay.UseSmartHost = Convert.ToBoolean(dr["UseSmartHost"]);
- Relay.Dns1 = dr["Dns1"].ToString();
- Relay.Dns2 = dr["Dns2"].ToString();
- Relay.RelayInterval = Convert.ToInt32(dr["RelayInterval"]);
- Relay.RelayRetryInterval = Convert.ToInt32(dr["RelayRetryInterval"]);
- Relay.RelayUndelWarning = Convert.ToInt32(dr["RelayUndeliveredWarning"]);
- Relay.RelayUndelivered = Convert.ToInt32(dr["RelayUndelivered"]);
- Relay.MaxRelayThreads = Convert.ToInt32(dr["MaxRelayThreads"]);
- Relay.UndeliveredTemplate = dr["UndeliveredTemplate"].ToString();
- Relay.UndelWarningTemplate = dr["UndeliveredWarningTemplate"].ToString();
- //-----------------------------------------------------------//
- //----- Logging settings -------------------------------------//
- SMTP_Server.LogCommands = Convert.ToBoolean(dr["LogSMTPCmds"]);
- POP3_Server.LogCommands = Convert.ToBoolean(dr["LogPOP3Cmds"]);
- //------------------------------------------------------------//
- SCore.WriteLog(m_SartUpPath + "Logs\Server\server.log","//---- Server settings loaded " + DateTime.Now);
- }
- }
- catch(Exception x)
- {
- Error.DumpError(x,new System.Diagnostics.StackTrace());
- }
- }
- #endregion
- #region function LoadLocalDomains
- private void LoadLocalDomains()
- {
- try
- {
- lock(this){
- m_pAPI.LoadDomains();
- m_DomainsDate = File.GetLastWriteTime(m_SartUpPath + "\Settings\Domains.xml");
-
- SCore.WriteLog(m_SartUpPath + "Logs\Server\server.log","//---- Local Domains loaded " + DateTime.Now);
- }
- }
- catch(Exception x)
- {
- Error.DumpError(x,new System.Diagnostics.StackTrace());
- }
- }
- #endregion
- #region function LoadLocalUsers
- private void LoadLocalUsers()
- {
- try
- {
- lock(this){
- m_pAPI.LoadUsers();
- m_UsersDate = File.GetLastWriteTime(m_SartUpPath + "\Settings\Users.xml");
- SCore.WriteLog(m_SartUpPath + "Logs\Server\server.log","//---- Local Users loaded " + DateTime.Now);
- }
- }
- catch(Exception x)
- {
- Error.DumpError(x,new System.Diagnostics.StackTrace());
- }
- }
- #endregion
- #region function LoadLocalAliases
- private void LoadLocalAliases()
- {
- try
- {
- lock(this){
- m_pAPI.LoadAliases();
- m_AliasesDate = File.GetLastWriteTime(m_SartUpPath + "\Settings\Aliases.xml");
- SCore.WriteLog(m_SartUpPath + "Logs\Server\server.log","//---- Local Aliaeses loaded " + DateTime.Now);
- }
- }
- catch(Exception x)
- {
- Error.DumpError(x,new System.Diagnostics.StackTrace());
- }
- }
- #endregion
- #region function LoadRoutes
- private void LoadRoutes()
- {
- try
- {
- lock(this){
- m_pAPI.LoadRouting();
- m_RoutingDate = File.GetLastWriteTime(m_SartUpPath + "\Settings\Routing.xml");
- SCore.WriteLog(m_SartUpPath + "Logs\Server\server.log","//---- Local Routes loaded " + DateTime.Now);
- }
- }
- catch(Exception x)
- {
- Error.DumpError(x,new System.Diagnostics.StackTrace());
- }
- }
- #endregion
- #region function LoadLocalSecurity
- private void LoadLocalSecurity()
- {
- try
- {
- lock(this){
- m_pAPI.LoadSecurity();
- m_SecurityDate = File.GetLastWriteTime(m_SartUpPath + "\Settings\Security.xml");
- SCore.WriteLog(m_SartUpPath + "Logs\Server\server.log","//---- Local Security loaded " + DateTime.Now);
- }
- }
- catch(Exception x)
- {
- Error.DumpError(x,new System.Diagnostics.StackTrace());
- }
- }
- #endregion
- #endregion
-
- #region function Ip_to_longStr
- /// <summary>
- /// Removes points from ip and fill all blocks eg.(10.0.0.1 = 10 000 000 001).
- /// </summary>
- /// <param name="ip"></param>
- /// <returns></returns>
- private string Ip_to_longStr(string ip)
- {
- try
- {
- string retVal = "";
- string[] str = ip.Split(new char[]{'.'});
- // loop through all ip blocks.
- foreach(string ipBlock in str){
- string buff = ipBlock;
- // If block size is smaller than 3, append '0' at the beginning of string.
- if(ipBlock.Length < 3){
- for(int i=0;i<3;i++){
- if(buff.Length >= 3){
- break;
- }
- buff = "0" + buff;
- }
- }
- retVal += buff;
- }
- return retVal;
- }
- catch(Exception x)
- {
- Error.DumpError(x,new System.Diagnostics.StackTrace());
- return "";
- }
- }
- #endregion
-
- #region Properties Implementation
- /// <summary>
- ///
- /// </summary>
- internal static ServerAPI API
- {
- get{ return m_pAPI; }
- }
- #endregion
-
- }
- }