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

SIP Stack with SIP Proxy - (VOIP)

, 11 Jun 2007 CPOL
C# implementation of SIP
SIP_Proxy_demo.zip
SIP_Proxy_demo
SIP_Proxy_demo.suo
SIP_Proxy_demo
bin
Debug
LumiSoft.Net.dll
SIP_Proxy_demo.exe
SIP_Proxy_demo.vshost.exe
dep
LumiSoft.Net.dll
LumiSoft.Net.pdb
Properties
Settings.settings
Resources
add.ico
app.ico
delete.ico
edit.ico
error.ico
info.ico
refresh.ico
rule.ico
server_running.ico
server_stopped.ico
viewmessages.ico
Stack.zip
Net
docs
dns
dns_records.jpg
dns_records.vsd
Net
_junk
_Obsolete
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
RTP
SDP
ServersCore
SIP
Client
Message
Proxy
Stack
SMTP
Client
Server
STUN
Client
Message
URI
using System;
using System.IO;
using System.Collections.Generic;
using System.Text;

namespace LumiSoft.Net.IMAP.Server
{
    /// <summary>
    /// Provides data to event GetMessageItems.
    /// </summary>
    public class IMAP_eArgs_MessageItems
    {
        private IMAP_Session           m_pSession           = null;
        private IMAP_Message           m_pMessageInfo       = null;
        private IMAP_MessageItems_enum m_MessageItems       = IMAP_MessageItems_enum.Message;
        private bool                   m_CloseMessageStream = true;
        private Stream                 m_MessageStream      = null;
        private long                   m_MessageStartOffset = 0;
        private byte[]                 m_Header             = null;
        private string                 m_Envelope           = null;
        private string                 m_BodyStructure      = null;
        private bool                   m_MessageExists      = true;

        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="session">Reference to current IMAP session.</param>
        /// <param name="messageInfo">Message info what message items to get.</param>
        /// <param name="messageItems">Specifies message items what must be filled.</param>
        public IMAP_eArgs_MessageItems(IMAP_Session session,IMAP_Message messageInfo,IMAP_MessageItems_enum messageItems)
        {
            m_pSession     = session;
            m_pMessageInfo = messageInfo;
            m_MessageItems = messageItems;
        }

        /// <summary>
        /// Default deconstructor.
        /// </summary>
        ~IMAP_eArgs_MessageItems()
        {
            Dispose();
        }

        #region method Dispose

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        public void Dispose()
        {
            if(m_CloseMessageStream && m_MessageStream != null){
                m_MessageStream.Dispose();
                m_MessageStream = null;
            }
        }

        #endregion


        #region internal method Validate

        /// <summary>
        /// Checks that all required data items are provided, if not throws exception.
        /// </summary>
        internal void Validate()
        {
            if((m_MessageItems & IMAP_MessageItems_enum.BodyStructure) != 0 && m_BodyStructure == null){
                throw new Exception("IMAP BODYSTRUCTURE is required, but not provided to IMAP server component !");
            }
            if((m_MessageItems & IMAP_MessageItems_enum.Envelope) != 0 && m_Envelope == null){
                throw new Exception("IMAP ENVELOPE is required, but not provided to IMAP server component  !");
            }
            if((m_MessageItems & IMAP_MessageItems_enum.Header) != 0 && m_Header == null){
                throw new Exception("Message header is required, but not provided to IMAP server component  !");
            }
            if((m_MessageItems & IMAP_MessageItems_enum.Message) != 0 && m_MessageStream == null){
                throw new Exception("Full message is required, but not provided to IMAP server component  !");
            }
        }

        #endregion


        #region Properties Implementation

        /// <summary>
        /// Gets reference to current IMAP session.
        /// </summary>
        public IMAP_Session Session
        {
            get{ return m_pSession; }
        }

        /// <summary>
        /// Gets message info what message items to get.
        /// </summary>
        public IMAP_Message MessageInfo
        {
            get{ return m_pMessageInfo; }
        }

        /// <summary>
        /// Gets what message items must be filled.
        /// </summary>
        public IMAP_MessageItems_enum MessageItems
        {
            get{ return m_MessageItems; }
        }

        /// <summary>
        /// Gets or sets if message stream is closed automatically if all actions on it are completed.
        /// Default value is true.
        /// </summary>
        public bool CloseMessageStream
        {
            get{ return m_CloseMessageStream; }

            set{ m_CloseMessageStream = value; }
        }

        /// <summary>
        /// Gets or sets message stream. When setting this property Stream position must be where message begins.
        /// Fill this property only if IMAP_MessageItems_enum.Message flag is specified.
        /// </summary>
        public Stream MessageStream
        {
            get{
                if(m_MessageStream != null){
                    m_MessageStream.Position = m_MessageStartOffset;
                }
                return m_MessageStream; 
            }

            set{
                if(value == null){
                    throw new ArgumentNullException("Property MessageStream value can't be null !");
                }
                if(!value.CanSeek){
                    throw new Exception("Stream must support seeking !");
                }

                m_MessageStream = value;
                m_MessageStartOffset = m_MessageStream.Position;
            }
        }

        /// <summary>
        /// Gets message size in bytes.
        /// </summary>
        public long MessageSize
        {
            get{
                if(m_MessageStream == null){
                    throw new Exception("You must set MessageStream property first to use this property !");
                }
                else{
                    return m_MessageStream.Length - m_MessageStream.Position;
                }
            }
        }
        
        /// <summary>
        /// Gets or sets message main header.
        /// Fill this property only if IMAP_MessageItems_enum.Header flag is specified.
        /// </summary>
        public byte[] Header
        {
            get{ return m_Header; }

            set{
                if(value == null){
                    throw new ArgumentNullException("Property Header value can't be null !");
                }

                m_Header = value;
            }
        }

        /// <summary>
        /// Gets or sets IMAP ENVELOPE string.
        /// Fill this property only if IMAP_MessageItems_enum.Envelope flag is specified.
        /// </summary>
        public string Envelope
        {
            get{ return m_Envelope; }

            set{
                if(value == null){
                    throw new ArgumentNullException("Property Envelope value can't be null !");
                }

                m_Envelope = value;
            }
        }

        /// <summary>
        /// Gets or sets IMAP BODYSTRUCTURE string.
        /// Fill this property only if IMAP_MessageItems_enum.BodyStructure flag is specified.
        /// </summary>
        public string BodyStructure
        {
            get{ return m_BodyStructure; }

            set{
                if(value == null){
                    throw new ArgumentNullException("Property BodyStructure value can't be null !");
                }

                m_BodyStructure = value;
            }
        }

        /// <summary>
        /// Gets or sets if message exists. Set this false, if message actually doesn't exist any more.
        /// </summary>
        public bool MessageExists
        {
            get{ return m_MessageExists; }

            set{ m_MessageExists = value; }
        }

        #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
Web04 | 2.8.150331.1 | Last Updated 11 Jun 2007
Article Copyright 2007 by Ivar Lumi
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid