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

[Outlook] Under certain conditions, the "AttachmentChanged" event Is not triggered, and "Office.context.mailbox.item.getAttachmentsAsync" cannot obtain attachment information. #4867

Open Shintaro-My opened 2 months ago

Shintaro-My commented 2 months ago

Provide required information needed to triage your issue

I am currently developing an Outlook add-in that combines launchevent and taskpane to check the status of email attachments before sending an email. Specifically, we have prepared a handler for the AttachmentChanged event and call Office.context.mailbox.item.getAttachmentsAsync when the event is triggered.

At this time, we have confirmed cases where the event is not triggered despite attaching or deleting an attachment under certain conditions, and cases where the information of the attached file cannot be obtained.

Here are the conditions and corresponding cases:

Your Environment

Expected behavior

Current behavior

Steps to reproduce

  1. Prepare the code like the following in your Add-In.

    // typescript
    
    type FixedAttachmentDetailsCompose = Office.AttachmentDetailsCompose & { contentType?: string } // fixing a missing parameter (@types/office-js@1.0.418 and the official documentation)
    
    Office.context.mailbox.item.addHandlerAsync(
        Office.EventType.AttachmentsChanged,
        () => {
    
            Office.context.mailbox.item.getAttachmentsAsync(
                (result: Office.AsyncResult<FixedAttachmentDetailsCompose[]>) => {
                    if (result.status == Office.AsyncResultStatus.Succeeded) {
                        console.log(result.value)
                        // [
                        //     {
                        //         "id": "AAMkADQ...",
                        //         "name": "test.xlsx",
                        //         "contentType": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
                        //         "size": 25694019,
                        //         "attachmentType": "file",
                        //         "isInline": false
                        //     },
                        //     {
                        //         "id": "AAMkADQ...",
                        //         "name": "sample.png",
                        //         "contentType": "image/png",
                        //         "size": 8687,
                        //         "attachmentType": "file",
                        //         "isInline": true
                        //     },
                        //     ...
                        // ]
                    }
                }
            )
    
        }
    )
  2. Open Outlook.
  3. Compose a new message.
  4. Add cloud-based attachments (-A).
    • the event will NOT be triggered
  5. Add attachments by copy (-B).
    • the event will be triggered
    • only the attachments by copy (-B) will be populated in the array returned
  6. Copy and paste some images into the body of the new message (inline images (-C)).
    • the event will be triggered
    • the inline images (-C) will be newly added in the array returned
  7. Remove the pasted images.
    • the event will NOT be triggered
  8. Remove attachments by copy (-B).
    • the event will be triggered
    • the empty array will be returned

Provide additional details

This is a similar issue: #2888

kumarshrey-msft commented 1 month ago

Hi @Shintaro-My, can you please confirm if the issue you are facing is same as #4677? If yes, then this is by design and is the expected behavior as mentioned here.

Shintaro-My commented 1 month ago

Hi @kumarshrey-msft !

Yes, it seems that is the case, so I will retract the issue of "cloud-based attachments".

However, there is still the issue of "inline images".

Swathy-Mothilal commented 1 month ago

@Shintaro-My Since you are trying it in Outlook new, could you please confirm the behavior on other platforms?

Shintaro-My commented 1 month ago

Hi @Swathy-Mothilal !

I have tried this on other platforms:

Office on the web (Chrome): The same situation occurred.

Classic Outlook:

(Microsoft® Outlook® for Microsoft 365 MSO (version: 2408, build: 16.0.17928.20114) 64-bit)

  • When selecting an image via Insert > Picture, it does not seem to be recognized as an attachment.
  • When copying and pasting an image into the body, the image is handled as "attachments by copy" rather than "inline images". Threfore, the issue does not occur. スクリーンショット 2024-09-26 100024
    [
    {
        "id": "4",
        "name": "スクリーンショット 2024-06-17 155724.png",
        "size": 81652,
        "attachmentType": "file",
        "isInline": false // <- !
    }
    ]