Special Characters not retrieved from Exchange Web Server

Hi,

I have been having trouble retrieving messages from the Exchange Web Service via Aspose Email IEWSClient.

Retrieval of the message does occur. The problem is that emails containing some “special” characters do not display them as expected when retrieved via IEWSClient. If I open up the email in Outlook and then save it to an MSG file, it saves the special characters and the MapiMessage object can read it and even when its converted from a MapiMessage to a MailMessage it has the special characters. It’s only a problem when retrieving it from the Aspose IEWSClient I cannot get the actual character.

One of the problem character’s is “»”.
Note: you can hold your key and press 0187 on your keyboard’s number pad to produce it.

Our code is similar to this: -<!–[if gte mso 10]>

/* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi; mso-fareast-language:EN-US;}

<![endif]–>

NetworkCredential credential = CredentialCache.DefaultNetworkCredentials;
string MailboxUri = @“https://exchange_hostname/ews/exchange.asmx”;
Aspose.Email.Mail.MailMessage m;
var builder = new ExchangeQueryBuilder();
builder.HasNoFlags(ExchangeMessageFlag.IsRead);
var query = builder.GetQuery();

char lookForChar = ‘»’;

IEWSClient client = EWSClient.GetEWSClient(MailboxUri, credential);
var msgCollection = client.ListMessages(client.MailboxInfo.InboxUri, 1000, query, false);

foreach (
var msgInfo in msgCollection
.Where(
s => s.Subject == “Subject of Problem Email for diagnosis”
)
)
{
var strMessageUri = msgInfo.UniqueUri;
MailMessage emailMessage = client.FetchMessage(strMessageUri);
if ((emailMessage.Body.IndexOf(lookForChar) > -1))
{
Console.WriteLine(“Is Working correctly”);
}
else
{
Console.WriteLine(“Is NOT Working correctly”);
}
}

This returns: -
Is NOT Working correctly
BodyType : PlainText
BodyEncoding : null
PreferredTextEncoding : System.Text.UTF8Encoding


Note that I’ve tried to loop through every permutation of encodings, SaveOptions and MailMessageSaveType’s to see if that would make any difference by saving to a file but it didn’t work.

Note that when I save the email from Outlook it has its Format Text set to “Plain Text”, but when I read it as a MapiMessage and convert it to MailMessage it is "Html"

When I read the file saved by Outlook using the following: -
string fileNameToRead = @“locationOfSavedOutlookFile.msg”;
MapiMessage mapiMsg = MapiMessage.FromFile(fileNameToRead);
// get MailMessageInterpretor instance
MailMessageInterpretor mi = MailMessageInterpretorFactory.Instance.GetIntepretor(mapiMsg .MessageClass);
// get MailMessage instance
MailMessage message = mi.Interpret(mapiMsg);

Console.Write(
string.Concat(
"BodyType : ", (message.BodyType == null) ? “null” : message.BodyType.ToString(), Environment.NewLine,
"BodyEncoding : ", (message.BodyEncoding == null) ? “null” : message.BodyEncoding.ToString(), Environment.NewLine,
"PreferredTextEncoding : ", message.PreferredTextEncoding, Environment.NewLine
)
);

Returns: -
BodyType : Html
BodyEncoding : System.Text.Latin1Encoding
PreferredTextEncoding : System.Text.Latin1Encoding


What is going on here? Am I not converting correctly or is there a bug in the reader?

Thanks
Ralph

Hi Ralph,

Thank you for contacting Aspose Support team.

We have tested this issue and found that this is not a problem with Aspose.Email API. If you fetch the email from server and save to disc as EML, then open it in notepad, you will see that the special character has been replaced by “>” as per server converted encoding. Thus, it is not an issue at our end and specific behavior related to the server.

Hi Kashif,

I know the character is being replaced by “>”.
I tried every combination of saving I could think of as possible as explained above.

I do not have this problem in Outlook, it displays the character correcty “»” - so why is it being replaced in Aspose?

Is it EWSClient that is the problem?

Thanks
Ralph

Hi Ralph,

Aspose.Email doesn’t replace the special character in the email. It is done at the server end and is no issue with the EWSClient. If you check the base 64 data received from server by converting it to UTF-8 format, for example here, you will see that this conversion comes from server and has nothing to do with our API. Please let us know if we can be of any additional help to you in this regard.

Thanks Kashif!
Could you please give us an example on how you got the Base64 data received from the server?

Hi Ralph,

We are sorry for a delayed response.

The response was received within our API code using the ExchangeServiceBinding class that is generated as Microsoft Web Service proxy class. You may use it to write your own code for receiving such a response in your test application.