Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » C# » General » Downloads
 
Add your own
alternative version
Go to top

STUN Client

, 20 Apr 2007
STUN client C# implementation with sample application
Stun.zip
Stun
Net
docs
dns
dns_records.jpg
dns_records.vsd
Net
_junk
_Obsolete
_Stuff
AUTH
bin
Release
LumiSoft.Net.dll
Data
Dns
Client
FTP
Client
Server
HTTP
Server
ICMP
IMAP
Client
Server
IO
Log
LumiSoft.Net
Mime
vCard
Net.csproj.user
Net.suo
NNTP
Client
POP3
Client
Server
SDP
ServersCore
SIP
Client
Message
Proxy
Stack
SMTP
Client
Server
STUN
Client
Message
STUN_Client_app
STUN_Client_app.suo
STUN_Client_app
bin
Debug
LumiSoft.Net.dll
STUN_Client_app.exe
STUN_Client_app.vshost.exe
dep
LumiSoft.Net.dll
Properties
Settings.settings
using System;
using System.IO;

using LumiSoft.Net.IMAP.Server;

namespace LumiSoft.Net.IMAP.Client
{
	/// <summary>
	/// IMAP fetch item.
	/// </summary>
	public class IMAP_FetchItem
	{
		private int                  m_No            = 0;
		private int                  m_UID           = 0;
		private int                  m_Size          = 0;	
		private string               m_InternalDate  = "";
		private byte[]               m_Data          = null;
		private IMAP_FetchItem_Flags m_FetchFlags    = IMAP_FetchItem_Flags.MessageFlags;
		private IMAP_MessageFlags    m_Flags         = IMAP_MessageFlags.Recent;
		private string               m_Envelope      = "";
        private string               m_BodyStructure = "";

		/// <summary>
		/// Default constructor.
		/// </summary>
		/// <param name="no">Number of message in folder.</param>
		/// <param name="uid">Message UID.</param>
		/// <param name="size">Message size.</param>
		/// <param name="data">Message data.</param>
		/// <param name="flags">Message flags.</param>
		/// <param name="internalDate">Message INTERNALDATE.</param>
		/// <param name="envelope">Envelope string.</param>
        /// <param name="bodyStructure">BODYSTRUCTURE string.</param>
		/// <param name="fetchFlags">Specifies what data fetched from IMAP server.</param>
		internal IMAP_FetchItem(int no,int uid,int size,byte[] data,IMAP_MessageFlags flags,string internalDate,string envelope,string bodyStructure,IMAP_FetchItem_Flags fetchFlags)
		{	
			m_No            = no;
			m_UID           = uid;
			m_Size          = size;
			m_Data          = data;
			m_Flags         = flags;
			m_InternalDate  = internalDate;
			m_Envelope      = envelope;
			m_FetchFlags    = fetchFlags;
            m_BodyStructure = bodyStructure;
		}


		#region Properties Implementation

		/// <summary>
		/// Specifies what data this IMAP_FetchItem contains. This is flagged value and can contain multiple values.
		/// </summary>
		public IMAP_FetchItem_Flags FetchFlags
		{
			get{ return m_FetchFlags; }
		}

		/// <summary>
		/// Gets number of message in folder.
		/// </summary>
		public int MessageNumber
		{
			get{ return m_No; }
		}

		/// <summary>
		/// Gets message UID. This property is available only if IMAP_FetchItem_Flags.UID was specified,
		/// otherwise throws exception.
		/// </summary>
		public int UID
		{	
			get{ 
				if((m_FetchFlags & IMAP_FetchItem_Flags.UID) == 0){
					throw new Exception("IMAP_FetchItem_Flags.UID wasn't specified in FetchMessages command, becuse of it this property is unavailable.");
				}

				return m_UID; 
			}
		}

		/// <summary>
		/// Gets message size. This property is available only if IMAP_FetchItem_Flags.Size was specified,
		/// otherwise throws exception.
		/// </summary>
		public int Size
		{	
			get{
				if((m_FetchFlags & IMAP_FetchItem_Flags.Size) == 0){
					throw new Exception("IMAP_FetchItem_Flags.Size wasn't specified in FetchMessages command, becuse of it this property is unavailable.");
				}

				return m_Size; 
			}
		}

		/// <summary>
		/// Gets message IMAP server INTERNAL date. This property is available only if IMAP_FetchItem_Flags.InternalDate was specified,
		/// otherwise throws exception.
		/// </summary>
		public DateTime InternalDate
		{	
			get{ 
				if((m_FetchFlags & IMAP_FetchItem_Flags.InternalDate) == 0){
					throw new Exception("IMAP_FetchItem_Flags.InternalDate wasn't specified in FetchMessages command, becuse of it this property is unavailable.");
				}

				return IMAP_Utils.ParseDate(m_InternalDate); 
			}
		}

