Click here to Skip to main content
15,894,312 members
Articles / Web Development / HTML

My own Mailinator in 5 minutes

Rate me:
Please Sign up or sign in to vote.
5.00/5 (6 votes)
19 Nov 2012CPOL6 min read 31.7K   405   13  
A simple Mailinator clone developed in five minutes with the NetFluid framework
using System;
using System.Collections.Generic;
using System.Text;

namespace LumiSoft.Net.FTP
{
    /// <summary>
    /// This class represent s FTP server reply-line.
    /// </summary>
    public class FTP_t_ReplyLine
    {
        private int    m_ReplyCode  = 0;
        private string m_Text       = null;
        private bool   m_IsLastLine = true;

        /// <summary>
        /// Default constructor.
        /// </summary>
        /// <param name="replyCode">FTP server reply code.</param>
        /// <param name="text">FTP server reply text.</param>
        /// <param name="isLastLine">Specifies if this line is last line in response.</param>
        public FTP_t_ReplyLine(int replyCode,string text,bool isLastLine)
        {
            if(text == null){
                text = "";
            }

            m_ReplyCode  = replyCode;
            m_Text       = text;
            m_IsLastLine = isLastLine;
        }


        #region static method Parse

        /// <summary>
        /// Parses FTP reply-line from 
        /// </summary>
        /// <param name="line">FTP server reply-line.</param>
        /// <returns>Returns parsed FTP server reply-line.</returns>
        /// <exception cref="ArgumentNullException">Is raised when <b>line</b> is null reference.</exception>
        /// <exception cref="ParseException">Is raised when reply-line parsing fails.</exception>
        public static FTP_t_ReplyLine Parse(string line)
        {
            if(line == null){
                throw new ArgumentNullException("line");
            }
            if(line.Length < 3){
                throw new ParseException("Invalid FTP server reply-line '" + line + "'.");
            }

            int replyCode = 0;
            if(!int.TryParse(line.Substring(0,3),out replyCode)){
                throw new ParseException("Invalid FTP server reply-line '" + line + "' reply-code.");
            }
            
            bool isLastLine = true;            
            if(line.Length > 3){
                isLastLine = (line[3] == ' ');
            }

            string text = "";
            if(line.Length > 5){
                text = line.Substring(4);
            }

            return new FTP_t_ReplyLine(replyCode,text,isLastLine);
        }

        #endregion


        #region override method ToString

        /// <summary>
        /// Returns this as FTP server <b>reply-line</b>.
        /// </summary>
        /// <returns>Returns this as FTP server <b>reply-line</b>.</returns>
        public override string ToString()
        {
            if(m_IsLastLine){
                return m_ReplyCode.ToString() + " " + m_Text + "\r\n";
            }
            else{
                return m_ReplyCode.ToString() + "-" + m_Text + "\r\n";
            }
        }

        #endregion


        #region Properties implementation

        /// <summary>
        /// Gets SMTP server reply code.
        /// </summary>
        public int ReplyCode
        {
            get{ return m_ReplyCode; }
        }

        /// <summary>
        /// Gets SMTP server relpy text.
        /// </summary>
        public string Text
        {
            get{ return m_Text; }
        }

        /// <summary>
        /// Gets if this is last reply line.
        /// </summary>
        public bool IsLastLine
        {
            get{ return m_IsLastLine; }
        }

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


Written By
Chief Technology Officer Genny Mobility
Italy Italy
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions