OpenSim.Modules.EMail/src/MailKit/Net/Pop3/AsyncPop3Client.cs

1497 lines
62 KiB
C#

//
// AsyncPop3Client.cs
//
// Author: Jeffrey Stedfast <jestedfa@microsoft.com>
//
// Copyright (c) 2013-2020 .NET Foundation and Contributors
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Threading;
using System.Net.Sockets;
using System.Threading.Tasks;
using System.Collections.Generic;
using MimeKit;
using MailKit.Security;
namespace MailKit.Net.Pop3
{
public partial class Pop3Client
{
/// <summary>
/// Asynchronously authenticate using the specified SASL mechanism.
/// </summary>
/// <remarks>
/// <para>Authenticates using the specified SASL mechanism.</para>
/// <para>For a list of available SASL authentication mechanisms supported by the server,
/// check the <see cref="AuthenticationMechanisms"/> property after the service has been
/// connected.</para>
/// </remarks>
/// <returns>An asynchronous task context.</returns>
/// <param name="mechanism">The SASL mechanism.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <exception cref="System.ArgumentNullException">
/// <paramref name="mechanism"/> is <c>null</c>.
/// </exception>
/// <exception cref="System.ObjectDisposedException">
/// The <see cref="Pop3Client"/> has been disposed.
/// </exception>
/// <exception cref="ServiceNotConnectedException">
/// The <see cref="Pop3Client"/> is not connected.
/// </exception>
/// <exception cref="System.InvalidOperationException">
/// The <see cref="Pop3Client"/> is already authenticated.
/// </exception>
/// <exception cref="System.OperationCanceledException">
/// The operation was canceled via the cancellation token.
/// </exception>
/// <exception cref="MailKit.Security.AuthenticationException">
/// Authentication using the supplied credentials has failed.
/// </exception>
/// <exception cref="MailKit.Security.SaslException">
/// A SASL authentication error occurred.
/// </exception>
/// <exception cref="System.IO.IOException">
/// An I/O error occurred.
/// </exception>
/// <exception cref="Pop3CommandException">
/// A POP3 command failed.
/// </exception>
/// <exception cref="Pop3ProtocolException">
/// An POP3 protocol error occurred.
/// </exception>
public override Task AuthenticateAsync (SaslMechanism mechanism, CancellationToken cancellationToken = default (CancellationToken))
{
return AuthenticateAsync (mechanism, true, cancellationToken);
}
/// <summary>
/// Asynchronously authenticates using the supplied credentials.
/// </summary>
/// <remarks>
/// <para>If the POP3 server supports the APOP authentication mechanism,
/// then APOP is used.</para>
/// <para>If the APOP authentication mechanism is not supported and the
/// server supports one or more SASL authentication mechanisms, then
/// the SASL mechanisms that both the client and server support are tried
/// in order of greatest security to weakest security. Once a SASL
/// authentication mechanism is found that both client and server support,
/// the credentials are used to authenticate.</para>
/// <para>If the server does not support SASL or if no common SASL mechanisms
/// can be found, then the <c>USER</c> and <c>PASS</c> commands are used as a
/// fallback.</para>
/// <note type="tip"><para>To prevent the usage of certain authentication mechanisms,
/// simply remove them from the <see cref="AuthenticationMechanisms"/> hash set
/// before calling this method.</para>
/// <para>In the case of the APOP authentication mechanism, remove it from the
/// <see cref="Capabilities"/> property instead.</para></note>
/// </remarks>
/// <returns>An asynchronous task context.</returns>
/// <param name="encoding">The text encoding to use for the user's credentials.</param>
/// <param name="credentials">The user's credentials.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <exception cref="System.ArgumentNullException">
/// <para><paramref name="encoding"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="credentials"/> is <c>null</c>.</para>
/// </exception>
/// <exception cref="System.ObjectDisposedException">
/// The <see cref="Pop3Client"/> has been disposed.
/// </exception>
/// <exception cref="ServiceNotConnectedException">
/// The <see cref="Pop3Client"/> is not connected.
/// </exception>
/// <exception cref="System.InvalidOperationException">
/// The <see cref="Pop3Client"/> is already authenticated.
/// </exception>
/// <exception cref="System.OperationCanceledException">
/// The operation was canceled via the cancellation token.
/// </exception>
/// <exception cref="MailKit.Security.AuthenticationException">
/// Authentication using the supplied credentials has failed.
/// </exception>
/// <exception cref="MailKit.Security.SaslException">
/// A SASL authentication error occurred.
/// </exception>
/// <exception cref="System.IO.IOException">
/// An I/O error occurred.
/// </exception>
/// <exception cref="Pop3CommandException">
/// A POP3 command failed.
/// </exception>
/// <exception cref="Pop3ProtocolException">
/// An POP3 protocol error occurred.
/// </exception>
public override Task AuthenticateAsync (Encoding encoding, ICredentials credentials, CancellationToken cancellationToken = default (CancellationToken))
{
return AuthenticateAsync (encoding, credentials, true, cancellationToken);
}
/// <summary>
/// Asynchronously establish a connection to the specified POP3 or POP3/S server.
/// </summary>
/// <remarks>
/// <para>Establishes a connection to the specified POP3 or POP3/S server.</para>
/// <para>If the <paramref name="port"/> has a value of <c>0</c>, then the
/// <paramref name="options"/> parameter is used to determine the default port to
/// connect to. The default port used with <see cref="SecureSocketOptions.SslOnConnect"/>
/// is <c>995</c>. All other values will use a default port of <c>110</c>.</para>
/// <para>If the <paramref name="options"/> has a value of
/// <see cref="SecureSocketOptions.Auto"/>, then the <paramref name="port"/> is used
/// to determine the default security options. If the <paramref name="port"/> has a value
/// of <c>995</c>, then the default options used will be
/// <see cref="SecureSocketOptions.SslOnConnect"/>. All other values will use
/// <see cref="SecureSocketOptions.StartTlsWhenAvailable"/>.</para>
/// <para>Once a connection is established, properties such as
/// <see cref="AuthenticationMechanisms"/> and <see cref="Capabilities"/> will be
/// populated.</para>
/// </remarks>
/// <example>
/// <code language="c#" source="Examples\Pop3Examples.cs" region="DownloadMessages"/>
/// </example>
/// <returns>An asynchronous task context.</returns>
/// <param name="host">The host name to connect to.</param>
/// <param name="port">The port to connect to. If the specified port is <c>0</c>, then the default port will be used.</param>
/// <param name="options">The secure socket options to when connecting.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <exception cref="System.ArgumentNullException">
/// <paramref name="host"/> is <c>null</c>.
/// </exception>
/// <exception cref="System.ArgumentOutOfRangeException">
/// <paramref name="port"/> is not between <c>0</c> and <c>65535</c>.
/// </exception>
/// <exception cref="System.ArgumentException">
/// The <paramref name="host"/> is a zero-length string.
/// </exception>
/// <exception cref="System.ObjectDisposedException">
/// The <see cref="Pop3Client"/> has been disposed.
/// </exception>
/// <exception cref="System.InvalidOperationException">
/// The <see cref="Pop3Client"/> is already connected.
/// </exception>
/// <exception cref="System.OperationCanceledException">
/// The operation was canceled via the cancellation token.
/// </exception>
/// <exception cref="System.NotSupportedException">
/// <paramref name="options"/> was set to
/// <see cref="MailKit.Security.SecureSocketOptions.StartTls"/>
/// and the POP3 server does not support the STLS extension.
/// </exception>
/// <exception cref="System.Net.Sockets.SocketException">
/// A socket error occurred trying to connect to the remote host.
/// </exception>
/// <exception cref="SslHandshakeException">
/// An error occurred during the SSL/TLS negotiations.
/// </exception>
/// <exception cref="System.IO.IOException">
/// An I/O error occurred.
/// </exception>
/// <exception cref="Pop3CommandException">
/// A POP3 command failed.
/// </exception>
/// <exception cref="Pop3ProtocolException">
/// A POP3 protocol error occurred.
/// </exception>
public override Task ConnectAsync (string host, int port = 0, SecureSocketOptions options = SecureSocketOptions.Auto, CancellationToken cancellationToken = default (CancellationToken))
{
return ConnectAsync (host, port, options, true, cancellationToken);
}
/// <summary>
/// Asynchronously establish a connection to the specified POP3 or POP3/S server using the provided socket.
/// </summary>
/// <remarks>
/// <para>Establishes a connection to the specified POP3 or POP3/S server using
/// the provided socket.</para>
/// <para>If the <paramref name="options"/> has a value of
/// <see cref="SecureSocketOptions.Auto"/>, then the <paramref name="port"/> is used
/// to determine the default security options. If the <paramref name="port"/> has a value
/// of <c>995</c>, then the default options used will be
/// <see cref="SecureSocketOptions.SslOnConnect"/>. All other values will use
/// <see cref="SecureSocketOptions.StartTlsWhenAvailable"/>.</para>
/// <para>Once a connection is established, properties such as
/// <see cref="AuthenticationMechanisms"/> and <see cref="Capabilities"/> will be
/// populated.</para>
/// <note type="info">With the exception of using the <paramref name="port"/> to determine the
/// default <see cref="SecureSocketOptions"/> to use when the <paramref name="options"/> value
/// is <see cref="SecureSocketOptions.Auto"/>, the <paramref name="host"/> and
/// <paramref name="port"/> parameters are only used for logging purposes.</note>
/// </remarks>
/// <returns>An asynchronous task context.</returns>
/// <param name="socket">The socket to use for the connection.</param>
/// <param name="host">The host name to connect to.</param>
/// <param name="port">The port to connect to. If the specified port is <c>0</c>, then the default port will be used.</param>
/// <param name="options">The secure socket options to when connecting.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <exception cref="System.ArgumentNullException">
/// <para><paramref name="socket"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="host"/> is <c>null</c>.</para>
/// </exception>
/// <exception cref="System.ArgumentOutOfRangeException">
/// <paramref name="port"/> is not between <c>0</c> and <c>65535</c>.
/// </exception>
/// <exception cref="System.ArgumentException">
/// <para><paramref name="socket"/> is not connected.</para>
/// <para>-or-</para>
/// <para>The <paramref name="host"/> is a zero-length string.</para>
/// </exception>
/// <exception cref="System.ObjectDisposedException">
/// The <see cref="Pop3Client"/> has been disposed.
/// </exception>
/// <exception cref="System.InvalidOperationException">
/// The <see cref="Pop3Client"/> is already connected.
/// </exception>
/// <exception cref="System.NotSupportedException">
/// <paramref name="options"/> was set to
/// <see cref="MailKit.Security.SecureSocketOptions.StartTls"/>
/// and the POP3 server does not support the STLS extension.
/// </exception>
/// <exception cref="System.OperationCanceledException">
/// The operation was canceled via the cancellation token.
/// </exception>
/// <exception cref="SslHandshakeException">
/// An error occurred during the SSL/TLS negotiations.
/// </exception>
/// <exception cref="System.IO.IOException">
/// An I/O error occurred.
/// </exception>
/// <exception cref="Pop3CommandException">
/// A POP3 command failed.
/// </exception>
/// <exception cref="Pop3ProtocolException">
/// A POP3 protocol error occurred.
/// </exception>
public override Task ConnectAsync (Socket socket, string host, int port = 0, SecureSocketOptions options = SecureSocketOptions.Auto, CancellationToken cancellationToken = default (CancellationToken))
{
return ConnectAsync (socket, host, port, options, true, cancellationToken);
}
/// <summary>
/// Asynchronously establish a connection to the specified POP3 or POP3/S server using the provided stream.
/// </summary>
/// <remarks>
/// <para>Establishes a connection to the specified POP3 or POP3/S server using
/// the provided stream.</para>
/// <para>If the <paramref name="options"/> has a value of
/// <see cref="SecureSocketOptions.Auto"/>, then the <paramref name="port"/> is used
/// to determine the default security options. If the <paramref name="port"/> has a value
/// of <c>995</c>, then the default options used will be
/// <see cref="SecureSocketOptions.SslOnConnect"/>. All other values will use
/// <see cref="SecureSocketOptions.StartTlsWhenAvailable"/>.</para>
/// <para>Once a connection is established, properties such as
/// <see cref="AuthenticationMechanisms"/> and <see cref="Capabilities"/> will be
/// populated.</para>
/// <note type="info">With the exception of using the <paramref name="port"/> to determine the
/// default <see cref="SecureSocketOptions"/> to use when the <paramref name="options"/> value
/// is <see cref="SecureSocketOptions.Auto"/>, the <paramref name="host"/> and
/// <paramref name="port"/> parameters are only used for logging purposes.</note>
/// </remarks>
/// <returns>An asynchronous task context.</returns>
/// <param name="stream">The socket to use for the connection.</param>
/// <param name="host">The host name to connect to.</param>
/// <param name="port">The port to connect to. If the specified port is <c>0</c>, then the default port will be used.</param>
/// <param name="options">The secure socket options to when connecting.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <exception cref="System.ArgumentNullException">
/// <para><paramref name="stream"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="host"/> is <c>null</c>.</para>
/// </exception>
/// <exception cref="System.ArgumentOutOfRangeException">
/// <paramref name="port"/> is not between <c>0</c> and <c>65535</c>.
/// </exception>
/// <exception cref="System.ArgumentException">
/// The <paramref name="host"/> is a zero-length string.
/// </exception>
/// <exception cref="System.ObjectDisposedException">
/// The <see cref="Pop3Client"/> has been disposed.
/// </exception>
/// <exception cref="System.InvalidOperationException">
/// The <see cref="Pop3Client"/> is already connected.
/// </exception>
/// <exception cref="System.NotSupportedException">
/// <paramref name="options"/> was set to
/// <see cref="MailKit.Security.SecureSocketOptions.StartTls"/>
/// and the POP3 server does not support the STLS extension.
/// </exception>
/// <exception cref="System.OperationCanceledException">
/// The operation was canceled via the cancellation token.
/// </exception>
/// <exception cref="SslHandshakeException">
/// An error occurred during the SSL/TLS negotiations.
/// </exception>
/// <exception cref="System.IO.IOException">
/// An I/O error occurred.
/// </exception>
/// <exception cref="Pop3CommandException">
/// A POP3 command failed.
/// </exception>
/// <exception cref="Pop3ProtocolException">
/// A POP3 protocol error occurred.
/// </exception>
public override Task ConnectAsync (Stream stream, string host, int port = 0, SecureSocketOptions options = SecureSocketOptions.Auto, CancellationToken cancellationToken = default (CancellationToken))
{
return ConnectAsync (stream, host, port, options, true, cancellationToken);
}
/// <summary>
/// Asynchronously disconnect the service.
/// </summary>
/// <remarks>
/// If <paramref name="quit"/> is <c>true</c>, a <c>QUIT</c> command will be issued in order to disconnect cleanly.
/// </remarks>
/// <example>
/// <code language="c#" source="Examples\Pop3Examples.cs" region="DownloadMessages"/>
/// </example>
/// <returns>An asynchronous task context.</returns>
/// <param name="quit">If set to <c>true</c>, a <c>QUIT</c> command will be issued in order to disconnect cleanly.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <exception cref="System.ObjectDisposedException">
/// The <see cref="Pop3Client"/> has been disposed.
/// </exception>
public override Task DisconnectAsync (bool quit, CancellationToken cancellationToken = default (CancellationToken))
{
return DisconnectAsync (quit, true, cancellationToken);
}
/// <summary>
/// Asynchronously get the message count.
/// </summary>
/// <remarks>
/// Asynchronously gets the message count.
/// </remarks>
/// <returns>The message count.</returns>
/// <param name="cancellationToken">The cancellation token.</param>
/// <exception cref="System.ObjectDisposedException">
/// The <see cref="Pop3Client"/> has been disposed.
/// </exception>
/// <exception cref="ServiceNotConnectedException">
/// The <see cref="Pop3Client"/> is not connected.
/// </exception>
/// <exception cref="ServiceNotAuthenticatedException">
/// The <see cref="Pop3Client"/> is not authenticated.
/// </exception>
/// <exception cref="System.OperationCanceledException">
/// The operation was canceled via the cancellation token.
/// </exception>
/// <exception cref="System.IO.IOException">
/// An I/O error occurred.
/// </exception>
/// <exception cref="Pop3CommandException">
/// The POP3 command failed.
/// </exception>
/// <exception cref="Pop3ProtocolException">
/// A POP3 protocol error occurred.
/// </exception>
public override async Task<int> GetMessageCountAsync (CancellationToken cancellationToken = default (CancellationToken))
{
CheckDisposed ();
CheckConnected ();
CheckAuthenticated ();
await UpdateMessageCountAsync (true, cancellationToken).ConfigureAwait (false);
return Count;
}
/// <summary>
/// Ping the POP3 server to keep the connection alive.
/// </summary>
/// <remarks>Mail servers, if left idle for too long, will automatically drop the connection.</remarks>
/// <returns>An asynchronous task context.</returns>
/// <param name="cancellationToken">The cancellation token.</param>
/// <exception cref="System.ObjectDisposedException">
/// The <see cref="Pop3Client"/> has been disposed.
/// </exception>
/// <exception cref="ServiceNotConnectedException">
/// The <see cref="Pop3Client"/> is not connected.
/// </exception>
/// <exception cref="ServiceNotAuthenticatedException">
/// The <see cref="Pop3Client"/> is not authenticated.
/// </exception>
/// <exception cref="System.OperationCanceledException">
/// The operation was canceled via the cancellation token.
/// </exception>
/// <exception cref="System.IO.IOException">
/// An I/O error occurred.
/// </exception>
/// <exception cref="Pop3CommandException">
/// The POP3 command failed.
/// </exception>
/// <exception cref="Pop3ProtocolException">
/// A POP3 protocol error occurred.
/// </exception>
public override Task NoOpAsync (CancellationToken cancellationToken = default (CancellationToken))
{
return NoOpAsync (true, cancellationToken);
}
/// <summary>
/// Asynchronously enable UTF8 mode.
/// </summary>
/// <remarks>
/// The POP3 UTF8 extension allows the client to retrieve messages in the UTF-8 encoding and
/// may also allow the user to authenticate using a UTF-8 encoded username or password.
/// </remarks>
/// <returns>An asynchronous task context.</returns>
/// <param name="cancellationToken">The cancellation token.</param>
/// <exception cref="System.ObjectDisposedException">
/// The <see cref="Pop3Client"/> has been disposed.
/// </exception>
/// <exception cref="ServiceNotConnectedException">
/// The <see cref="Pop3Client"/> is not connected.
/// </exception>
/// <exception cref="System.InvalidOperationException">
/// The <see cref="Pop3Client"/> has already been authenticated.
/// </exception>
/// <exception cref="System.OperationCanceledException">
/// The operation was canceled via the cancellation token.
/// </exception>
/// <exception cref="System.NotSupportedException">
/// The POP3 server does not support the UTF8 extension.
/// </exception>
/// <exception cref="System.IO.IOException">
/// An I/O error occurred.
/// </exception>
/// <exception cref="Pop3CommandException">
/// The POP3 command failed.
/// </exception>
/// <exception cref="Pop3ProtocolException">
/// A POP3 protocol error occurred.
/// </exception>
public Task EnableUTF8Async (CancellationToken cancellationToken = default (CancellationToken))
{
return EnableUTF8Async (true, cancellationToken);
}
/// <summary>
/// Asynchronously get the list of languages supported by the POP3 server.
/// </summary>
/// <remarks>
/// If the POP3 server supports the LANG extension, it is possible to
/// query the list of languages supported by the POP3 server that can
/// be used for error messages.
/// </remarks>
/// <returns>The supported languages.</returns>
/// <param name="cancellationToken">The cancellation token.</param>
/// <exception cref="System.ObjectDisposedException">
/// The <see cref="Pop3Client"/> has been disposed.
/// </exception>
/// <exception cref="ServiceNotConnectedException">
/// The <see cref="Pop3Client"/> is not connected.
/// </exception>
/// <exception cref="System.OperationCanceledException">
/// The operation was canceled via the cancellation token.
/// </exception>
/// <exception cref="System.NotSupportedException">
/// The POP3 server does not support the LANG extension.
/// </exception>
/// <exception cref="System.IO.IOException">
/// An I/O error occurred.
/// </exception>
/// <exception cref="Pop3CommandException">
/// The POP3 command failed.
/// </exception>
/// <exception cref="Pop3ProtocolException">
/// A POP3 protocol error occurred.
/// </exception>
public Task<IList<Pop3Language>> GetLanguagesAsync (CancellationToken cancellationToken = default (CancellationToken))
{
return GetLanguagesAsync (true, cancellationToken);
}
/// <summary>
/// Asynchronously set the language used by the POP3 server for error messages.
/// </summary>
/// <remarks>
/// If the POP3 server supports the LANG extension, it is possible to
/// set the language used by the POP3 server for error messages.
/// </remarks>
/// <returns>An asynchronous task context.</returns>
/// <param name="lang">The language code.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <exception cref="System.ArgumentNullException">
/// <paramref name="lang"/> is <c>null</c>.
/// </exception>
/// <exception cref="System.ArgumentException">
/// <paramref name="lang"/> is empty.
/// </exception>
/// <exception cref="System.ObjectDisposedException">
/// The <see cref="Pop3Client"/> has been disposed.
/// </exception>
/// <exception cref="ServiceNotConnectedException">
/// The <see cref="Pop3Client"/> is not connected.
/// </exception>
/// <exception cref="System.OperationCanceledException">
/// The operation was canceled via the cancellation token.
/// </exception>
/// <exception cref="System.NotSupportedException">
/// The POP3 server does not support the LANG extension.
/// </exception>
/// <exception cref="System.IO.IOException">
/// An I/O error occurred.
/// </exception>
/// <exception cref="Pop3CommandException">
/// The POP3 command failed.
/// </exception>
/// <exception cref="Pop3ProtocolException">
/// A POP3 protocol error occurred.
/// </exception>
public Task SetLanguageAsync (string lang, CancellationToken cancellationToken = default (CancellationToken))
{
return SetLanguageAsync (lang, true, cancellationToken);
}
/// <summary>
/// Asynchronously get the UID of the message at the specified index.
/// </summary>
/// <remarks>
/// <para>Gets the UID of the message at the specified index.</para>
/// <note type="warning">Not all servers support UIDs, so you should first check the
/// <see cref="Capabilities"/> property for the <see cref="Pop3Capabilities.UIDL"/> flag or
/// the <see cref="SupportsUids"/> convenience property.</note>
/// </remarks>
/// <returns>The message UID.</returns>
/// <param name="index">The message index.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <exception cref="System.ArgumentOutOfRangeException">
/// <paramref name="index"/> is not a valid message index.
/// </exception>
/// <exception cref="System.ObjectDisposedException">
/// The <see cref="Pop3Client"/> has been disposed.
/// </exception>
/// <exception cref="ServiceNotConnectedException">
/// The <see cref="Pop3Client"/> is not connected.
/// </exception>
/// <exception cref="ServiceNotAuthenticatedException">
/// The <see cref="Pop3Client"/> is not authenticated.
/// </exception>
/// <exception cref="System.NotSupportedException">
/// The POP3 server does not support the UIDL extension.
/// </exception>
/// <exception cref="System.OperationCanceledException">
/// The operation was canceled via the cancellation token.
/// </exception>
/// <exception cref="System.IO.IOException">
/// An I/O error occurred.
/// </exception>
/// <exception cref="Pop3CommandException">
/// The POP3 command failed.
/// </exception>
/// <exception cref="Pop3ProtocolException">
/// A POP3 protocol error occurred.
/// </exception>
public override Task<string> GetMessageUidAsync (int index, CancellationToken cancellationToken = default (CancellationToken))
{
return GetMessageUidAsync (index, true, cancellationToken);
}
/// <summary>
/// Asynchronously get the full list of available message UIDs.
/// </summary>
/// <remarks>
/// <para>Gets the full list of available message UIDs.</para>
/// <note type="warning">Not all servers support UIDs, so you should first check the
/// <see cref="Capabilities"/> property for the <see cref="Pop3Capabilities.UIDL"/> flag or
/// the <see cref="SupportsUids"/> convenience property.</note>
/// </remarks>
/// <example>
/// <code language="c#" source="Examples\Pop3Examples.cs" region="DownloadNewMessages"/>
/// </example>
/// <returns>The message uids.</returns>
/// <param name="cancellationToken">The cancellation token.</param>
/// <exception cref="System.ObjectDisposedException">
/// The <see cref="Pop3Client"/> has been disposed.
/// </exception>
/// <exception cref="ServiceNotConnectedException">
/// The <see cref="Pop3Client"/> is not connected.
/// </exception>
/// <exception cref="ServiceNotAuthenticatedException">
/// The <see cref="Pop3Client"/> is not authenticated.
/// </exception>
/// <exception cref="System.NotSupportedException">
/// The POP3 server does not support the UIDL extension.
/// </exception>
/// <exception cref="System.OperationCanceledException">
/// The operation was canceled via the cancellation token.
/// </exception>
/// <exception cref="System.IO.IOException">
/// An I/O error occurred.
/// </exception>
/// <exception cref="Pop3CommandException">
/// The POP3 command failed.
/// </exception>
/// <exception cref="Pop3ProtocolException">
/// A POP3 protocol error occurred.
/// </exception>
public override Task<IList<string>> GetMessageUidsAsync (CancellationToken cancellationToken = default (CancellationToken))
{
return GetMessageUidsAsync (true, cancellationToken);
}
/// <summary>
/// Asynchronously get the size of the specified message, in bytes.
/// </summary>
/// <remarks>
/// Gets the size of the specified message, in bytes.
/// </remarks>
/// <returns>The message size, in bytes.</returns>
/// <param name="index">The index of the message.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <exception cref="System.ArgumentOutOfRangeException">
/// <paramref name="index"/> is not a valid message index.
/// </exception>
/// <exception cref="System.ObjectDisposedException">
/// The <see cref="Pop3Client"/> has been disposed.
/// </exception>
/// <exception cref="ServiceNotConnectedException">
/// The <see cref="Pop3Client"/> is not connected.
/// </exception>
/// <exception cref="ServiceNotAuthenticatedException">
/// The <see cref="Pop3Client"/> is not authenticated.
/// </exception>
/// <exception cref="System.OperationCanceledException">
/// The operation was canceled via the cancellation token.
/// </exception>
/// <exception cref="System.IO.IOException">
/// An I/O error occurred.
/// </exception>
/// <exception cref="Pop3CommandException">
/// The POP3 command failed.
/// </exception>
/// <exception cref="Pop3ProtocolException">
/// A POP3 protocol error occurred.
/// </exception>
public override Task<int> GetMessageSizeAsync (int index, CancellationToken cancellationToken = default (CancellationToken))
{
return GetMessageSizeAsync (index, true, cancellationToken);
}
/// <summary>
/// Asynchronously get the sizes for all available messages, in bytes.
/// </summary>
/// <remarks>
/// Gets the sizes for all available messages, in bytes.
/// </remarks>
/// <returns>The message sizes, in bytes.</returns>
/// <param name="cancellationToken">The cancellation token.</param>
/// <exception cref="System.ObjectDisposedException">
/// The <see cref="Pop3Client"/> has been disposed.
/// </exception>
/// <exception cref="ServiceNotConnectedException">
/// The <see cref="Pop3Client"/> is not connected.
/// </exception>
/// <exception cref="ServiceNotAuthenticatedException">
/// The <see cref="Pop3Client"/> is not authenticated.
/// </exception>
/// <exception cref="System.OperationCanceledException">
/// The operation was canceled via the cancellation token.
/// </exception>
/// <exception cref="System.IO.IOException">
/// An I/O error occurred.
/// </exception>
/// <exception cref="Pop3CommandException">
/// The POP3 command failed.
/// </exception>
/// <exception cref="Pop3ProtocolException">
/// A POP3 protocol error occurred.
/// </exception>
public override Task<IList<int>> GetMessageSizesAsync (CancellationToken cancellationToken = default (CancellationToken))
{
return GetMessageSizesAsync (true, cancellationToken);
}
/// <summary>
/// Asynchronously get the headers for the message at the specified index.
/// </summary>
/// <remarks>
/// Gets the headers for the message at the specified index.
/// </remarks>
/// <returns>The message headers.</returns>
/// <param name="index">The index of the message.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <exception cref="System.ArgumentOutOfRangeException">
/// <paramref name="index"/> is not a valid message index.
/// </exception>
/// <exception cref="System.ObjectDisposedException">
/// The <see cref="Pop3Client"/> has been disposed.
/// </exception>
/// <exception cref="ServiceNotConnectedException">
/// The <see cref="Pop3Client"/> is not connected.
/// </exception>
/// <exception cref="ServiceNotAuthenticatedException">
/// The <see cref="Pop3Client"/> is not authenticated.
/// </exception>
/// <exception cref="System.OperationCanceledException">
/// The operation was canceled via the cancellation token.
/// </exception>
/// <exception cref="System.IO.IOException">
/// An I/O error occurred.
/// </exception>
/// <exception cref="Pop3CommandException">
/// The POP3 command failed.
/// </exception>
/// <exception cref="Pop3ProtocolException">
/// A POP3 protocol error occurred.
/// </exception>
public override Task<HeaderList> GetMessageHeadersAsync (int index, CancellationToken cancellationToken = default (CancellationToken))
{
CheckDisposed ();
CheckConnected ();
CheckAuthenticated ();
if (index < 0 || index >= total)
throw new ArgumentOutOfRangeException (nameof (index));
var ctx = new DownloadHeaderContext (this, parser);
return ctx.DownloadAsync (index + 1, true, true, cancellationToken);
}
/// <summary>
/// Asynchronously get the headers for the messages at the specified indexes.
/// </summary>
/// <remarks>
/// <para>Gets the headers for the messages at the specified indexes.</para>
/// <para>When the POP3 server supports the <see cref="Pop3Capabilities.Pipelining"/>
/// extension, this method will likely be more efficient than using
/// <see cref="GetMessageHeaders(int,CancellationToken)"/> for each message because
/// it will batch the commands to reduce latency.</para>
/// </remarks>
/// <returns>The headers for the specified messages.</returns>
/// <param name="indexes">The indexes of the messages.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <exception cref="System.ArgumentNullException">
/// <paramref name="indexes"/> is <c>null</c>.
/// </exception>
/// <exception cref="System.ArgumentException">
/// One or more of the <paramref name="indexes"/> are invalid.
/// </exception>
/// <exception cref="System.ObjectDisposedException">
/// The <see cref="Pop3Client"/> has been disposed.
/// </exception>
/// <exception cref="ServiceNotConnectedException">
/// The <see cref="Pop3Client"/> is not connected.
/// </exception>
/// <exception cref="ServiceNotAuthenticatedException">
/// The <see cref="Pop3Client"/> is not authenticated.
/// </exception>
/// <exception cref="System.NotSupportedException">
/// The POP3 server does not support the UIDL extension.
/// </exception>
/// <exception cref="System.OperationCanceledException">
/// The operation was canceled via the cancellation token.
/// </exception>
/// <exception cref="System.IO.IOException">
/// An I/O error occurred.
/// </exception>
/// <exception cref="Pop3CommandException">
/// The POP3 command failed.
/// </exception>
/// <exception cref="Pop3ProtocolException">
/// A POP3 protocol error occurred.
/// </exception>
public override Task<IList<HeaderList>> GetMessageHeadersAsync (IList<int> indexes, CancellationToken cancellationToken = default (CancellationToken))
{
CheckDisposed ();
CheckConnected ();
CheckAuthenticated ();
if (indexes == null)
throw new ArgumentNullException (nameof (indexes));
if (indexes.Count == 0)
return Task.FromResult ((IList<HeaderList>) new HeaderList[0]);
var seqids = new int[indexes.Count];
for (int i = 0; i < indexes.Count; i++) {
if (indexes[i] < 0 || indexes[i] >= total)
throw new ArgumentException ("One or more of the indexes are invalid.", nameof (indexes));
seqids[i] = indexes[i] + 1;
}
var ctx = new DownloadHeaderContext (this, parser);
return ctx.DownloadAsync (seqids, true, true, cancellationToken);
}
/// <summary>
/// Asynchronously get the headers of the messages within the specified range.
/// </summary>
/// <remarks>
/// <para>Gets the headers of the messages within the specified range.</para>
/// <para>When the POP3 server supports the <see cref="Pop3Capabilities.Pipelining"/>
/// extension, this method will likely be more efficient than using
/// <see cref="GetMessageHeaders(int,CancellationToken)"/> for each message because
/// it will batch the commands to reduce latency.</para>
/// </remarks>
/// <returns>The headers of the messages within the specified range.</returns>
/// <param name="startIndex">The index of the first message to get.</param>
/// <param name="count">The number of messages to get.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <exception cref="System.ArgumentOutOfRangeException">
/// <paramref name="startIndex"/> and <paramref name="count"/> do not specify
/// a valid range of messages.
/// </exception>
/// <exception cref="System.ObjectDisposedException">
/// The <see cref="Pop3Client"/> has been disposed.
/// </exception>
/// <exception cref="ServiceNotConnectedException">
/// The <see cref="Pop3Client"/> is not connected.
/// </exception>
/// <exception cref="ServiceNotAuthenticatedException">
/// The <see cref="Pop3Client"/> is not authenticated.
/// </exception>
/// <exception cref="System.NotSupportedException">
/// The POP3 server does not support the UIDL extension.
/// </exception>
/// <exception cref="System.OperationCanceledException">
/// The operation was canceled via the cancellation token.
/// </exception>
/// <exception cref="System.IO.IOException">
/// An I/O error occurred.
/// </exception>
/// <exception cref="Pop3CommandException">
/// The POP3 command failed.
/// </exception>
/// <exception cref="Pop3ProtocolException">
/// A POP3 protocol error occurred.
/// </exception>
public override Task<IList<HeaderList>> GetMessageHeadersAsync (int startIndex, int count, CancellationToken cancellationToken = default (CancellationToken))
{
CheckDisposed ();
CheckConnected ();
CheckAuthenticated ();
if (startIndex < 0 || startIndex >= total)
throw new ArgumentOutOfRangeException (nameof (startIndex));
if (count < 0 || count > (total - startIndex))
throw new ArgumentOutOfRangeException (nameof (count));
if (count == 0)
return Task.FromResult ((IList<HeaderList>) new HeaderList[0]);
var seqids = new int[count];
for (int i = 0; i < count; i++)
seqids[i] = startIndex + i + 1;
var ctx = new DownloadHeaderContext (this, parser);
return ctx.DownloadAsync (seqids, true, true, cancellationToken);
}
/// <summary>
/// Asynchronously get the message at the specified index.
/// </summary>
/// <remarks>
/// Gets the message at the specified index.
/// </remarks>
/// <example>
/// <code language="c#" source="Examples\Pop3Examples.cs" region="DownloadMessages"/>
/// </example>
/// <returns>The message.</returns>
/// <param name="index">The index of the message.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="progress">The progress reporting mechanism.</param>
/// <exception cref="System.ArgumentOutOfRangeException">
/// <paramref name="index"/> is not a valid message index.
/// </exception>
/// <exception cref="System.ObjectDisposedException">
/// The <see cref="Pop3Client"/> has been disposed.
/// </exception>
/// <exception cref="ServiceNotConnectedException">
/// The <see cref="Pop3Client"/> is not connected.
/// </exception>
/// <exception cref="ServiceNotAuthenticatedException">
/// The <see cref="Pop3Client"/> is not authenticated.
/// </exception>
/// <exception cref="System.OperationCanceledException">
/// The operation was canceled via the cancellation token.
/// </exception>
/// <exception cref="System.IO.IOException">
/// An I/O error occurred.
/// </exception>
/// <exception cref="Pop3CommandException">
/// The POP3 command failed.
/// </exception>
/// <exception cref="Pop3ProtocolException">
/// A POP3 protocol error occurred.
/// </exception>
public override Task<MimeMessage> GetMessageAsync (int index, CancellationToken cancellationToken = default (CancellationToken), ITransferProgress progress = null)
{
CheckDisposed ();
CheckConnected ();
CheckAuthenticated ();
if (index < 0 || index >= total)
throw new ArgumentOutOfRangeException (nameof (index));
var ctx = new DownloadMessageContext (this, parser, progress);
return ctx.DownloadAsync (index + 1, false, true, cancellationToken);
}
/// <summary>
/// Asynchronously get the messages at the specified indexes.
/// </summary>
/// <remarks>
/// <para>Gets the messages at the specified indexes.</para>
/// <para>When the POP3 server supports the <see cref="Pop3Capabilities.Pipelining"/>
/// extension, this method will likely be more efficient than using
/// <see cref="GetMessage(int,CancellationToken,ITransferProgress)"/> for each message
/// because it will batch the commands to reduce latency.</para>
/// </remarks>
/// <returns>The messages.</returns>
/// <param name="indexes">The indexes of the messages.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="progress">The progress reporting mechanism.</param>
/// <exception cref="System.ArgumentNullException">
/// <paramref name="indexes"/> is <c>null</c>.
/// </exception>
/// <exception cref="System.ArgumentException">
/// One or more of the <paramref name="indexes"/> are invalid.
/// </exception>
/// <exception cref="System.ObjectDisposedException">
/// The <see cref="Pop3Client"/> has been disposed.
/// </exception>
/// <exception cref="ServiceNotConnectedException">
/// The <see cref="Pop3Client"/> is not connected.
/// </exception>
/// <exception cref="ServiceNotAuthenticatedException">
/// The <see cref="Pop3Client"/> is not authenticated.
/// </exception>
/// <exception cref="System.NotSupportedException">
/// The POP3 server does not support the UIDL extension.
/// </exception>
/// <exception cref="System.OperationCanceledException">
/// The operation was canceled via the cancellation token.
/// </exception>
/// <exception cref="System.IO.IOException">
/// An I/O error occurred.
/// </exception>
/// <exception cref="Pop3CommandException">
/// The POP3 command failed.
/// </exception>
/// <exception cref="Pop3ProtocolException">
/// A POP3 protocol error occurred.
/// </exception>
public override Task<IList<MimeMessage>> GetMessagesAsync (IList<int> indexes, CancellationToken cancellationToken = default (CancellationToken), ITransferProgress progress = null)
{
CheckDisposed ();
CheckConnected ();
CheckAuthenticated ();
if (indexes == null)
throw new ArgumentNullException (nameof (indexes));
if (indexes.Count == 0)
return Task.FromResult ((IList<MimeMessage>) new MimeMessage[0]);
var seqids = new int[indexes.Count];
for (int i = 0; i < indexes.Count; i++) {
if (indexes[i] < 0 || indexes[i] >= total)
throw new ArgumentException ("One or more of the indexes are invalid.", nameof (indexes));
seqids[i] = indexes[i] + 1;
}
var ctx = new DownloadMessageContext (this, parser, progress);
return ctx.DownloadAsync (seqids, false, true, cancellationToken);
}
/// <summary>
/// Asynchronously get the messages within the specified range.
/// </summary>
/// <remarks>
/// <para>Gets the messages within the specified range.</para>
/// <para>When the POP3 server supports the <see cref="Pop3Capabilities.Pipelining"/>
/// extension, this method will likely be more efficient than using
/// <see cref="GetMessage(int,CancellationToken,ITransferProgress)"/> for each message
/// because it will batch the commands to reduce latency.</para>
/// </remarks>
/// <example>
/// <code language="c#" source="Examples\Pop3Examples.cs" region="BatchDownloadMessages"/>
/// </example>
/// <returns>The messages.</returns>
/// <param name="startIndex">The index of the first message to get.</param>
/// <param name="count">The number of messages to get.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="progress">The progress reporting mechanism.</param>
/// <exception cref="System.ArgumentOutOfRangeException">
/// <paramref name="startIndex"/> and <paramref name="count"/> do not specify
/// a valid range of messages.
/// </exception>
/// <exception cref="System.ObjectDisposedException">
/// The <see cref="Pop3Client"/> has been disposed.
/// </exception>
/// <exception cref="ServiceNotConnectedException">
/// The <see cref="Pop3Client"/> is not connected.
/// </exception>
/// <exception cref="ServiceNotAuthenticatedException">
/// The <see cref="Pop3Client"/> is not authenticated.
/// </exception>
/// <exception cref="System.NotSupportedException">
/// The POP3 server does not support the UIDL extension.
/// </exception>
/// <exception cref="System.OperationCanceledException">
/// The operation was canceled via the cancellation token.
/// </exception>
/// <exception cref="System.IO.IOException">
/// An I/O error occurred.
/// </exception>
/// <exception cref="Pop3CommandException">
/// The POP3 command failed.
/// </exception>
/// <exception cref="Pop3ProtocolException">
/// A POP3 protocol error occurred.
/// </exception>
public override Task<IList<MimeMessage>> GetMessagesAsync (int startIndex, int count, CancellationToken cancellationToken = default (CancellationToken), ITransferProgress progress = null)
{
CheckDisposed ();
CheckConnected ();
CheckAuthenticated ();
if (startIndex < 0 || startIndex >= total)
throw new ArgumentOutOfRangeException (nameof (startIndex));
if (count < 0 || count > (total - startIndex))
throw new ArgumentOutOfRangeException (nameof (count));
if (count == 0)
return Task.FromResult ((IList<MimeMessage>) new MimeMessage[0]);
var seqids = new int[count];
for (int i = 0; i < count; i++)
seqids[i] = startIndex + i + 1;
var ctx = new DownloadMessageContext (this, parser, progress);
return ctx.DownloadAsync (seqids, false, true, cancellationToken);
}
/// <summary>
/// Asynchronously get the message or header stream at the specified index.
/// </summary>
/// <remarks>
/// Gets the message or header stream at the specified index.
/// </remarks>
/// <returns>The message or header stream.</returns>
/// <param name="index">The index of the message.</param>
/// <param name="headersOnly"><c>true</c> if only the headers should be retrieved; otherwise, <c>false</c>.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="progress">The progress reporting mechanism.</param>
/// <exception cref="System.ArgumentOutOfRangeException">
/// <paramref name="index"/> is not a valid message index.
/// </exception>
/// <exception cref="System.ObjectDisposedException">
/// The <see cref="Pop3Client"/> has been disposed.
/// </exception>
/// <exception cref="ServiceNotConnectedException">
/// The <see cref="Pop3Client"/> is not connected.
/// </exception>
/// <exception cref="ServiceNotAuthenticatedException">
/// The <see cref="Pop3Client"/> is not authenticated.
/// </exception>
/// <exception cref="System.OperationCanceledException">
/// The operation was canceled via the cancellation token.
/// </exception>
/// <exception cref="System.IO.IOException">
/// An I/O error occurred.
/// </exception>
/// <exception cref="Pop3CommandException">
/// The POP3 command failed.
/// </exception>
/// <exception cref="Pop3ProtocolException">
/// A POP3 protocol error occurred.
/// </exception>
public override Task<Stream> GetStreamAsync (int index, bool headersOnly = false, CancellationToken cancellationToken = default (CancellationToken), ITransferProgress progress = null)
{
CheckDisposed ();
CheckConnected ();
CheckAuthenticated ();
if (index < 0 || index >= total)
throw new ArgumentOutOfRangeException (nameof (index));
var ctx = new DownloadStreamContext (this, progress);
return ctx.DownloadAsync (index + 1, headersOnly, true, cancellationToken);
}
/// <summary>
/// Asynchronously get the message or header streams at the specified indexes.
/// </summary>
/// <remarks>
/// <para>Get the message or header streams at the specified indexes.</para>
/// <para>If the POP3 server supports the <see cref="Pop3Capabilities.Pipelining"/>
/// extension, this method will likely be more efficient than using
/// <see cref="GetStream(int,bool,CancellationToken,ITransferProgress)"/> for each message
/// because it will batch the commands to reduce latency.</para>
/// </remarks>
/// <returns>The message or header streams.</returns>
/// <param name="indexes">The indexes of the messages.</param>
/// <param name="headersOnly"><c>true</c> if only the headers should be retrieved; otherwise, <c>false</c>.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="progress">The progress reporting mechanism.</param>
/// <exception cref="System.ArgumentNullException">
/// <paramref name="indexes"/> is <c>null</c>.
/// </exception>
/// <exception cref="System.ArgumentException">
/// One or more of the <paramref name="indexes"/> are invalid.
/// </exception>
/// <exception cref="System.ObjectDisposedException">
/// The <see cref="Pop3Client"/> has been disposed.
/// </exception>
/// <exception cref="ServiceNotConnectedException">
/// The <see cref="Pop3Client"/> is not connected.
/// </exception>
/// <exception cref="ServiceNotAuthenticatedException">
/// The <see cref="Pop3Client"/> is not authenticated.
/// </exception>
/// <exception cref="System.NotSupportedException">
/// The POP3 server does not support the UIDL extension.
/// </exception>
/// <exception cref="System.OperationCanceledException">
/// The operation was canceled via the cancellation token.
/// </exception>
/// <exception cref="System.IO.IOException">
/// An I/O error occurred.
/// </exception>
/// <exception cref="Pop3CommandException">
/// The POP3 command failed.
/// </exception>
/// <exception cref="Pop3ProtocolException">
/// A POP3 protocol error occurred.
/// </exception>
public override Task<IList<Stream>> GetStreamsAsync (IList<int> indexes, bool headersOnly = false, CancellationToken cancellationToken = default (CancellationToken), ITransferProgress progress = null)
{
CheckDisposed ();
CheckConnected ();
CheckAuthenticated ();
if (indexes == null)
throw new ArgumentNullException (nameof (indexes));
if (indexes.Count == 0)
return Task.FromResult ((IList<Stream>) new Stream[0]);
var seqids = new int[indexes.Count];
for (int i = 0; i < indexes.Count; i++) {
if (indexes[i] < 0 || indexes[i] >= total)
throw new ArgumentException ("One or more of the indexes are invalid.", nameof (indexes));
seqids[i] = indexes[i] + 1;
}
var ctx = new DownloadStreamContext (this, progress);
return ctx.DownloadAsync (seqids, headersOnly, true, cancellationToken);
}
/// <summary>
/// Asynchronously get the message or header streams within the specified range.
/// </summary>
/// <remarks>
/// <para>Gets the message or header streams within the specified range.</para>
/// <para>If the POP3 server supports the <see cref="Pop3Capabilities.Pipelining"/>
/// extension, this method will likely be more efficient than using
/// <see cref="GetStream(int,bool,CancellationToken,ITransferProgress)"/> for each message
/// because it will batch the commands to reduce latency.</para>
/// </remarks>
/// <returns>The message or header streams.</returns>
/// <param name="startIndex">The index of the first stream to get.</param>
/// <param name="count">The number of streams to get.</param>
/// <param name="headersOnly"><c>true</c> if only the headers should be retrieved; otherwise, <c>false</c>.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="progress">The progress reporting mechanism.</param>
/// <exception cref="System.ArgumentOutOfRangeException">
/// <paramref name="startIndex"/> and <paramref name="count"/> do not specify
/// a valid range of messages.
/// </exception>
/// <exception cref="System.ObjectDisposedException">
/// The <see cref="Pop3Client"/> has been disposed.
/// </exception>
/// <exception cref="ServiceNotConnectedException">
/// The <see cref="Pop3Client"/> is not connected.
/// </exception>
/// <exception cref="ServiceNotAuthenticatedException">
/// The <see cref="Pop3Client"/> is not authenticated.
/// </exception>
/// <exception cref="System.NotSupportedException">
/// The POP3 server does not support the UIDL extension.
/// </exception>
/// <exception cref="System.OperationCanceledException">
/// The operation was canceled via the cancellation token.
/// </exception>
/// <exception cref="System.IO.IOException">
/// An I/O error occurred.
/// </exception>
/// <exception cref="Pop3CommandException">
/// The POP3 command failed.
/// </exception>
/// <exception cref="Pop3ProtocolException">
/// A POP3 protocol error occurred.
/// </exception>
public override Task<IList<Stream>> GetStreamsAsync (int startIndex, int count, bool headersOnly = false, CancellationToken cancellationToken = default (CancellationToken), ITransferProgress progress = null)
{
CheckDisposed ();
CheckConnected ();
CheckAuthenticated ();
if (startIndex < 0 || startIndex >= total)
throw new ArgumentOutOfRangeException (nameof (startIndex));
if (count < 0 || count > (total - startIndex))
throw new ArgumentOutOfRangeException (nameof (count));
if (count == 0)
return Task.FromResult ((IList<Stream>) new Stream[0]);
var seqids = new int[count];
for (int i = 0; i < count; i++)
seqids[i] = startIndex + i + 1;
var ctx = new DownloadStreamContext (this, progress);
return ctx.DownloadAsync (seqids, headersOnly, true, cancellationToken);
}
/// <summary>
/// Asynchronously mark the specified message for deletion.
/// </summary>
/// <remarks>
/// Messages marked for deletion are not actually deleted until the session
/// is cleanly disconnected
/// (see <see cref="Pop3Client.Disconnect(bool, CancellationToken)"/>).
/// </remarks>
/// <example>
/// <code language="c#" source="Examples\Pop3Examples.cs" region="DownloadMessages"/>
/// </example>
/// <returns>An asynchronous task context.</returns>
/// <param name="index">The index of the message.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <exception cref="System.ArgumentOutOfRangeException">
/// <paramref name="index"/> is not a valid message index.
/// </exception>
/// <exception cref="System.ObjectDisposedException">
/// The <see cref="Pop3Client"/> has been disposed.
/// </exception>
/// <exception cref="ServiceNotConnectedException">
/// The <see cref="Pop3Client"/> is not connected.
/// </exception>
/// <exception cref="ServiceNotAuthenticatedException">
/// The <see cref="Pop3Client"/> is not authenticated.
/// </exception>
/// <exception cref="System.OperationCanceledException">
/// The operation was canceled via the cancellation token.
/// </exception>
/// <exception cref="System.IO.IOException">
/// An I/O error occurred.
/// </exception>
/// <exception cref="Pop3CommandException">
/// The POP3 command failed.
/// </exception>
/// <exception cref="Pop3ProtocolException">
/// A POP3 protocol error occurred.
/// </exception>
public override Task DeleteMessageAsync (int index, CancellationToken cancellationToken = default (CancellationToken))
{
return DeleteMessageAsync (index, true, cancellationToken);
}
/// <summary>
/// Asynchronously mark the specified messages for deletion.
/// </summary>
/// <remarks>
/// Messages marked for deletion are not actually deleted until the session
/// is cleanly disconnected
/// (see <see cref="Pop3Client.Disconnect(bool, CancellationToken)"/>).
/// </remarks>
/// <returns>An asynchronous task context.</returns>
/// <param name="indexes">The indexes of the messages.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <exception cref="System.ArgumentNullException">
/// <paramref name="indexes"/> is <c>null</c>.
/// </exception>
/// <exception cref="System.ArgumentException">
/// One or more of the <paramref name="indexes"/> are invalid.
/// </exception>
/// <exception cref="System.ObjectDisposedException">
/// The <see cref="Pop3Client"/> has been disposed.
/// </exception>
/// <exception cref="ServiceNotConnectedException">
/// The <see cref="Pop3Client"/> is not connected.
/// </exception>
/// <exception cref="ServiceNotAuthenticatedException">
/// The <see cref="Pop3Client"/> is not authenticated.
/// </exception>
/// <exception cref="System.OperationCanceledException">
/// The operation was canceled via the cancellation token.
/// </exception>
/// <exception cref="System.IO.IOException">
/// An I/O error occurred.
/// </exception>
/// <exception cref="Pop3CommandException">
/// The POP3 command failed.
/// </exception>
/// <exception cref="Pop3ProtocolException">
/// A POP3 protocol error occurred.
/// </exception>
public override Task DeleteMessagesAsync (IList<int> indexes, CancellationToken cancellationToken = default (CancellationToken))
{
return DeleteMessagesAsync (indexes, true, cancellationToken);
}
/// <summary>
/// Asynchronously mark the specified range of messages for deletion.
/// </summary>
/// <remarks>
/// Messages marked for deletion are not actually deleted until the session
/// is cleanly disconnected
/// (see <see cref="Pop3Client.Disconnect(bool, CancellationToken)"/>).
/// </remarks>
/// <example>
/// <code language="c#" source="Examples\Pop3Examples.cs" region="BatchDownloadMessages"/>
/// </example>
/// <returns>An asynchronous task context.</returns>
/// <param name="startIndex">The index of the first message to mark for deletion.</param>
/// <param name="count">The number of messages to mark for deletion.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <exception cref="System.ArgumentOutOfRangeException">
/// <paramref name="startIndex"/> and <paramref name="count"/> do not specify
/// a valid range of messages.
/// </exception>
/// <exception cref="System.ObjectDisposedException">
/// The <see cref="Pop3Client"/> has been disposed.
/// </exception>
/// <exception cref="ServiceNotConnectedException">
/// The <see cref="Pop3Client"/> is not connected.
/// </exception>
/// <exception cref="ServiceNotAuthenticatedException">
/// The <see cref="Pop3Client"/> is not authenticated.
/// </exception>
/// <exception cref="System.OperationCanceledException">
/// The operation was canceled via the cancellation token.
/// </exception>
/// <exception cref="System.IO.IOException">
/// An I/O error occurred.
/// </exception>
/// <exception cref="Pop3CommandException">
/// The POP3 command failed.
/// </exception>
/// <exception cref="Pop3ProtocolException">
/// A POP3 protocol error occurred.
/// </exception>
public override Task DeleteMessagesAsync (int startIndex, int count, CancellationToken cancellationToken = default (CancellationToken))
{
return DeleteMessagesAsync (startIndex, count, true, cancellationToken);
}
/// <summary>
/// Asynchronously mark all messages for deletion.
/// </summary>
/// <remarks>
/// Messages marked for deletion are not actually deleted until the session
/// is cleanly disconnected
/// (see <see cref="Pop3Client.Disconnect(bool, CancellationToken)"/>).
/// </remarks>
/// <returns>An asynchronous task context.</returns>
/// <param name="cancellationToken">The cancellation token.</param>
/// <exception cref="System.ObjectDisposedException">
/// The <see cref="Pop3Client"/> has been disposed.
/// </exception>
/// <exception cref="ServiceNotConnectedException">
/// The <see cref="Pop3Client"/> is not connected.
/// </exception>
/// <exception cref="ServiceNotAuthenticatedException">
/// The <see cref="Pop3Client"/> is not authenticated.
/// </exception>
/// <exception cref="System.OperationCanceledException">
/// The operation was canceled via the cancellation token.
/// </exception>
/// <exception cref="System.IO.IOException">
/// An I/O error occurred.
/// </exception>
/// <exception cref="Pop3CommandException">
/// The POP3 command failed.
/// </exception>
/// <exception cref="Pop3ProtocolException">
/// A POP3 protocol error occurred.
/// </exception>
public override async Task DeleteAllMessagesAsync (CancellationToken cancellationToken = default (CancellationToken))
{
if (total > 0)
await DeleteMessagesAsync (0, total, cancellationToken).ConfigureAwait (false);
}
/// <summary>
/// Asynchronously reset the state of all messages marked for deletion.
/// </summary>
/// <remarks>
/// Messages marked for deletion are not actually deleted until the session
/// is cleanly disconnected
/// (see <see cref="Pop3Client.Disconnect(bool, CancellationToken)"/>).
/// </remarks>
/// <returns>An awaitable task.</returns>
/// <param name="cancellationToken">The cancellation token.</param>
/// <exception cref="System.ObjectDisposedException">
/// The <see cref="Pop3Client"/> has been disposed.
/// </exception>
/// <exception cref="ServiceNotConnectedException">
/// The <see cref="Pop3Client"/> is not connected.
/// </exception>
/// <exception cref="ServiceNotAuthenticatedException">
/// The <see cref="Pop3Client"/> is not authenticated.
/// </exception>
/// <exception cref="System.OperationCanceledException">
/// The operation was canceled via the cancellation token.
/// </exception>
/// <exception cref="System.IO.IOException">
/// An I/O error occurred.
/// </exception>
/// <exception cref="Pop3CommandException">
/// The POP3 command failed.
/// </exception>
/// <exception cref="Pop3ProtocolException">
/// A POP3 protocol error occurred.
/// </exception>
public override Task ResetAsync (CancellationToken cancellationToken = default (CancellationToken))
{
return ResetAsync (true, cancellationToken);
}
}
}