Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Outlook ReportItem.Body returning messed up encoding

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 there is a unicode string that has been parsed as a UTF-8 string - so it looks like Chinese.

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.

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 garbled text In VBA it attempts to parse it as ASCII and returns a large block of "?". In .Net it returns the value parsed as UTF-8 and we get the characters that appear Chinese. In either case the report item in the inbox begins displaying as Chinese characters and continues to do so for all users of that inbox.

like image 422
MattB Avatar asked Mar 13 '15 19:03

MattB


1 Answers

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)
like image 171
Bluey Avatar answered Oct 27 '22 11:10

Bluey