Click here to Skip to main content
15,893,368 members
Articles / Programming Languages / C#

SMTP and POP3 Mail Server

Rate me:
Please Sign up or sign in to vote.
4.88/5 (96 votes)
29 Sep 20031 min read 1M   18.9K   315  
An SMTP and POP3 mail server written using the .NET Framework and C#.
using System;

namespace LumiSoft.Net.IMAP.Server
{
	/// <summary>
	/// IMAP message info.
	/// </summary>
	public class IMAP_Message
	{
		private IMAP_Messages     m_Messages  = null;
		private string            m_MessageID = "";
		private int               m_UID       = 1;
		private IMAP_MessageFlags m_Flags;
		private long              m_Size      = 0;
		private DateTime          m_Date;

		/// <summary>
		/// Default constructor.
		/// </summary>
		/// <param name="messages"></param>
		/// <param name="messageID">Internal messageID.</param>
		/// <param name="UID">Message UID. NOTE: message uid must increase all the time, for new messages.</param>
		/// <param name="flags">Message flags.</param>
		/// <param name="size">Message size.</param>
		/// <param name="date">Message recieve date.</param>
		internal IMAP_Message(IMAP_Messages messages,string messageID,int UID,IMAP_MessageFlags flags,long size,DateTime date)
		{
			m_Messages  = messages;
			m_MessageID = messageID;
			m_UID       = UID;
			m_Flags     = flags;
			m_Size      = size;
			m_Date      = date;
		}


		#region function FlagsToString

		/// <summary>
		/// Converts message flags to string. Eg. \SEEN \DELETED .
		/// </summary>
		/// <returns></returns>
		public string FlagsToString()
		{
			string retVal = "";
			if(((int)IMAP_MessageFlags.Answered & (int)this.Flags) != 0){
				retVal += " \\ANSWERED";
			}
			if(((int)IMAP_MessageFlags.Flagged & (int)this.Flags) != 0){
				retVal += " \\FLAGGED";
			}
			if(((int)IMAP_MessageFlags.Deleted & (int)this.Flags) != 0){
				retVal += " \\DELETED";
			}
			if(((int)IMAP_MessageFlags.Seen & (int)this.Flags) != 0){
				retVal += " \\SEEN";
			}
			if(((int)IMAP_MessageFlags.Draft & (int)this.Flags) != 0){
				retVal += " \\DRAFT";
			}

			return retVal.Trim();
		}

		#endregion

		#region function SetFlags

		internal void SetFlags(IMAP_MessageFlags flags)
		{
			m_Flags = flags;
		}

		#endregion


		#region Properties Implementation

		/// <summary>
		/// Gets message number.
		/// </summary>
		public int MessageNo
		{
			get{
				if(m_Messages != null){
					return m_Messages.IndexOf(this);
				}
				else{
					return -1;
				}
			}
		}

		/// <summary>
		/// Gets internal messageID.
		/// </summary>
		public string MessageID
		{
			get{ return m_MessageID; }

			set{ m_MessageID = value; }
		}

		/// <summary>
		/// Gets message UID.
		/// </summary>
		public int MessageUID
		{
			get{ return m_UID; }
		}

		/// <summary>
		/// Gets message flags.
		/// </summary>
		public IMAP_MessageFlags Flags
		{
			get{ return m_Flags; }
		}

		/// <summary>
		/// Gets message size.
		/// </summary>
		public long Size
		{
			get{ return m_Size; }
		}

		/// <summary>
		/// Gets message size.
		/// </summary>
		public DateTime Date
		{
			get{ return m_Date; }
		}

		#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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


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