IImap ClientIdentify Method
Identify the client implementation to the server and obtain the server implementation details.
Definition
Namespace: MailKit.Net.Imap
Assembly: MailKit (in MailKit.dll) Version: 5.0.0
The implementation details of the server if available; otherwise, .
Assembly: MailKit (in MailKit.dll) Version: 5.0.0
C#
ImapImplementation Identify(
ImapImplementation clientImplementation,
CancellationToken cancellationToken = default
)Parameters
- clientImplementation ImapImplementation
- The client implementation.
- cancellationToken CancellationToken (Optional)
- The cancellation token.
Return Value
ImapImplementationThe implementation details of the server if available; otherwise, .
Remarks
Passes along the client implementation details to the server while also obtaining implementation details from the server.
If the clientImplementation is or no properties have been set, no identifying information will be sent to the server.
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);
}
}
Exceptions
| ObjectDisposedException | The ImapClient has been disposed. |
| ServiceNotConnectedException | The ImapClient is not connected. |
| NotSupportedException | The IMAP server does not support the ID extension. |
| OperationCanceledException | The operation was canceled via the cancellation token. |
| IOException | An I/O error occurred. |
| ImapCommandException | The server replied to the ID command with a NO or BAD response. |
| ImapProtocolException | An IMAP protocol error occurred. |