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
686 stars 95 forks source link

When replying as an email in plain text format, body.getAsync() returns an incorrect value. #3988

Closed t-miyake closed 6 months ago

t-miyake commented 10 months ago

Provide required information needed to triage your issue

In Outlook on the web or New Outlook for Windows, when replying as an email in plain text format, body.getAsync() returns an incorrect value. Specifically, the quoted part of the email is duplicated.

This issue does not occur when replying in HTML format or when using body.getAsync() with received emails.

Additionally, the same problem occurs regardless of whether Office.CoercionType.Html or Office.CoercionType.Text is specified as the argument when using body.getAsync().

Your Environment

Expected behavior

Appropriately get the value of the mail body.

Current behavior

The quoted part (Original Message) of the email body is duplicated.

Steps to reproduce

  1. Open a received email and press the reply button.
  2. Change the format of the email to Plain Text. Alternatively, set the default Compose format to Plain Text in the settings of Outlook, and then press the reply button on an email that is in Plain Text format.
  3. Execute body.getAsync. Whether the email is edited or not seems to be irrelevant to this issue.

Link to live example(s)

I have created a simple sample. The URL for the manifest file is as follows: https://outlook.addin.app/getbody/OutlookGetBody.xml

Manifest

<?xml version="1.0" encoding="UTF-8"?>
<OfficeApp
  xmlns="http://schemas.microsoft.com/office/appforoffice/1.1"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:bt="http://schemas.microsoft.com/office/officeappbasictypes/1.0"
  xmlns:mailappor="http://schemas.microsoft.com/office/mailappversionoverrides/1.0"
  xsi:type="MailApp">
  <Id>734D9496-3F0F-406E-AFB6-93033D13EA14</Id>
  <Version>1.0.0.0</Version>
  <ProviderName>T.Miyake</ProviderName>
  <DefaultLocale>en-US</DefaultLocale>
  <DisplayName DefaultValue="GetBody" />
  <Description DefaultValue="GetBody" />
  <IconUrl DefaultValue="https://outlook.addin.app/getbody/images/Icon64.png" />
  <SupportUrl DefaultValue="https://www.noraneko.co.jp/" />
  <AppDomains>
    <AppDomain>https://outlook.addin.app</AppDomain>
  </AppDomains>
  <Hosts>
    <Host Name="Mailbox" />
  </Hosts>
  <Requirements>
    <Sets>
      <Set Name="Mailbox" MinVersion="1.1" />
    </Sets>
  </Requirements>
  <FormSettings>
    <Form xsi:type="ItemRead">
      <DesktopSettings>
        <SourceLocation DefaultValue="https://outlook.addin.app/getbody/" />
        <RequestedHeight>250</RequestedHeight>
      </DesktopSettings>
    </Form>
  </FormSettings>
  <Permissions>ReadWriteMailbox</Permissions>
  <Rule xsi:type="RuleCollection" Mode="Or">
    <Rule xsi:type="ItemIs" ItemType="Message" FormType="Read" />
  </Rule>
  <DisableEntityHighlighting>false</DisableEntityHighlighting>
  <VersionOverrides xmlns="http://schemas.microsoft.com/office/mailappversionoverrides"
    xsi:type="VersionOverridesV1_0">
    <Requirements>
      <bt:Sets DefaultMinVersion="1.3">
        <bt:Set Name="Mailbox" />
      </bt:Sets>
    </Requirements>
    <Hosts>
      <Host xsi:type="MailHost">
        <DesktopFormFactor>
          <ExtensionPoint xsi:type="MessageReadCommandSurface">
            <OfficeTab id="TabDefault">
              <Group id="group1">
                <Label resid="groupLabel" />
                <Control xsi:type="Button" id="msgReadOpenPaneButton">
                  <Label resid="taskpaneButtonLabel" />
                  <Supertip>
                    <Title resid="taskpaneButtonLabel" />
                    <Description resid="taskpaneButtonTooltip" />
                  </Supertip>
                  <Icon>
                    <bt:Image size="16" resid="icon16" />
                    <bt:Image size="32" resid="icon32" />
                    <bt:Image size="64" resid="icon64" />
                    <bt:Image size="80" resid="icon80" />
                  </Icon>
                  <Action xsi:type="ShowTaskpane">
                    <SourceLocation resid="taskpaneUrl" />
                  </Action>
                </Control>
              </Group>
            </OfficeTab>
          </ExtensionPoint>
          <ExtensionPoint xsi:type="MessageComposeCommandSurface">
            <OfficeTab id="TabDefault">
              <Group id="group2">
                <Label resid="groupLabel" />
                <Control xsi:type="Button" id="msgComposeOpenPaneButton">
                  <Label resid="taskpaneButtonLabel" />
                  <Supertip>
                    <Title resid="taskpaneButtonLabel" />
                    <Description resid="taskpaneButtonTooltip" />
                  </Supertip>
                  <Icon>
                    <bt:Image size="16" resid="icon16" />
                    <bt:Image size="32" resid="icon32" />
                    <bt:Image size="64" resid="icon64" />
                    <bt:Image size="80" resid="icon80" />
                  </Icon>
                  <Action xsi:type="ShowTaskpane">
                    <SourceLocation resid="taskpaneUrl" />
                  </Action>
                </Control>
              </Group>
            </OfficeTab>
          </ExtensionPoint>
        </DesktopFormFactor>
      </Host>
    </Hosts>
    <Resources>
      <bt:Images>
        <bt:Image id="icon16" DefaultValue="https://outlook.addin.app/getbody/images/Icon16.png" />
        <bt:Image id="icon32" DefaultValue="https://outlook.addin.app/getbody/images/Icon32.png" />
        <bt:Image id="icon64" DefaultValue="https://outlook.addin.app/getbody/images/Icon64.png" />
        <bt:Image id="icon80" DefaultValue="https://outlook.addin.app/getbody/images/Icon80.png" />
      </bt:Images>
      <bt:Urls>
        <bt:Url id="taskpaneUrl" DefaultValue="https://outlook.addin.app/getbody/taskpane.html" />
      </bt:Urls>
      <bt:ShortStrings>
        <bt:String id="groupLabel" DefaultValue="GetBody" />
        <bt:String id="taskpaneButtonLabel" DefaultValue="GetBody" />
      </bt:ShortStrings>
      <bt:LongStrings>
        <bt:String id="taskpaneButtonTooltip" DefaultValue="GetBody" />
      </bt:LongStrings>
    </Resources>
  </VersionOverrides>
