Hunny Software Library Reference

Imap4Client.Fetch Method

Sends a FETCH command.

Overload List

Sends a FETCH command with a range of message sequence numbers.

public void Fetch(int,int,string);

Sends a FETCH command with a single message sequence number.

public void Fetch(int,string);

Sends a FETCH command with a set of message sequence numbers.

public void Fetch(string,string);

Remarks

A FETCH command requests the server to return one or more messages, parts of messages, or message attributes. The server responds with one or more FETCH responses that contain the requested information.

The third version of the overloaded method allows information for multiple messages to be fetched, as specified by a set of message sequence numbers. The messageSet parameter should specify a set of message sequence numbers in the syntax given in RFC 3501. In this syntax, individual sequence numbers or sequence number ranges are separated by commas, and ranges are indicated using a colon.

Example:

            void foo(Imap4Client client)
            {
                // fetch the FLAGS, INTERNALDATE, RFC822.SIZE, and ENVELOPE
                const char* set = "1:2,5";
                // Note: "ALL" is a macro, so it does not go in parentheses
                const char* items = "ALL";
                client.Fetch(set, items);
                // process the responses
                // [...]
                // fetch the UID and message body
                items = "(UID BODY.PEEK[TEXT])";
                client.Fetch(set, items);
                // process the responses
                // [...]
            }
            

Note: Some data items that can be fetched can be very large, as, for example, an entire message. If a data item is very large, it is a good idea to fetch it in several fragments. For example, to fetch a message with sequence number 3 that is 200K in size, you could do it with these two FETCH commands, which fetch the message in two 100,000 byte fragments:

                1 FETCH 3 (BODY[]<0.100000>)
                2 FETCH 3 (BODY[]<100000.100000>)
            

By fetching the message in fragments, you can also provide feedback to a user on the progress of the fetch operation.

See Also

Imap4Client Class | Hunny.Mail Namespace | FetchResponse | FETCH command in the IMAP4 specification