using System; using System.Collections.Generic; namespace Unosquare.Swan.Networking { /// /// Represents the state of an SMTP session associated with a client. /// public class SmtpSessionState { #region Constructors /// /// Initializes a new instance of the class. /// public SmtpSessionState() { this.DataBuffer = new List(); this.Reset(true); this.ResetAuthentication(); } #endregion #region Properties /// /// Gets the contents of the data buffer. /// public List DataBuffer { get; protected set; } /// /// Gets or sets a value indicating whether this instance has initiated. /// public Boolean HasInitiated { get; set; } /// /// Gets or sets a value indicating whether the current session supports extensions. /// public Boolean SupportsExtensions { get; set; } /// /// Gets or sets the client hostname. /// public String ClientHostname { get; set; } /// /// Gets or sets a value indicating whether the session is currently receiving DATA. /// public Boolean IsInDataMode { get; set; } /// /// Gets or sets the sender address. /// public String SenderAddress { get; set; } /// /// Gets the recipients. /// public List Recipients { get; } = new List(); /// /// Gets or sets the extended data supporting any additional field for storage by a responder implementation. /// public Object ExtendedData { get; set; } #endregion #region AUTH State /// /// Gets or sets a value indicating whether this instance is in authentication mode. /// public Boolean IsInAuthMode { get; set; } /// /// Gets or sets the username. /// public String Username { get; set; } /// /// Gets or sets the password. /// public String Password { get; set; } /// /// Gets a value indicating whether this instance has provided username. /// public Boolean HasProvidedUsername => String.IsNullOrWhiteSpace(this.Username) == false; /// /// Gets or sets a value indicating whether this instance is authenticated. /// public Boolean IsAuthenticated { get; set; } /// /// Gets or sets the authentication mode. /// public String AuthMode { get; set; } /// /// Gets or sets a value indicating whether this instance is channel secure. /// public Boolean IsChannelSecure { get; set; } /// /// Resets the authentication state. /// public void ResetAuthentication() { this.Username = String.Empty; this.Password = String.Empty; this.AuthMode = String.Empty; this.IsInAuthMode = false; this.IsAuthenticated = false; } #endregion #region Methods /// /// Resets the data mode to false, clears the recipients, the sender address and the data buffer. /// public void ResetEmail() { this.IsInDataMode = false; this.Recipients.Clear(); this.SenderAddress = String.Empty; this.DataBuffer.Clear(); } /// /// Resets the state table entirely. /// /// if set to true [clear extension data]. public void Reset(Boolean clearExtensionData) { this.HasInitiated = false; this.SupportsExtensions = false; this.ClientHostname = String.Empty; this.ResetEmail(); if(clearExtensionData) { this.ExtendedData = null; } } /// /// Creates a new object that is a copy of the current instance. /// /// A clone. public virtual SmtpSessionState Clone() { SmtpSessionState clonedState = this.CopyPropertiesToNew(new[] { nameof(this.DataBuffer) }); clonedState.DataBuffer.AddRange(this.DataBuffer); clonedState.Recipients.AddRange(this.Recipients); return clonedState; } #endregion } }