ews-javascript-api icon indicating copy to clipboard operation
ews-javascript-api copied to clipboard

MessageBody text needs to be xml encoded

Open tomika opened this issue 4 years ago • 5 comments

Following code : const message = new EmailMessage(service); message.Subject = "Subject"; message.Body = new MessageBody(BodyType.Text, "

Hello"); message.ToRecipients.Add("[email protected]"); message.SendAndSaveCopy(); results e-mail with empty body. The reason is: the program doesn't escapes the body text when sending in soap message. As I saw there is some other issues open in connection with string parameters unescaped, maybe the reason is the same. Is it by design that the user of the library has to pass string parameters xml encoded?

tomika avatar Nov 16 '20 18:11 tomika

Yes, you are supposed to pass escaped body

gautamsi avatar Nov 16 '20 19:11 gautamsi

May I ask you, if it is intentional and will remain in future versions? And it is true for every string parameter in the api, ie: Subject and/or Property values?

tomika avatar Nov 16 '20 21:11 tomika

I am keeping this close to original api and not changing that. I can probably add helper functions to ease this.

This is true for subject field as well as any property you are adding string with special characters

gautamsi avatar Nov 17 '20 03:11 gautamsi

I haven't used the .NET version of this API, but I can hardly beleive that you have to xml escape all string parameters you pass to functions.

tomika avatar Nov 17 '20 10:11 tomika

@tomika, rather agree with you that it would be convenient if xml-escaping would be part of the module. Meanwhile I use the following code to escape subject field.

const encode = (str) => str
  .replace(/&/g, '&')
  .replace(/</g, '&lt;')
  .replace(/>/g, '&gt;')
  .replace(/"/g, '&quot;')
  .replace(/'/g, '&apos;');

bladerunner2020 avatar Nov 21 '20 09:11 bladerunner2020