Click here to Skip to main content
12,359,751 members (65,255 online)
Click here to Skip to main content
Articles » Languages » C# » General » Downloads

Stats

171.1K views
9.5K downloads
65 bookmarked
Posted

STUN Client

, 20 Apr 2007 CPOL
STUN client C# implementation with sample application
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
using System;
using System.Collections.Generic;
using System.Text;

namespace LumiSoft.Net.IMAP.Server
{
    /// <summary>
    /// Holds IMAP selected folder info.
    /// </summary>
    public class IMAP_SelectedFolder
    {
        private string                 m_Folder    = "";
        private long                   m_FolderUID = 0;
        private bool                   m_ReadOnly  = false;
        private IMAP_MessageCollection m_pMessages = null;
        
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="folder">Folder name.</param>
        internal IMAP_SelectedFolder(string folder)
        {
            m_Folder    = folder;
            m_pMessages = new IMAP_MessageCollection();
        }


        #region method Update

        /// <summary>
        /// Updates current folder messages info with new messages info.
        /// </summary>
        /// <param name="folder"></param>
        /// <returns></returns>
        internal string Update(IMAP_SelectedFolder folder)
        {
            StringBuilder retVal = new StringBuilder();
            long          maxUID = this.MessageUidNext - 1;

            long countExists = this.Messages.Count;
            long countRecent = this.RecentCount;

            // Add new messages
            for(int i=folder.Messages.Count-1;i>0;i--){
                IMAP_Message message = folder.Messages[i];
                // New message
                if(message.UID > maxUID){
                    m_pMessages.Add(
                        message.ID,
                        message.UID,
                        message.InternalDate,
                        message.Size,
                        message.Flags
                    );
                }
                // New messages ended
                else{
                    break;
                }
            }
                       
            // Remove deleted messages
            for(int i=0;i<m_pMessages.Count-1;i++){
                IMAP_Message message = m_pMessages[i];
                
                if(!folder.m_pMessages.ContainsUID(message.UID)){
                    retVal.Append("* " + message.SequenceNo + " EXPUNGE\r\n");
                    m_pMessages.Remove(message);
                    i--;
                }
            }

            if(countExists != this.Messages.Count){
                retVal.Append("* " + this.Messages.Count + " EXISTS\r\n");
            }
            if(countRecent != this.RecentCount){
                retVal.Append("* " + this.RecentCount + " RECENT\r\n");
            }

            return retVal.ToString();
        }

        #endregion


        #region Properties Implementation

        /// <summary>
        /// Gets selected folder name.
        /// </summary>
        public string Folder
        {
            get{ return m_Folder; }
        }

        /// <summary>
        /// Gets folder UID(UIDVADILITY) value.
        /// </summary>
        public long FolderUID
        {
            get{ return m_FolderUID; }

            set{ m_FolderUID = value; }
        }

        /// <summary>
        /// Gets or sets if folder is read only.
        /// </summary>
        public bool ReadOnly
        {
            get{ return m_ReadOnly; }

            set{ m_ReadOnly = value; }
        }
                
        /// <summary>
        /// Gets selected folder messages info.
        /// </summary>
        public IMAP_MessageCollection Messages
        {
            get{ return m_pMessages; }
        }

        /// <summary>
        /// Gets number of messages with \UNSEEN flags in the collection.
        /// </summary>
        public int UnSeenCount
        {
            get{ 
                int count = 0;
                foreach(IMAP_Message message in m_pMessages){
                    if((message.Flags & IMAP_MessageFlags.Seen) == 0){
                        count++;
                    }
                }
                return count; 
            }
        }

        /// <summary>
        /// Gets number of messages with \RECENT flags in the collection.
        /// </summary>
        public int RecentCount
        {
            get{ 
                int count = 0;
                foreach(IMAP_Message message in m_pMessages){
                    if((message.Flags & IMAP_MessageFlags.Recent) != 0){
                        count++;
                    }
                }
                return count; 
            }
        }

        /// <summary>
        /// Gets number of messages with \DELETED flags in the collection.
        /// </summary>
        public int DeletedCount
        {
            get{ 
                int count = 0;
                foreach(IMAP_Message message in m_pMessages){
                    if((message.Flags & IMAP_MessageFlags.Deleted) != 0){
                        count++;
                    }
                }
                return count; 
            }
        }

        /// <summary>
        /// Gets first message index in the collection which has not \SEEN flag set.
        /// </summary>
        public int FirstUnseen
        {
            get{ 
                int index = 1;
                foreach(IMAP_Message message in m_pMessages){
                    if((message.Flags & IMAP_MessageFlags.Seen) == 0){
                        return index;                   
                    }
                    index++;
                }

                return 0;
            }
        }

        /// <summary>
        /// Gets next new message predicted UID.
        /// </summary>
        public long MessageUidNext
        {
            get{ 
                if(m_pMessages.Count > 0){
                    return m_pMessages[m_pMessages.Count - 1].UID + 1;
                }
                else{
                    return 1; 
                }
            }
        }

        #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

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160621.1 | Last Updated 20 Apr 2007
Article Copyright 2007 by Ivar Lumi
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid