开发者

How to get encoding from MAPI message with PR_BODY_A tag (windows mobile)?

I am developing a program, that handles incoming e-mail and sms through windows-mobile MAPI. The code basically looks like that:

   ulBodyProp = PR_BODY_A;
   hr = piMessage->OpenProperty(ulBodyProp, NULL, STGM_READ, 0, (LPUNKNOWN*)&piStream);

   if (hr == S_OK)
   {
      // ... get body size in bytes ...
      STATSTG statstg;
      piStream->Stat(&statstg, 0);
      ULONG cbBody = statstg.cbSize.LowPart;

      // ... allocate memory for the buffer ...
      BYTE* pszBodyInBytes = NULL;
      boost::scoped_array<BYTE> szBodyInBytesPtr(pszBodyInBytes = new BYTE[cbBody+2]);

      // ... read body into the pszBodyInBytes ...      
   }

That works and I have a message body. The problem is that this body is multibyte encoded and I need to return a Unicode string. I guess, I have to use ::MultiByteToWideChar() function, but how can I guess, what codepage should I apply? Using CP_UTF8 is naive, because it can simply be not in UTF8. Using CP_ACP works, well, sometimes, but sometimes does not. So, my qu开发者_JAVA百科estion is: how can I retrieve the information about message codepage. Does MAPI provide any functions for it? Or is there a way to decode multibyte string, other than MultiByteToWideChar()?

Thanks!


Don't know about mobile, but is PR_BODY_W available? Do you also have the PR_RTF_COMPRESSED property? it contains the code page in the RTF header.

Dmitry Streblechenko (MVP) http://www.dimastr.com/ OutlookSpy - Outlook, CDO and MAPI Developer Tool


Take a look at this article by Stephen Griffin about reading an RTF Stream. It explains how you can go from PR_RTF_COMPRESSED directly to UNICODE text using HrTextFromCompressedRTFStreamEx. It works "as advertised" by Stephen and does indeed have some issues when changing code page.

In my experience this type of issue tends to manifest in regions where the local text is routinely interspersed with English text. We have seen this in the Asia Pacific region.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