// // IMailSpool.cs // // Author: Jeffrey Stedfast // // 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.IO; using System.Threading; using System.Threading.Tasks; using System.Collections.Generic; using MimeKit; namespace MailKit { /// /// An interface for retreiving messages from a spool. /// /// /// An interface for retreiving messages from a spool. /// public interface IMailSpool : IMailService, IEnumerable { /// /// Get the number of messages available in the message spool. /// /// /// Gets the number of messages available in the message spool. /// Once authenticated, the property will be set /// to the number of available messages in the spool. /// /// The message count. int Count { get; } /// /// Get whether or not the service supports referencing messages by UIDs. /// /// /// Not all servers support referencing messages by UID, so this property should /// be checked before using /// and . /// If the server does not support UIDs, then all methods that take UID arguments /// along with and /// will fail. /// /// true if supports uids; otherwise, false. bool SupportsUids { get; } /// /// Get the message count. /// /// /// Gets the message count. /// /// The message count. /// The cancellation token. int GetMessageCount (CancellationToken cancellationToken = default (CancellationToken)); /// /// Get the UID of the message at the specified index. /// /// /// Not all servers support UIDs, so you should first check /// the property. /// /// The message UID. /// The message index. /// The cancellation token. string GetMessageUid (int index, CancellationToken cancellationToken = default (CancellationToken)); /// /// Asynchronously get the UID of the message at the specified index. /// /// /// Not all servers support UIDs, so you should first check /// the property. /// /// The message UID. /// The message index. /// The cancellation token. Task GetMessageUidAsync (int index, CancellationToken cancellationToken = default (CancellationToken)); /// /// Get the full list of available message UIDs. /// /// /// Not all servers support UIDs, so you should first check /// the property. /// /// The message UIDs. /// The cancellation token. IList GetMessageUids (CancellationToken cancellationToken = default (CancellationToken)); /// /// Asynchronously get the full list of available message UIDs. /// /// /// Not all servers support UIDs, so you should first check /// the property. /// /// The message UIDs. /// The cancellation token. Task> GetMessageUidsAsync (CancellationToken cancellationToken = default (CancellationToken)); /// /// Get the size of the specified message, in bytes. /// /// /// Gets the size of the specified message, in bytes. /// /// The message size, in bytes. /// The index of the message. /// The cancellation token. int GetMessageSize (int index, CancellationToken cancellationToken = default (CancellationToken)); /// /// Asynchronously get the size of the specified message, in bytes. /// /// /// Asynchronously gets the size of the specified message, in bytes. /// /// The message size, in bytes. /// The index of the message. /// The cancellation token. Task GetMessageSizeAsync (int index, CancellationToken cancellationToken = default (CancellationToken)); /// /// Get the sizes for all available messages, in bytes. /// /// /// Gets the sizes for all available messages, in bytes. /// /// The message sizes, in bytes. /// The cancellation token. IList GetMessageSizes (CancellationToken cancellationToken = default (CancellationToken)); /// /// Asynchronously get the sizes for all available messages, in bytes. /// /// /// Asynchronously gets the sizes for all available messages, in bytes. /// /// The message sizes, in bytes. /// The cancellation token. Task> GetMessageSizesAsync (CancellationToken cancellationToken = default (CancellationToken)); /// /// Get the headers for the specified message. /// /// /// Gets the headers for the specified message. /// /// The message headers. /// The index of the message. /// The cancellation token. HeaderList GetMessageHeaders (int index, CancellationToken cancellationToken = default (CancellationToken)); /// /// Asynchronously get the headers for the specified message. /// /// /// Asynchronously gets the headers for the specified message. /// /// The message headers. /// The index of the message. /// The cancellation token. Task GetMessageHeadersAsync (int index, CancellationToken cancellationToken = default (CancellationToken)); /// /// Get the headers for the specified messages. /// /// /// Gets the headers for the specified messages. /// /// The headers for the specified messages. /// The indexes of the messages. /// The cancellation token. IList GetMessageHeaders (IList indexes, CancellationToken cancellationToken = default (CancellationToken)); /// /// Asynchronously get the headers for the specified messages. /// /// /// Asynchronously gets the headers for the specified messages. /// /// The headers for the specified messages. /// The indexes of the messages. /// The cancellation token. Task> GetMessageHeadersAsync (IList indexes, CancellationToken cancellationToken = default (CancellationToken)); /// /// Get the headers of the messages within the specified range. /// /// /// Gets the headers of the messages within the specified range. /// /// The headers of the messages within the specified range. /// The index of the first message to get. /// The number of messages to get. /// The cancellation token. IList GetMessageHeaders (int startIndex, int count, CancellationToken cancellationToken = default (CancellationToken)); /// /// Get the headers of the messages within the specified range. /// /// /// Gets the headers of the messages within the specified range. /// /// The headers of the messages within the specified range. /// The index of the first message to get. /// The number of messages to get. /// The cancellation token. Task> GetMessageHeadersAsync (int startIndex, int count, CancellationToken cancellationToken = default (CancellationToken)); /// /// Get the message at the specified index. /// /// /// Gets the message at the specified index. /// /// The message. /// The index of the message. /// The cancellation token. /// The progress reporting mechanism. MimeMessage GetMessage (int index, CancellationToken cancellationToken = default (CancellationToken), ITransferProgress progress = null); /// /// Asynchronously get the message at the specified index. /// /// /// Asynchronously gets the message at the specified index. /// /// The message. /// The index of the message. /// The cancellation token. /// The progress reporting mechanism. Task GetMessageAsync (int index, CancellationToken cancellationToken = default (CancellationToken), ITransferProgress progress = null); /// /// Get the messages at the specified indexes. /// /// /// Gets the messages at the specified indexes. /// /// The messages. /// The indexes of the messages. /// The cancellation token. /// The progress reporting mechanism. IList GetMessages (IList indexes, CancellationToken cancellationToken = default (CancellationToken), ITransferProgress progress = null); /// /// Asynchronously get the messages at the specified indexes. /// /// /// Asynchronously gets the messages at the specified indexes. /// /// The messages. /// The indexes of the messages. /// The cancellation token. /// The progress reporting mechanism. Task> GetMessagesAsync (IList indexes, CancellationToken cancellationToken = default (CancellationToken), ITransferProgress progress = null); /// /// Get the messages within the specified range. /// /// /// Gets the messages within the specified range. /// /// The messages. /// The index of the first message to get. /// The number of messages to get. /// The cancellation token. /// The progress reporting mechanism. IList GetMessages (int startIndex, int count, CancellationToken cancellationToken = default (CancellationToken), ITransferProgress progress = null); /// /// Asynchronously get the messages within the specified range. /// /// /// Asynchronously gets the messages within the specified range. /// /// The messages. /// The index of the first message to get. /// The number of messages to get. /// The cancellation token. /// The progress reporting mechanism. Task> GetMessagesAsync (int startIndex, int count, CancellationToken cancellationToken = default (CancellationToken), ITransferProgress progress = null); /// /// Get the message or header stream at the specified index. /// /// /// Gets the message or header stream at the specified index. /// /// The message or header stream. /// The index of the message. /// true if only the headers should be retrieved; otherwise, false. /// The cancellation token. /// The progress reporting mechanism. Stream GetStream (int index, bool headersOnly = false, CancellationToken cancellationToken = default (CancellationToken), ITransferProgress progress = null); /// /// Asynchronously get the message or header stream at the specified index. /// /// /// Asynchronously gets the message or header stream at the specified index. /// /// The message or header stream. /// The index of the message. /// true if only the headers should be retrieved; otherwise, false. /// The cancellation token. /// The progress reporting mechanism. Task GetStreamAsync (int index, bool headersOnly = false, CancellationToken cancellationToken = default (CancellationToken), ITransferProgress progress = null); /// /// Get the message or header streams at the specified index. /// /// /// Gets the message or header streams at the specified index. /// /// The message or header streams. /// The indexes of the messages. /// true if only the headers should be retrieved; otherwise, false. /// The cancellation token. /// The progress reporting mechanism. IList GetStreams (IList indexes, bool headersOnly = false, CancellationToken cancellationToken = default (CancellationToken), ITransferProgress progress = null); /// /// Asynchronously get the message or header streams at the specified indexes. /// /// /// Asynchronously gets the message or header streams at the specified indexes. /// /// The message or header streams. /// The indexes of the messages. /// true if only the headers should be retrieved; otherwise, false. /// The cancellation token. /// The progress reporting mechanism. Task> GetStreamsAsync (IList indexes, bool headersOnly = false, CancellationToken cancellationToken = default (CancellationToken), ITransferProgress progress = null); /// /// Get the message or header streams within the specified range. /// /// /// Gets the message or header streams within the specified range. /// /// The message or header streams. /// The index of the first stream to get. /// The number of streams to get. /// true if only the headers should be retrieved; otherwise, false. /// The cancellation token. /// The progress reporting mechanism. IList GetStreams (int startIndex, int count, bool headersOnly = false, CancellationToken cancellationToken = default (CancellationToken), ITransferProgress progress = null); /// /// Asynchronously get the message or header streams within the specified range. /// /// /// Asynchronously gets the message or header streams within the specified range. /// /// The messages. /// The index of the first stream to get. /// The number of streams to get. /// true if only the headers should be retrieved; otherwise, false. /// The cancellation token. /// The progress reporting mechanism. Task> GetStreamsAsync (int startIndex, int count, bool headersOnly = false, CancellationToken cancellationToken = default (CancellationToken), ITransferProgress progress = null); /// /// Mark the specified message for deletion. /// /// /// Messages marked for deletion are not actually deleted until the session /// is cleanly disconnected /// (see ). /// /// The index of the message. /// The cancellation token. void DeleteMessage (int index, CancellationToken cancellationToken = default (CancellationToken)); /// /// Asynchronously mark the specified message for deletion. /// /// /// Messages marked for deletion are not actually deleted until the session /// is cleanly disconnected /// (see ). /// /// An asynchronous task context. /// The index of the message. /// The cancellation token. Task DeleteMessageAsync (int index, CancellationToken cancellationToken = default (CancellationToken)); /// /// Mark the specified messages for deletion. /// /// /// Messages marked for deletion are not actually deleted until the session /// is cleanly disconnected /// (see ). /// /// The indexes of the messages. /// The cancellation token. void DeleteMessages (IList indexes, CancellationToken cancellationToken = default (CancellationToken)); /// /// Asynchronously mark the specified messages for deletion. /// /// /// Messages marked for deletion are not actually deleted until the session /// is cleanly disconnected /// (see ). /// /// An asynchronous task context. /// The indexes of the messages. /// The cancellation token. Task DeleteMessagesAsync (IList indexes, CancellationToken cancellationToken = default (CancellationToken)); /// /// Mark the specified range of messages for deletion. /// /// /// Messages marked for deletion are not actually deleted until the session /// is cleanly disconnected /// (see ). /// /// The index of the first message to mark for deletion. /// The number of messages to mark for deletion. /// The cancellation token. void DeleteMessages (int startIndex, int count, CancellationToken cancellationToken = default (CancellationToken)); /// /// Asynchronously mark the specified range of messages for deletion. /// /// /// Messages marked for deletion are not actually deleted until the session /// is cleanly disconnected /// (see ). /// /// An asynchronous task context. /// The index of the first message to mark for deletion. /// The number of messages to mark for deletion. /// The cancellation token. Task DeleteMessagesAsync (int startIndex, int count, CancellationToken cancellationToken = default (CancellationToken)); /// /// Mark all messages for deletion. /// /// /// Messages marked for deletion are not actually deleted until the session /// is cleanly disconnected /// (see ). /// /// The cancellation token. void DeleteAllMessages (CancellationToken cancellationToken = default (CancellationToken)); /// /// Asynchronously mark all messages for deletion. /// /// /// Messages marked for deletion are not actually deleted until the session /// is cleanly disconnected /// (see ). /// /// An asynchronous task context. /// The cancellation token. Task DeleteAllMessagesAsync (CancellationToken cancellationToken = default (CancellationToken)); /// /// Reset the state of all messages marked for deletion. /// /// /// Messages marked for deletion are not actually deleted until the session /// is cleanly disconnected /// (see ). /// /// The cancellation token. void Reset (CancellationToken cancellationToken = default (CancellationToken)); /// /// Asynchronously reset the state of all messages marked for deletion. /// /// /// Messages marked for deletion are not actually deleted until the session /// is cleanly disconnected /// (see ). /// /// An asynchronous task context. /// The cancellation token. Task ResetAsync (CancellationToken cancellationToken = default (CancellationToken)); } }