Skip to content

Commit

Permalink
[FIX] account_edi: enable to parse XML facturx in mail
Browse files Browse the repository at this point in the history
Issue:

  When receiving a mail with a facturx XML file as attachment,
  the datas in the XML files are not parsed.

Cause:

  For security reason, if a mail attachment is a XML file, it will
  be saved as plain text and therefore not be parsed.

Solution:

  If attachment mimetype is `plain/text` and content starts with
  `<?xml`, consider attachment as XML for the parsing.

opw-2655445

closes odoo#91570

X-original-commit: c402815
Signed-off-by: William André (wan) <wan@odoo.com>
  • Loading branch information
nboulif committed May 17, 2022
1 parent 30f6847 commit b0537fe
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion addons/account_edi/models/account_edi_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,12 @@ def _decode_attachment(self, attachment):
content = base64.b64decode(attachment.with_context(bin_size=False).datas)
to_process = []

# XML attachments received by mail have a 'text/plain' mimetype.
# Therefore, if content start with '<?xml', it is considered as XML.
is_text_plain_xml = 'text/plain' in attachment.mimetype and content.startswith(b'<?xml')
if 'pdf' in attachment.mimetype:
to_process.extend(self._decode_pdf(attachment.name, content))
elif 'xml' in attachment.mimetype:
elif 'xml' in attachment.mimetype or is_text_plain_xml:
to_process.extend(self._decode_xml(attachment.name, content))
else:
to_process.extend(self._decode_binary(attachment.name, content))
Expand Down

0 comments on commit b0537fe

Please sign in to comment.