		/// <summary>
		/// Gets message flags. This property is available only if IMAP_FetchItem_Flags.MessageFlags was specified,
		/// otherwise throws exception.
		/// </summary>
		public IMAP_MessageFlags MessageFlags
		{
			get{ 
				if((m_FetchFlags & IMAP_FetchItem_Flags.MessageFlags) == 0){
					throw new Exception("IMAP_FetchItem_Flags.MessageFlags wasn't specified in FetchMessages command, becuse of it this property is unavailable.");
				}

				return m_Flags; 
			}
		}

		/// <summary>
		/// Gets message IMAP ENVELOPE. This property is available only if IMAP_FetchItem_Flags.Envelope was specified,
		/// otherwise throws exception.
		/// </summary>
		public IMAP_Envelope Envelope
		{
			get{ 
				if((m_FetchFlags & IMAP_FetchItem_Flags.Envelope) == 0){
					throw new Exception("IMAP_FetchItem_Flags.Envelope wasn't specified in FetchMessages command, becuse of it this property is unavailable.");
				}

				IMAP_Envelope envelope = new IMAP_Envelope();
				envelope.Parse(m_Envelope);
				return envelope; 
			}
		}

        /// <summary>
		/// Gets message IMAP BODYSTRUCTURE. This property is available only if IMAP_FetchItem_Flags.BodyStructure was specified,
		/// otherwise throws exception.
		/// </summary>
        public IMAP_BODY BodyStructure
        {
            get{
                if((m_FetchFlags & IMAP_FetchItem_Flags.BodyStructure) == 0){
					throw new Exception("IMAP_FetchItem_Flags.BodyStructure wasn't specified in FetchMessages command, becuse of it this property is unavailable.");
				}
                
                IMAP_BODY bodyStructure = new IMAP_BODY();
                bodyStructure.Parse(m_BodyStructure);
                return bodyStructure;
            }
        }

		/// <summary>
		/// Gets message header data. This property is available only if IMAP_FetchItem_Flags.Header was specified,
		/// otherwise throws exception.
		/// </summary>
		public byte[] HeaderData
		{
			get{
				if(!((m_FetchFlags & IMAP_FetchItem_Flags.Header) != 0 || (m_FetchFlags & IMAP_FetchItem_Flags.Message) != 0)){
					throw new Exception("IMAP_FetchItem_Flags.Header wasn't specified in FetchMessages command, becuse of it this property is unavailable.");
				}

				if((m_FetchFlags & IMAP_FetchItem_Flags.Message) != 0){
					return System.Text.Encoding.ASCII.GetBytes(LumiSoft.Net.Mime.MimeUtils.ParseHeaders(new MemoryStream(m_Data)));
				}
				else{
					return m_Data;
				}
			}
		}

		/// <summary>
		/// Gets message data. This property is available only if IMAP_FetchItem_Flags.Message was specified,
		/// otherwise throws exception.
		/// </summary>
		public byte[] MessageData
		{
			get{ 
				if((m_FetchFlags & IMAP_FetchItem_Flags.Message) == 0){
					throw new Exception("IMAP_FetchItem_Flags.Message wasn't specified in FetchMessages command, becuse of it this property is unavailable.");
				}

				return m_Data; 
			}
		}
				
		/// <summary>
		/// Gets if message is unseen. This property is available only if IMAP_FetchItem_Flags.MessageFlags was specified,
		/// otherwise throws exception.
		/// </summary>
		public bool IsNewMessage
		{
			get{ 
				if((m_FetchFlags & IMAP_FetchItem_Flags.MessageFlags) == 0){
					throw new Exception("IMAP_FetchItem_Flags.MessageFlags wasn't specified in FetchMessages command, becuse of it this property is unavailable.");
				}

				return (m_Flags & IMAP_MessageFlags.Seen) == 0; 
			}
		}

		/// <summary>
		/// Gets if message is answered. This property is available only if IMAP_FetchItem_Flags.MessageFlags was specified,
		/// otherwise throws exception.
		/// </summary>
		public bool IsAnswered
		{
			get{
				if((m_FetchFlags & IMAP_FetchItem_Flags.MessageFlags) == 0){
					throw new Exception("IMAP_FetchItem_Flags.MessageFlags wasn't specified in FetchMessages command, becuse of it this property is unavailable.");
				}

				return (m_Flags & IMAP_MessageFlags.Answered) != 0; 
			}
		}




		/// <summary>
		/// Gets message data(headers or full message), it depends on HeadersOnly property.
		/// </summary>
		[Obsolete("Use HeaderData or MessageData data instead.")]
		public byte[] Data
		{
			get{ return m_Data; }
		}

		/// <summary>
		/// Gets if headers or full message requested in fetch.
		/// </summary>
		[Obsolete("Use FetchFlags property instead !")]
		public bool HeadersOnly
		{
			get{ return (m_FetchFlags & IMAP_FetchItem_Flags.Header) != 0; }
		}

		#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)

Share

About the Author

Ivar Lumi

Estonia Estonia
No Biography provided

| Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 20 Apr 2007
Article Copyright 2007 by Ivar Lumi
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid