Skip to content

Commit

Permalink
Removed ReplayConnect and ReplayConnectAsync methods
Browse files Browse the repository at this point in the history
These were only needed for unit testing the clients, but they aren't
necessary anymore because Connect(Stream, ...) and ConnectAsync(Stream, ...)
were added ages ago.

By getting rid of the ReplayConnect/Async methods, it allows us to better
test *actual* code-paths used by the Connect and ConnectAsync methods.
  • Loading branch information
jstedfast committed Sep 13, 2023
1 parent c0b3ec5 commit 42c8988
Show file tree
Hide file tree
Showing 12 changed files with 481 additions and 659 deletions.
55 changes: 0 additions & 55 deletions MailKit/Net/Imap/ImapClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ public ImapClient (IProtocolLogger protocolLogger) : base (protocolLogger)

// Note: This is only needed for UnitTests.
internal char TagPrefix {
get { return engine.TagPrefix; }
set { engine.TagPrefix = value; }
}

Expand Down Expand Up @@ -1346,60 +1345,6 @@ public override void Authenticate (Encoding encoding, ICredentials credentials,
OnAuthenticated (ic.ResponseText ?? string.Empty, cancellationToken);
}

internal void ReplayConnect (string host, Stream replayStream, CancellationToken cancellationToken = default)
{
CheckDisposed ();

if (host == null)
throw new ArgumentNullException (nameof (host));

if (replayStream == null)
throw new ArgumentNullException (nameof (replayStream));

engine.Uri = new Uri ($"imap://{host}:143");
engine.Connect (new ImapStream (replayStream, ProtocolLogger), cancellationToken);
engine.TagPrefix = 'A';
secure = false;

if (engine.CapabilitiesVersion == 0)
engine.QueryCapabilities (cancellationToken);

// Note: we capture the state here in case someone calls Authenticate() from within the Connected event handler.
var authenticated = engine.State == ImapEngineState.Authenticated;

OnConnected (host, 143, SecureSocketOptions.None);

if (authenticated)
OnAuthenticated (string.Empty, cancellationToken);
}

internal async Task ReplayConnectAsync (string host, Stream replayStream, CancellationToken cancellationToken = default)
{
CheckDisposed ();

if (host == null)
throw new ArgumentNullException (nameof (host));

if (replayStream == null)
throw new ArgumentNullException (nameof (replayStream));

engine.Uri = new Uri ($"imap://{host}:143");
await engine.ConnectAsync (new ImapStream (replayStream, ProtocolLogger), cancellationToken).ConfigureAwait (false);
engine.TagPrefix = 'A';
secure = false;

if (engine.CapabilitiesVersion == 0)
await engine.QueryCapabilitiesAsync (cancellationToken).ConfigureAwait (false);

// Note: we capture the state here in case someone calls Authenticate() from within the Connected event handler.
var authenticated = engine.State == ImapEngineState.Authenticated;

OnConnected (host, 143, SecureSocketOptions.None);

if (authenticated)
await OnAuthenticatedAsync (string.Empty, cancellationToken).ConfigureAwait (false);
}

