如何从带有 PR_BODY_A 标记的 MAPI 消息中获取编码(Windows Mobile)?
我正在开发一个程序,通过 windows-mobile MAPI 处理传入的电子邮件和短信。代码基本上如下所示:
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 ...
}
可以工作,并且我有一个消息正文。问题是这个主体是多字节编码的,我需要返回一个 Unicode 字符串。我想,我必须使用 ::MultiByteToWideChar() 函数,但是我怎么猜测,我应该应用什么代码页?使用 CP_UTF8 很幼稚,因为它可能根本就不是 UTF8。使用 CP_ACP 有时有效,但有时无效。所以,我的问题是:如何检索有关消息代码页的信息。 MAPI有提供什么功能吗?或者除了 MultiByteToWideChar() 之外还有其他方法可以解码多字节字符串吗?
谢谢!
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 question 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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不了解移动设备,但 PR_BODY_W 可以使用吗?
您还有 PR_RTF_COMPRESSED 属性吗?它包含 RTF 标头中的代码页。
德米特里·斯特雷布莱琴科 (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook,CDO
和 MAPI 开发工具
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
查看 Stephen Griffin 撰写的关于 读取 RTF 流。它解释了如何使用
HrTextFromcompressedRTFStreamEx
从 PR_RTF_COMPRESSED 直接转为 UNICODE 文本。它的工作原理“正如斯蒂芬所宣传的那样”,并且在更改代码页时确实存在一些问题。根据我的经验,此类问题往往会在本地文本经常穿插有英文文本的地区出现。我们在亚太地区已经看到了这一点。
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.