Click here to Skip to main content
15,892,537 members
Articles / Programming Languages / C#

LumiSoft MailServer

Rate me:
Please Sign up or sign in to vote.
3.79/5 (22 votes)
17 Nov 2006CPOL1 min read 323K   4.9K   74  
Full featured SMTP/POP3/IMAP server
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Timers;

using LumiSoft;

namespace LumiSoft.MailServer
{
    /// <summary>
    /// Recycle bin messages manager.
    /// </summary>
    internal class RecycleBinManager : IDisposable
    {
        private IMailServerApi m_pApi   = null;
        private Timer          m_pTimer = null;
        private DateTime       m_LastCleanTime;

        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="api">Virtual server api</param>
        public RecycleBinManager(IMailServerApi api)
        {
            m_pApi          = api;
            
            m_pTimer = new Timer();
            m_pTimer.Interval = 1000 * 60 * 60;
            m_pTimer.Elapsed += new ElapsedEventHandler(m_pTimer_Elapsed);

            m_LastCleanTime = DateTime.MinValue;
        }

        #region method Dispose

        /// <summary>
        /// Cleans up any resources being used.
        /// </summary>
        public void Dispose()
        {
            if(m_pTimer != null){
                m_pTimer.Dispose();
                m_pTimer = null;
            }
        }

        #endregion


        #region Events Handling

        #region method m_pTimer_Elapsed

        private void m_pTimer_Elapsed(object sender,ElapsedEventArgs e)
        {
            DoCleanUp();
        }

        #endregion

        #endregion


        #region method DoCleanUp

        /// <summary>
        /// Deletes recycle bin messages what 'delete after days' has exceeded.
        /// </summary>
        public void DoCleanUp()
        {
            try{
                int delAferDays = Convert.ToInt32(m_pApi.GetRecycleBinSettings().Rows[0]["DeleteMessagesAfter"]);

                foreach(DataRowView drV in m_pApi.GetRecycleBinMessagesInfo(null,DateTime.MinValue,DateTime.Today.AddDays(-delAferDays))){
                    if(DateTime.Now > Convert.ToDateTime(drV["DeleteTime"]).AddDays(delAferDays)){
                        try{
                            m_pApi.DeleteRecycleBinMessage(drV["MessageID"].ToString());
                        }
                        catch{
                            // RecycelBin message file is probably locked, so skip it now.
                        }
                    }
                }

                m_LastCleanTime = DateTime.Now;
            }
            catch(Exception x){
                Error.DumpError(x,new System.Diagnostics.StackTrace());
            }
        }

        #endregion


        #region Properties Implementation

        /// <summary>
        /// Gets when last clean up was done.
        /// </summary>
        public DateTime LastCleanUpTime
        {
            get{ return m_LastCleanTime; }
        }

        #endregion

    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Estonia Estonia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions