S22.Imap Defines supported means of authenticating with an IMAP server. Automatically selects the most-secure authentication mechanism supported by the server. Login using plaintext password authentication; This is supported by most servers. Login using the SASL PLAIN authentication mechanism. Login using the CRAM-MD5 authentication mechanism. Login using the DIGEST-MD5 authentication mechanism. Login using OAuth via the SASL XOAuth mechanism. Login using OAuth 2.0 via the SASL XOAUTH2 mechanism. Login using the NTLM authentication mechanism. Login using the NTLMv2 authentication mechanism. Login using the NTLM/NTLMv2 authentication mechanism via Microsoft's Security Support Provider Interface (SSPI). Login using Kerberos authentication via the SASL GSSAPI mechanism. Login using the SCRAM-SHA-1 authentication mechanism. Login using the Secure Remote Password (SRP) authentication mechanism. The SRP mechanism is only available when targeting .NET 4.0 or newer. A utility class modeled after the BCL StringBuilder to simplify building binary-data messages. The actual byte buffer. The current position in the buffer. Resizes the internal byte buffer. Amount in bytes by which to increase the size of the buffer. Appends one or several byte values to this instance. Byte values to append. A reference to the calling instance. Appends the specified number of bytes from the specified buffer starting at the specified offset to this instance. The buffer to append bytes from. The offset into the buffert at which to start reading bytes from. The number of bytes to read from the buffer. A reference to the calling instance. Appends the specified 32-bit integer value to this instance. A 32-bit integer value to append. Set this to true, to append the value as big-endian. A reference to the calling instance. Appends the specified 16-bit short value to this instance. A 16-bit short value to append. Set this to true, to append the value as big-endian. A reference to the calling instance. Appends the specified 16-bit unsigend short value to this instance. A 16-bit unsigend short value to append. Set this to true, to append the value as big-endian. A reference to the calling instance. Appends the specified 32-bit unsigned integer value to this instance. A 32-bit unsigned integer value to append. Set this to true, to append the value as big-endian. A reference to the calling instance. Appends the specified 64-bit integer value to this instance. A 64-bit integer value to append. Set this to true, to append the value as big-endian. A reference to the calling instance. Appends the specified string using the specified encoding to this instance. The string vale to append. The encoding to use for decoding the string value into a sequence of bytes. If this is null, ASCII encoding is used as a default. A reference to the calling instance. Returns the ByteBuilder's content as an array of bytes. An array of bytes. Removes all bytes from the current ByteBuilder instance. The length of the underlying data buffer. A filter stream sitting between Negotiate- and NetworkStream to enable managed NTLM/GSSAPI authentication. We use a filter for hooking into the NegotiateStream protocol rather than p/invoking SSPI directly as that would require unmanaged code privileges (internally NegotiateStream uses an SSPI wrapper). NegotiateStream - FilterStream - NetworkStream. A buffer for accumulating handshake data until an entire handshake has been read. A buffer for accumulating the payload data following the handshake data. The latest handshake header sent by the client. The buffer from which client reads will be satisfied. The number of bytes the client has already consumed/read from the receivedData buffer. The current state of the filter stream. Determines whether this instance should close the inner stream when disposed. An error code as specified by the NegotiateStream protocol which is handed to the NegotiateStream instance in case authentication unexpectedly fails. Gets the stream used by this FilterStream for sending and receiving data. Initializes a new instance of the FilterStream class using the specified Stream. A Stream object used by the FilterStream for sending and receiving data. Set to true to indicate that closing this FilterStream has no effect on innerstream, or set to false to indicate that closing this FilterStream also closes innerStream. Reads data from this stream and stores it in the specified array. A byte array that receives the bytes read from the stream. The zero-based index into the buffer at which to begin storing the data read from this stream. The the maximum number of bytes to read from the stream. The the number of bytes read from the underlying stream. When there is no more data to be read, returns 0. The read operation failed. Reads the server response from the underlying inner stream. Write the specified number of bytes to the underlying stream using the specified buffer and offset. A byte array that supplies the bytes written to the stream. The zero-based index in the buffer at which to begin reading bytes to be written to the stream. The number of bytes to read from buffer. The write operation failed. Reads the client's handshake from the specified buffer. A byte array from which the handshake data will be read. The zero-based index in the buffer at which to begin reading bytes. The number of bytes to read from buffer. True if the handshake has been read completely, otherwise false. Reads the payload from the specified buffer. A byte array from which the payload data will be read. The zero-based index in the buffer at which to begin reading bytes. The number of bytes to read from buffer. True if all of the payload data has been read, otherwise false. Sends the accumulated payload data to the server. true if the client is done sending data, otherwise false. Reads a line of ASCII-encoded text terminated by a CRLF from the specified stream. The stream to read the line of text from. Set this to true, to resolve automatically resolve possible literals. A line of ASII-encoded text read from the specified stream. "Literals" are a special feature of IMAP, employed by some server implementations. Please refer to RFC 3501 Section 4.3 for details. Reads the specified number of bytes from the specified stream and returns them as an ASCII-encoded string. The stream to read from. The number of bytes to read. The read bytes encoded as an ASCII string. Causes any buffered data to be written to the underlying device. Throws NotSupportedException. This value is ignored. This value is ignored. Always throws a NotSupportedException. Sets the length of the underlying stream. A value that specifies the length of the stream. Releases all resources used by the stream. True to release both managed and unmanaged resources, false to release only unmanaged resources. Gets a boolean value that indicates whether the underlying stream is readable. Gets a boolean value that indicates whether the underlying stream is seekable. Gets a boolean value that indicates whether the underlying stream supports time-outs. Gets a boolean value that indicates whether the underlying stream is writable. Gets the length of the underlying stream. Gets or sets the current position in the underlying stream. Setting this property is not supported. The different states the FilterStream can be in. The stream is reading the client's handshake message. The stream is reading the client's payload data. The stream is waiting for the server's response. The stream has buffered the server's response and is satisfying client reads from its buffer. Represents a NegotiateStream handshake message. This is the only permissible value according to specification. This is the only permissible value according to specification. Creates a new instance of the Handshake class using the specified type and payload size. The type of handshake. The size, in bytes, of the payload following the handshake header. Private default constructor for deserializing. Deserializes a handshake instance from the specified byte array. An array of bytes containing handshake data. An initialized instance of the Handshake class deserialized from the specified byte array. Thrown if the specified byte array does not contain valid handshake data. Serializes an instance of the Handshake class to a sequence of bytes. A sequence of bytes representing this Handshake instance. The type of the handshake message. Specifies the major version of the NegotiateStream protocol being used. Specifies the minor version of the NegotiateStream protocol being used. Defines the size, in bytes, of the AuthPayload field, which immediately follows the handshake. Describes the different types of handshake messages. The handshake has completed successfully. An error occurred during the handshake. The AuthPayload field contains an HRESULT. The message is part of the handshake phase and is not the final message from the host. The final Handshake message from a host is always transferred in a HandshakeDone message. Implements the Sasl SCRAM-SHA-1 authentication method as described in RFC 5802. The abstract base class from which all classes implementing a Sasl authentication mechanism must derive. Computes the client response to a challenge sent by the server. The client response to the specified challenge. Retrieves the base64-encoded client response for the specified base64-encoded challenge sent by the server. A base64-encoded string representing a challenge sent by the server. A base64-encoded string representing the client response to the server challenge. The IMAP, POP3 and SMTP authentication commands expect challenges and responses to be base64-encoded. This method automatically decodes the server challenge before passing it to the Sasl implementation and encodes the client response to a base64-string before returning it to the caller. Thrown if the client response could not be retrieved. Refer to the inner exception for error details. Retrieves the client response for the specified server challenge. A byte array containing the challenge sent by the server. An array of bytes representing the client response to the server challenge. IANA name of the authentication mechanism. True if the authentication exchange between client and server has been completed. A map of mechanism-specific properties which are needed by the authentication mechanism to compute it's challenge-responses. The client nonce value used during authentication. Scram-Sha-1 involves several steps. The salted password. This is needed for client authentication and later on again for verifying the server signature. The auth message is part of the authentication exchange and is needed for authentication as well as for verifying the server signature. Private constructor for use with Sasl.SaslFactory. Internal constructor used for unit testing. The username to authenticate with. The plaintext password to authenticate with. The client nonce value to use. Thrown if the username or the password parameter is null. Thrown if the username parameter is empty. Creates and initializes a new instance of the SaslScramSha1 class using the specified username and password. The username to authenticate with. The plaintext password to authenticate with. Thrown if the username or the password parameter is null. Thrown if the username parameter is empty. Computes the client response to the specified SCRAM-SHA-1 challenge. The challenge sent by the server The response to the SCRAM-SHA-1 challenge. Thrown if the response could not be computed. Computes the initial response sent by the client to the server. An array of bytes containing the initial client response. Computes the "client-final-message" which completes the authentication process. The "server-first-message" challenge received from the server in response to the initial client response. An array of bytes containing the client's challenge response. Verifies the nonce value sent by the server. The nonce value sent by the server as part of the server-first-message. True if the nonce value is valid, otherwise false. Verifies the server signature which is sent by the server as the final step of the authentication process. The server signature as a base64-encoded string. The client's response to the server. This will be an empty byte array if verification was successful, or the '*' SASL cancellation token. Parses the "server-first-message" received from the server. The challenge received from the server. A collection of key/value pairs contained extracted from the server message. Thrown if the message parameter is null. Computes the "Hi()"-formula which is part of the client's response to the server challenge. The supplied password to use. The salt received from the server. The iteration count. An array of bytes containing the result of the computation of the "Hi()"-formula. Hi is, essentially, PBKDF2 with HMAC as the pseudorandom function (PRF) and with dkLen == output length of HMAC() == output length of H(). (Refer to RFC 5802, p.6) Applies the HMAC keyed hash algorithm using the specified key to the specified input data. The key to use for initializing the HMAC provider. The input to compute the hashcode for. The hashcode of the specified data input. Applies the HMAC keyed hash algorithm using the specified key to the specified input string. The key to use for initializing the HMAC provider. The input string to compute the hashcode for. The hashcode of the specified string. Applies the cryptographic hash function SHA-1 to the specified data array. The data array to apply the hash function to. The hash value for the specified byte array. Applies the exclusive-or operation to combine the specified byte array a with the specified byte array b. The first byte array. The second byte array. An array of bytes of the same length as the input arrays containing the result of the exclusive-or operation. Thrown if either argument is null. Thrown if the input arrays are not of the same length. Generates a random cnonce-value which is a "client-specified data string which must be different each time a digest-response is sent". A random "cnonce-value" string. Prepares the specified string as is described in RFC 5802. A string value. A "Saslprepped" string. True if the authentication exchange between client and server has been completed. The IANA name for the Scram-Sha-1 authentication mechanism as described in RFC 5802. The username to authenticate with. The password to authenticate with. Implements the Sasl Secure Remote Password (SRP) authentication mechanism as is described in the IETF SRP 08 draft. This requires .NET Framework 4 because it makes use of the System.Numeric namespace which has only been part of .NET since version 4. Some notes: - Don't bother with the example given in the IETF 08 draft document (7.5 Example); It is broken. - Integrity and confidentiality protection is not implemented. In fact, the "mandatory"-option is not supported at all. SRP involves several steps. The negotiated hash algorithm which will be used to perform any message digest calculations. The public key computed as part of the authentication exchange. The client's private key used for calculating the client evidence. The secret key shared between client and server. The client evidence calculated as part of the authentication exchange. The options chosen by the client, picked from the list of options advertised by the server. Private constructor for use with Sasl.SaslFactory. Internal constructor used for unit testing. The username to authenticate with. The plaintext password to authenticate with. The client private key to use. Thrown if the username or the password parameter is null. Thrown if the username parameter is empty. Creates and initializes a new instance of the SaslSrp class using the specified username and password. The username to authenticate with. The plaintext password to authenticate with. Thrown if the username or the password parameter is null. Thrown if the username parameter is empty. Computes the client response to the specified SRP challenge. The challenge sent by the server The response to the SRP challenge. Thrown if the response could not be computed. Computes the initial response sent by the client to the server. An array of bytes containing the initial client response. Computes the client response containing the client's public key and evidence. The challenge containing the protocol elements received from the server in response to the initial client response. An array of bytes containing the client's challenge response. Thrown if the server specified any mandatory options which are not supported. Verifies the server signature which is sent by the server as the final step of the authentication process. The server signature as a base64-encoded string. The client's response to the server. This will be an empty byte array if verification was successful, or the '*' SASL cancellation token. Selects a message digest algorithm from the specified list of supported algorithms. A tuple containing the name of the selected message digest algorithm as well as the type. Thrown if none of the algorithms specified in the list parameter is supported. True if the authentication exchange between client and server has been completed. The IANA name for the SRP authentication mechanism. The username to authenticate with. The password to authenticate with. The authorization id (userid in draft jargon). Represents the initial client-response sent to the server to initiate the authentication exchange. Creates a new instance of the ClientMessage1 class using the specified username. The username to authenticate with. The authorization id to authenticate with. Thrown if the username parameter is null. Serializes this instance of the ClientMessage1 class into a sequence of bytes according to the requirements of the SRP specification. A sequence of bytes representing this instance of the ClientMessage1 class. Thrown if the cummultative length of the serialized data fields exceeds the maximum number of bytes allowed as per SRP specification. SRP specification imposes a limit of 2,147,483,643 bytes on the serialized data. The username to authenticate with. SRP specification imposes a limit of 65535 bytes on this field. The authorization identity to authenticate with. SRP specification imposes a limit of 65535 bytes on this field. The session identifier of a previous session whose parameters the client wishes to re-use. SRP specification imposes a limit of 65535 bytes on this field. If the client wishes to initialize a new session, this parameter must be set to the empty string. The client's nonce used in deriving a new shared context key from the shared context key of the previous session. SRP specification imposes a limit of 255 bytes on this field. If not needed, it must be set to an empty byte array. Represents the second client-response sent to the server as part of the SRP authentication exchange. Creates and initializes a new instance of the ClientMessage2 class. Creates and initializes a new instance of the ClientMessage2 class using the specified public key and client proof. The client's public key. The calculated client proof. Thrown if either the public key or the proof parameter is null. Serializes this instance of the ClientMessage2 class into a sequence of bytes according to the requirements of the SRP specification. A sequence of bytes representing this instance of the ClientMessage2 class. Thrown if the cummultative length of the serialized data fields exceeds the maximum number of bytes allowed as per SRP specification. SRP specification imposes a limit of 2,147,483,643 bytes on the serialized data. Serializes the client's options collection into a comma-seperated options string. A comma-seperated string containing the client's chosen options. The client's ephemeral public key. The evidence which proves to the server client-knowledge of the shared context key. The options list indicating the security services chosen by the client. The initial vector the server will use to set up its encryption context, if confidentiality protection will be employed. Adds extension methods to the BinaryReader class to simplify the deserialization of SRP messages. Reads an unsigned integer value from the underlying stream, optionally using big endian byte ordering. Extension method for BinaryReader. Set to true to interpret the integer value as big endian value. The 32-byte unsigned integer value read from the underlying stream. Reads an unsigned short value from the underlying stream, optionally using big endian byte ordering. Extension method for BinaryReader. Set to true to interpret the short value as big endian value. The 16-byte unsigned short value read from the underlying stream. Reads a "multi-precision integer" from this instance. Extension method for the BinaryReader class. An instance of the Mpi class decoded from the bytes read from the underlying stream. Reads an "octet-sequence" from this instance. Extension method for the BinaryReader class. An instance of the OctetSequence class decoded from the bytes read from the underlying stream. Reads an UTF-8 string from this instance. Extension method for the BinaryReader class. An instance of the Utf8String class decoded from the bytes read from the underlying stream. Contains helper methods for calculating the various components of the SRP authentication exchange. The trace source used for informational and debug messages. Determines whether the specified modulus is valid. The modulus to validate. True if the specified modulus is valid, otherwise false. Determines whether the specified generator is valid. The generator to validate. True if the specified generator is valid, otherwise false. Generates a random "multi-precision integer" which will act as the client's private key. The client's ephemeral private key as a "multi-precision integer". Calculates the client's ephemeral public key. The generator sent by the server. The safe prime modulus sent by the server. The client's private key. The client's ephemeral public key as a "multi-precision integer". A = Client Public Key g = Generator a = Client Private Key N = Safe Prime Modulus Calculates the shared context key K from the given parameters. The user's password salt. The username to authenticate with. The password to authenticate with. The client's ephemeral public key. The server's ephemeral public key. The client's private key. The generator sent by the server. The safe prime modulus sent by the server. The negotiated hash algorithm to use for the calculations. The shared context key K as a "multi-precision integer". A = Client Public Key B = Server Public Key N = Safe Prime Modulus U = Username p = Password s = User's Password Salt a = Client Private Key g = Generator K = Shared Public Key Computes the client evidence from the given parameters. The safe prime modulus sent by the server. The generator sent by the server. The username to authenticate with. The client's password salt. The client's ephemeral public key. The server's ephemeral public key. The shared context key. The authorization identity. The raw options string as received from the server. The message digest algorithm to use for calculating the client proof. The client proof as an array of bytes. Computes the server evidence from the given parameters. The client's ephemeral public key. The shared context key. The authorization identity. The raw options string as sent by the client. The session id sent by the server. The time-to-live value for the session id sent by the server. The message digest algorithm to use for calculating the server proof. The server proof as an array of bytes. Applies the exclusive-or operation to combine the specified byte array a with the specified byte array b. The first byte array. The second byte array. An array of bytes of the same length as the input arrays containing the result of the exclusive-or operation. Thrown if either argument is null. Thrown if the input arrays are not of the same length. Recommended values for the safe prime modulus (Refer to Appendix A. "Modulus and Generator Values" of the IETF SRP draft). Represents a "multi-precision integer" (MPI) as is described in the SRP specification (3.2 Multi-Precision Integers, p.5). Multi-Precision Integers, or MPIs, are positive integers used to hold large integers used in cryptographic computations. Creates a new "multi-precision integer" from the specified array of bytes. A big-endian sequence of bytes forming the integer value of the multi-precision integer. Creates a new "multi-precision integer" from the specified BigInteger instance. The BigInteger instance to initialize the MPI with. Returns a sequence of bytes in big-endian order forming the integer value of this "multi-precision integer" instance. Returns a sequence of bytes in big-endian order representing this "multi-precision integer" instance. Serializes the "multi-precision integer" into a sequence of bytes according to the requirements of the SRP specification. A big-endian sequence of bytes representing the integer value of the MPI. The underlying BigInteger instance used to represent this "multi-precision integer". Represents an "octet-sequence" as is described in the SRP specification (3.3 Octet sequences, p.6). Creates a new instance of the OctetSequence class using the specified byte array. The sequence of bytes to initialize this instance of the OctetSequence class with. Serializes this instance of the OctetSequence class into a sequence of bytes according to the requirements of the SRP specification. A sequence of bytes representing this instance of the OctetSequence class. Thrown if the length of the byte sequence exceeds the maximum number of bytes allowed as per SRP specification. SRP specification imposes a limit of 255 bytes on the length of the underlying byte array. The underlying byte array forming this instance of the OctetSequence class. Represents the first message sent by the server in response to an initial client-response. Deserializes a new instance of the ServerMessage1 class from the specified buffer of bytes. The byte buffer to deserialize the ServerMessage1 instance from. An instance of the ServerMessage1 class deserialized from the specified byte array. Thrown if the byte buffer does not contain valid data. Parses the options string sent by the server. A comma-delimited options string. An initialized instance of the NameValueCollection class containing the parsed server options. The safe prime modulus sent by the server. The generator sent by the server. The user's password salt. The server's ephemeral public key. The options list indicating available security services. The raw options as received from the server. Represents the second message sent by the server as part of the SRP authentication exchange. Deserializes a new instance of the ServerMessage2 class from the specified buffer of bytes. The byte buffer to deserialize the ServerMessage2 instance from. An instance of the ServerMessage2 class deserialized from the specified byte array. Thrown if the byte buffer does not contain valid data. The evidence which proves to the client server-knowledge of the shared context key. The initial vector the client will use to set up its encryption context, if confidentiality protection will be employed. The session identifier the server has given to this session. The time period for which this session's parameters may be re-usable. Represents an UTF-8 string as is described in the SRP specification (3.5 Text, p.6). The value of the UTF-8 string. Creates a new instance of the Utf8String class using the specified string value. The string to initialize the Utf8String instance with. Serializes this instance of the Utf8String class into a sequence of bytes according to the requirements of the SRP specification. A sequence of bytes representing this instance of the Utf8String class. Thrown if the string value exceeds the maximum number of bytes allowed as per SRP specification. SRP specification imposes a limit of 65535 bytes on the string data after it has been encoded into a sequence of bytes using an encoding of UTF-8. Represents a MIME body part of a mail message that has multiple parts. Initializes a new instance of the Bodypart class with default values. The part number as is expected by the IMAP FETCH command. Returns a detailed description listing all properties of this Bodypart instance. A string describing this instance of the Bodypart class The body part number which acts as part specifier for the FETCH BODY command. The MIME content-type of this body part. The content-type is used to declare the general type of data. The MIME content-subtype of this body part. The subtype specifies a specific format for the type of data. Parameter values present in the MIME content-type header of this body part (for instance, 'charset'). The MIME content-id of this body part, if any. This value may be used for uniquely identifying MIME entities in several contexts. The MIME content-description of this body part. This value may contain some descriptive information on the body part. The MIME content-transfer-encoding mechanism used for encoding this body part's data. The size of this body part in bytes. Note that this size is the size in its transfer encoding and not the resulting size after any decoding. The size of the body in text lines. This field is only present in body parts with a content-type of text. The computed MD5-Hash of the body part. This field is not mandatory and may be empty. The MIME content-disposition for this body part. This field is not mandatory and may be empty. A string giving the body language. This field is not mandatory and may be empty. A string list giving the body content URI. This field is not mandatory and may be empty. Provides a means for parsing the textual description of the body structure of a mail message as is returned by an IMAP server for a "FETCH BODYSTRUCTURE" command. They couldn't have made the BODYSTRUCTURE any more complicated and unnecessarily hard to parse. I wonder what they were thinking when they came up with this. Parses the body structure of a mail message as is returned by the IMAP server in response to a FETCH BODYSTRUCTURE command. The body structure server response An array of initialized Bodypart objects representing the body structure of the mail message Thrown if the passed string does not contain a valid body structure and parsing failed. A Reader object initialized with the string containing the bodystructure response. Initializes a new instance of the Bodystructure class. Parses a bodypart entry from the body structure and advances the read pointer. The designated part specifier by which the body part is refered to by the server. Set to true if the bodypart is enclosed in parenthesis. Parses the mandatory extra fields that are present if the bodypart is of type message/rfc822 (see RFC 3501, p. 75). The bodypart instance the parsed fields will be added to. Parses the optional fields of a bodypart entry from the body structure and advances the read pointer. The bodypart instance the parsed fields will be added to. Set to true if the bodypart entry is enclosed in parenthesis. Parses a list of bodypart entries as is outlined in the description of the BODYPART response in RFC 3501. The nesting prefix that will be prefixed to the bodyparts partNumber. An array of initialized Bodypart objects parsed from the list. Advances the read pointer to skip over a multipart entry. Advances the read pointer to skip over an arbitrary expression enclosed in parentheses. Represents the content disposition as is presented in the BODYSTRUCTURE response by the IMAP server. Initializes a new instance of the ContentDisposition class with default values. Maps MIME content disposition string values to their corresponding counter-parts of the ContentDispositionType enumeration. The content disposition specifies the presentation style. Additional attribute fields for specifying the name of a file, the creation date and modification date, which can be used by the reader's mail user agent to store the attachment. Contains the name of the transmitted file if the content-disposition is of type "Attachment" and if the name value was provided as part of the header information. This field may be empty. Possible values for the content disposition type which determines the presentation style The content disposition could not be determined. An inline content disposition means that the content should be automatically displayed when the message is displayed. An attachment content disposition means that the content should not be displayed automatically and requires some form of action from the user to open it. Possible values for the "Encoding" property of the Bodypart class. The content transfer encoding indicates whether or not a binary-to-text encoding scheme has been used on top of the original encoding as specified within the Content-Type header. The content tranfer encoding could not be determined or is unknown. Up to 998 bytes per line of the code range 1 - 127 with CR and LF only allowed to appear as part of a CRLF line ending. Up to 998 bytes per line with CR and LF only allowed to appear as part of a CRLF line ending. Any sequence of bytes. Byte sequence is encoded using the quoted-printable encoding. Byte sequence is encoded using Base64 encoding. Possible values for the "Type" property of the Bodypart class. For a detailed description of MIME Media Types refer to RFC 2046. The "text" media type is intended for sending material which is principally textual in form. A media type of "image" indicates that the body contains an image. The subtype names the specific image format. A media type of "audio" indicates that the body contains audio data. A media type of "video" indicates that the body contains a time-varying-picture image, possibly with color and coordinated sound. The "application" media type is to be used for discrete data which do not fit in any of the other categories, and particularly for data to be processed by some type of application program. The "message" content type allows messages to contain other messages or pointers to other messages. The media type value is unknown or could not be determined. A helper class for parsing the BODYSTRUCTURE response of an IMAP FETCH command more conveniently. Initializes a new instance of the Reader class that reads from the specified string. The string to which the Reader instance should be initialized. Reads the next character from the input string and advances the character position by one character. The next character from the underlying string. Thrown when reading is attempted past the end of the underlying string. Returns the next available character but does not consume it. Set to true to skip any preceding whitespace characters. An integer representing the next character to be read, or -1 if no more characters are available. Advances the character position until the specified character is encountered. The character to skip to. Thrown when reading is attempted past the end of the underlying string. Advances the character position over any whitespace characters and subsequently ensures the next read will not return a whitespace character. Thrown when reading is attempted past the end of the underlying string. Reads characters until the specified character is encountered. The character to read up to. The read characters as a string value. Thrown when reading is attempted past the end of the underlying string. Reads a word from the underlying string. A word in this context is a literal enclosed in double-quotes. The read word. Thrown when reading is attempted past the end of the underlying string. Reads an integer from the underlying string. The read integer value. Thrown when reading is attempted past the end of the underlying string. Reads a list from the underlying string. A list in this context is a list of attribute/value literals (enclosed in double-quotes) enclosed in parenthesis. The read list as a dictionary with the attribute names as keys and attribute values as values. Thrown when reading is attempted past the end of the underlying string. Reads a disposition from the underlying string. A disposition in this context is a list of attribute/value literals (enclosed in double-quotes) preceded by a word enclosed in parenthesis. An initialized ContentDisposition instance representing the parsed disposition. Thrown when reading is attempted past the end of the underlying string. The exception that is thrown when reading is attempted past the end of a string. Initializes a new instance of the EndOfStringException class Initializes a new instance of the EndOfStringException class with its message string set to . A description of the error. The content of message is intended to be understood by humans. Initializes a new instance of the EndOfStringException class with its message string set to and a reference to the inner exception that is the cause of this exception. A description of the error. The content of message is intended to be understood by humans. The exception that is the cause of the current exception. Initializes a new instance of the EndOfStringException class with the specified serialization and context information. An object that holds the serialized object data about the exception being thrown. An object that contains contextual information about the source or destination. Defines the different means by which mail messages may be fetched from the server. Fetches the entire mail message with all of its content. Only the mail message headers will be retrieved, while the actual content will not be downloaded. If this option is specified, only the header fields of the returned MailMessage object will be initialized. Retrieves the mail message, but will only download content that has a content-type of text. This will retrieve text as well as HTML representation, while skipping inline content and attachments. Retrieves the mail message, but skips any content that is an attachment. Provides data for IMAP idle error events. Initializes a new instance of the IdleErrorEventArgs class. The exception that causes the event. The instance of the ImapClient class that raised the event. The exception parameter or the client parameter is null. The exception that caused the error event. The instance of the ImapClient class that raised the event. Provides data for IMAP idle notification events. Initializes a new instance of the IdleMessageEventArgs class and sets the MessageCount attribute to the value of the parameter. The number of messages in the selected mailbox. The unique identifier (UID) of the newest message in the mailbox. The instance of the ImapClient class that raised the event. The total number of messages in the selected mailbox. The unique identifier (UID) of the newest message in the mailbox. The UID can be passed to the GetMessage method in order to retrieve the mail message from the server. The instance of the ImapClient class that raised the event. Enables applications to communicate with a mail server using the Internet Message Access Protocol (IMAP). Attempts to establish an authenticated session with the server using the specified credentials. The username with which to login in to the IMAP server. The password with which to log in to the IMAP server. The requested method of authentication. Can be one of the values of the AuthMethod enumeration. The username parameter or the password parameter is null. There was a failure writing to or reading from the network. The server rejected the supplied credentials. The specified authentication method is not supported by the server. This example demonstrates how to authenticate with an IMAP server once a connection has been established. Notice that you can also connect and login in one step using one of the overloaded constructors. // Connect to Gmail's IMAP server on port 993 using SSL. ImapClient Client = new ImapClient("imap.gmail.com", 993, true); try { Client.Login("My_Username", "My_Password", AuthMethod.Auto); } catch(InvalidCredentialsException) { Console.WriteLine("The server rejected the supplied credentials."); } Client.Dispose(); Logs an authenticated client out of the server. After the logout sequence has been completed, the server closes the connection with the client. An unexpected response has been received from the server during the logout sequence. Calling this method in non-authenticated state has no effect. There was a failure writing to or reading from the network. The ImapClient object has been disposed. Returns an enumerable collection of capabilities the IMAP server supports. All strings in the returned collection are guaranteed to be upper-case. An unexpected response has been received from the server; The message property of the exception contains the error message returned by the server. There was a failure writing to or reading from the network. The ImapClient object has been disposed. An enumerable collection of capabilities supported by the server. This method may be called in non-authenticated state. Determines whether the specified capability is supported by the server. The IMAP capability to probe for (for example "IDLE"). The capability parameter is null. An unexpected response has been received from the server; The message property of the exception contains the error message returned by the server. There was a failure writing to or reading from the network. The ImapClient object has been disposed. true if the specified capability is supported by the server; Otherwise false. This method may be called in non-authenticated state. This example demonstrates how to connect and login to an IMAP server. // Connect to Gmail's IMAP server on port 993 using SSL. ImapClient Client = null; try { Client = new ImapClient("imap.gmail.com", 993, "My_Username", "My_Password", true, AuthMethod.Auto); // Check if the server supports IMAP IDLE. if(Client.Supports("IDLE")) Console.WriteLine("This server supports the IMAP4 IDLE specification"); else Console.WriteLine("This server does not support IMAP IDLE"); } catch(InvalidCredentialsException) { Console.WriteLine("The server rejected the supplied credentials"); } finally { // Release resources. if(Client != null) Client.Dispose(); } Changes the name of the specified mailbox. The mailbox to rename. The new name the mailbox will be renamed to. The mailbox parameter or the newName parameter is null. The mailbox could not be renamed; The message property of the exception contains the error message returned by the server. There was a failure writing to or reading from the network. The ImapClient object has been disposed. The method was called in non-authenticated state, i.e. before logging in. Permanently removes the specified mailbox. The name of the mailbox to remove. The mailbox parameter is null. The specified mailbox could not be removed. The message property of the exception contains the error message returned by the server. There was a failure writing to or reading from the network. The ImapClient object has been disposed. The method was called in non-authenticated state, i.e. before logging in. Creates a new mailbox with the specified name. The name of the mailbox to create. The mailbox parameter is null. The mailbox with the specified name could not be created. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. Retrieves a list of all available and selectable mailboxes on the server. An enumerable collection of the names of all available and selectable mailboxes. The list of mailboxes could not be retrieved. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. The mailbox name "INBOX" is a special name reserved to mean "the primary mailbox for this user on this server". Permanently removes all messages that have the \Deleted flag set from the specified mailbox. The mailbox to remove all messages from that have the \Deleted flag set. If this parameter is omitted, the value of the DefaultMailbox property is used to determine the mailbox to operate on. The expunge operation could not be completed. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. Retrieves status information (total number of messages, various attributes as well as quota information) for the specified mailbox. The mailbox to retrieve status information for. If this parameter is omitted, the value of the DefaultMailbox property is used to determine the mailbox to operate on. A MailboxInfo object containing status information for the mailbox. The operation could not be completed because the server returned an error. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. Not all IMAP servers support the retrieval of quota information. If it is not possible to retrieve this information, the UsedStorage and FreeStorage properties of the returned MailboxStatus instance are set to 0. ImapClient Client = new ImapClient("imap.gmail.com", 993, "My_UsernamMe", "My_Password", true, AuthMethod.Login); // Get a list of all mailboxes. foreach(string m in Client.ListMailboxes()) { MailboxInfo info = Client.GetMailboxInfo(m); Console.WriteLine(info.Name); Console.WriteLine("Used storage: " + info.UsedStorage); Console.WriteLine("Free storage: " + info.FreeStorage); Console.WriteLine("Next UID: " + info.NextUID); Console.WriteLine("Messages: " + info.Messages); Console.WriteLine("Unread: " + info.Unread); Console.WriteLine("Set Flags: "); foreach (MailboxFlag f in info.Flags) Console.Write(f.ToString() + ","); Console.WriteLine(); } Client.Dispose(); Searches the specified mailbox for messages that match the given search criteria. A search criteria expression; Only messages that match this expression will be included in the result set returned by this method. The mailbox that will be searched. If this parameter is omitted, the value of the DefaultMailbox property is used to determine the mailbox to operate on. The criteria parameter is null. The search could not be completed. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. The search values contain characters beyond the ASCII range and the server does not support handling non-ASCII strings. An enumerable collection of unique identifiers (UIDs) which can be used with the GetMessage family of methods to download the mail messages. A unique identifier (UID) is a 32-bit value assigned to each message which uniquely identifies the message within the respective mailbox. No two messages in a mailbox share the same UID. This example demonstrates how to use the search method to get a list of all unread messages in the mailbox. ImapClient Client = new ImapClient("imap.gmail.com", 993, "My_Username", "My_Password", true, AuthMethod.Login); // Get a list of unique identifiers (UIDs) of all unread messages in the mailbox. IEnumerable<uint> uids = Client.Search( SearchCondition.Unseen() ); // Fetch the messages and print out their subject lines. foreach(uint uid in uids) { MailMessage message = Client.GetMessage(uid); Console.WriteLine(message.Subject); } // Free up any resources associated with this instance. Client.Dispose(); This example demonstrates how to perform a search using multiple search criteria. ImapClient Client = new ImapClient("imap.gmail.com", 993, "My_Username", "My_Password", true, AuthMethod.Login); // Get a list of unique identifiers (UIDs) of all messages sent before the 01.04.2012 // and that are larger than 1 Kilobyte. IEnumerable<uint> uids = Client.Search( SearchCondition.SentBefore(new DateTime(2012, 4, 1)) .And( SearchCondition.Larger(1024) )); Console.WriteLine("Found " + uids.Count() + " messages"); // Free up any resources associated with this instance. Client.Dispose(); The following example demonstrates how to perform a search using characters outside the ASCII range. ImapClient Client = new ImapClient("imap.gmail.com", 993, "My_Username", "My_Password", true, AuthMethod.Login); // Get a list of unique identifiers (UIDs) of all messages that have // the Japanese expression "フーリエ変換" in their subject lines. try { IEnumerable<uint> uids = Client.Search(SearchCondition.Subject("フーリエ変換")); Console.WriteLine("Found " + uids.Count() + " messages"); } catch(NotSupportedException e) { // If this exception is thrown, the server does not support searching for characters // outside the ASCII range. Console.WriteLine("The server does not support searching for non-ASCII values."); } // Free up any resources associated with this instance. Client.Dispose(); Retrieves the mail message with the specified unique identifier (UID). The unique identifier of the mail message to retrieve. Set this to true to set the \Seen flag for this message on the server. The mailbox the message will be retrieved from. If this parameter is omitted, the value of the DefaultMailbox property is used to determine the mailbox to operate on. An initialized instance of the MailMessage class representing the fetched mail message. The mail message could not be fetched. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. A unique identifier (UID) is a 32-bit value assigned to each message which uniquely identifies the message within the respective mailbox. No two messages in a mailbox share the same UID. ImapClient Client = new ImapClient("imap.gmail.com", 993, "My_UsernamMe", "My_Password", true, AuthMethod.Login); // Find all messages in the mailbox that were sent from "John.Doe@gmail.com". IEnumerable<uint> uids = Client.Search( SearchCondition.From("John.Doe@gmail.com") ); // Fetch the first message and print it's subject and body. if(uids.Count() > 0) { MailMessage msg = Client.GetMessage(uids.First()); Console.WriteLine("Subject: " + msg.Subject); Console.WriteLine("Body: " + msg.Body); } Client.Dispose(); Retrieves the mail message with the specified unique identifier (UID) using the specified fetch-option. The unique identifier of the mail message to retrieve. A value from the FetchOptions enumeration which allows for fetching selective parts of a mail message. Set this to true to set the \Seen flag for this message on the server. The mailbox the message will be retrieved from. If this parameter is omitted, the value of the DefaultMailbox property is used to determine the mailbox to operate on. An initialized instance of the MailMessage class representing the fetched mail message. The mail message could not be fetched. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. A unique identifier (UID) is a 32-bit value assigned to each message which uniquely identifies the message within the respective mailbox. No two messages in a mailbox share the same UID. If you need more fine-grained control over which parts of a mail message to fetch, consider using one of the overloaded GetMessage methods. This example demonstrates how to fetch only the mail message headers of a mail message, instead of the entire message. ImapClient Client = new ImapClient("imap.gmail.com", 993, "My_UsernamMe", "My_Password", true, AuthMethod.Login); // Find all messages in the mailbox that have "Hello" in the subject. IEnumerable<uint> uids = Client.Search( SearchCondition.Subject("Hello") ); // Fetch the mail headers of the first message and print it's subject line. if(uids.Count() > 0) { MailMessage msg = Client.GetMessage(uids.First(), FetchOptions.HeadersOnly); Console.WriteLine("Subject: " + msg.Subject); } Client.Dispose(); Retrieves the mail message with the specified unique identifier (UID) while only fetching those parts of the message that satisfy the condition of the specified delegate. The unique identifier of the mail message to retrieve. A delegate which will be invoked for every MIME body-part of the mail message to determine whether the part should be fetched from the server or skipped. Set this to true to set the \Seen flag for this message on the server. The mailbox the message will be retrieved from. If this parameter is omitted, the value of the DefaultMailbox property is used to determine the mailbox to operate on. An initialized instance of the MailMessage class representing the fetched mail message. The callback parameter is null. The mail message could not be fetched. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. A unique identifier (UID) is a 32-bit value assigned to each message which uniquely identifies the message within the respective mailbox. No two messages in a mailbox share the same UID. This example demonstrates how to use the ExaminePartDelegate with the GetMessage method to only download message parts with a size of 1 Megabyte or less. ImapClient Client = new ImapClient("imap.gmail.com", 993, "My_UsernamMe", "My_Password", true, AuthMethod.Login); // Find all messages in the inbox. IEnumerable<uint> uids = Client.Search( SearchCondition.All() ); // Download each message but skip message parts that are larger than 1 Megabyte. foreach(uint uid in uids) { MailMessage msg = Client.GetMessage(uid, (Bodypart part) => { if(part.Size > (1024 * 1024)) return false; else return true; } ); } Client.Dispose(); Retrieves the set of mail messages with the specified unique identifiers (UIDs). An enumerable collection of unique identifiers of the mail messages to retrieve. Set this to true to set the \Seen flag for the fetched messages on the server. The mailbox the messages will be retrieved from. If this parameter is omitted, the value of the DefaultMailbox property is used to determine the mailbox to operate on. An enumerable collection of initialized instances of the MailMessage class representing the fetched mail messages. The uids parameter is null. The mail messages could not be fetched. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. A unique identifier (UID) is a 32-bit value assigned to each message which uniquely identifies the message within the respective mailbox. No two messages in a mailbox share the same UID. ImapClient Client = new ImapClient("imap.gmail.com", 993, "My_UsernamMe", "My_Password", true, AuthMethod.Login); // Find all messages that have been sent since June the 1st. IEnumerable<uint> uids = Client.Search( SearchCondition.SentSince( new DateTime(2012, 6, 1) ) ); // Fetch the messages and print out their subject lines. IEnumerable<MailMessage> messages = Client.GetMessages( uids ); foreach(MailMessage m in messages) Console.WriteLine("Subject: " + m.Subject); Client.Dispose(); Retrieves the set of mail messages with the specified unique identifiers (UIDs) while only fetching those parts of the messages that satisfy the condition of the specified delegate. An enumerable collection of unique identifiers of the mail messages to retrieve. A delegate which will be invoked for every MIME body-part of each mail message to determine whether the part should be fetched from the server or skipped. Set this to true to set the \Seen flag for the fetched messages on the server. The mailbox the messages will be retrieved from. If this parameter is omitted, the value of the DefaultMailbox property is used to determine the mailbox to operate on. An enumerable collection of initialized instances of the MailMessage class representing the fetched mail messages. The uids parameter or the callback parameter is null. The mail messages could not be fetched. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. A unique identifier (UID) is a 32-bit value assigned to each message which uniquely identifies the message within the respective mailbox. No two messages in a mailbox share the same UID. Retrieves the set of mail messages with the specified unique identifiers (UIDs) using the specified fetch-option. An enumerable collection of unique identifiers of the mail messages to retrieve. A value from the FetchOptions enumeration which allows for fetching selective parts of a mail message. Set this to true to set the \Seen flag for the fetched messages on the server. The mailbox the messages will be retrieved from. If this parameter is omitted, the value of the DefaultMailbox property is used to determine the mailbox to operate on. An enumerable collection of initialized instances of the MailMessage class representing the fetched mail messages. The uids parameter is null. The mail messages could not be fetched. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. A unique identifier (UID) is a 32-bit value assigned to each message which uniquely identifies the message within the respective mailbox. No two messages in a mailbox share the same UID. ImapClient Client = new ImapClient("imap.gmail.com", 993, "My_UsernamMe", "My_Password", true, AuthMethod.Login); // Find all messages that have been sent since June the 1st. IEnumerable<uint> uids = Client.Search( SearchCondition.SentSince( new DateTime(2012, 6, 1) ) ); // Retrieve the messages and print out their subject lines. If any of the messages are multipart // messages, only those parts, that have a content-type of text will be fetched. IEnumerable<MailMessage> messages = Client.GetMessages( uids, FetchOptions.TextOnly ); foreach(MailMessage m in messages) Console.WriteLine("Subject: " + m.Subject); Client.Dispose(); Stores the specified mail message on the IMAP server. The mail message to store on the server. Set this to true to set the \Seen flag for the message on the server. The mailbox the message will be stored in. If this parameter is omitted, the value of the DefaultMailbox property is used to determine the mailbox to store the message in. The unique identifier (UID) of the stored message. The message parameter is null. The mail message could not be stored. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. A unique identifier (UID) is a 32-bit value assigned to each message which uniquely identifies the message within the respective mailbox. No two messages in a mailbox share the same UID. This example demonstrates how to store a mail message on an IMAP server. ImapClient Client = new ImapClient("imap.gmail.com", 993, "My_UsernamMe", "My_Password", true, AuthMethod.Login); MailMessage message = CreateSimpleMailMessage(); uint uid = Client.StoreMessage(message); Console.WriteLine("The UID of the stored mail message is " + uid); Client.Dispose(); // ........... // This creates a simple mail message with a text/plain body and a PNG image // as a file attachment. // Consult the MSDN website for more details on the System.Net.Mail.Mailmessage class. static MailMessage CreateSimpleMailMessage() { MailMessage message = new MailMessage(); message.From = new MailAddress("someone@someplace.com"); message.To.Add("john.doe@someplace.com"); message.Subject = "This is just a test!"; message.Body = "This is the text/plain body. An additional HTML body " + "can optionally be attached as an alternate view"; // Add the attachment. Attachment attachment = new Attachment("some_image.png", "image/png"); attachment.Name = "my_attached_image.png"; message.Attachments.Add(attachment); return message; } Stores the specified mail messages on the IMAP server. An enumerable collection of mail messages to store on the server. Set this to true to set the \Seen flag for each message on the server. The mailbox the messages will be stored in. If this parameter is omitted, the value of the DefaultMailbox property is used to determine the mailbox to store the messages in. An enumerable collection of unique identifiers (UID) representing the stored messages on the server. The messages parameter is null. The mail messages could not be stored. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. A unique identifier (UID) is a 32-bit value assigned to each message which uniquely identifies the message within the respective mailbox. No two messages in a mailbox share the same UID. Copies the mail message with the specified UID to the specified destination mailbox. The UID of the mail message to copy. The name of the mailbox to copy the message to. The mailbox the message will be copied from. If this parameter is omitted, the value of the DefaultMailbox property is used to determine the mailbox to operate on. The destination parameter is null. The mail message could not be copied to the specified destination. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. Copies the mail messages with the specified UIDs to the specified destination mailbox. An enumerable collection of UIDs of the mail messages to copy. The name of the mailbox to copy the messages to. The mailbox the message will be copied from. If this parameter is omitted, the value of the DefaultMailbox property is used to determine the mailbox to operate on. When copying many messages, this method is more efficient than calling for each individual message. The uids parameter or the destination parameter is null. The specified collection of UIDs is empty. The mail messages could not be copied to the specified destination. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. Moves the mail message with the specified UID to the specified destination mailbox. The UID of the mail message to move. The name of the mailbox to move the message into. The mailbox the message will be moved from. If this parameter is omitted, the value of the DefaultMailbox property is used to determine the mailbox to operate on. The destination parameter is null. The mail message could not be moved to the specified destination. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. Moves the mail messages with the specified UIDs to the specified destination mailbox. An enumerable collection of UIDs of the mail messages to move. The name of the mailbox to move the messages into. The mailbox the messages will be moved from. If this parameter is omitted, the value of the DefaultMailbox property is used to determine the mailbox to operate on. When moving many messages, this method is more efficient than calling for each individual message. The uids parameter or the destination parameter is null. The mail messages could not be moved to the specified destination. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. Deletes the mail message with the specified UID. The UID of the mail message to delete. The mailbox the message will be deleted from. If this parameter is omitted, the value of the DefaultMailbox property is used to determine the mailbox to operate on. The mail message could not be deleted. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. Deletes the mail messages with the specified UIDs. An enumerable collection of UIDs of the mail messages to delete. The mailbox the messages will be deleted from. If this parameter is omitted, the value of the DefaultMailbox property is used to determine the mailbox to operate on. When deleting many messages, this method is more efficient than calling for each individual message. The uids parameter is null. The specified collection of UIDs is empty. The mail messages could not be deleted. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. Retrieves the IMAP message flag attributes for the mail message with the specified unique identifier (UID). The UID of the mail message to retrieve the flag attributes for. The mailbox the message will be retrieved from. If this parameter is omitted, the value of the DefaultMailbox property is used to determine the mailbox to operate on. An enumerable collection of message flags set for the message with the specified UID. The mail message flags could not be retrieved. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. Sets the IMAP message flag attributes for the mail message with the specified unique identifier (UID). The UID of the mail message to set the flag attributes for. The mailbox that contains the mail message. If this parameter is null, the value of the DefaultMailbox property is used to determine the mailbox to operate on. One or multiple message flags from the MessageFlag enumeration. The mail message flags could not be set. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. This method replaces the current flag attributes of the message with the specified new flags. If you wish to retain the old attributes, use the method instead. Adds the specified set of IMAP message flags to the existing flag attributes of the mail message with the specified unique identifier (UID). The UID of the mail message to add the flag attributes to. The mailbox that contains the mail message. If this parameter is null, the value of the DefaultMailbox property is used to determine the mailbox to operate on. One or multiple message flags from the MessageFlag enumeration. The mail message flags could not be added. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. This method adds the specified set of flags to the existing set of flag attributes of the message. If you wish to replace the old attributes, use the method instead. Removes the specified set of IMAP message flags from the existing flag attributes of the mail message with the specified unique identifier (UID). The UID of the mail message to remove the flag attributes for. The mailbox that contains the mail message. If this parameter is null, the value of the DefaultMailbox property is used to determine the mailbox to operate on. One or multiple message flags from the MessageFlag enumeration. The mail message flags could not be removed. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. This method removes the specified set of flags from the existing set of flag attributes of the message. If you wish to replace the old attributes, use the method instead. The default mailbox to operate on. The property is being set and the value is null. The property is being set and the value is the empty string. The default value for this property is "INBOX" which is a special name reserved to mean "the primary mailbox for this user on this server". Determines whether the client is authenticated with the server. The event that is raised when a new mail message has been received by the server. To probe a server for IMAP IDLE support, the method can be used, specifying "IDLE" for the capability parameter. Please note that the event handler will be executed on a threadpool thread. This example demonstrates how to receive IMAP IDLE notifications. ImapClient Client = new ImapClient("imap.gmail.com", 993, "My_UsernamMe", "My_Password", true, AuthMethod.Login); // Make sure our server actually supports IMAP IDLE. if(!Client.Supports("IDLE")) throw new Exception("This server does not support IMAP IDLE"); // Our event handler will be called whenever a new message is received // by the server. Client.NewMessage += new EventHandler<IdleMessageEventArgs>(OnNewMessage); // ......... Client.Dispose(); // ........ void OnNewMessage(object sender, IdleMessageEventArgs e) { Console.WriteLine("Received a new message!"); Console.WriteLine("Total number of messages in the mailbox: " + e.MessageCount); } The event that is raised when a message has been deleted on the server. To probe a server for IMAP IDLE support, the method can be used, specifying "IDLE" for the capability parameter. Please note that the event handler will be executed on a threadpool thread. This example demonstrates how to receive IMAP IDLE notifications. ImapClient Client = new ImapClient("imap.gmail.com", 993, "My_UsernamMe", "My_Password", true, AuthMethod.Login); // Make sure our server actually supports IMAP IDLE. if(!Client.Supports("IDLE")) throw new Exception("This server does not support IMAP IDLE"); // Our event handler will be called whenever a message is deleted on the server. Client.MessageDeleted += new EventHandler<IdleMessageEventArgs>(OnMessageDeleted); // ......... // Don't forget to dispose the client once you're done with it. Client.Dispose(); // ........ void OnMessageDeleted(object sender, IdleMessageEventArgs e) { Console.WriteLine("A mail message was deleted on the server!"); Console.WriteLine("Total number of mail messages in the mailbox: " + e.MessageCount); } Enables applications to communicate with a mail server using the Internet Message Access Protocol (IMAP). This constructor is solely used for unit testing. A stream to initialize the ImapClient instance with. Initializes a new instance of the ImapClient class and connects to the specified port on the specified host, optionally using the Secure Socket Layer (SSL) security protocol. The DNS name of the server to which you intend to connect. The port number of the server to which you intend to connect. Set to true to use the Secure Socket Layer (SSL) security protocol. Delegate used for verifying the remote Secure Sockets Layer (SSL) certificate which is used for authentication. Can be null if not needed. The port parameter is not between MinPort and MaxPort. The hostname parameter is null. An unexpected response has been received from the server upon connecting. There was a failure writing to or reading from the network. An error occurred while accessing the socket used for establishing the connection to the IMAP server. Use the ErrorCode property to obtain the specific error code. An authentication error occured while trying to establish a secure connection. This example shows how to establish a connection with an IMAP server and print out the IMAP options, which the server supports. // Connect to Gmail's IMAP server on port 993 using SSL. ImapClient Client = new ImapClient("imap.gmail.com", 993, true); // Print out the server's capabilities. foreach(string s in Client.Capabilities()) Console.WriteLine(s); Client.Dispose(); Initializes a new instance of the ImapClient class and connects to the specified port on the specified host, optionally using the Secure Socket Layer (SSL) security protocol and attempts to authenticate with the server using the specified authentication method and credentials. The DNS name of the server to which you intend to connect. The port number of the server to which you intend to connect. The username with which to login in to the IMAP server. The password with which to log in to the IMAP server. The requested method of authentication. Can be one of the values of the AuthMethod enumeration. Set to true to use the Secure Socket Layer (SSL) security protocol. Delegate used for verifying the remote Secure Sockets Layer (SSL) certificate which is used for authentication. Can be null if not needed. The port parameter is not between MinPort and MaxPort. The hostname parameter is null. An unexpected response has been received from the server upon connecting. There was a failure writing to or reading from the network. The provided credentials were rejected by the server. An error occurred while accessing the socket used for establishing the connection to the IMAP server. Use the ErrorCode property to obtain the specific error code. An authentication error occured while trying to establish a secure connection. This example demonstrates how to connect and login to an IMAP server. // Connect to Gmail's IMAP server on port 993 using SSL. ImapClient Client = null; try { Client = new ImapClient("imap.gmail.com", 993, "My_Username", "My_Password", true, AuthMethod.Auto); // Check if the server supports IMAP IDLE. if(Client.Supports("IDLE")) Console.WriteLine("This server supports the IMAP4 IDLE specification"); else Console.WriteLine("This server does not support IMAP IDLE"); } catch(InvalidCredentialsException) { Console.WriteLine("The server rejected the supplied credentials"); } finally { // Release resources. if(Client != null) Client.Dispose(); } Connects to the specified port on the specified host, optionally using the Secure Socket Layer (SSL) security protocol. The DNS name of the server to which you intend to connect. The port number of the server to which you intend to connect. Set to true to use the Secure Socket Layer (SSL) security protocol. Delegate used for verifying the remote Secure Sockets Layer (SSL) certificate which is used for authentication. Can be null if not needed. The port parameter is not between MinPort and MaxPort. The hostname parameter is null. An unexpected response has been received from the server upon connecting. There was a failure writing to or reading from the network. An error occurred while accessing the socket used for establishing the connection to the IMAP server. Use the ErrorCode property to obtain the specific error code. An authentication error occured while trying to establish a secure connection. Determines whether the specified response is a valid IMAP OK response. A response string received from the server. A tag if the response is associated with a command. true if the response is a valid IMAP OK response; Otherwise false. Attempts to establish an authenticated session with the server using the specified credentials. The username with which to login in to the IMAP server. The password with which to log in to the IMAP server. The requested method of authentication. Can be one of the values of the AuthMethod enumeration. The username parameter or the password parameter is null. There was a failure writing to or reading from the network. The server rejected the supplied credentials. The specified authentication method is not supported by the server. This example demonstrates how to authenticate with an IMAP server once a connection has been established. Notice that you can also connect and login in one step using one of the overloaded constructors. // Connect to Gmail's IMAP server on port 993 using SSL. ImapClient Client = new ImapClient("imap.gmail.com", 993, true); try { Client.Login("My_Username", "My_Password", AuthMethod.Auto); } catch(InvalidCredentialsException) { Console.WriteLine("The server rejected the supplied credentials."); } Client.Dispose(); Performs authentication using the most secure authentication mechanism supported by the server. The tag identifier to use for performing the authentication commands. The username with which to login in to the IMAP server. The password with which to log in to the IMAP server. The response sent by the server. The order of preference of authentication types employed by this method is Ntlm, Scram-Sha-1, Digest-Md5, followed by Cram-Md5 and finally plaintext Login as a last resort. Performs an actual IMAP "LOGIN" command using the specified username and plain-text password. The tag identifier to use for performing the authentication commands. The username with which to login in to the IMAP server. The password with which to log in to the IMAP server. The response sent by the server. Performs NTLM and Kerberos authentication via the Security Support Provider Interface (SSPI). The tag identifier to use for performing the authentication commands. The username with which to login in to the IMAP server. The password with which to log in to the IMAP server. True to authenticate using NTLM, otherwise GSSAPI (Kerberos) is used. The response sent by the server. The specified authentication method is not supported by the server. Performs authentication using a SASL authentication mechanism via IMAP's authenticate command. The tag identifier to use for performing the authentication commands. The username with which to login in to the IMAP server. The password with which to log in to the IMAP server. The name of the SASL authentication mechanism to use. The response sent by the server. The authentication mechanism with the specified name could not be found. The specified authentication mechanism is not supported by the server. An unexpected response has been received from the server. Logs an authenticated client out of the server. After the logout sequence has been completed, the server closes the connection with the client. An unexpected response has been received from the server during the logout sequence. Calling this method in non-authenticated state has no effect. There was a failure writing to or reading from the network. The ImapClient object has been disposed. Generates a unique identifier to prefix a command with, as is required by the IMAP protocol. A unique identifier string. Sends a command string to the server. This method blocks until the command has been transmitted. The command to send to the server. The string is suffixed by CRLF prior to sending. Sends a command string to the server and subsequently waits for a response, which is then returned to the caller. This method blocks until the server response has been received. The command to send to the server. This is suffixed by CRLF prior to sending. Set to true to resolve possible literals returned by the server (Refer to RFC 3501 Section 4.3 for details). The response received by the server. Waits for a response from the server. This method blocks until a response has been received. Set to true to resolve possible literals returned by the server (Refer to RFC 3501 Section 4.3 for details). A response string from the server The underlying socket is closed or there was a failure reading from the network. Reads the specified amount of bytes from the server. This method blocks until the specified amount of bytes has been read from the network stream. The number of bytes to read. The read bytes as an ASCII-encoded string. The underlying socket is closed or there was a failure reading from the network. Returns an enumerable collection of capabilities the IMAP server supports. All strings in the returned collection are guaranteed to be upper-case. An unexpected response has been received from the server; The message property of the exception contains the error message returned by the server. There was a failure writing to or reading from the network. The ImapClient object has been disposed. An enumerable collection of capabilities supported by the server. This method may be called in non-authenticated state. Determines whether the specified capability is supported by the server. The IMAP capability to probe for (for example "IDLE"). The capability parameter is null. An unexpected response has been received from the server; The message property of the exception contains the error message returned by the server. There was a failure writing to or reading from the network. The ImapClient object has been disposed. true if the specified capability is supported by the server; Otherwise false. This method may be called in non-authenticated state. This example demonstrates how to connect and login to an IMAP server. // Connect to Gmail's IMAP server on port 993 using SSL. ImapClient Client = null; try { Client = new ImapClient("imap.gmail.com", 993, "My_Username", "My_Password", true, AuthMethod.Auto); // Check if the server supports IMAP IDLE. if(Client.Supports("IDLE")) Console.WriteLine("This server supports the IMAP4 IDLE specification"); else Console.WriteLine("This server does not support IMAP IDLE"); } catch(InvalidCredentialsException) { Console.WriteLine("The server rejected the supplied credentials"); } finally { // Release resources. if(Client != null) Client.Dispose(); } Changes the name of the specified mailbox. The mailbox to rename. The new name the mailbox will be renamed to. The mailbox parameter or the newName parameter is null. The mailbox could not be renamed; The message property of the exception contains the error message returned by the server. There was a failure writing to or reading from the network. The ImapClient object has been disposed. The method was called in non-authenticated state, i.e. before logging in. Permanently removes the specified mailbox. The name of the mailbox to remove. The mailbox parameter is null. The specified mailbox could not be removed. The message property of the exception contains the error message returned by the server. There was a failure writing to or reading from the network. The ImapClient object has been disposed. The method was called in non-authenticated state, i.e. before logging in. Creates a new mailbox with the specified name. The name of the mailbox to create. The mailbox parameter is null. The mailbox with the specified name could not be created. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. Selects the specified mailbox so that the messages of the mailbox can be accessed. The mailbox to select. If this parameter is null, the default mailbox is selected. The specified mailbox could not be selected. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. IMAP Idle must be paused or stopped before calling this method. Retrieves a list of all available and selectable mailboxes on the server. An enumerable collection of the names of all available and selectable mailboxes. The list of mailboxes could not be retrieved. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. The mailbox name "INBOX" is a special name reserved to mean "the primary mailbox for this user on this server". Permanently removes all messages that have the \Deleted flag set from the specified mailbox. The mailbox to remove all messages from that have the \Deleted flag set. If this parameter is omitted, the value of the DefaultMailbox property is used to determine the mailbox to operate on. The expunge operation could not be completed. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. Retrieves status information (total number of messages, various attributes as well as quota information) for the specified mailbox. The mailbox to retrieve status information for. If this parameter is omitted, the value of the DefaultMailbox property is used to determine the mailbox to operate on. A MailboxInfo object containing status information for the mailbox. The operation could not be completed because the server returned an error. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. Not all IMAP servers support the retrieval of quota information. If it is not possible to retrieve this information, the UsedStorage and FreeStorage properties of the returned MailboxStatus instance are set to 0. ImapClient Client = new ImapClient("imap.gmail.com", 993, "My_UsernamMe", "My_Password", true, AuthMethod.Login); // Get a list of all mailboxes. foreach(string m in Client.ListMailboxes()) { MailboxInfo info = Client.GetMailboxInfo(m); Console.WriteLine(info.Name); Console.WriteLine("Used storage: " + info.UsedStorage); Console.WriteLine("Free storage: " + info.FreeStorage); Console.WriteLine("Next UID: " + info.NextUID); Console.WriteLine("Messages: " + info.Messages); Console.WriteLine("Unread: " + info.Unread); Console.WriteLine("Set Flags: "); foreach (MailboxFlag f in info.Flags) Console.Write(f.ToString() + ","); Console.WriteLine(); } Client.Dispose(); Retrieves the set of special-use flags associated with the specified mailbox. The mailbox to receive the special-use flags for. If this parameter is omitted, the value of the DefaultMailbox property is used to determine the mailbox to operate on. The operation could not be completed because the server returned an error. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. An enumerable collection of special-use flags set on the specified mailbox. This feature is an optional extension to the IMAP protocol and as such some servers may not report any flags at all. Retrieves status information (total number of messages, number of unread messages, etc.) for the specified mailbox. The mailbox to retrieve status information for. If this parameter is omitted, the value of the DefaultMailbox property is used to determine the mailbox to operate on. A MailboxStatus object containing status information for the mailbox. The operation could not be completed because the server returned an error. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. Searches the specified mailbox for messages that match the given search criteria. A search criteria expression; Only messages that match this expression will be included in the result set returned by this method. The mailbox that will be searched. If this parameter is omitted, the value of the DefaultMailbox property is used to determine the mailbox to operate on. The criteria parameter is null. The search could not be completed. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. The search values contain characters beyond the ASCII range and the server does not support handling non-ASCII strings. An enumerable collection of unique identifiers (UIDs) which can be used with the GetMessage family of methods to download the mail messages. A unique identifier (UID) is a 32-bit value assigned to each message which uniquely identifies the message within the respective mailbox. No two messages in a mailbox share the same UID. This example demonstrates how to use the search method to get a list of all unread messages in the mailbox. ImapClient Client = new ImapClient("imap.gmail.com", 993, "My_Username", "My_Password", true, AuthMethod.Login); // Get a list of unique identifiers (UIDs) of all unread messages in the mailbox. IEnumerable<uint> uids = Client.Search( SearchCondition.Unseen() ); // Fetch the messages and print out their subject lines. foreach(uint uid in uids) { MailMessage message = Client.GetMessage(uid); Console.WriteLine(message.Subject); } // Free up any resources associated with this instance. Client.Dispose(); This example demonstrates how to perform a search using multiple search criteria. ImapClient Client = new ImapClient("imap.gmail.com", 993, "My_Username", "My_Password", true, AuthMethod.Login); // Get a list of unique identifiers (UIDs) of all messages sent before the 01.04.2012 // and that are larger than 1 Kilobyte. IEnumerable<uint> uids = Client.Search( SearchCondition.SentBefore(new DateTime(2012, 4, 1)) .And( SearchCondition.Larger(1024) )); Console.WriteLine("Found " + uids.Count() + " messages"); // Free up any resources associated with this instance. Client.Dispose(); The following example demonstrates how to perform a search using characters outside the ASCII range. ImapClient Client = new ImapClient("imap.gmail.com", 993, "My_Username", "My_Password", true, AuthMethod.Login); // Get a list of unique identifiers (UIDs) of all messages that have // the Japanese expression "フーリエ変換" in their subject lines. try { IEnumerable<uint> uids = Client.Search(SearchCondition.Subject("フーリエ変換")); Console.WriteLine("Found " + uids.Count() + " messages"); } catch(NotSupportedException e) { // If this exception is thrown, the server does not support searching for characters // outside the ASCII range. Console.WriteLine("The server does not support searching for non-ASCII values."); } // Free up any resources associated with this instance. Client.Dispose(); Retrieves the mail message with the specified unique identifier (UID). The unique identifier of the mail message to retrieve. Set this to true to set the \Seen flag for this message on the server. The mailbox the message will be retrieved from. If this parameter is omitted, the value of the DefaultMailbox property is used to determine the mailbox to operate on. An initialized instance of the MailMessage class representing the fetched mail message. The mail message could not be fetched. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. A unique identifier (UID) is a 32-bit value assigned to each message which uniquely identifies the message within the respective mailbox. No two messages in a mailbox share the same UID. ImapClient Client = new ImapClient("imap.gmail.com", 993, "My_UsernamMe", "My_Password", true, AuthMethod.Login); // Find all messages in the mailbox that were sent from "John.Doe@gmail.com". IEnumerable<uint> uids = Client.Search( SearchCondition.From("John.Doe@gmail.com") ); // Fetch the first message and print it's subject and body. if(uids.Count() > 0) { MailMessage msg = Client.GetMessage(uids.First()); Console.WriteLine("Subject: " + msg.Subject); Console.WriteLine("Body: " + msg.Body); } Client.Dispose(); Retrieves the mail message with the specified unique identifier (UID) using the specified fetch-option. The unique identifier of the mail message to retrieve. A value from the FetchOptions enumeration which allows for fetching selective parts of a mail message. Set this to true to set the \Seen flag for this message on the server. The mailbox the message will be retrieved from. If this parameter is omitted, the value of the DefaultMailbox property is used to determine the mailbox to operate on. An initialized instance of the MailMessage class representing the fetched mail message. The mail message could not be fetched. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. A unique identifier (UID) is a 32-bit value assigned to each message which uniquely identifies the message within the respective mailbox. No two messages in a mailbox share the same UID. If you need more fine-grained control over which parts of a mail message to fetch, consider using one of the overloaded GetMessage methods. This example demonstrates how to fetch only the mail message headers of a mail message, instead of the entire message. ImapClient Client = new ImapClient("imap.gmail.com", 993, "My_UsernamMe", "My_Password", true, AuthMethod.Login); // Find all messages in the mailbox that have "Hello" in the subject. IEnumerable<uint> uids = Client.Search( SearchCondition.Subject("Hello") ); // Fetch the mail headers of the first message and print it's subject line. if(uids.Count() > 0) { MailMessage msg = Client.GetMessage(uids.First(), FetchOptions.HeadersOnly); Console.WriteLine("Subject: " + msg.Subject); } Client.Dispose(); Retrieves the mail message with the specified unique identifier (UID) while only fetching those parts of the message that satisfy the condition of the specified delegate. The unique identifier of the mail message to retrieve. A delegate which will be invoked for every MIME body-part of the mail message to determine whether the part should be fetched from the server or skipped. Set this to true to set the \Seen flag for this message on the server. The mailbox the message will be retrieved from. If this parameter is omitted, the value of the DefaultMailbox property is used to determine the mailbox to operate on. An initialized instance of the MailMessage class representing the fetched mail message. The callback parameter is null. The mail message could not be fetched. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. A unique identifier (UID) is a 32-bit value assigned to each message which uniquely identifies the message within the respective mailbox. No two messages in a mailbox share the same UID. This example demonstrates how to use the ExaminePartDelegate with the GetMessage method to only download message parts with a size of 1 Megabyte or less. ImapClient Client = new ImapClient("imap.gmail.com", 993, "My_UsernamMe", "My_Password", true, AuthMethod.Login); // Find all messages in the inbox. IEnumerable<uint> uids = Client.Search( SearchCondition.All() ); // Download each message but skip message parts that are larger than 1 Megabyte. foreach(uint uid in uids) { MailMessage msg = Client.GetMessage(uid, (Bodypart part) => { if(part.Size > (1024 * 1024)) return false; else return true; } ); } Client.Dispose(); Retrieves the set of mail messages with the specified unique identifiers (UIDs). An enumerable collection of unique identifiers of the mail messages to retrieve. Set this to true to set the \Seen flag for the fetched messages on the server. The mailbox the messages will be retrieved from. If this parameter is omitted, the value of the DefaultMailbox property is used to determine the mailbox to operate on. An enumerable collection of initialized instances of the MailMessage class representing the fetched mail messages. The uids parameter is null. The mail messages could not be fetched. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. A unique identifier (UID) is a 32-bit value assigned to each message which uniquely identifies the message within the respective mailbox. No two messages in a mailbox share the same UID. ImapClient Client = new ImapClient("imap.gmail.com", 993, "My_UsernamMe", "My_Password", true, AuthMethod.Login); // Find all messages that have been sent since June the 1st. IEnumerable<uint> uids = Client.Search( SearchCondition.SentSince( new DateTime(2012, 6, 1) ) ); // Fetch the messages and print out their subject lines. IEnumerable<MailMessage> messages = Client.GetMessages( uids ); foreach(MailMessage m in messages) Console.WriteLine("Subject: " + m.Subject); Client.Dispose(); Retrieves the set of mail messages with the specified unique identifiers (UIDs) while only fetching those parts of the messages that satisfy the condition of the specified delegate. An enumerable collection of unique identifiers of the mail messages to retrieve. A delegate which will be invoked for every MIME body-part of each mail message to determine whether the part should be fetched from the server or skipped. Set this to true to set the \Seen flag for the fetched messages on the server. The mailbox the messages will be retrieved from. If this parameter is omitted, the value of the DefaultMailbox property is used to determine the mailbox to operate on. An enumerable collection of initialized instances of the MailMessage class representing the fetched mail messages. The uids parameter or the callback parameter is null. The mail messages could not be fetched. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. A unique identifier (UID) is a 32-bit value assigned to each message which uniquely identifies the message within the respective mailbox. No two messages in a mailbox share the same UID. Retrieves the set of mail messages with the specified unique identifiers (UIDs) using the specified fetch-option. An enumerable collection of unique identifiers of the mail messages to retrieve. A value from the FetchOptions enumeration which allows for fetching selective parts of a mail message. Set this to true to set the \Seen flag for the fetched messages on the server. The mailbox the messages will be retrieved from. If this parameter is omitted, the value of the DefaultMailbox property is used to determine the mailbox to operate on. An enumerable collection of initialized instances of the MailMessage class representing the fetched mail messages. The uids parameter is null. The mail messages could not be fetched. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. A unique identifier (UID) is a 32-bit value assigned to each message which uniquely identifies the message within the respective mailbox. No two messages in a mailbox share the same UID. ImapClient Client = new ImapClient("imap.gmail.com", 993, "My_UsernamMe", "My_Password", true, AuthMethod.Login); // Find all messages that have been sent since June the 1st. IEnumerable<uint> uids = Client.Search( SearchCondition.SentSince( new DateTime(2012, 6, 1) ) ); // Retrieve the messages and print out their subject lines. If any of the messages are multipart // messages, only those parts, that have a content-type of text will be fetched. IEnumerable<MailMessage> messages = Client.GetMessages( uids, FetchOptions.TextOnly ); foreach(MailMessage m in messages) Console.WriteLine("Subject: " + m.Subject); Client.Dispose(); Stores the specified mail message on the IMAP server. The mail message to store on the server. Set this to true to set the \Seen flag for the message on the server. The mailbox the message will be stored in. If this parameter is omitted, the value of the DefaultMailbox property is used to determine the mailbox to store the message in. The unique identifier (UID) of the stored message. The message parameter is null. The mail message could not be stored. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. A unique identifier (UID) is a 32-bit value assigned to each message which uniquely identifies the message within the respective mailbox. No two messages in a mailbox share the same UID. This example demonstrates how to store a mail message on an IMAP server. ImapClient Client = new ImapClient("imap.gmail.com", 993, "My_UsernamMe", "My_Password", true, AuthMethod.Login); MailMessage message = CreateSimpleMailMessage(); uint uid = Client.StoreMessage(message); Console.WriteLine("The UID of the stored mail message is " + uid); Client.Dispose(); // ........... // This creates a simple mail message with a text/plain body and a PNG image // as a file attachment. // Consult the MSDN website for more details on the System.Net.Mail.Mailmessage class. static MailMessage CreateSimpleMailMessage() { MailMessage message = new MailMessage(); message.From = new MailAddress("someone@someplace.com"); message.To.Add("john.doe@someplace.com"); message.Subject = "This is just a test!"; message.Body = "This is the text/plain body. An additional HTML body " + "can optionally be attached as an alternate view"; // Add the attachment. Attachment attachment = new Attachment("some_image.png", "image/png"); attachment.Name = "my_attached_image.png"; message.Attachments.Add(attachment); return message; } Stores the specified mail messages on the IMAP server. An enumerable collection of mail messages to store on the server. Set this to true to set the \Seen flag for each message on the server. The mailbox the messages will be stored in. If this parameter is omitted, the value of the DefaultMailbox property is used to determine the mailbox to store the messages in. An enumerable collection of unique identifiers (UID) representing the stored messages on the server. The messages parameter is null. The mail messages could not be stored. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. A unique identifier (UID) is a 32-bit value assigned to each message which uniquely identifies the message within the respective mailbox. No two messages in a mailbox share the same UID. Retrieves the mail header for the mail message with the specified unique identifier (UID). The UID of the mail message to retrieve the mail header for. Set this to true to set the \Seen flag for the fetched messages on the server. The mailbox the messages will be retrieved from. If this parameter is omitted, the value of the DefaultMailbox property is used to determine the mailbox to operate on. A string containing the raw mail header of the mail message with the specified UID. The mail header could not be fetched. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. Retrieves the body structure for the mail message with the specified unique identifier (UID). The UID of the mail message to retrieve the body structure for. The mailbox the messages will be retrieved from. If this parameter is omitted, the value of the DefaultMailbox property is used to determine the mailbox to operate on. A string containing the raw body structure of the mail message with the specified UID. The body structure could not be fetched. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. A body structure is a textual description of the layout of a mail message. It is described in some detail in RFC 3501 under 7.4.2 FETCH response. Retrieves the MIME body-part with the specified part number of the multipart message with the specified unique identifier (UID). The UID of the mail message to retrieve a MIME body part for. The part number of the body part to fetch. Set this to true to set the \Seen flag for the fetched messages on the server. The mailbox the messages will be retrieved from. If this parameter is omitted, the value of the DefaultMailbox property is used to determine the mailbox to operate on. A string containing the specified body part of the mail message with the specified UID. The body part could not be fetched. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. Retrieves the raw MIME/RFC822 mail message data for the mail message with the specified UID. The UID of the mail message to retrieve as a MIME/RFC822 string. Set this to true to set the \Seen flag for the fetched message on the server. The mailbox the message will be retrieved from. If this parameter is omitted, the value of the DefaultMailbox property is used to determine the mailbox to operate on. A string containing the raw MIME/RFC822 data of the mail message with the specified UID. The mail message data could not be fetched. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. Retrieves the highest UID in the specified mailbox. The mailbox to find the highest UID for. If this parameter is null, the value of the DefaultMailbox property is used to determine the mailbox to operate on. The highest unique identifier value (UID) in the mailbox. The UID could not be determined. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. The highest UID usually corresponds to the newest message in a mailbox. Copies the mail message with the specified UID to the specified destination mailbox. The UID of the mail message to copy. The name of the mailbox to copy the message to. The mailbox the message will be copied from. If this parameter is omitted, the value of the DefaultMailbox property is used to determine the mailbox to operate on. The destination parameter is null. The mail message could not be copied to the specified destination. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. Copies the mail messages with the specified UIDs to the specified destination mailbox. An enumerable collection of UIDs of the mail messages to copy. The name of the mailbox to copy the messages to. The mailbox the message will be copied from. If this parameter is omitted, the value of the DefaultMailbox property is used to determine the mailbox to operate on. When copying many messages, this method is more efficient than calling for each individual message. The uids parameter or the destination parameter is null. The specified collection of UIDs is empty. The mail messages could not be copied to the specified destination. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. Moves the mail message with the specified UID to the specified destination mailbox. The UID of the mail message to move. The name of the mailbox to move the message into. The mailbox the message will be moved from. If this parameter is omitted, the value of the DefaultMailbox property is used to determine the mailbox to operate on. The destination parameter is null. The mail message could not be moved to the specified destination. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. Moves the mail messages with the specified UIDs to the specified destination mailbox. An enumerable collection of UIDs of the mail messages to move. The name of the mailbox to move the messages into. The mailbox the messages will be moved from. If this parameter is omitted, the value of the DefaultMailbox property is used to determine the mailbox to operate on. When moving many messages, this method is more efficient than calling for each individual message. The uids parameter or the destination parameter is null. The mail messages could not be moved to the specified destination. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. Deletes the mail message with the specified UID. The UID of the mail message to delete. The mailbox the message will be deleted from. If this parameter is omitted, the value of the DefaultMailbox property is used to determine the mailbox to operate on. The mail message could not be deleted. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. Deletes the mail messages with the specified UIDs. An enumerable collection of UIDs of the mail messages to delete. The mailbox the messages will be deleted from. If this parameter is omitted, the value of the DefaultMailbox property is used to determine the mailbox to operate on. When deleting many messages, this method is more efficient than calling for each individual message. The uids parameter is null. The specified collection of UIDs is empty. The mail messages could not be deleted. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. Retrieves the IMAP message flag attributes for the mail message with the specified unique identifier (UID). The UID of the mail message to retrieve the flag attributes for. The mailbox the message will be retrieved from. If this parameter is omitted, the value of the DefaultMailbox property is used to determine the mailbox to operate on. An enumerable collection of message flags set for the message with the specified UID. The mail message flags could not be retrieved. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. Sets the IMAP message flag attributes for the mail message with the specified unique identifier (UID). The UID of the mail message to set the flag attributes for. The mailbox that contains the mail message. If this parameter is null, the value of the DefaultMailbox property is used to determine the mailbox to operate on. One or multiple message flags from the MessageFlag enumeration. The mail message flags could not be set. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. This method replaces the current flag attributes of the message with the specified new flags. If you wish to retain the old attributes, use the method instead. Adds the specified set of IMAP message flags to the existing flag attributes of the mail message with the specified unique identifier (UID). The UID of the mail message to add the flag attributes to. The mailbox that contains the mail message. If this parameter is null, the value of the DefaultMailbox property is used to determine the mailbox to operate on. One or multiple message flags from the MessageFlag enumeration. The mail message flags could not be added. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. This method adds the specified set of flags to the existing set of flag attributes of the message. If you wish to replace the old attributes, use the method instead. Removes the specified set of IMAP message flags from the existing flag attributes of the mail message with the specified unique identifier (UID). The UID of the mail message to remove the flag attributes for. The mailbox that contains the mail message. If this parameter is null, the value of the DefaultMailbox property is used to determine the mailbox to operate on. One or multiple message flags from the MessageFlag enumeration. The mail message flags could not be removed. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The method was called in non-authenticated state, i.e. before logging in. This method removes the specified set of flags from the existing set of flag attributes of the message. If you wish to replace the old attributes, use the method instead. Starts receiving of IMAP IDLE notifications from the IMAP server. An unexpected program condition occured. The IDLE operation could not be completed. The message property of the exception contains the error message returned by the server. The server does not support the IMAP4 IDLE command. There was a failure writing to or reading from the network. The ImapClient object has been disposed. The method was called in non-authenticated state, i.e. before logging in. Calling this method when already receiving idle notifications has no effect. Stops receiving IMAP IDLE notifications from the IMAP server. The IDLE operation could not be completed. The message property of the exception contains the error message returned by the server. The server does not support the IMAP4 IDLE command. There was a failure writing to or reading from the network. The ImapClient object has been disposed. The method was called in non-authenticated state, i.e. before logging in. Calling this method when not receiving idle notifications has no effect. Temporarily pauses receiving IMAP IDLE notifications from the IMAP server. The IDLE operation could not be completed. The message property of the exception contains the error message returned by the server. The server does not support the IMAP4 IDLE command. There was a failure writing to or reading from the network. The ImapClient object has been disposed. The method was called in non-authenticated state, i.e. before logging in. To resume receiving IDLE notifications ResumeIdling must be called. Resumes receiving IMAP IDLE notifications from the IMAP server. An unexpected program condition occured. The IDLE operation could not be completed. The message property of the exception contains the error message returned by the server. The server does not support the IMAP4 IDLE command. There was a failure writing to or reading from the network. The ImapClient object has been disposed. The method was called in non-authenticated state, i.e. before logging in. The main idle loop. Waits for incoming IMAP IDLE notifications and dispatches them as events. This runs in its own thread whenever IMAP IDLE notifications are being received. Blocks on a queue and wakes up whenever a new notification is put into the queue. The notification is then examined and dispatched as an event. Issues a NOOP command to the IMAP server. Called in the context of a System.Timer event when IDLE notifications are being received. This is needed by the IMAP IDLE mechanism to give the server an indication that the connection is still active. Retrieves IMAP QUOTA information for the specified mailbox. The mailbox to retrieve QUOTA information for. If this parameter is null, the value of the DefaultMailbox property is used to determine the mailbox to operate on. An enumerable collection of MailboxQuota objects describing usage and limits of the quota roots for the mailbox. The quota operation could not be completed. The message property of the exception contains the error message returned by the server. The ImapClient object has been disposed. There was a failure writing to or reading from the network. The IMAP4 QUOTA extension is not supported by the server. The method was called in non-authenticated state, i.e. before logging in. Releases all resources used by the current instance of the ImapClient class. Releases all resources used by the current instance of the ImapClient class, optionally disposing of managed resource. true to dispose of managed resources, otherwise false. Asserts the instance has not been disposed of and is in a valid state. The ImapClient object has been disposed. The method was called in non-authenticated state, i.e. before logging in. The default mailbox to operate on. The property is being set and the value is null. The property is being set and the value is the empty string. The default value for this property is "INBOX" which is a special name reserved to mean "the primary mailbox for this user on this server". Determines whether the client is authenticated with the server. The event that is raised when a new mail message has been received by the server. To probe a server for IMAP IDLE support, the method can be used, specifying "IDLE" for the capability parameter. Please note that the event handler will be executed on a threadpool thread. This example demonstrates how to receive IMAP IDLE notifications. ImapClient Client = new ImapClient("imap.gmail.com", 993, "My_UsernamMe", "My_Password", true, AuthMethod.Login); // Make sure our server actually supports IMAP IDLE. if(!Client.Supports("IDLE")) throw new Exception("This server does not support IMAP IDLE"); // Our event handler will be called whenever a new message is received // by the server. Client.NewMessage += new EventHandler<IdleMessageEventArgs>(OnNewMessage); // ......... Client.Dispose(); // ........ void OnNewMessage(object sender, IdleMessageEventArgs e) { Console.WriteLine("Received a new message!"); Console.WriteLine("Total number of messages in the mailbox: " + e.MessageCount); } The event that is raised when a message has been deleted on the server. To probe a server for IMAP IDLE support, the method can be used, specifying "IDLE" for the capability parameter. Please note that the event handler will be executed on a threadpool thread. This example demonstrates how to receive IMAP IDLE notifications. ImapClient Client = new ImapClient("imap.gmail.com", 993, "My_UsernamMe", "My_Password", true, AuthMethod.Login); // Make sure our server actually supports IMAP IDLE. if(!Client.Supports("IDLE")) throw new Exception("This server does not support IMAP IDLE"); // Our event handler will be called whenever a message is deleted on the server. Client.MessageDeleted += new EventHandler<IdleMessageEventArgs>(OnMessageDeleted); // ......... // Don't forget to dispose the client once you're done with it. Client.Dispose(); // ........ void OnMessageDeleted(object sender, IdleMessageEventArgs e) { Console.WriteLine("A mail message was deleted on the server!"); Console.WriteLine("Total number of mail messages in the mailbox: " + e.MessageCount); } The event that is raised when an I/O exception occurs in the idle-thread. An I/O exception can occur if the underlying network connection has been reset or the server unexpectedly closed the connection. A delegate which is invoked during a call to GetMessage or GetMessages for every MIME part in a multipart mail message. The delegate can examine the MIME body part and decide to either include it in the returned mail message or dismiss it. A MIME body part of a mail message which consists of multiple parts. true to include the body part in the returned MailMessage object, or false to skip it. The exception that is thrown when an unexpected response is received from the server. Initializes a new instance of the BadServerResponseException class Initializes a new instance of the BadServerResponseException class with its message string set to . A description of the error. The content of message is intended to be understood by humans. Initializes a new instance of the BadServerResponseException class with its message string set to and a reference to the inner exception that is the cause of this exception. A description of the error. The content of message is intended to be understood by humans. The exception that is the cause of the current exception. Initializes a new instance of the BadServerResponseException class with the specified serialization and context information. An object that holds the serialized object data about the exception being thrown. An object that contains contextual information about the source or destination. The exception that is thrown when the supplied credentials were rejected by the server. Initializes a new instance of the InvalidCredentialsException class Initializes a new instance of the InvalidCredentialsException class with its message string set to . A description of the error. The content of message is intended to be understood by humans. Initializes a new instance of the InvalidCredentialsException class with its message string set to and a reference to the inner exception that is the cause of this exception. A description of the error. The content of message is intended to be understood by humans. The exception that is the cause of the current exception. Initializes a new instance of the InvalidCredentialsException class with the specified serialization and context information. An object that holds the serialized object data about the exception being thrown. An object that contains contextual information about the source or destination. The exception that is thrown when a client has not authenticated with the server and attempts to call a method which can only be called when authenticated. Initializes a new instance of the NotAuthenticatedException class Initializes a new instance of the NotAuthenticatedException class with its message string set to . A description of the error. The content of message is intended to be understood by humans. Initializes a new instance of the NotAuthenticatedException class with its message string set to and a reference to the inner exception that is the cause of this exception. A description of the error. The content of message is intended to be understood by humans. The exception that is the cause of the current exception. Initializes a new instance of the NotAuthenticatedException class with the specified serialization and context information. An object that holds the serialized object data about the exception being thrown. An object that contains contextual information about the source or destination. Provides access to status information such as the total number of messages and quota information for a mailbox. The terms "mailbox" and "folder" can be used interchangeably and refer to the IMAP concept of multiple server-side directories into which messages can be stored (such as "Inbox", "Sent Items", "Trash", etc.). Initializes a new instance of the MailboxInfo class with the specified values. The IMAP name of the mailbox. The IMAP flags set on this mailbox. The number of messages in the mailbox. The number of unread messages in the mailbox. The next unique identifier (UID) of the mailbox. The amount of used storage of the mailbox, in bytes. The amount of free storage of the mailbox, in bytes. Returns the name of the mailbox. The name of the mailbox The name of the mailbox. An enumerable collection of flags set on the mailbox. The total number of messages in the mailbox. The number of unread (unseen) messages in the mailbox. The next unique identifier value of the mailbox. The amount of used storage in the mailbox, measured in bytes. Not all IMAP servers support the retrieval of quota information. If it is not possible to retrieve the amount of used storage, this property will be 0. The amount of free storage in the mailbox, measured in bytes. Not all IMAP servers support the retrieval of quota information. If it is not possible to retrieve the amount of free storage, this property will be 0. Defines possible attributes for mailboxes. An IMAP mailbox can have a number of flags (read: attributes) set on it, indicating its designated purpose (such as "Spam" or "Drafts"). This is especially convenient when dealing with international mailbox names, because, by examining the associated flags, the mailbox purpose can be determined, even if the mailbox name provides no useful indication. Unfortunately, as with many things IMAP, reporting the flags described here is an optional extension (XLIST) to the IMAP protocol and as such may or may not be supported by an IMAP server. The mailbox presents a view on all messages in the user's message store. The mailbox is used to archive messages. The meaning of an "archival" mailbox is server dependent. The mailbox is used to hold draft messages, typically these are messages that are being composed but have not yet been sent. The mailbox is used to hold copies of messages that have been sent. The mailbox is where messages deemed to be junk mail (spam) are held. The mailbox is used to hold messages that have been deleted or marked for deletion. Represents an IMAP QUOTA entry for a resource which typically consists of a resource name, the current usage of the resource, and the resource limit. Initializes a new instance of the MailboxQuota class with the specified values. The name of the resource this MailboxQuota instance describes. The current usage of the resource in units of 1024 bytes. The limit of the resource in units of 1024 bytes. The name of the resource this MailboxQuota instance describes. The current usage of the resource this MailboxQuota instance describes, in bytes. The limit of the resource this MailboxQuota instance describes, in bytes. Represents the status information of a mailbox which can be constructed from the server response to a STATUS command. Initializes a new MailboxStatus instance with the specified number of total and unread messages. The total number of messages in the mailbox. The number of unread (unseen) messages in the mailbox. The next unique identifier value of the mailbox The next unique identifier value of the mailbox. The total number of messages in the mailbox. The number of unread (unseen) messages in the mailbox. Adds extension methods to the MailMessage class of the .NET Framework. Most of the methods are only used internally and are not visible outside of the S22.Imap assembly. Returns the date and time the mail message was composed. The MailMessage instance to return the date and time for. The date and time the mail message was composed, or null if the mail message does not contain any date information. Constructs a textual representation of a mail message from the specified MailMessage instance compliant with the RFC822 and MIME standards. The MailMessage instance to construct the textual representation from. An RFC822/MIME-compliant string representing the specified mail message. The From property is null or has not been properly initialized. Builds a RFC822/MIME-compliant mail header from the specified MailMessage instance and returns it as a NameValueCollection. The MailMessage instance to build the header from. A NameValueCollection representing the RFC822/MIME mail header fields. A map for mapping the values of the MailPriority enumeration to their corresponding MIME priority values as defined in RFC2156. A map for mapping the values of the MailPriority enumeration to their corresponding MIME importance values as defined in RFC2156. Takes a unicode string and encodes it using Q-encoding. The string to encode. The input string encoded as Q-encoded string containing only ASCII characters. Takes a unicode string and encodes it using Base64-encoding. The string to encode. The input string encoded as Base64-encoded string containing only ASCII characters. Creates an address string from the specified MailAddress instance in compliance with the address specification as outlined in RFC2822 under section 3.4 The MailAddress instance to create the address string from. An address string as is used in RFC822 mail headers. Generates a unique sequence of characters for indicating a boundary between parts in a multipart message. A unique content boundary string. Builds an RFC822/MIME-compliant mail body from the specified MailMessage instance and returns it as a formatted string. The MailMessage instance to build the mail body from. The RFC822/MIME mail header to use for constructing the mail body. An RFC822/MIME-compliant mail body as a string. According to RFC2822 each line of a mail message should at max be 78 characters in length excluding carriage return and newline characters. This method accounts for that and ensures line breaks are inserted to meet this requirement. Adds a body part to the specified Stringbuilder object composed from the Body and BodyEncoding properties of the MailMessage class. The Stringbuilder to append the body part to. The MailMessage instance to build the body part from. The RFC822/MIME mail header to use for constructing the mail body. Set to true to append body headers before adding the actual body part content. Creates a MIME body part from an entry of the AlternateView or Attachments collection of a MailMessage instance and appends it to the specified Stringbuilder instance. The Stringbuilder instance to append the body part to. An entry from either the AlternateView or the Attachments collection of a MailMessage instance. Creates a nested multipart/alternative part which contains all entries from the AlternateViews collection of the specified MailMessage instance as well as the body part for the Body and BodyEncoding properties of the specified MailMessage instance. The StringBuilder instance to append to. The MailMessage instance whose AlternateView collection will be added to the nested multipart/alternative part. The RFC822/MIME mail header to use for constructing the mail body. This is used if the MailMessage instance contains both alternative views and attachments. In this case the created RFC822/MIME mail message will contain nested body parts. Creates a nested multipart/mixed part which contains all entries from the Attachments collection of the specified MailMessage instance. The StringBuilder instance to append to. The MailMessage instance whose Attachments collection will be added to the nested multipart/mixed part. This is used if the MailMessage instance contains both alternative views and attachments. In this case the created RFC822/MIME mail message will contain nested body parts. A helper class for reading mail message data and building a MailMessage instance out of it. Creates a new empty instance of the MailMessage class from a string containing a raw mail message header. The mail header to create the MailMessage instance from. A MailMessage instance with initialized Header fields but without any content. Creates a new instance of the MailMessage class from a string containing raw RFC822/MIME mail message data. The mail message data to create the MailMessage instance from. An initialized instance of the MailMessage class. This is used when fetching entire messages instead of the partial-fetch mechanism because it saves redundant round-trips to the server. Parses the mail header of a mail message and returns it as a NameValueCollection. The mail header to parse. A NameValueCollection containing the header fields as keys with their respective values as values. Strips RFC822/MIME comments from the specified string. The string to strip comments from. A new string stripped of any comments. Parses a MIME header field which can contain multiple 'parameter = value' pairs (such as Content-Type: text/html; charset=iso-8859-1). The header field to parse. A NameValueCollection containing the parameter names as keys with the respective parameter values as values. The value of the actual field disregarding the 'parameter = value' pairs is stored in the collection under the key "value" (in the above example of Content-Type, this would be "text/html"). Parses a mail header address-list field such as To, Cc and Bcc which can contain multiple email addresses. The address-list field to parse An array of MailAddress objects representing the parsed mail addresses. Splits the specified address-list into individual parts consisting of a mail address and optionally a display-name. The address-list to split into parts. An enumerable collection of parts. Parses a mail message identifier from a string. The field to parse the message id from The field argument does not contain a valid message identifier. The parsed message id. A message identifier (msg-id) is a globally unique identifier for a message. Parses the priority of a mail message which can be specified as part of the header information. The mail header priority value. The value can be null in which case a "normal priority" is returned. A value from the MailPriority enumeration corresponding to the specified mail priority. If the passed priority value is null or invalid, a normal priority is assumed and MailPriority.Normal is returned. Sets the address fields (From, To, CC, etc.) of a MailMessage object using the specified mail message header information. The MailMessage instance to operate on. A collection of mail and MIME headers. Adds a body part to an existing MailMessage instance. Extension method for the MailMessage class. The body part to add to the MailMessage instance. The content of the body part. Creates an instance of the Attachment class used by the MailMessage class to store mail message attachments. The MIME body part to create the attachment from. An array of bytes composing the content of the attachment. An initialized instance of the Attachment class. Creates an instance of the AlternateView class used by the MailMessage class to store alternate views of the mail message's content. The MIME body part to create the alternate view from. An array of bytes composing the content of the alternate view. An initialized instance of the AlternateView class. Parses the body part of a MIME/RFC822 mail message. The body of the mail message. The header of the mail message whose body will be parsed. An array of initialized MIMEPart instances representing the body parts of the mail message. Parses the body of a multipart MIME mail message. An instance of the StringReader class initialized with a string containing the body of the mail message. The boundary value as is present as part of the Content-Type header field in multipart mail messages. An array of initialized MIMEPart instances representing the various parts of the MIME mail message. Glue method to create a bodypart from a MIMEPart instance. The MIMEPart instance to create the bodypart instance from. An initialized instance of the Bodypart class. Defines possible attributes for mail messages on an IMAP server. Indicates that the message has been read. Indicates that the message has been answered. Indicates that the message is "flagged" for urgent/special attention. Indicates that the message has been marked as "deleted" and will be removed upon the next call to the Expunge method. Indicates that the message has not completed composition and is marked as a draft. Indicates that the message has recently arrived in the mailbox. Represents a part of a MIME multi-part message. Each part consists of its own content header and a content body. A collection containing the content header information as key-value pairs. A string containing the content body of the part. A thread-safe Queue. Adds an object to the end of the queue. The object to add to the queue. Removes and returns the object at the beginning of the queue. If the queue is empty, the method blocks the calling thread until an object is put into the queue by another thread. The object that was removed from the beginning of the queue. Adds extension methods to the BinaryReader class to simplify the deserialization of NTLM messages. Reads an ASCII-string of the specified length from this instance. Extension method for the BinaryReader class. The number of bytes to read from the underlying stream. A string decoded from the bytes read from the underlying stream using the ASCII character set. The NTLM flags which are contained in a bitfield within the header of an NTLM message. Indicates that Unicode strings are supported for use in security buffer data. Indicates that OEM strings are supported for use in security buffer data. Requests that the server's authentication realm be included in the Type 2 message. Specifies that authenticated communication between the client and server should carry a digital signature (message integrity). Specifies that authenticated communication between the client and server should be encrypted (message confidentiality). Indicates that datagram authentication is being used. Indicates that the Lan Manager Session Key should be used for signing and sealing authenticated communications. This flag's usage has not been identified. Indicates that NTLM authentication is being used. Sent by the client in the Type 3 message to indicate that an anonymous context has been established. This also affects the response fields. Sent by the client in the Type 1 message to indicate that the name of the domain in which the client workstation has membership is included in the message. This is used by the server to determine whether the client is eligible for local authentication. Sent by the client in the Type 1 message to indicate that the client workstation's name is included in the message. This is used by the server to determine whether the client is eligible for local authentication. Sent by the server to indicate that the server and client are on the same machine. Implies that the client may use the established local credentials for authentication instead of calculating a response to the challenge. Indicates that authenticated communication between the client and server should be signed with a "dummy" signature. Sent by the server in the Type 2 message to indicate that the target authentication realm is a domain. Sent by the server in the Type 2 message to indicate that the target authentication realm is a server. Sent by the server in the Type 2 message to indicate that the target authentication realm is a share. Presumably, this is for share-level authentication. Usage is unclear. Indicates that the NTLM2 signing and sealing scheme should be used for protecting authenticated communications. Note that this refers to a particular session security scheme, and is not related to the use of NTLMv2 authentication. This flag can, however, have an effect on the response calculations. This flag's usage has not been identified. This flag's usage has not been identified. This flag's usage has not been identified. Sent by the server in the Type 2 message to indicate that it is including a Target Information block in the message. The Target Information block is used in the calculation of the NTLMv2 response. Indicates that 128-bit encryption is supported. Indicates that the client will provide an encrypted master key in the "Session Key" field of the Type 3 message. Indicates that 56-bit encryption is supported. Represents the data contained in the target information block of an NTLM type 2 message. The server name. The domain name. The fully-qualified DNS host name. The fully-qualified DNS domain name. Describes the different versions of the Type 2 message that have been observed. The version is unknown. This form is seen in older Win9x-based systems. This form is seen in most out-of-box shipping versions of Windows. This form was introduced in a relatively recent Service Pack, and is seen on currently-patched versions of Windows 2000, Windows XP, and Windows 2003. Indicates the type of data in Type 2 target information blocks. Signals the end of the target information block. The data in the information block contains the server name. The data in the information block contains the domain name. The data in the information block contains the DNS hostname. The data in the information block contans the DNS domain name. Computes the MD4 hash value for the input data. Courtesy of Keith Wood. Describes the different types of NTLM messages. An NTLM type 1 message is the initial client response to the server. An NTLM type 2 message is the challenge sent by the server in response to an NTLM type 1 message. An NTLM type 3 message is the challenge response sent by the client in response to an NTLM type 2 message. Indicates the version and build number of the operating system. Default constructor. Creates a new instance of the OSVersion class using the specified values. The major version of the operating system. The minor version of the operating system. The build number of the operating systen. Serializes this instance of the OSVersion class to an array of bytes. An array of bytes representing this instance of the OSVersion class. The major version number of the operating system. The minor version number of the operating system. The build number of the operating system. Contains methods for calculating the various Type 3 challenge responses. Computes the LM-response to the challenge sent as part of an NTLM type 2 message. The challenge sent by the server. The user account password. An array of bytes representing the response to the specified challenge. Computes the NTLM-response to the challenge sent as part of an NTLM type 2 message. The challenge sent by the server. The user account password. An array of bytes representing the response to the specified challenge. Computes the NTLMv2-response to the challenge sent as part of an NTLM type 2 message. The name of the authentication target. The user account name to authenticate with. The user account password. The target information block from the NTLM type 2 message. The challenge sent by the server. A random 8-byte client nonce. An array of bytes representing the response to the specified challenge. Computes the LMv2-response to the challenge sent as part of an NTLM type 2 message. The name of the authentication target. The user account to authenticate with. The user account password. The challenge sent by the server. A random 8-byte client nonce. An array of bytes representing the response to the specified challenge. Creates the LM Hash of the specified password. The password to create the LM Hash of. The LM Hash of the given password, used in the calculation of the LM Response. Thrown if the password argument is null. Creates a DES encryption key from the specified key material. The key material to create the DES encryption key from. An offset into the byte array at which to extract the key material from. A 56-bit DES encryption key as an array of bytes. Applies odd parity to the specified byte array. The byte array to apply odd parity to. A reference to the byte array. Creates the LM Response from the specified hash and Type 2 challenge. An LM or NTLM hash. The server challenge from the Type 2 message. The challenge response as an array of bytes. Thrown if the hash or the challenge parameter is null. Creates the NTLM Hash of the specified password. The password to create the NTLM hash of. The NTLM hash for the specified password. Thrown if the password parameter is null. Creates the NTLMv2 Hash of the specified target, username and password values. The name of the authentication target as is specified in the target name field of the NTLM type 3 message. The user account name. The password for the user account. The NTLMv2 hash for the specified input values. Thrown if the username or the password parameter is null. Returns the current time as the number of tenths of a microsecond since January 1, 1601. The current time as the number of tenths of a microsecond since January 1, 1601. Creates the "blob" data block which is part of the NTLMv2 challenge response. The target information block from the NTLM type 2 message. A random 8-byte client nonce. The blob, used in the calculation of the NTLMv2 Response. Creates the LMv2 Response from the given NTLMv2 hash, client data, and Type 2 challenge. The NTLMv2 Hash. The client data (blob or client nonce). The server challenge from the Type 2 message. The response which is either for NTLMv2 or LMv2, depending on the client data. Represents an NTLM security buffer, which is a structure used to point to a buffer of binary data within an NTLM message. Creates a new instance of the SecurityBuffer class using the specified values. The length of the buffer described by this instance of the SecurityBuffer class. The offset at which the buffer starts, in bytes. Thrown if the length value exceeds the maximum value allowed. The security buffer structure stores the length value as a 2-byte short value. Creates a new instance of the SecurityBuffer class using the specified values. The data of the buffer described by this instance of the SecurityBuffer class. The offset at which the buffer starts, in bytes. Thrown if the length of the data buffer exceeds the maximum value allowed. The security buffer structure stores the buffer length value as a 2-byte short value. Serializes this instance of the SecurityBuffer into an array of bytes. A byte array representing this instance of the SecurityBuffer class. The length of the buffer content in bytes (may be zero). The allocated space for the buffer in bytes (typically the same as the length). The offset from the beginning of the NTLM message to the start of the buffer, in bytes. Represents an NTLM Type 1 Message. The NTLM message signature which is always "NTLMSSP". The NTML message type which is always 1 for an NTLM Type 1 message. Creates a new instance of the Type1Message class using the specified domain and workstation names. The domain in which the client's workstation has membership. The client's workstation name. Thrown if the domain or the workstation parameter is null. Thrown if the domain or the workstation name exceeds the maximum allowed string length. The domain as well as the workstation name is restricted to ASCII characters and must not be longer than 65536 characters. Serializes this instance of the Type1 class to an array of bytes. An array of bytes representing this instance of the Type1 class. The NTLM flags set on this instance. The supplied domain name as an array of bytes in the ASCII range. The offset within the message where the domain name data starts. The supplied workstation name as an array of bytes in the ASCII range. The offset within the message where the workstation name data starts. The length of the supplied workstation name as a 16-bit short value. Contains information about the client's OS version. Represents an NTLM Type 2 Message. The NTLM message signature which is always "NTLMSSP". The NTML message type which is always 2 for an NTLM Type 2 message. Private constructor. Deserializes a Type 2 message instance from the specified buffer of bytes. The buffer containing a sequence of bytes representing an NTLM Type 2 message. An initialized instance of the Type2 class. Thrown if an error occurs during deserialization of the Type 2 message. Determines the version of an NTLM type 2 message. The target offset field of the NTLM type 2 message. A value from the Type2Version enumeration. Reads the OS information data present in version 3 of an NTLM type 2 message from the specified BinaryReader. The BinaryReader instance to read from. An initialized instance of the OSVersion class. Reads the target information data present in version 2 and 3 of an NTLM type 2 message from the specified BinaryReader. The BinaryReader instance to read from. An initialized instance of the Type2TargetInformation class. Retrieves the target name from the specified byte array. A byte array containing the target name. If true the target name will be decoded using UTF-16 unicode encoding. The challenge is an 8-byte block of random data. The target name of the authentication target. The NTLM flags set on this message. The SSPI context handle when a local call is being made, otherwise null. Contains the data present in the OS version structure. The version of this Type 2 message instance. Contains the data present in the target information block. Contains the raw data present in the target information block. Represents an NTLM Type 3 Message. The NTLM message signature which is always "NTLMSSP". The NTML message type which is always 3 for an NTLM Type 3 message. Creates a new instance of an NTLM type 3 message using the specified values. The Windows account name to use for authentication. The Windows account password to use for authentication. The challenge received from the server as part of the NTLM type 2 message. The client's workstation name. Set to true to send an NTLMv2 challenge response. The authentication realm in which the authenticating account has membership. The target information block from the NTLM type 2 message. The target name is a domain name for domain accounts, or a server name for local machine accounts. All security buffers will be encoded as Unicode. Creates a new instance of an NTLM type 3 message using the specified values. The Windows account name to use for authentication. The Windows account password to use for authentication. The challenge received from the server as part of the NTLM type 2 message. Set this to true, if Unicode encoding has been negotiated between client and server. The client's workstation name. Set to true to send an NTLMv2 challenge response. The authentication realm in which the authenticating account has membership. The target information block from the NTLM type 2 message. The target name is a domain name for domain accounts, or a server name for local machine accounts. Thrown if the username, password or challenge parameters are null. Serializes this instance of the Type3 class to an array of bytes. An array of bytes representing this instance of the Type3 class. Returns a random 8-byte cnonce value. A random 8-byte cnonce value. The NTLM flags set on this instance. The "Lan Manager" challenge response. The offset at which the LM challenge response data starts. The NTLM challenge response. The offset at which the NTLM challenge response data starts. The authentication realm in which the authenticating account has membership. The offset at which the target name data starts. The authenticating account name. The offset at which the username data starts. The client workstation's name. The offset at which the client workstation's name data starts. The session key value which is used by the session security mechanism during key exchange. The offset at which the session key data starts. Contains the data present in the OS version structure. The encoding used for transmitting the contents of the various security buffers. Implements the Sasl Cram-Md5 authentication method as described in RFC 2195. Private constructor for use with Sasl.SaslFactory. Creates and initializes a new instance of the SaslCramMd5 class using the specified username and password. The username to authenticate with. The plaintext password to authenticate with. Thrown if the username or the password parameter is null. Thrown if the username parameter is empty. Computes the client response to the specified Cram-Md5 challenge. The challenge sent by the server The response to the Cram-Md5 challenge. Thrown if the response could not be computed. True if the authentication exchange between client and server has been completed. The IANA name for the Cram-Md5 authentication mechanism as described in RFC 2195. The username to authenticate with. The password to authenticate with. Implements the Sasl Cram-Md5 authentication method as described in RFC 2831. The client nonce value used during authentication. Cram-Md5 involves several steps. Private constructor for use with Sasl.SaslFactory. Internal constructor used for unit testing. The username to authenticate with. The plaintext password to authenticate with. The client nonce value to use. Thrown if the username or the password parameter is null. Thrown if the username parameter is empty. Creates and initializes a new instance of the SaslDigestMd5 class using the specified username and password. The username to authenticate with. The plaintext password to authenticate with. Thrown if the username or the password parameter is null. Thrown if the username parameter is empty. Computes the client response to the specified Digest-Md5 challenge. The challenge sent by the server The response to the Digest-Md5 challenge. Thrown if the response could not be computed. Parses the challenge string sent by the server in response to a Digest-Md5 authentication request. The challenge sent by the server as part of "Step One" of the Digest-Md5 authentication mechanism. An initialized NameValueCollection instance made up of the attribute/value pairs contained in the challenge. Thrown if the challenge parameter is null. Refer to RFC 2831 section 2.1.1 for a detailed description of the format of the challenge sent by the server. Computes the "response-value" hex-string which is part of the Digest-MD5 challenge-response. A collection containing the attributes and values of the challenge sent by the server. The cnonce value to use for computing the response-value. The "digest-uri" string to use for computing the response-value. The username to use for computing the response-value. The password to use for computing the response-value. A string containing a hash-value which is part of the response sent by the client. Refer to RFC 2831, section 2.1.2.1 for a detailed description of the computation of the response-value. Calculates the MD5 hash value for the specified string. The string to calculate the MD5 hash value for. The encoding to employ for encoding the characters in the specified string into a sequence of bytes for which the MD5 hash will be calculated. An MD5 hash as a 32-character hex-string. Thrown if the input string is null. Encloses the specified string in double-quotes. The string to enclose in double-quote characters. The enclosed string. Generates a random cnonce-value which is a "client-specified data string which must be different each time a digest-response is sent". A random "cnonce-value" string. True if the authentication exchange between client and server has been completed. The IANA name for the Digest-Md5 authentication mechanism as described in RFC 2195. The username to authenticate with. The password to authenticate with. Implements the Sasl NTLM authentication method which is used in various Microsoft network protocol implementations. Implemented with the help of the excellent documentation on NTLM composed by Eric Glass. NTLM involves several steps. Private constructor for use with Sasl.SaslFactory. Creates and initializes a new instance of the SaslNtlm class using the specified username and password. The username to authenticate with. The plaintext password to authenticate with. Thrown if the username or the password parameter is null. Thrown if the username parameter is empty. Computes the client response to the specified NTLM challenge. The challenge sent by the server The response to the NTLM challenge. Thrown if the response could not be computed. Computes the initial client response to an NTLM challenge. The challenge sent by the server. Since NTLM expects an initial client response, this will usually be empty. The initial response to the NTLM challenge. Thrown if the response could not be computed. Computes the actual challenge response to an NTLM challenge which is sent as part of an NTLM type 2 message. The challenge sent by the server. The response to the NTLM challenge. Thrown if the challenge response could not be computed. True if the authentication exchange between client and server has been completed. The IANA name for the NTLM authentication mechanism. The username to authenticate with. The password to authenticate with. Implements the Sasl NTLMv2 authentication method which addresses some of the security issues present in NTLM version 1. Private constructor for use with Sasl.SaslFactory. Creates and initializes a new instance of the SaslNtlmv2 class using the specified username and password. The username to authenticate with. The plaintext password to authenticate with. Thrown if the username or the password parameter is null. Thrown if the username parameter is empty. Computes the client response to the specified NTLM challenge. The challenge sent by the server The response to the NTLM challenge. Thrown if the response could not be computed. Computes the actual challenge response to an NTLM challenge which is sent as part of an NTLM type 2 message. The challenge sent by the server. The response to the NTLM challenge. Thrown if the challenge response could not be computed. Implements the Sasl OAuth authentication method. Private constructor for use with Sasl.SaslFactory. Creates and initializes a new instance of the SaslOAuth class using the specified username and password. The username to authenticate with. Thrown if the accessToken parameter is null. Thrown if the accessToken parameter is empty. Computes the client response for a OAuth challenge. The challenge sent by the server. The response to the OAuth challenge. Thrown if the response could not be computed. True if the authentication exchange between client and server has been completed. The IANA name for the OAuth authentication mechanism. The access token to authenticate with. Implements the Sasl OAuth 2.0 authentication method. The server sends an error response in case authentication fails which must be acknowledged. Private constructor for use with Sasl.SaslFactory. Creates and initializes a new instance of the SaslOAuth class using the specified username and password. The username to authenticate with. The username to authenticate with. Thrown if the username or the accessToken parameter is null. Thrown if the username or the accessToken parameter is empty. Computes the client response to an XOAUTH2 challenge. The challenge sent by the server. The response to the OAuth2 challenge. Thrown if the response could not be computed. Computes the initial client response to an XOAUTH2 challenge. The challenge sent by the server. The response to the OAuth2 challenge. Thrown if the response could not be computed. True if the authentication exchange between client and server has been completed. The IANA name for the OAuth 2.0 authentication mechanism. The username to authenticate with. The access token to authenticate with. Implements the Sasl Plain authentication method as described in RFC 4616. Private constructor for use with Sasl.SaslFactory. Creates and initializes a new instance of the SaslPlain class using the specified username and password. The username to authenticate with. The plaintext password to authenticate with. Thrown if the username or the password parameter is null. Thrown if the username parameter is empty. Computes the client response for a plain-challenge. The challenge sent by the server. For the "plain" mechanism this will usually be empty. The response for the "plain"-challenge. Thrown if the response could not be computed. True if the authentication exchange between client and server has been completed. The IANA name for the Plain authentication mechanism as described in RFC 4616. The username to authenticate with. The plain-text password to authenticate with. The exception is thrown when a Sasl-related error or unexpected condition occurs. Initializes a new instance of the SaslException class Initializes a new instance of the SaslException class with its message string set to . A description of the error. The content of message is intended to be understood by humans. Initializes a new instance of the SaslException class with its message string set to and a reference to the inner exception that is the cause of this exception. A description of the error. The content of message is intended to be understood by humans. The exception that is the cause of the current exception. Initializes a new instance of the SaslException class with the specified serialization and context information. An object that holds the serialized object data about the exception being thrown. An object that contains contextual information about the source or destination. A factory class for producing instances of Sasl mechanisms. Creates an instance of the Sasl mechanism with the specified name. The name of the Sasl mechanism of which an instance will be created. An instance of the Sasl mechanism with the specified name. Thrown if the name parameter is null. Thrown if the Sasl mechanism with the specified name is not registered with Sasl.SaslFactory. Registers a Sasl mechanism with the factory using the specified name. The name with which to register the Sasl mechanism with the factory class. The type of the class implementing the Sasl mechanism. The implementing class must be a subclass of Sasl.SaslMechanism. Thrown if the name or the t parameter is null. Thrown if the class represented by the specified type does not derive from Sasl.SaslMechanism. Thrown if the Sasl mechanism could not be registered with the factory. Refer to the inner exception for error details. Static class constructor. Initializes static properties. A dictionary of Sasl mechanisms registered with the factory class. Represents chainable search conditions that can be used with the Search method. Finds all messages in the mailbox. A SearchCondition object representing the "all" search criterion. Finds messages that contain the specified string in the header or body of the message. String to search messages for. A SearchCondition object representing the "text" search criterion. The text parameter is null. Finds messages that contain the specified string in the envelope structure's BCC field. String to search the envelope structure's BCC field for. A SearchCondition object representing the "BCC" search criterion. The text parameter is null. Finds messages whose internal date (disregarding time and timezone) is earlier than the specified date. The date to compare the message's internal date with. A SearchCondition object representing the "Before" search criterion. Finds messages that contain the specified string in the body of the message. String to search the message body for. A SearchCondition object representing the "Body" search criterion. The text parameter is null. Finds messages that contain the specified string in the envelope structure's CC field. String to search the envelope structure's CC field for. A SearchCondition object representing the "CC" search criterion. The text parameter is null. Finds messages that contain the specified string in the envelope structure's FROM field. String to search the envelope structure's FROM field for. A SearchCondition object representing the "FROM" search criterion. The text parameter is null. Finds messages that have a header with the specified field-name and that contains the specified string in the text of the header. field-name of the header to search for. String to search for in the text of the header. A SearchCondition object representing the "HEADER" search criterion. If the string to search is zero-length, this matches all messages that have a header line with the specified field-name regardless of the contents. The name parameter or the text parameter is null. Finds messages with the specified keyword flag set. The keyword flag to search for. A SearchCondition object representing the "KEYWORD" search criterion. The text parameter is null. Finds messages with a size larger than the specified number of bytes. Minimum size, in bytes a message must have to be included in the search result. A SearchCondition object representing the "LARGER" search criterion. Finds messages with a size smaller than the specified number of bytes. Maximum size, in bytes a message must have to be included in the search result. A SearchCondition object representing the "SMALLER" search criterion. Finds messages whose Date: header (disregarding time and timezone) is earlier than the specified date. The date to compare the Date: header field with. A SearchCondition object representing the "SENTBEFORE" search criterion. Finds messages whose Date: header (disregarding time and timezone) is within the specified date. The date to compare the Date: header field with. A SearchCondition object representing the "SENTON" search criterion. Finds messages whose Date: header (disregarding time and timezone) is within or later than the specified date. The date to compare the Date: header field with. A SearchCondition object representing the "SENTSINCE" search criterion. Finds messages that contain the specified string in the envelope structure's SUBJECT field. String to search the envelope structure's SUBJECT field for. A SearchCondition object representing the "SUBJECT" search criterion. The text parameter is null. Finds messages that contain the specified string in the envelope structure's TO field. String to search the envelope structure's TO field for. A SearchCondition object representing the "TO" search criterion. The text parameter is null. Finds messages with unique identifiers corresponding to the specified unique identifier set. One or several unique identifiers (UID). A SearchCondition object representing the "UID" search criterion. Finds messages with a unique identifier greater than the specified unique identifier. A unique identifier (UID). A SearchCondition object representing the "UID" search criterion. Because of the nature of the IMAP search mechanism, the result set will always contain the UID of the last message in the mailbox, even if said UID is smaller than the UID specified. Finds messages with a unique identifier less than the specified unique identifier. A unique identifier (UID). A SearchCondition object representing the "UID" search criterion. Finds messages that do not have the specified keyword flag set. The IMAP keyword flag to search for. A SearchCondition object representing the "UNKEYWORD" search criterion. The text parameter is null. Finds messages that have the \Answered flag set. A SearchCondition object representing the "ANSWERED" search criterion. Finds messages that have the \Deleted flag set. A SearchCondition object representing the "DELETED" search criterion. Finds messages that have the \Draft flag set. A SearchCondition object representing the "DRAFT" search criterion. Finds messages that have the \Flagged flag set. A SearchCondition object representing the "FLAGGED" search criterion. Finds messages that have the \Recent flag set but not the \Seen flag. A SearchCondition object representing the "NEW" search criterion. Finds messages that do not have the \Recent flag set. A SearchCondition object representing the "OLD" search criterion. Finds messages that have the \Recent flag set. A SearchCondition object representing the "RECENT" search criterion. Finds messages that have the \Seen flag set. A SearchCondition object representing the "SEEN" search criterion. Finds messages that do not have the \Answered flag set. A SearchCondition object representing the "UNANSWERED" search criterion. Finds messages that do not have the \Deleted flag set. A SearchCondition object representing the "UNDELETED" search criterion. Finds messages that do not have the \Draft flag set. A SearchCondition object representing the "UNDRAFT" search criterion. Finds messages that do not have the \Flagged flag set. A SearchCondition object representing the "UNFLAGGED" search criterion. Finds messages that do not have the \Seen flag set. A SearchCondition object representing the "UNSEEN" search criterion. Logically ANDs multiple search conditions, meaning a message will only be included in the search result if both of the ANDed conditions are met. A search condition to logically AND this SearchCondition instance with. A new SearchCondition instance which can be further chained with other search conditions. The other parameter is null. Logically negates search conditions, meaning a message will only be included in the search result if the specified conditions are not met. A search condition that must not be met by a message for it to be included in the search result set. A new SearchCondition instance which can be further chained with other search conditions. The other parameter is null. Logically ORs multiple search conditions, meaning a message will be included in the search result if it meets at least either of the conditions. A search condition to logically OR this SearchCondition instance with. A new SearchCondition instance which can be further chained with other search conditions. The other parameter is null. Joins two SearchCondition objects into a new one using the specified logical operator. The logical operator to use for joining the search conditions. Possible values are "OR", "NOT" and the empty string "" which denotes a logical AND. The first SearchCondition object The second SearchCondition object A new SearchCondition object representing the two search conditions joined by the specified logical operator. Concatenates the members of a collection, using the specified separator between each member. The type of the members of values. The string to use as a separator. A collection that contains the objects to concatenate. A string that consists of the members of values delimited by the separator string. If values has no members, the method returns System.String.Empty. The values parameter is null. This is already part of the String class in .NET 4.0 and newer but is needed for backwards compatibility with .NET 3.5. Constructs a string from the SearchCondition object using the proper syntax as is required for the IMAP SEARCH command. A string representing this SearchCondition instance that can be used with the IMAP SEARCH command. The search keys which can be used with the IMAP SEARCH command, as are defined in section 6.4.4 of RFC 3501. A static utility class containing methods for decoding encoded non-ASCII data as well as extension methods for some classes of the base class library. Returns a copy of the string enclosed in double-quotes and with escaped CRLF, back-slash and double-quote characters (as is expected by some commands of the IMAP protocol). Extends the System.String class A copy of the string enclosed in double-quotes and properly escaped as is required by the IMAP protocol. Returns true if the string contains only ASCII characters. Extension method for the String class. true if the string contains only ASCII characters; Otherwise false. Splits a string into chunks of the specified number of characters. Extension method for the String class. The length of a chunk, measured in characters. An array of string chunks. Determines whether the specified string occurs within this string. Extension method for the String class. The string to seek. One of the enumeration values that specifies the rules for the search. true if the value parameter occurs within this string, or if value is the empty string (""); otherwise, false. The value parameter is null. Raises the event. Ensures the event is only raised, if it is not null. Extends System.EventHandler class. Extends System.EventHandler class. The sender of the event. The event arguments associated with this event. Throws an ArgumentNullException if the given data item is null. The item to check for nullity. The name to use when throwing an exception, if necessary. Courtesy of Jon Skeet. Throws an ArgumentNullException if the given data item is null. The item to check for nullity. Courtesy of Jon Skeet. Throws an ArgumentNullException if the given string is null or throws an ArgumentException if the given string is empty. The string to check for nullity and emptiness. Throws an ArgumentNullException if the given string is null or throws an ArgumentException if the given string is empty. The string to check for nullity and emptiness. The name to use when throwing an exception, if necessary. Reads an unsigned short value from the underlying stream, optionally using big-endian byte ordering. Extension method for BinaryReader. Set to true to interpret the short value as big endian value. The 16-byte unsigned short value read from the underlying stream. Decodes a string composed of one or several MIME 'encoded-words'. A string to composed of one or several MIME 'encoded-words'. An unknown encoding (other than Q-Encoding or Base64) is encountered. A concatenation of all enconded-words in the passed string Internal function reuse to add separation between multiple 'encoded-word's correctly. The regular expression for matching encoded-words. This also accounts for the extension for including language information (as defined in RFC2231). Decodes a MIME 'encoded-word' string. The encoded word to decode An unknown encoding (other than Q-Encoding or Base64) is encountered. A decoded string MIME encoded-word syntax is a way to encode strings that contain non-ASCII data. Commonly used encodings for the encoded-word sytax are Q-Encoding and Base64. For an in-depth description, refer to RFC 2047. Takes a Q-encoded string and decodes it using the specified encoding. The Q-encoded string to decode. The encoding to use for encoding the returned string. The string is not a valid Q-encoded string. The Q-decoded string. Takes a quoted-printable encoded string and decodes it using the specified encoding. The quoted-printable-encoded string to decode. The encoding to use for encoding the returned string. The string is not a valid quoted-printable encoded string. A quoted-printable decoded string. Decodes the specified MIME parameter value. The MIME parameter value to decode. The decoded MIME parameter value. The specified value is not a valid Rfc2231-encoded string. Refer to RFC2231 for the details of the encoding mechanism. Takes a Base64-encoded string and decodes it. The Base64-encoded string to decode. A byte array containing the Base64-decoded bytes of the input string. The value parameter is null. The length of value, ignoring white-space characters, is not zero or a multiple of 4, or the format of value is invalid, or the value contains a non-base-64 character, more than two padding characters, or a non-white space-character among the padding characters. Takes a UTF-16 encoded string and encodes it as modified UTF-7. The string to encode. A UTF-7 encoded string IMAP uses a modified version of UTF-7 for encoding international mailbox names. For details, refer to RFC 3501 section 5.1.3 (Mailbox International Naming Convention). Takes a modified UTF-7 encoded string and decodes it. The UTF-7 encoded string to decode. A UTF-16 encoded "standard" C# string The input string is not a properly UTF-7 encoded string. IMAP uses a modified version of UTF-7 for encoding international mailbox names. For details, refer to RFC 3501 section 5.1.3 (Mailbox International Naming Convention). This just wraps Encoding.GetEncoding in a try-catch block to ensure it never fails. If the encoding can not be determined ASCII is returned as a default. The code page name of the preferred encoding. Any value returned by System.Text.Encoding.WebName is a valid input. The System.Text.Encoding associated with the specified code page or Encoding.ASCII if the specified code page could not be resolved. Converts the specified enumerable collection of UIDs into an IMAP sequence-set. An enumerable collection of UIDs. An IMAP sequence-set suitable for use with IMAP commands. The uids parameter is null. The specified collection of UIDs is empty. Refer to RFC3501, 9.Formal Syntax "sequence-set" for a description of IMAP sequence-sets.