private bool disposedValue = false; // To detect redundant calls /// <summary> /// Initializes a new instance of the <see cref="TcpClientConnectionChannel"/> class. /// </summary> /// <param name="tcpClient">The tcpClient<see cref="TcpClient"/></param> public TcpClientConnectionChannel(TcpClient tcpClient, Encoding fallbackEncoding) { this.tcpClient = tcpClient; this.stream = tcpClient.GetStream(); this.IsConnected = true; this.fallbackEncoding = fallbackEncoding; this.writer = new SmtpStreamWriter(this.stream, false) { AutoFlush = true }; this.SetupReader(); }
private void SetupReaderAndWriter() { if (this.reader != null) { this.reader.Dispose(); } this.reader = new SmtpStreamReader(this.stream, this.fallbackEncoding, true); if (this.writer != null) { this.writer.Dispose(); } this.writer = new SmtpStreamWriter(this.stream, true) { AutoFlush = true }; }
/// <summary> /// Initializes a new instance of the <see cref="MemorySession"/> class. /// </summary> /// <param name="clientAddress">The clientAddress<see cref="IPAddress"/>.</param> /// <param name="startDate">The startDate<see cref="DateTime"/>.</param> public MemorySession(IPAddress clientAddress, DateTime startDate) : base(clientAddress, startDate) { this.log = new SmtpStreamWriter(this.logStream, false); }
/// <inheritdoc/> public virtual async Task Process(IConnection connection, SmtpCommand command) { if (connection.CurrentMessage == null) { await connection.WriteResponse(new SmtpResponse( StandardSmtpResponseCode.BadSequenceOfCommands, "Bad sequence of commands")).ConfigureAwait(false); return; } connection.CurrentMessage.SecureConnection = connection.Session.SecureConnection; await connection.WriteResponse(new SmtpResponse( StandardSmtpResponseCode.StartMailInputEndWithDot, "End message with period")).ConfigureAwait(false); using (SmtpStreamWriter writer = new SmtpStreamWriter(await connection.CurrentMessage.WriteData().ConfigureAwait(false), false)) { bool firstLine = true; do { string line = await connection.ReadLine().ConfigureAwait(false); if (line != ".") { line = this.ProcessLine(line); if (!firstLine) { writer.Write("\r\n"); } writer.Write(line); } else { break; } firstLine = false; }while (true); writer.Flush(); long?maxMessageSize = await connection.Server.Behaviour.GetMaximumMessageSize(connection).ConfigureAwait(false); if (maxMessageSize.HasValue && writer.BaseStream.Length > maxMessageSize.Value) { await connection.WriteResponse( new SmtpResponse( StandardSmtpResponseCode.ExceededStorageAllocation, "Message exceeds fixed size limit")).ConfigureAwait(false); } else { writer.Dispose(); await connection.Server.Behaviour.OnMessageCompleted(connection).ConfigureAwait(false); await connection.WriteResponse(new SmtpResponse(StandardSmtpResponseCode.OK, "Mail accepted")).ConfigureAwait(false); await connection.CommitMessage().ConfigureAwait(false); } } }