MAPI

With a Imapifolder, how can i access each message and get its content

Thanks



Answer this question

MAPI

  • Chrishuang

    Here is some sample code that should help you to get started:

    HRESULT SearchMessagesInFolder(IMAPIFolder* pmfParent)
    {
    IMAPITable* pmtContent;
    SRowSet* psrsMessages;
    SRow* psrMessage;
    ULONG i;
    HRESULT hr;
    ULONG rgulContentPropTags[] =
    {
    5,
    PR_ENTRYID,
    PR_PARENT_ENTRYID,
    PR_SUBJECT,
    PR_SENDER_EMAIL_ADDRESS,
    PR_MESSAGE_CLASS
    };

    hr = E_FAIL;

    pmtContent = NULL;
    if (pmfParent)
    {
    // Get the table containing all objects in this folder
    hr = pmfParent->GetContentsTable(0, &pmtContent);
    // Set the columns that we want to see in the table
    if (SUCCEEDED(hr) && pmtContent)
    hr = pmtContent->SetColumns((SPropTagArray*)rgulContentPropTags, 0);
    }

    psrsMessages = NULL;
    if (SUCCEEDED(hr) && pmtContent)
    {

    while (SUCCEEDED(pmtContent->QueryRows(kcMaxQueryRows, 0, &psrsMessages)))
    {

    // Check if we are done
    if (psrsMessages->cRows == 0)
    break;

    for (i = 0; i < psrsMessages->cRows; i++)
    {
    psrMessage = &(psrsMessages->aRowIdea);

    // Access the subject field
    if ((psrMessage->lpProps[2].ulPropTag == PR_SUBJECT) && psrMessage->lpProps[2].Value.lpszW)
    {
    wprintf(L"Subject: %s", psrMessage->lpProps[2].Value.lpszW);
    }
    }

    FreeProws(psrsMessages);
    psrsMessages = NULL;
    }
    }

    if (psrsMessages)
    FreeProws(psrsMessages);

    if (pmtContent)
    pmtContent->Release();

    return (hr);
    }


  • MAPI