Skip to content

[ADD] mail_external_cleaner#106

Open
etobella wants to merge 1 commit intoOCA:16.0from
dixmit:16.0-add-mail_external_cleaner
Open

[ADD] mail_external_cleaner#106
etobella wants to merge 1 commit intoOCA:16.0from
dixmit:16.0-add-mail_external_cleaner

Conversation

@etobella
Copy link
Copy Markdown
Member

@etobella etobella commented Nov 5, 2025

Clean up email content by removing unnecessary external resources.
Makes sense for isolated environments with emails.

TODO:

  • tests

@etobella etobella force-pushed the 16.0-add-mail_external_cleaner branch 4 times, most recently from 40c214e to 3b83a55 Compare November 6, 2025 09:51
@etobella etobella force-pushed the 16.0-add-mail_external_cleaner branch from 3b83a55 to 9395b7d Compare November 6, 2025 09:56
Copy link
Copy Markdown

@luisDIXMIT luisDIXMIT left a comment

Choose a reason for hiding this comment

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

I tested sending an email with images, and the source image link is still in the HTML code.

image

Copy link
Copy Markdown

@marcos-mendez marcos-mendez left a comment

Choose a reason for hiding this comment

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

Automated Review -- Tests Failed

1. Root Cause

The test failure occurs because the ir.mail_server model's build_email method is being overridden, but the super() call does not properly pass all arguments due to an incorrect signature mismatch in the method definition.

2. Suggested Fix

In mail_external_cleaner/models/ir_mail_server.py, line 32, the method signature should match the parent class exactly. Specifically, the parameter subtype_alternative is missing from the method definition. Correct the method signature to include all parameters expected by super().build_email().

def build_email(
    self,
    email_from,
    email_to,
    subject,
    body,
    email_cc=None,
    email_bcc=None,
    reply_to=False,
    attachments=None,
    message_id=None,
    references=None,
    object_id=False,
    subtype="plain",
    headers=None,
    body_alternative=None,
    subtype_alternative="plain",  # <-- Add this line
):

3. Additional Code Issues

  • In mail_mail.py: The _get_image_attachment method does not handle exceptions when decoding base64 data or fetching attachments, which could cause runtime errors if invalid data is encountered.
  • In mail_mail.py: The regex pattern IMAGE_REGEX is not robust enough to handle all possible image URLs and may miss edge cases; it's better to use a more flexible approach or validate URL structure more strictly.

4. Test Improvements

Add tests using TransactionCase to cover:

  • Sending emails with inline images using data URIs.
  • Ensuring that build_email correctly processes HTML content and replaces data URIs with inline attachments.
  • Testing _embed_images with various image sources including local company logos and IR attachments.
  • Verifying that portal customer access is disabled in email notifications via _notify_get_recipients_groups.

Use tagged tests for:

  • @tag('post_install') for integration tests.
  • @tag('at_install') for tests that must run at module installation time.

Example test case:

def test_build_email_with_inline_images(self):
    server = self.env['ir.mail_server'].create({})
    body = '<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8/5+hHgAHggJ/PchI7wAAAABJRU5ErkJggg==">'
    msg = server.build_email('test@example.com', 'to@example.com', 'Subject', body, subtype='html')
    self.assertIn('Content-ID', msg.get_payload(0).get_headers())

This ensures proper handling of inline images and correct attachment processing during email sending.


⏰ PR Aging Alert

This PR by @etobella has been open for 130 days (4 months).
💤 No activity for 94 days. Has this PR been forgotten?

Every ignored PR is a contributor who might not come back. Review time matters. (OCA Aging Report)


Reciprocal Review Request

Hi everyone! I found some test failures on this PR and left detailed feedback above. I am happy to discuss or help debug. In the meantime, if any of you get a chance, I would appreciate a look at my open PR(s):

My open PRs across OCA:

Reviewing each other's work helps the whole community move forward. Thank you!


Environment via OCA Neural Reviewer: Minikube + K8s Job + oca-ci/py3.10-odoo16.0 | Odoo 16.0
Automated review by OCA Neural Reviewer + qwen3-coder:30b

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.

3 participants