Skip to content

[FIX] Outlook: fix crash when adding inline images #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

juwu-odoo
Copy link

Currently logging emails can crash if there are more inline image attachments than img tags.

Steps to reproduce

  1. Reply to an email that has an inline image
  2. From the reply, select "Log Email Into Contact"
  3. No log is created and the button is stuck in the loading state

Cause

Currently, we loop through inlineAttachments to match them one-to-one with the document's img tags. But the counter does not consider the case where there's a different number of inlineAttachments and imageElements. This usually happens when there's an img in the email history which is removed at the top of the function, but the attachment still exists. Some emails can also have embeded inline attachments that are unused.

Fix

Use two counters so that we don't hit an index out of bounds error. Also filter by img elements using cid: in src, so we don't overwrite img elements using URL images.

opw-4855422

Currently logging emails can crash if there are more inline image attachments than img tags.

Steps to reproduce
-----
1. Reply to an email that has an inline image
2. From the reply, select "Log Email Into Contact"
3. No log is created and the button is stuck in the loading state

Cause
-----
Currently, we loop through `inlineAttachments` to match them one-to-one with the document's `img` tags.
But the counter does not consider the case where there's a different number of `inlineAttachments` and `imageElements`.
This usually happens when there's an img in the email history which is removed at the top of the function, but the attachment still exists.
Some emails can also have embeded inline attachments that are unused.

Fix
-----
Use two counters so that we don't hit an index out of bounds error. Also filter by `img` elements using `cid:` in src,
so we don't overwrite `img` elements using URL images.

opw-4855422
@@ -120,30 +120,35 @@ class Logger extends React.Component<LoggerProps, LoggerState> {
}
}
});
// a counter is needed to map img tags with attachments, as outlook does not provide
// attempt to map img tags with attachments by index, as outlook does not provide
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

previous code seems fishy, can't it be rework ?
(yours with 2 indexes look even more fishy)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a task to rework the addon, but not the time atm (in the oxp rush)
I can have a look when I rework them if you don't find

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm mapping by indices since the Office API does not expose any way to map via contentId. This seems to be a known limitation: OfficeDev/office-js#4987 which is probably the same issue the original code was working around. Two indices are needed since the arrays could be of different lengths. There is still a rare case if the attachments are in a different order than the body, then they will be inserted in the wrong order.

The most robust way to do this would be to fetch the entire .eml file and process the attachments through that since the contentId will be in the .eml data (the linked issue describes this). However I think this method could be saved for the addon rework.

@juwu-odoo juwu-odoo requested a review from std-odoo July 18, 2025 18:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants