Search code examples
lotus-dominoc-api

How do I read the data from a TYPE_MIME_PART item?


It kinda works, but the problem is that it seems that the MIME_PART structure is not initialized ? all it's properties has the same values, even if I try to open a different mime item.

MIME_PART *pMime;
DHANDLE hPart; 
char *pText;
WORD textLen;
if (error = NSFMimePartGetPart(bidLinksItem, &hPart)) {
 goto exit;
}

pMime = OSLock(MIME_PART, hPart);
textLen = (pMime->wByteCount) - pMime->wHeadersLen - pMime->wBoundaryLen;
pText = (char *)pMime + sizeof(MIME_PART) + wHeadersLen;
char *itemText = (char *)malloc(textLen);       
memcpy(itemText, pText, textLen); 
itemText[textLen] = '\0';
OSUnlock(hPart);

The itemText string has most of the content, but since the MIME_PART structure is not properly set, the pointer to the text is off...

So how do I properly set the MIME_PART?


Solution

  • Your code should do something like this instead:

    DHANDLE hPart; 
    char *pchPart;
    if (error = NSFMimePartGetPart(bidLinksItem, &hPart)) {
      goto exit;
    }
    
    pchPart = OSLock(char, hPart);
    

    In other words, lock the handle as type char instead of type MIME_PART. At this point, pchPart points to the beginning of the raw part data -- starting with a boundary (if present) and the headers. You can use NSFMimePartGetInfoByBLOCKID to get the length of the boundary and headers.

    I realize this contradicts the documentation, but I've confirmed with a subject matter expert: The documentation is wrong.