gautamsi / ews-javascript-api

EWS API for TypeScript/JavaScript - ported from OfficeDev/ews-managed-api - node, cordova, meteor, Ionic, Electron, Outlook Add-Ins
MIT License
281 stars 72 forks source link

MessageBody text needs to be xml encoded #368

Open tomika opened 3 years ago

tomika commented 3 years ago

Following code : const message = new EmailMessage(service); message.Subject = "Subject"; message.Body = new MessageBody(BodyType.Text, "Hello"); message.ToRecipients.Add("a@b.com"); 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?

gautamsi commented 3 years ago

Yes, you are supposed to pass escaped body

tomika commented 3 years ago

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?

gautamsi commented 3 years ago

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

tomika commented 3 years ago

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.

bladerunner2020 commented 3 years ago

@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;');