Example #1
0
        /// <summary>
        /// Get the pop3 server information from
        /// the configuration file, the host and
        /// port of the pop3 server is located in
        /// the default section, this data is used
        /// to connect to the pop3 server.
        /// </summary>
        private void GetPop3ServerHost()
        {
            try
            {
                // Create a new connection adapter.
                _connection = new Pop3ConnectionAdapter();

                // If no host name set then
                // use the defualt values.
                if (String.IsNullOrEmpty(_pop3ServerName))
                {
                    // Create a new default host type
                    // an load the values from the configuration
                    // file into the default host type.
                    ProxyPop3ServerDefaultHost defaultHost =
                        (ProxyPop3ServerDefaultHost)System.Configuration.ConfigurationManager.GetSection(
                            "ProxyPop3ServerGroup/ProxyPop3ServerDefaultHost");

                    // If the port is greater than zero then
                    // assign the port number.
                    if (defaultHost.HostSection.PortAttribute > 0)
                    {
                        _connection.Port = defaultHost.HostSection.PortAttribute;
                    }

                    // Get the pop3 server.
                    _connection.Server = defaultHost.HostSection.HostAttribute;
                }
                else
                {
                    // Create a new host type
                    // an load the values from the configuration
                    // file into the host type.
                    ProxyPop3ServerHosts hosts =
                        (ProxyPop3ServerHosts)System.Configuration.ConfigurationManager.GetSection(
                            "ProxyPop3ServerGroup/ProxyPop3ServerHosts");

                    // If the port is greater than zero then
                    // assign the port number.
                    if (hosts.HostSection[_pop3ServerName].PortAttribute > 0)
                    {
                        _connection.Port = hosts.HostSection[_pop3ServerName].PortAttribute;
                    }

                    // Get the pop3 server.
                    _connection.Server = hosts.HostSection[_pop3ServerName].HostAttribute;
                }
            }
            catch (Exception e)
            {
                // Detect a thread abort exception.
                if (e is ThreadAbortException)
                {
                    Thread.ResetAbort();
                }

                base.Write("Pop3SslProxyServer", "GetListeningPort", e.Message,
                           246, WriteTo.EventLog, LogType.Error);
            }
        }
Example #2
0
        /// <summary>
        /// Get the maximum number of clients from the configuration
        /// file, if no value is specified then default or
        /// the current value will be used.
        /// </summary>
        private void GetMaxNumClients()
        {
            try
            {
                // If no host name set then
                // use the defualt values.
                if (String.IsNullOrEmpty(_hostName))
                {
                    // Create a new default host type
                    // an load the values from the configuration
                    // file into the default host type.
                    ProxyPop3ServerDefaultHost defaultHost =
                        (ProxyPop3ServerDefaultHost)System.Configuration.ConfigurationManager.GetSection(
                            "ProxyPop3ServerGroup/ProxyPop3ServerDefaultHost");

                    // If the value is greater than zero then
                    // assign the port number.
                    if (defaultHost.HostSection.MaxNumClientsAttribute > 0)
                    {
                        _maxNumClients = defaultHost.HostSection.MaxNumClientsAttribute;
                    }
                }
                else
                {
                    // Create a new host type
                    // an load the values from the configuration
                    // file into the host type.
                    ProxyPop3ServerHosts hosts =
                        (ProxyPop3ServerHosts)System.Configuration.ConfigurationManager.GetSection(
                            "ProxyPop3ServerGroup/ProxyPop3ServerHosts");

                    // If the value is greater than zero then
                    // assign the port number.
                    if (hosts.HostSection[_hostName].MaxNumClientsAttribute > 0)
                    {
                        _maxNumClients = hosts.HostSection[_hostName].MaxNumClientsAttribute;
                    }
                }

                // Create a new client array.
                _client = new Pop3SslProxyConnection[_maxNumClients];
            }
            catch (Exception e)
            {
                // Detect a thread abort exception.
                if (e is ThreadAbortException)
                {
                    Thread.ResetAbort();
                }

                base.Write("Pop3SslProxyServer", "GetMaxNumClients", e.Message,
                           246, WriteTo.EventLog, LogType.Error);
            }
        }
Example #3
0
        /// <summary>
        /// Get the server credentials from the certificate store or file.
        /// </summary>
        /// <returns>The x509 certificate else null.</returns>
        private X509Certificate2 GetServerCredentials()
        {
            X509Certificate2 certificate = null;

            try
            {
                // Create a new default host type
                // an load the values from the configuration
                // file into the default host type.
                ProxyPop3ServerDefaultHost defaultHost =
                    (ProxyPop3ServerDefaultHost)System.Configuration.ConfigurationManager.GetSection(
                        "ProxyPop3ServerGroup/ProxyPop3ServerDefaultHost");

                // Make sure the section is defined.
                if (defaultHost == null)
                {
                    throw new Exception("Configuration section ProxyPop3ServerDefaultHost has not been defined.");
                }

                // Get the server credetials element.
                ProxyPop3ServerCredentialsElement serverCredentials = defaultHost.ServerCredentialsSection;
                if (serverCredentials == null)
                {
                    throw new Exception("Configuration element ServerCredentials has not been defined.");
                }

                // If using the certificate store.
                if (serverCredentials.UseCertificateStore)
                {
                    // Get the certificate from the store.
                    ProxyPop3ServerCredentialsStoreElement certificateStore = serverCredentials.CertificateStore;
                    if (certificateStore == null)
                    {
                        throw new Exception("Configuration element CertificateStore has not been defined.");
                    }

                    // Get the certificate refrence details from the certificate store.
                    certificate = X509Certificate2Store.GetCertificate(
                        certificateStore.StoreName,
                        certificateStore.StoreLocation,
                        certificateStore.X509FindType,
                        certificateStore.FindValue,
                        false);
                }
                else
                {
                    // Get the certificate path
                    ProxyPop3ServerCredentialsPathElement certificatePath = serverCredentials.CertificatePath;
                    if (certificatePath == null)
                    {
                        throw new Exception("Configuration element CertificatePath has not been defined.");
                    }

                    // Get the certificate path details and create
                    // the x509 certificate reference.
                    certificate = X509Certificate2Store.GetCertificate(certificatePath.Path, certificatePath.Password);
                }
            }
            catch (Exception e)
            {
                // Detect a thread abort exception.
                if (e is ThreadAbortException)
                {
                    Thread.ResetAbort();
                }

                base.Write("Pop3SslProxyConnection", "GetServerCredentials", e.Message,
                           553, WriteTo.EventLog, LogType.Error);
            }

            // Return the certificate.
            return(certificate);
        }