Skip to content
Snippets Groups Projects
user avatar
Nasreddin Boulif (bon) authored
Steps to reproduce:

  On Odoo:
  - Install `Documents` module
  - Go to `Settings` and set a Custom Email Server(ex. `mydomain.com`)
  - Ensure an alias exist for the model `document.document` with
    `inbox-financial` as alias name

  In mail client:
  - Send a mail with an image in the body to the following email:
    inbox-financial@mydomain.com

Issue:

  Mail not received (traceback in logs)

Cause:

  Since we use the email alias `inbox-financial`, we process the mail
  through the `document.document` model where we have an override of the
  `_message_post_after_hook` method that is called after that the
  `msg_values` values are post-processed and where we do another
  message_post() for the new document create for the attachment (in
  this case, an image).

  https://github.com/odoo/enterprise/blob/2c3596e4e18c201809558d3ea878b141e366a027/documents/models/document.py#L305

  During the parsing, the mail values are updated through the
  `_process_attachments_for_post` method:

  https://github.com/odoo/odoo/blob/6c0d2d7a9d44459f3e09a38bd80ef9b018e8c946/addons/mail/models/mail_thread.py#L1881-L1904

  On posting the first time, the original type of the `body` value is a
  `str`, but the post-processed value (because there is some CIDS in the
  body) is of type `bytes` (because using `encoding='UTF-8'` with
  `lxml.html.tostring`).

  https://github.com/odoo/odoo/blob/510a997017a9cbe14522a0013a578f6d1d9b257a/addons/mail/models/mail_thread.py#L2209

  Then in the `_message_post_after_hook` we call post again on the
  newly created document record by using post-processed value of body
  who is of type `bytes`.

  On posting the second time (for the document record), the `body`
  value is of type `bytes` and when checking if the body is empty with
  `is_html_empty` that received a string as param, an error is
  raised.

Solution:

  Use `encoding='unicode'` to return a string instead of bytes.

  https://lxml.de/api/lxml.etree-module.html#tostring

ENT PR : https://github.com/odoo/enterprise/pull/42653



opw-3273583

closes odoo/odoo#133339

Signed-off-by: default avatarThibault Delavallee (tde) <tde@openerp.com>
f910987c
History
Name Last commit Last update
..
account
account_check_printing
account_debit_note
account_edi
account_edi_extended
account_edi_facturx
account_edi_proxy_client
account_edi_ubl
account_edi_ubl_cii
account_fleet
account_lock
account_payment
account_qr_code_sepa
account_tax_python
account_test
adyen_platforms
analytic
association
attachment_indexation
auth_ldap
auth_oauth
auth_password_policy
auth_password_policy_portal
auth_password_policy_signup
auth_signup
auth_totp
auth_totp_portal
barcodes
base_address_city
base_address_extended
base_automation
base_geolocalize
base_iban
base_import
base_import_module
base_setup
base_sparse_field
base_vat
board
bus
calendar
calendar_sms
contacts
coupon
crm
crm_iap_lead
crm_iap_lead_enrich
crm_iap_lead_website
crm_livechat
crm_sms
delivery
digest
event
event_crm
event_crm_sale
event_sale
event_sms
fetchmail
fetchmail_gmail
fetchmail_outlook
fleet
gamification
gamification_sale_crm
google_account
google_calendar
google_drive
google_gmail
google_recaptcha
google_spreadsheet
hr
hr_attendance
hr_contract
hr_expense
hr_fleet
hr_gamification
hr_holidays
hr_holidays_attendance
hr_maintenance
hr_org_chart
hr_presence
hr_recruitment
hr_recruitment_survey
hr_skills
hr_skills_slides
hr_skills_survey
hr_timesheet
hr_timesheet_attendance
hr_work_entry
http_routing
hw_drivers
hw_escpos
hw_posbox_homepage
iap
iap_crm
iap_mail
im_livechat
im_livechat_mail_bot
l10n_account_edi_ubl_cii_tests
l10n_ae
l10n_ar