Using Message Flags

Message flags provide you with many options to manipulate mail messages. In fact, you do not write code to perform the low-level operations. You simply set appropriate flags and the system takes care of the rest. For example, if you want to retrieve a message from the Inbox folder only, you set the dwFlags member of the MailMsg structure to MAIL_FOLDER_INBOX before you call MailFirst.

You can use other message flags to enhance the performance of your application. You use MAIL_GET_BODY and MAIL_GET_FLAGS to determine how much of the message is to be read into memory. If you set MAIL_GET_BODY, the entire message is read into memory. Otherwise, everything except the message body is read into memory. In either case, the system allocates memory from the local heap. A handle to the heap is passed back through the hHeap member of the MailMsg structure.

To get minimal information about the messages, without allocating memory, you set dwFlags to MAIL_GET_FLAGS. MAIL_GET_FLAGS instructs the system to read only the dwFlags member of the MailMsg structure. For example, you can build an array of pointers to unopened messages stored in the Inbox folder.

    To build an array of pointers to unopened messages stored in the Inbox folder
  1. Call MailFirst to get the flags and object identifier of the first unopened message in the Inbox.
  2. Store the identifier number and any other desired information.
  3. Reset the flags to specify the same folder and type of message.
  4. Call MailNext with the MAIL_GET_FLAGS flag set to retrieve the flags and object identifier of the next message.
  5. Save the information.
  6. Repeat steps 3, 4, and 5 until you have handled all of the messages in the Inbox.

To retrieve a particular message body, you can pass the object identifier to MailGet.