OfficeDev / office-js

A repo and NPM package for Office.js, corresponding to a copy of what gets published to the official "evergreen" Office.js CDN, at https://appsforoffice.microsoft.com/lib/1/hosted/office.js.
https://learn.microsoft.com/javascript/api/overview
Other
689 stars 95 forks source link

mailbox.item.body.getAsync is not returning content in correct format when text is copied #3726

Open elemen7s opened 1 year ago

elemen7s commented 1 year ago

We have an event based addin and on ItemSend we are getting the body of the email in Text format. When the content is copied from somewhere (such as from a notepad), the new lines are removed even tough in the UI of the email it shows perfectly fine.

The body content is retrieved using the call Office?.context?.mailbox?.item?.body.getAsync(Office.CoercionType.Text,

Example: The content of the below email is retrieved like this (note that there is no space between the text 'line 1' and 'line 2'): image

image

Your Environment

Expected behavior

Expected behavior is to always provide the content as is without any modification, especially to new lines.

Current behavior

New lines are removed and combined into one line without any spacing between one line and another.

Steps to reproduce

Create an email and write 3 lines Copy them and paste them in a notepad Copy from notepad and paste in email overwriting everything In addin call - Office?.context?.mailbox?.item?.body.getAsync(Office.CoercionType.Text,

Context

The content is not provided as it is shown in the email.

DivyaPatidar commented 1 year ago

@elemen7s Can you try to get HTML body in the last step and see if body contains newline character(\r or \n)? I think copying to notepad is changing the formatting and the new text contains
for new lines, which would not be returned in Text CoercionType.

elemen7s commented 1 year ago

@DivyaPatidar This is what the HTML returns: <div style=\"font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);\" class=\"elementToProof ContentPasted0\">line 1<div class=\"ContentPasted0\">line 2</div>line 3<br></div>

When using Text CoercionType, ideally it should at least return a space between the different lines and not join them together as the last word of one line is currently being joined with the first word of the next line which does not make sense at all.

Html CoercionType is not an option for us as it returns a lot of unnecessarily text which we do not want. We only care about the text written by the user which I think is the purpose of the Text CoercionType.

exextoc commented 1 year ago

Thanks for reporting this issue regarding mailbox.item.body.getAsync API. It has been put on our backlog. We unfortunately have no timelines to share at this point. As a workaround you can get HTML body and convert it to text. Internal tracking id: Office: 3997097