Outlook ReportItem.Body returning messed up encoding for some users

只愿长相守 提交于 2019-12-10 13:22:24

问题


We have a weird issue with Outlook lately that is impacting some users.

If certain users automate the Outlook Client to view bounce backs/ReportItems in a shared inbox, rather than returning the clear text of the message as indicated by the documentation we get back a unicode string that has been parsed as a UTF-8 string - so it looks like Chinese.

Now I can get past that with some code, but the additional issue is that this change occurs in outlook as well for all users with access to that inbox. The message itself as viewed in outlook appears as Chinese characters - the original unicode html parsed as UTF-8.

It seems like this might be a known issue, but I wanted to see if I could get some advice here.

We are using the normal methods to access the report item:

For Counter as Integer = Inbox.Items.Count To 1 Step -1
    Dim Report As Outlook.ReportItem = Inbox.Items(Counter)
    Dim Body As String = Report.Body

The last line is where we get the garbaled text. In VBA it attempts to parse it as ASCII and returns a large block of "?" while in .Net it returns the value parsed as UTF-8 and we get the characters that appear Chinese. In either case the original report item in the inbox begins displaying as Chinese characters and continues to do so for all users of that inbox.

Any ideas?

UPDATE: I wanted to share an update on this since it seems like a few people are still seeing it.

I want to quickly emphasize that the encoding issue is discussed well here and that accessing the body text of the message via code is covered and fairly easy. However, the encoding issue continues to exist in the Outlook client and was never resolved, and this issue was my going concern. There must be some bug in the .Body property which buggers up the encoding on the original message object on the Exchange server. Good luck to anyone who needs to resolve that particular issue.

UPDATE AGAIN: An answer and a more detailed description of the issue is posted below and selected as the answer.


回答1:


Yes, there is a problem with ReportItem.Body property in the Outlook Object Model (present in Outlook 2013 abd 2016) - you can see it in OutlookSpy: select an NDR message, click Item button, select the Body property - it will be garbled. Worse than that, once the report item is touched with OOM, Outlook will display the same junk in the preview pane.

The report text is stored in various MAPI recipient properties (click IMessage button in OutlookSpy and go to the GetRecipientTable tab). The problem is the ReportItem object does not expose the Recipients collection. The workaround is to either use Extended MAPI (C++ or Delphi) or Redemption (any language) - its ReportItem.ReportText property does not have this problem:

set oItem = Application.ActiveExplorer.Selection(1)
set oSession = CreateObject("Redemption.RDOSession")
oSession.MAPIOBJECT = Application.Session.MAPIOBJECT
set rItem = oSession.GetRDOObjectFromOutlookObject(oItem)
MsgBox rItem.ReportText



回答2:


I just had this happen to my VBA function in Outlook that processes email bounce backs for orders and marks those orders as requiring attention. The original email in outlook looks fine but when I attempt to process it, the characters change to Chinese and Report.Body just shows question marks.

I found using StrConv to convert to Unicode could get me the correct body contents for processing.

Dim strBody as String
strBody = StrConv(Report.Body, vbUnicode)



回答3:


Are you sure that the Inbox.Items(Counter) call returns an instance of the ReportItem class? Did you have a chance to check out the MessageClass property?

Most probably you try to cast an instance of the MailItem class to the ReportItem class. Is that the case?

Also I'd suggest using any low-level property viewer such as MFCMAPI or OutlookSpy for observing properties at runtime. Do you see "chinese" charactere there?



来源:https://stackoverflow.com/questions/29040321/outlook-reportitem-body-returning-messed-up-encoding-for-some-users

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!