namespace Unosquare.Swan.Networking { using System.Collections.Generic; /// /// 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() { DataBuffer = new List(); Reset(true); 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 bool HasInitiated { get; set; } /// /// Gets or sets a value indicating whether the current session supports extensions. /// public bool 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 bool 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 bool 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 bool HasProvidedUsername => string.IsNullOrWhiteSpace(Username) == false; /// /// Gets or sets a value indicating whether this instance is authenticated. /// public bool 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 bool IsChannelSecure { get; set; } /// /// Resets the authentication state. /// public void ResetAuthentication() { Username = string.Empty; Password = string.Empty; AuthMode = string.Empty; IsInAuthMode = false; IsAuthenticated = false; } #endregion #region Methods /// /// Resets the data mode to false, clears the recipients, the sender address and the data buffer. /// public void ResetEmail() { IsInDataMode = false; Recipients.Clear(); SenderAddress = string.Empty; DataBuffer.Clear(); } /// /// Resets the state table entirely. /// /// if set to true [clear extension data]. public void Reset(bool clearExtensionData) { HasInitiated = false; SupportsExtensions = false; ClientHostname = string.Empty; ResetEmail(); if (clearExtensionData) ExtendedData = null; } /// /// Creates a new object that is a copy of the current instance. /// /// A clone. public virtual SmtpSessionState Clone() { var clonedState = this.CopyPropertiesToNew(new[] {nameof(DataBuffer)}); clonedState.DataBuffer.AddRange(DataBuffer); clonedState.Recipients.AddRange(Recipients); return clonedState; } #endregion } }