Hunny Software Library Reference

Imap4Client Class

Class that represents an IMAP4 client connection.

For a list of all members of this type, see Imap4Client Members.

System.Object
   Imap4Client

[Visual Basic]
Public Class Imap4Client
Implements IDisposable
[C#]
public class Imap4Client : IDisposable

Remarks

Imap4Client is a class that represents an IMAP4 client connection.

The IMAP4 client commands are described in the IMAP4rev1 specification, RFC 3501. All commands have straightforward translations into methods in the Imap4Client class. RFC 3501 also details the possible server responses. All server responses have straightforward translations into subclasses of Response. Brief descriptions of some of the client commands are included in this documentation. However, RFC 3501 is authorative on the IMAP4rev1 protocol, so it's a very good idea to refer to it frequently.

To use the Imap4Client class, first create an instance of the class. Then call the Connect method to connect to the IMAP4 server. After you have connected, you may invoke client commands on the IMAP4 server by calling the corresponding methods of Imap4Client. After each command, you must process the responses received from the IMAP4 server. When you are finished invoking commands, call Logout to log out from the session, followed by Disconnect to close the connection to the server.

After invoking a client command, you must process the server's responses, which are collected by the Imap4Client instance. The client command methods are synchronous, which means that when you call one of the methods, it does not return until it has received a success or failure response from the IMAP4 server. An IMAP4 server can send any number of responses following a client command. To see how many responses were received, get the value of the NumResponses property. Once you know how many responses there are, you may call ResponseAt to iterate through them or to access them randomly. The collection of responses is cleared at the beginning of each client command.

When you invoke an IMAP4 client command, you must be prepared to handle errors. If a network error occurs, the library throws an instance of Hunny.Mail.Exception. Your program should be prepared to catch these exceptions. In addition to network errors, your code should be prepared to handle IMAP4 server errors. After you invoke a client command, you should check the responses from the server. A tagged OK response from the server indicates no error. A tagged NO or BAD response indicates an error. You may get more information about the error from the response code or response text. (See NoResponse or BadResponse.) You may call the convenience method CommandStatus to check if the command succeeded or failed.

As with any network protocol, it is possible for a connection to stop responding. This could happen, for example, if a network element were to stop functioning or if the server stopped responding. To recover from this situation, the Imap4Client class provides a Cancel method. You can call Cancel safely from another thread to terminate the network connection and unblock the thread that is blocked on a client command execution. After you call Cancel, all client command methods return an error, which is the normal behavior when there is no connection to an IMAP4 server. To continue with the recovery, you must call Connect again to re-establish the connection to the server.

Requirements

Namespace: Hunny.Mail

Assembly: Hunny.Mail (in Hunny.Mail.dll)

See Also

Imap4Client Members | Hunny.Mail Namespace | RFC 3501: Internet Message Access Protocol - Version 4rev1