When you work with messages in a Read state, you will still use the same structures, the MAPIMessage, MAPIRecip and MAPIFile structures. Instead of setting values in these structures, you'll be using them to read in messages and determine what type of message you have received and the different attributes of the message.
You start the process by using the MAPIFindNext API call. This call will initiate the process of retrieving messages.
'Initiate the process by doing a FindNext iStatus = MAPIFindNext(gMAPISession, 0&, gMessageClass, sMessageID, 0, 0, sMessageID) If iStatus <> SUCCESS_SUCCESS Then MsgBox "Unable to get next message." End If
If the iStatus that is returned is SUCCESS_SUCCESS, you know that you have messages in the inbox and can then begin working with them. For a good experiment, you may want to read in each message and place it in a table. To walk down through your inbox, you'll use continuous calls to the MAPIReadMail and MAPIFindNext calls. The code sample below will help explain this point.
'If there are messages to process, loop through them to see 'what's available. Do While iStatus = SUCCESS_SUCCESS 'Read the current message, the header information 'for the message was returned by MAPIFindNext iStatus = MAPIReadMail(gMAPISession, 0, sMessageID, 0, 0, tMessage, tOriginator, tRecips(), tFiles(), NumRecips, NumFiles) 'Add the message information to the table. ... 'read the next message. iStatus = MAPIFindNext(gMAPISession, 0&, gMessageClass, sMessageID, 0, 0, sMessageID) Loop
Be sure to use the same variables for the sMessageID parameters as this is how MAPI knows where to look to retrieve the next message. These are also the values that you'll set when you need to retrieve a specific message with MAPIReadMail.
When you are examining the messages, you'll want to be sure you capture the different fields from the MAPIMessage structure (tMessage above). This will allow you to review the message type, subject, sender information, etc.
If you only want to retrieve a certain type of message, based on message class, you use the gMessageClass variable. Setting this value will limit the scope of the messages that you will receive when you initiate the search process. This is how you retrieve IPC-type messages that have arrived at your system; set the value of the gMessageClass variable to the message class that you need and issue the MAPIFindFirst call as outlined above. This will initiate the request for only those messages. They will not be shown in the standard inbox (if they are IPC messages), but will be available on the system when you specifically request them.