public void TestDisconnect() { server.EnqueueResponse("+OK PopPseudoServer ready\r\n"); var session = new PopSession(host, port); session.Disconnect(false); Assert.IsTrue(session.IsDisposed); try { session.NoOp(); Assert.Fail("ObjectDisposedException not thrown"); } catch (ObjectDisposedException) { } }
public static PopCommandResult CreateSession(IPopSessionProfile profile, SaslClientMechanism authMechanismSpecified, UpgradeConnectionStreamCallback createSslStreamCallback, out PopSession session) { if (profile == null) throw new ArgumentNullException("profile"); var authority = profile.Authority; var securePort = string.Equals(authority.Scheme, PopUri.UriSchemePops, StringComparison.OrdinalIgnoreCase); if (securePort && createSslStreamCallback == null) throw new ArgumentNullException("createSslStreamCallback"); PopCommandResult result; session = null; session = new PopSession(authority.Host, authority.Port, profile.Timeout, securePort ? createSslStreamCallback : null); session.HandlesIncapableAsException = false; session.TransactionTimeout = profile.Timeout; session.SendTimeout = profile.SendTimeout; session.ReceiveTimeout = profile.ReceiveTimeout; // try querying server capability (ignore error; POP3 Extension Mechanism might not supported) session.Capa(); if (profile.UseTlsIfAvailable && session.ServerCapabilities.IsCapable(PopCapability.Stls) && !session.IsSecureConnection) { var r = session.Stls(createSslStreamCallback, false); if (r.Failed) throw new PopUpgradeConnectionException(r.ResultText); // try re-querying server capability (ignore error; POP3 Extension Mechanism might not supported) session.Capa(); } if (authMechanismSpecified == null) result = Authenticate(session, profile); else result = session.Auth(authMechanismSpecified); if (result == null) { throw new PopAuthenticationException("appropriate authentication mechanism not found"); } else if (result.Failed) { try { try { session.Disconnect(false); } catch (PopConnectionException) { // ignore } } finally { session = null; } } return result; }