internal static void ComputeDefaultValues (string host, ref int port, ref SecureSocketOptions options, out Uri uri, out bool starttls)
{
switch (options) {
Expand Down
40 changes: 0 additions & 40 deletions MailKit/Net/Pop3/Pop3Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -995,46 +995,6 @@ public override void Authenticate (Encoding encoding, ICredentials credentials,
OnAuthenticated (message, cancellationToken);
}

internal void ReplayConnect (string host, Stream replayStream, CancellationToken cancellationToken = default)
{
if (host == null)
throw new ArgumentNullException (nameof (host));

if (replayStream == null)
throw new ArgumentNullException (nameof (replayStream));

CheckDisposed ();

probed = ProbedCapabilities.None;
secure = false;

engine.Uri = new Uri ($"pop://{host}:110");
engine.Connect (new Pop3Stream (replayStream, ProtocolLogger), cancellationToken);
engine.QueryCapabilities (cancellationToken);
engine.Disconnected += OnEngineDisconnected;
OnConnected (host, 110, SecureSocketOptions.None);
}

internal async Task ReplayConnectAsync (string host, Stream replayStream, CancellationToken cancellationToken = default)
{
if (host == null)
throw new ArgumentNullException (nameof (host));

if (replayStream == null)
throw new ArgumentNullException (nameof (replayStream));

CheckDisposed ();

probed = ProbedCapabilities.None;
secure = false;

engine.Uri = new Uri ($"pop://{host}:110");
await engine.ConnectAsync (new Pop3Stream (replayStream, ProtocolLogger), cancellationToken).ConfigureAwait (false);
await engine.QueryCapabilitiesAsync (cancellationToken).ConfigureAwait (false);
engine.Disconnected += OnEngineDisconnected;
OnConnected (host, 110, SecureSocketOptions.None);
}

internal static void ComputeDefaultValues (string host, ref int port, ref SecureSocketOptions options, out Uri uri, out bool starttls)
{
switch (options) {
Expand Down
37 changes: 0 additions & 37 deletions MailKit/Net/Smtp/AsyncSmtpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -396,43 +396,6 @@ public override async Task AuthenticateAsync (Encoding encoding, ICredentials cr
throw new NotSupportedException ("No compatible authentication mechanisms found.");
}

internal async Task ReplayConnectAsync (string host, Stream replayStream, CancellationToken cancellationToken = default)
{
CheckDisposed ();

if (host == null)
throw new ArgumentNullException (nameof (host));

if (replayStream == null)
throw new ArgumentNullException (nameof (replayStream));

Stream = new SmtpStream (replayStream, ProtocolLogger);
capabilities = SmtpCapabilities.None;
AuthenticationMechanisms.Clear ();
uri = new Uri ($"smtp://{host}:25");
secure = false;
MaxSize = 0;

try {
// read the greeting
var response = await Stream.ReadResponseAsync (cancellationToken).ConfigureAwait (false);

if (response.StatusCode != SmtpStatusCode.ServiceReady)
throw new SmtpCommandException (SmtpErrorCode.UnexpectedStatusCode, response.StatusCode, response.Response);

// Send EHLO and get a list of supported extensions
await EhloAsync (cancellationToken).ConfigureAwait (false);

connected = true;
} catch {
Stream.Dispose ();
Stream = null;
throw;
}

OnConnected (host, 25, SecureSocketOptions.None);
}

async Task SslHandshakeAsync (SslStream ssl, string host, CancellationToken cancellationToken)
{
#if NET5_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER
Expand Down
37 changes: 0 additions & 37 deletions MailKit/Net/Smtp/SmtpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1172,43 +1172,6 @@ public override void Authenticate (Encoding encoding, ICredentials credentials,
throw new NotSupportedException ("No compatible authentication mechanisms found.");
}

internal void ReplayConnect (string host, Stream replayStream, CancellationToken cancellationToken = default)
{
CheckDisposed ();

if (host == null)
throw new ArgumentNullException (nameof (host));

if (replayStream == null)
throw new ArgumentNullException (nameof (replayStream));

Stream = new SmtpStream (replayStream, ProtocolLogger);
capabilities = SmtpCapabilities.None;
AuthenticationMechanisms.Clear ();
uri = new Uri ($"smtp://{host}:25");
secure = false;
MaxSize = 0;

try {
// read the greeting
var response = Stream.ReadResponse (cancellationToken);

if (response.StatusCode != SmtpStatusCode.ServiceReady)
throw new SmtpCommandException (SmtpErrorCode.UnexpectedStatusCode, response.StatusCode, response.Response);

// Send EHLO and get a list of supported extensions
Ehlo (cancellationToken);

connected = true;
} catch {
Stream.Dispose ();
Stream = null;
throw;
}

OnConnected (host, 25, SecureSocketOptions.None);
}

internal static void ComputeDefaultValues (string host, ref int port, ref SecureSocketOptions options, out Uri uri, out bool starttls)
{
switch (options) {
Expand Down
Loading

0 comments on commit 42c8988

Please sign in to comment.