/// <summary>
        /// Factory constructor.
        /// </summary>
        public MailFilterAgentFactory()
        {
            // Initialize fields, parameters, and data structures.
            hashManager = new SHA256Managed();

            // Get the path to where the data files should be.
            // The final result is calculated in relation to the
            // binary DLL that contains this class and can easily
            // be set to almost any directory. The only requirement
            // is that the "Network Service" user has write permission
            // to whatever directory is specified.
            Assembly currAssembly = Assembly.GetAssembly(this.GetType());
            string   assemblyPath = Path.GetDirectoryName(currAssembly.Location);

            this.dataPath = Path.Combine(assemblyPath, RelativeDataPath);

            // Read the XML configuration file and apply its settings.
            this.MailFilterSettings = new MailFilterSettings(Path.Combine(this.dataPath, ConfigFileName));

            // Initialize the empty database tables.
            this.verifiedDB = new MailFilterDatabase(
                this.MailFilterSettings.MaxVerifiedEntries,
                this.MailFilterSettings.BucketSize);

            this.unverifiedDB = new MailFilterDatabase(
                this.MailFilterSettings.MaxUnverifiedEntries,
                this.MailFilterSettings.BucketSize);

            // Try loading the contents of a persisted data file into
            // the temporarily blocked sender list tables.
            this.verifiedDB.ReadPersistedData(Path.Combine(this.dataPath, VerifiedDataFile));

            this.unverifiedDB.ReadPersistedData(Path.Combine(this.dataPath, UnverifiedDataFile));
        }
        /// <summary>
        /// The constructor registers all event handlers and creates
        /// local references to the session database tables. It should only be called
        /// from the MailFilterAgentFactory class.
        /// </summary>
        /// <param name="settings">A reference to a settings object.</param>
        /// <param name="verifiedDatabase">A reference to the table of verified entries.</param>
        /// <param name="unverifiedDatabase">A reference to the table of unverified entries.</param>
        /// <param name="hashManager">A reference to the hash class instance in the factory.</param>
        /// <param name="server">A reference to the SMTP server, passed from the factory.</param>
        public MailFilterAgent(
            MailFilterSettings settings,
            MailFilterDatabase verifiedDatabase,
            MailFilterDatabase unverifiedDatabase,
            SHA256Managed hashManager,
            SmtpServer server)
        {
            // Initialize instance variables.
            this.settings           = settings;
            this.server             = server;
            this.verifiedDatabase   = verifiedDatabase;
            this.unverifiedDatabase = unverifiedDatabase;
            this.testOnEndOfHeaders = false;
            this.hashManager        = hashManager;

            // Set up the hooks to have your functions called when certain events occur.
            this.OnRcptCommand  += new RcptCommandEventHandler(this.OnRcptCommandHandler);
            this.OnEndOfHeaders += new EndOfHeadersEventHandler(this.OnEndOfHeaderHandler);
        }