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

Calling `item.body.getAsync` returns different results and possibly incomplete data #5036

Open GirtsJermacans opened 2 weeks ago

GirtsJermacans commented 2 weeks ago

Provide required information needed to triage your issue

We've been processing body of coerciontype 'html' returned from item.body.getAsync when sending new mail item. If inline images are included, then up until now, the method call would always return a body with img tag that contains src attribute in it. The src attribute as well as img tagwould differ slightly, depending on the platform and how the inline image is added to the message, however attribute itself would always be present.

Just recently, without a specific reason, for Environment B and Environment C (see below), and potentially other environments, item.body.getAsync started to return img tag without src attribute in it, therefore without some of the data usually associated with it.

This is causing issue to process the body correctly.

I have seen this issue for mac, but it seems that it does not relate to the issue described above.

Your Environment

3 different environments

Environment A:

Environment B:

Environment C:

Expected behavior

Calling item.body.getAsync returns html body with image tag, that has src and originalsrc attribute in it. See below example for Environment A:

image

Current behavior

For Platform B and C, calling item.body.getAsync returns html body with image tag, that has only 'originalsrc' attribute in it. See below example for Environment B and C:

image

With this behavior, it is not possible to identify, for example, which attachment it is when getting attachments using item.getAttachmentsAsync method call. Src attribute contains id, which has 1 to 1 relation with id property on Office.AttachmentDetailsCompose type. In some cases, it also has attachment content itself, which is a workaround for this [issue].(https://github.com/OfficeDev/office-js/issues/5031). Additionally, consistency is helpful, when processing data.

Steps to reproduce

  1. By using Environment B or C, start composing new mail.
  2. Copy-paste an png or jpg into the message body as inline image (additionally, you can add it as message attachment, then right click and move it into message body as inline image - result will be the same).
  3. Click send. At this point check the value that is returned by item.body.getAsync of coerciontype 'html'. You will get html body with img tag that has no src attribute in it.

Context

Our Addin processes information provided by the html body, including the inline attachments, performs some checks on it, and then creates a modified html body based on that information.# It is important to match up the inline image on the html body, with what is returned from item.getAttachmentsAsync. Getting back just cid in originalsrc has no relation to any of the ids that are available on Office.AttachmentDetailsCompose interface, essentially making that inline attachment unknown to the rest of the app. Up until now, src attribute always returned just enough to be able to work with it, however now for Environment B and C, it simply started to give back this different body. It could be that this is happening in other environments, and is not related just these specific ones.

Useful logs

We use @types/office-js version 1.0.401. Here is example code how to get html body:

function getMailbox() : Office.Mailbox {
    const result = getContext().mailbox;
    if (result) {
        return Office.context.mailbox;
    }
    throw new Error();
}

function getMailboxItem() : MailboxItem {
    const result = getMailbox().item;
    if (result) {
        return result;
    }
    throw new Error();
}

getItemBodyAsync(): Promise<string> {
      return new Promise((resolve, reject) => {
          this.getMailboxItem().body.getAsync('html', (asyncResult) => {
              if (asyncResult.status === Office.AsyncResultStatus.Failed) {
                  reject(asyncResult.error);
              } else {
                  resolve(asyncResult.value);
              }
          });
      });
}

Thank you for taking the time to report an issue. Our triage team will respond to you in less than 72 hours. Normally, response time is <10 hours Monday through Friday. We do not triage on weekends.

mmanjaree-msft commented 2 weeks ago

Could you please confirm if you get the same response for every image copied from different sources? As per a repro we had, sometimes we do get src attribute as well.

gauravsoni119 commented 2 weeks ago

We are also facing similar issues from past couple of days. Our add-in is also relying on getAsync to get body. But now for inline attachments it has originalsrc only which is causing issues for our add-in as well.

geoffreyreemer commented 2 weeks ago

Confirming the same issue for us. Since originalsrc only returns the cid (which we can't support in our add-in), it means that inline images aren't processed well anymore, leading to potential data loss. Could this please be looked into as soon as possible?

mmanjaree-msft commented 2 weeks ago

@geoffreyreemer @gauravsoni119 @GirtsJermacans Could you please share how are these images or attachments added to body in your cases. I was able to repro the issue but only sometimes. Looking for any recent change that might have broken this but meanwhile knowing the source of attachments in your cases would help

GirtsJermacans commented 2 weeks ago

@mmanjaree-msft Just checked on Environment B following ways to add inline images. For the following scenarios, the body is missing src attribute:

For the following scenarios, the body has src attribute

Img tag example for the above 2 scenarios: <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAdUAAAEHCAYAAAD4T9zTAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAFxEAABcRAcom8z8AAP+lSURBVHhebL0FlF/V9b89E5+4ezLRmehk4u7uIY7T4FacIsUpxQqUIi1OoVAoxVqgeKGlFEpxd5dAAjFCsP0+z87crPT3/r9r3XXv994j+9j+nL3PPvuUlJTsEyW19o2SntybcpXw3JV725rntjX/....... and so on...." id="image_0" style="max-width: 424px;">

I think this covers all the possible scenarios, how to add inline image. Will confirm a bit later today if the Environment C, has the same outcomes.

gauravsoni119 commented 2 weeks ago

@geoffreyreemer @gauravsoni119 @GirtsJermacans Could you please share how are these images or attachments added to body in your cases. I was able to repro the issue but only sometimes. Looking for any recent change that might have broken this but meanwhile knowing the source of attachments in your cases would help

@mmanjaree-msft we have similar steps mentioned by @GirtsJermacans. While composing, use 'Insert - Pictures' and select the image.

GirtsJermacans commented 2 weeks ago

@mmanjaree-msft Just checked on Environment B following ways to add inline images. For the following scenarios, the body is missing src attribute:

  • Add as attachment, then move into message body.
  • Open file directory, single click on image, copy it and paste it into the body.
  • Use some snipping tool - create a snip, paste it into the body.
  • Select following - 'Insert - Pictures' and select the image (it should add it to the body)

For the following scenarios, the body has src attribute

  • Create a signature, compose new mail, insert signature to the body, click send.
  • Create a signature, select it to appear automatically on compose new mail, compose new mail, click send.

Img tag example for the above 2 scenarios: <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAdUAAAEHCAYAAAD4T9zTAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAAFxEAABcRAcom8z8AAP+lSURBVHhebL0FlF/V9b89E5+4ezLRmehk4u7uIY7T4FacIsUpxQqUIi1OoVAoxVqgeKGlFEpxd5dAAjFCsP0+z87crPT3/r9r3XXv994j+9j+nL3PPvuUlJTsEyW19o2SntybcpXw3JV725rntjX/....... and so on...." id="image_0" style="max-width: 424px;">

I think this covers all the possible scenarios, how to add inline image. Will confirm a bit later today if the Environment C, has the same outcomes.

Checked - Environment C has the same results.

mmanjaree-msft commented 2 weeks ago

We have the bug in our backlog. We haven't root cause or any eta to share at this point. Internal tracking id: 5054071