</OfficeApp>

JavaScript

Office.onReady().then(() => {
    Office.context.mailbox.item.body.getAsync(Office.CoercionType.Html, (result) => {
            document.getElementById("htmlBody").innerHTML = escapeHtml(result.value);
    });
    Office.context.mailbox.item.body.getAsync(Office.CoercionType.Text, (result) => {
            document.getElementById("textBody").innerHTML = escapeHtml(result.value);
    });
});

function escapeHtml(html) {
    return html
        .replace(/&/g, "&amp;")
        .replace(/</g, "&lt;")
        .replace(/>/g, "&gt;")
        .replace(/"/g, "&quot;")
        .replace(/'/g, "&#039;");
}

HTML

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8" />
</head>
<body>
    <p>--HTML Body--</p>
    <p id="htmlBody"></p>
    <br><br>
    <p>--Text Body--</p>
    <p id="textBody"></p>
    <script src="https://appsforoffice.microsoft.com/lib/1.1/hosted/office.js"></script>
    <script src="taskpane.js"></script>
</body>
</html>

Context

I am facing challenges due to this issue, as it leads to providing users with incorrect information about the email body.

Useful logs

This is the result of running the above sample. It might be a bit hard to understand, but please check the issue.

Replying to a text format email in text format ※Issue present Text-Text

Replying to an HTML format email in text format ※Issue present Html-Text

Replying to a text format email in HTML format ※No issue Text-Html

Replying to an HTML format email in HTML format ※No issue Html-Html

Reading text format emails ※No issue Read-Text

Reading HTML format emails ※No issue Read-HTML

Outlook for Windows (Traditional ) ※No issue Windows

bchenhs commented 10 months ago

We also observed this issue and it is impacting over 100k of our add-in users. @exextoc we would much appreciate an update and eta on a fix so we can communicate to our impacted users. Thank you!

t-miyake commented 10 months ago

@exextoc Could you please provide an update on the status of this issue? Given the significant impact of the problem, I am hoping for a fix. We also have over 150k users affected by this. Thanks!

ajays-msft commented 10 months ago

We are actively investigating this and will get back soon.

ajays-msft commented 10 months ago

@t-miyake The issue has been resolved at the server side. Can you please check in couple of hours and reply back?

t-miyake commented 10 months ago

@ajays-msft Thank you. I have confirmed that the issue I reported has been completely fixed. However, a new issue has arisen. It appears that when replying to an email in HTML format, the quoted part cannot be got using body.getAsync().

Here are the results of my tests:

Replying to a text format email in text format ※Issue is Fixed. TEXT2TEXT

Replying to an HTML format email in text format ※Issue is Fixed. HTML2TEXT

Replying to a text format email in HTML format ※New issue. TEXT2HTML

Replying to an HTML format email in HTML format ※New issue. HTML2HTML

ajays-msft commented 10 months ago

The new issue you mentioned is a known bug for long. A fix to that issue has caused a regression and we reverted it. You can track the fix for the HTML issue in this github post. https://github.com/OfficeDev/office-js/issues/2317

t-miyake commented 10 months ago

@ajays-msft Thank you very much. I understand. This Issue has been Fixed so I will be closed.

bchenhs commented 10 months ago

Hi @ajays-msft, thanks for the update on the fix.

bchenhs commented 7 months ago

Hi @exextoc @ajays-msft We just started seeing this issue again. Did another update rollout that re-introduced this bug?

neprasad-microsoft commented 6 months ago

The fix for this issue caused another issue (#4392 ) . So, we are reverting this and are working on this issue. Unfortunately, we do not have any timelines for this right now.

ajays-msft commented 6 months ago

This issue is fixed now.