0

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?

nthjelme
  • 33
  • 3

2 Answers2

1

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.

Dave Delay
  • 1,292
  • 8
  • 12
0

Wrong answer, but the comments may be useful. My other answer is more correct.

This question could be improved. For example, you could show some sample data and describe the results when you try to read that data with your code.

But I'll try to answer based on the information I have. You calculated the text length like this:

textLen = (pMime->wByteCount) - pMime->wHeadersLen - pMime->wBoundaryLen;

That looks right to me, but then you do this:

pText = (char *)pMime + sizeof(MIME_PART) + wHeadersLen;

Is wHeadersLen guaranteed to be equal to pMime->wHeadersLen? Also, you didn't consider the boundary length. Shouldn't you calculate the address like this instead?

pText = (char *)pMime + sizeof(MIME_PART) + pMime->wHeadersLen + pMime->wBoundaryLen;
Dave Delay
  • 1,292
  • 8
  • 12
  • the wHeadersLen was supose to be pMime->wHeadersLen. The issue is that the pMime-wHeadersLen is always that the value is 8250, the MIME_PART structure does not seem to be set with the correct value – nthjelme Oct 04 '18 at 10:18
  • I'm not an expert in this area, but I looked at some other code that uses `NSFMimePartGetPart`. That code uses `OSLock(char, hPart)` to lock the part handle. In other words, it doesn't expect `NSFMimePartGetPart` to return a handle to a `MIME_PART`. It expects a handle to the part data itself (starting with the boundary and headers). You would use `NSFMimePartGetInfoByBLOCKID` to get the length of the boundary and headers. I realize this is NOT how `NSFMimePartGetPart` is documented. Can you look at the memory returned by `OSLock`? Is it just part data? – Dave Delay Oct 04 '18 at 12:50