Example: imap_fetch_ex

In the following example, the imap_fetch_ex function fetches information from messages 1 through 10—Message ID, flags, and the RFC822 size and header of the message.

imap_fetch_ex(&imap2, "FetchMessages", 
        "Mode=", 
        "Fetch=1:10 (UID FLAGS RFC822.SIZE RFC822.HEADER)", ENDITEM, 
        LAST );

Example 2

The next example saves the message to a parameter "Message" using the saveto parameter. imap_set_max_param_len indicates the size of the buffer to hold the message.

imap_set_max_param_len_ex(&imap2,"16384");
imap_fetch_ex(&imap2, "FetchMessages", "Mode=UID",
               "Fetch=3 (UID RFC822.SIZE BODY[]<0.6144>)",
               "saveto=Message", ENDITEM, LAST );
lr_log_message("Message = %s", lr_eval_string("<Message>"));

Example 3

In the following example, the imap_search_ex function gets UIDs, which can then be used by imap_fetch_ex

imap_search_ex(&imap1, "SearchMessages",
		"Mode=UID",
		"Search=ALL", // or any other search criteria
		"SaveTo=search_res1", ENDITEM,
		LAST);

Parse "search_res1" to get the UIDs. Example of the contents search_res1: “1 3 5”. “1 3 5” are the message IDs separated by spaces.

Replace the spaces with commas (“1,3,5”) and use the new string as below. One way to parse "search_re1" is with strtok.

imap_fetch_ex(&imap1, "FetchMessages", 
		"Mode=", 
		"Fetch=1,3,5 (UID)", ENDITEM, //1,3,5 should be replaced by result from imap_search_ex
		LAST);