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

STUN Client

, 20 Apr 2007 CPOL
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.Collections.Generic;
using System.Text;

namespace LumiSoft.Net.IMAP.Client
{
    /// <summary>
    /// IMAP namespaces info. Defined in RFC 2342.
    /// </summary>
    public class IMAP_NamespacesInfo
    {
        private IMAP_Namespace[] m_pPersonalNamespaces   = null;
        private IMAP_Namespace[] m_pOtherUsersNamespaces = null;
        private IMAP_Namespace[] m_pSharedNamespaces     = null;

        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="personalNamespaces">IMAP server "Personal Namespaces".</param>
        /// <param name="otherUsersNamespaces">IMAP server "Other Users Namespaces".</param>
        /// <param name="sharedNamespaces">IMAP server "Shared Namespaces".</param>
        public IMAP_NamespacesInfo(IMAP_Namespace[] personalNamespaces,IMAP_Namespace[] otherUsersNamespaces,IMAP_Namespace[] sharedNamespaces)
        {
            m_pPersonalNamespaces   = personalNamespaces;
            m_pOtherUsersNamespaces = otherUsersNamespaces;
            m_pSharedNamespaces     = sharedNamespaces;
        }


        #region Parse

        #region static method Parse

        /// <summary>
        /// Parses namespace info from IMAP NAMESPACE response string.
        /// </summary>
        /// <param name="namespaceString">IMAP NAMESPACE response string.</param>
        /// <returns></returns>
        internal static IMAP_NamespacesInfo Parse(string namespaceString)
        {
            StringReader r = new StringReader(namespaceString);
            // Skip NAMESPACE
            r.ReadWord();
            
            IMAP_Namespace[] personalNamespaces   = null;
            IMAP_Namespace[] otherUsersNamespaces = null;
            IMAP_Namespace[] sharedNamespaces     = null;
       
            // Personal namespace
            r.ReadToFirstChar();
            if(r.StartsWith("(")){
                personalNamespaces = ParseNamespaces(r.ReadParenthesized());
            }
            // NIL, skip it.
            else{
                r.ReadWord();
            }

            // Users Shared namespace
            r.ReadToFirstChar();
            if(r.StartsWith("(")){
                otherUsersNamespaces = ParseNamespaces(r.ReadParenthesized());
            }
            // NIL, skip it.
            else{
                r.ReadWord();
            }

            // Shared namespace
            r.ReadToFirstChar();
            if(r.StartsWith("(")){
                sharedNamespaces = ParseNamespaces(r.ReadParenthesized());
            }
            // NIL, skip it.
            else{
                r.ReadWord();
            }

            return new IMAP_NamespacesInfo(personalNamespaces,otherUsersNamespaces,sharedNamespaces);
        }

        #endregion

        #region static method ParseNamespaces

        private static IMAP_Namespace[] ParseNamespaces(string val)
        {
            StringReader r = new StringReader(val);
            r.ReadToFirstChar();

            List<IMAP_Namespace> namespaces = new List<IMAP_Namespace>();
            while(r.StartsWith("(")){
                namespaces.Add(ParseNamespace(r.ReadParenthesized()));
            }

            return namespaces.ToArray();
        }

        #endregion

        #region static method ParseNamespace

        private static IMAP_Namespace ParseNamespace(string val)
        {
            string[] parts = TextUtils.SplitQuotedString(val,' ',true);
            string name = "";
            if(parts.Length > 0){
                name = parts[0];
            }
            string delimiter = "";
            if(parts.Length > 1){
                delimiter = parts[1];
            }

            // Remove delimiter from end, if it's there.
            if(name.EndsWith(delimiter)){
                name = name.Substring(0,name.Length - delimiter.Length);
            }

            return new IMAP_Namespace(name,delimiter);
        }

        #endregion

        #endregion


        #region Properties Implementation

        /// <summary>
        /// Gets IMAP server "Personal Namespaces". Returns null if namespace not defined.
        /// </summary>
        public IMAP_Namespace[] PersonalNamespaces
        {
            get{ return m_pPersonalNamespaces; }
        }

        /// <summary>
        /// Gets IMAP server "Other Users Namespaces". Returns null if namespace not defined.
        /// </summary>
        public IMAP_Namespace[] OtherUsersNamespaces
        {
            get{ return m_pOtherUsersNamespaces; }
        }

        /// <summary>
        /// Gets IMAP server "Shared Namespaces". Returns null if namespace not defined.
        /// </summary>
        public IMAP_Namespace[] SharedNamespaces
        {
            get{ return m_pSharedNamespaces; }
        }

        #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 | Terms of Use | Mobile
Web01 | 2.8.150302.1 | Last Updated 20 Apr 2007
Article Copyright 2007 by Ivar Lumi
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid