Pop3Capabilities Class

The set of capabilities supported by a POP3 server.

Definition

Namespace: MailKit.Net.Pop3
Assembly: MailKit (in MailKit.dll) Version: 5.0.0
C#
public sealed class Pop3Capabilities : IReadOnlyCollection<Pop3Capability>, 
	IEnumerable<Pop3Capability>, IEnumerable
Inheritance
Object    Pop3Capabilities
Implements
IEnumerablePop3Capability, IReadOnlyCollectionPop3Capability, IEnumerable

Remarks

Capabilities are read as part of the response to the CAPA command that is issued during the connection and authentication phases of the Pop3Client.

The capabilities can be accessed in two ways:

  • As a set of well-known Pop3Capability values that MailKit understands and makes use of. This is the recommended way of checking whether the server supports a particular feature (see Contains(Pop3Capability)).
  • As the raw list of capability keywords 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 Pop3Capability value.

  Note

The set of Pop3Capability values is not necessarily identical to what the server advertised. For example, Apop is determined by the server greeting and User is assumed to be supported until the server responds to the CAPA command. Capabilities may also be disabled (see Disable(Pop3Capability)) in order to prevent MailKit from using them, but disabling a capability does not affect the raw list of capability keywords advertised by the server.

Example

C#
                    public static void PrintCapabilities ()
{
    using (var client = new Pop3Client ()) {
        client.Connect ("pop.gmail.com", 995, SecureSocketOptions.SslOnConnect);

        if (client.Capabilities.Contains (Pop3Capability.Sasl)) {
            var mechanisms = string.Join (", ", client.AuthenticationMechanisms);
            Console.WriteLine ("The POP3 server supports the following SASL mechanisms: {0}", mechanisms);
        }

        client.Authenticate ("username", "password");

        if (client.Capabilities.Contains (Pop3Capability.Apop))
            Console.WriteLine ("The server supports APOP authentication.");

        if (client.Capabilities.Contains (Pop3Capability.Expire)) {
            if (client.ExpirePolicy > 0)
                Console.WriteLine ("The POP3 server automatically expires messages after {0} days", client.ExpirePolicy);
            else
                Console.WriteLine ("The POP3 server will never expire messages.");
        }

        if (client.Capabilities.Contains (Pop3Capability.LoginDelay))
            Console.WriteLine ("The minimum number of seconds between login attempts is {0}.", client.LoginDelay);

        if (client.Capabilities.Contains (Pop3Capability.Pipelining))
            Console.WriteLine ("The POP3 server can pipeline commands, so using client.GetMessages() will be faster.");

        if (client.Capabilities.Contains (Pop3Capability.Top))
            Console.WriteLine ("The POP3 server supports the TOP command, so it's possible to download message headers.");

        if (client.Capabilities.Contains (Pop3Capability.UIDL))
            Console.WriteLine ("The POP3 server supports the UIDL command which means we can track messages by UID.");

        client.Disconnect (true);
    }
}
                  

Constructors

Pop3Capabilities Initialize a new instance of the Pop3Capabilities class.

Properties

Count Get the number of well-known capabilities in the set.
Names Get the raw capability keywords advertised by the server.

Methods

Contains(Pop3Capability) Check whether the set contains the specified well-known capability.
Contains(String) Check whether the server advertised the specified capability keyword.
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 keyword.
ToString Get a string representation of the well-known capabilities in the set.
(Overrides ObjectToString)

See Also