/// <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; }
async Task <Pop3CommandStatus> QueryCapabilitiesAsync(bool doAsync, CancellationToken cancellationToken) { if (stream == null) { throw new InvalidOperationException(); } // clear all CAPA response capabilities (except the APOP and USER capabilities) Capabilities &= Pop3Capabilities.Apop | Pop3Capabilities.User; AuthenticationMechanisms.Clear(); Implementation = null; ExpirePolicy = 0; LoginDelay = 0; var pc = QueueCommand(cancellationToken, CapaHandler, "CAPA"); while (await IterateAsync(doAsync).ConfigureAwait(false) < pc.Id) { // continue processing commands... } return(pc.Status); }
public Pop3CommandStatus QueryCapabilities(CancellationToken cancellationToken) { if (stream == null) { throw new InvalidOperationException(); } // clear all CAPA response capabilities (except the APOP capability) Capabilities &= Pop3Capabilities.Apop; AuthenticationMechanisms.Clear(); Implementation = null; ExpirePolicy = 0; LoginDelay = 0; var pc = QueueCommand(cancellationToken, CapaHandler, "CAPA"); while (Iterate() < pc.Id) { // continue processing commands... } return(pc.Status); }
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; }