/// <summary> /// Takes posession of the <see cref="Pop3Stream"/> and reads the greeting. /// </summary> /// <remarks> /// Takes posession of the <see cref="Pop3Stream"/> and reads the greeting. /// </remarks> /// <param name="pop3">The pop3 stream.</param> /// <param name="cancellationToken">The cancellation token</param> public void Connect(Pop3Stream pop3, CancellationToken cancellationToken) { if (stream != null) { stream.Dispose(); } Capabilities = Pop3Capabilities.User; AuthenticationMechanisms.Clear(); State = Pop3EngineState.Disconnected; ApopToken = null; stream = pop3; // read the pop3 server greeting var greeting = ReadLine(cancellationToken).TrimEnd(); int index = greeting.IndexOf(' '); string token, text; if (index != -1) { token = greeting.Substring(0, index); while (index < greeting.Length && char.IsWhiteSpace(greeting[index])) { index++; } if (index < greeting.Length) { text = greeting.Substring(index); } else { text = string.Empty; } } else { text = string.Empty; token = greeting; } if (token != "+OK") { stream.Dispose(); stream = null; throw new Pop3ProtocolException(string.Format("Unexpected greeting from server: {0}", greeting)); } index = text.IndexOf('>'); if (text.Length > 0 && text[0] == '<' && index != -1) { ApopToken = text.Substring(0, index + 1); Capabilities |= Pop3Capabilities.Apop; } State = Pop3EngineState.Connected; }
/// <summary> /// Disconnects the <see cref="Pop3Stream"/>. /// </summary> public void Disconnect() { State = Pop3EngineState.Connection; if (stream != null) { stream.Dispose(); stream = null; } }
/// <summary> /// Disconnects the <see cref="Pop3Engine"/>. /// </summary> /// <remarks> /// Disconnects the <see cref="Pop3Engine"/>. /// </remarks> public void Disconnect() { if (stream != null) { stream.Dispose(); stream = null; } if (State != Pop3EngineState.Disconnected) { State = Pop3EngineState.Disconnected; OnDisconnected(); } }
/// <summary> /// Takes posession of the <see cref="Pop3Stream"/> and reads the greeting. /// </summary> /// <remarks> /// Takes posession of the <see cref="Pop3Stream"/> and reads the greeting. /// </remarks> /// <param name="pop3">The pop3 stream.</param> /// <param name="cancellationToken">The cancellation token</param> public Task ConnectAsync(Pop3Stream pop3, CancellationToken cancellationToken) { return(ConnectAsync(pop3, true, cancellationToken)); }
/// <summary> /// Takes posession of the <see cref="Pop3Stream"/> and reads the greeting. /// </summary> /// <remarks> /// Takes posession of the <see cref="Pop3Stream"/> and reads the greeting. /// </remarks> /// <param name="pop3">The pop3 stream.</param> /// <param name="cancellationToken">The cancellation token</param> public void Connect(Pop3Stream pop3, CancellationToken cancellationToken) { ConnectAsync(pop3, false, cancellationToken).GetAwaiter().GetResult(); }
async Task ConnectAsync(Pop3Stream pop3, bool doAsync, CancellationToken cancellationToken) { if (stream != null) { stream.Dispose(); } Capabilities = Pop3Capabilities.User; AuthenticationMechanisms.Clear(); State = Pop3EngineState.Disconnected; ApopToken = null; stream = pop3; // read the pop3 server greeting var greeting = (await ReadLineAsync(doAsync, cancellationToken).ConfigureAwait(false)).TrimEnd(); int index = greeting.IndexOf(' '); string token, text; if (index != -1) { token = greeting.Substring(0, index); while (index < greeting.Length && char.IsWhiteSpace(greeting[index])) { index++; } if (index < greeting.Length) { text = greeting.Substring(index); } else { text = string.Empty; } } else { text = string.Empty; token = greeting; } if (token != "+OK") { stream.Dispose(); stream = null; throw new Pop3ProtocolException(string.Format("Unexpected greeting from server: {0}", greeting)); } index = text.IndexOf('<'); if (index != -1 && index + 1 < text.Length) { int endIndex = text.IndexOf('>', index + 1); if (endIndex++ != -1) { ApopToken = text.Substring(index, endIndex - index); Capabilities |= Pop3Capabilities.Apop; } } State = Pop3EngineState.Connected; }
/// <summary> /// Disconnects the <see cref="Pop3Stream"/>. /// </summary> public void Disconnect() { State = Pop3EngineState.Connection; if (stream != null) { stream.Dispose (); stream = null; } }
/// <summary> /// Takes posession of the <see cref="Pop3Stream"/> and reads the greeting. /// </summary> /// <param name="pop3">The pop3 stream.</param> /// <param name="cancellationToken">A cancellation token</param> public void Connect(Pop3Stream pop3, CancellationToken cancellationToken) { if (stream != null) stream.Dispose (); Capabilities = Pop3Capabilities.User; AuthenticationMechanisms.Clear (); State = Pop3EngineState.Connection; ApopToken = null; stream = pop3; // read the pop3 server greeting var greeting = ReadLine (cancellationToken).TrimEnd (); int index = greeting.IndexOf (' '); string token, text; if (index != -1) { token = greeting.Substring (0, index); while (index < greeting.Length && char.IsWhiteSpace (greeting[index])) index++; if (index < greeting.Length) text = greeting.Substring (index); else text = string.Empty; } else { text = string.Empty; token = greeting; } if (token != "+OK") { stream.Dispose (); stream = null; throw new Pop3ProtocolException (string.Format ("Unexpected greeting from server: {0}", greeting)); } index = text.IndexOf ('>'); if (text.Length > 0 && text[0] == '<' && index != -1) { ApopToken = text.Substring (1, index - 1); Capabilities |= Pop3Capabilities.Apop; } State = Pop3EngineState.Authentication; }
/// <summary> /// Disconnects the <see cref="Pop3Engine"/>. /// </summary> /// <remarks> /// Disconnects the <see cref="Pop3Engine"/>. /// </remarks> public void Disconnect () { Uri = null; if (stream != null) { stream.Dispose (); stream = null; } if (State != Pop3EngineState.Disconnected) { State = Pop3EngineState.Disconnected; OnDisconnected (); } }