Imap Capabilities Class
The set of capabilities supported by an IMAP server.
Definition
Namespace: MailKit.Net.Imap
Assembly: MailKit (in MailKit.dll) Version: 5.0.0
Assembly: MailKit (in MailKit.dll) Version: 5.0.0
C#
public sealed class ImapCapabilities : IReadOnlyCollection<ImapCapability>,
IEnumerable<ImapCapability>, IEnumerable- Inheritance
- Object ImapCapabilities
Remarks
Capabilities are read as part of the response to the CAPABILITY command that is issued during the connection and authentication phases of the ImapClient.
The capabilities can be accessed in two ways:
- As a set of well-known ImapCapability values that MailKit understands and makes use of. This is the recommended way of checking whether the server supports a particular feature (see Contains(ImapCapability)).
- As the raw list of capability atoms that the server advertised, including any that MailKit does not know about (see Names, Contains(String) and GetValues(String)). This is useful for checking support for extensions that do not (yet) have a corresponding ImapCapability value.
Example
C#
public static void Capabilities ()
{
using (var client = new ImapClient ()) {
client.Connect ("imap.gmail.com", 993, SecureSocketOptions.SslOnConnect);
var mechanisms = string.Join (", ", client.AuthenticationMechanisms);
Console.WriteLine ("The IMAP server supports the following SASL authentication mechanisms: {0}", mechanisms);
client.Authenticate ("username", "password");
if (client.Capabilities.Contains (ImapCapability.Id)) {
var clientImplementation = new ImapImplementation { Name = "MailKit", Version = "1.0" };
var serverImplementation = client.Identify (clientImplementation);
Console.WriteLine ("Server implementation details:");
foreach (var property in serverImplementation.Properties)
Console.WriteLine (" {0} = {1}", property.Key, property.Value);
}
if (client.Capabilities.Contains (ImapCapability.Acl)) {
Console.WriteLine ("The IMAP server supports Access Control Lists.");
Console.WriteLine ("The IMAP server supports the following access rights: {0}", client.Rights);
Console.WriteLine ("The Inbox has the following access controls:");
var acl = client.Inbox.GetAccessControlList ();
foreach (var ac in acl)
Console.WriteLine (" {0} = {1}", ac.Name, ac.Rights);
var myRights = client.Inbox.GetMyAccessRights ();
Console.WriteLine ("Your current rights for the Inbox folder are: {0}", myRights);
}
if (client.Capabilities.Contains (ImapCapability.Quota)) {
Console.WriteLine ("The IMAP server supports quotas.");
Console.WriteLine ("The current quota for the Inbox is:");
var quota = client.Inbox.GetQuota ();
if (quota.StorageLimit.HasValue)
Console.WriteLine (" Limited by storage space. Using {0} out of {1} kilobytes.", quota.CurrentStorageSize.Value, quota.StorageLimit.Value);
if (quota.MessageLimit.HasValue)
Console.WriteLine (" Limited by the number of messages. Using {0} out of {1} messages.", quota.CurrentMessageCount.Value, quota.MessageLimit.Value);
Console.WriteLine ("The quota root is: {0}", quota.QuotaRoot);
}
if (client.Capabilities.Contains (ImapCapability.Thread)) {
if (client.ThreadingAlgorithms.Contains (ThreadingAlgorithm.OrderedSubject))
Console.WriteLine ("The IMAP server supports threading by subject.");
if (client.ThreadingAlgorithms.Contains (ThreadingAlgorithm.References))
Console.WriteLine ("The IMAP server supports threading by references.");
}
client.Disconnect (true);
}
}
Constructors
| ImapCapabilities | Initialize a new instance of the ImapCapabilities class. |
Properties
| Count | Get the number of well-known capabilities in the set. |
| Names | Get the raw capability atoms advertised by the server. |
Methods
| Contains(ImapCapability) | Check whether the set contains the specified well-known capability. |
| Contains(String) | Check whether the server advertised the specified capability atom. |
| Disable | Disable the specified well-known capability. |
| Equals | Determines whether the specified object is equal to the current object. (Inherited from Object) |
| GetEnumerator | Get an enumerator for the well-known capabilities in the set. |
| GetHashCode | Serves as the default hash function. (Inherited from Object) |
| GetType | Gets the Type of the current instance. (Inherited from Object) |
| GetValues | Get the values advertised for the specified capability atom. |
| ToString |
Get a string representation of the well-known capabilities in the set.
(Overrides ObjectToString) |