Skip to content
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

Email templates with <!--[if mso]> statements are broken #26396

Open
SvbZ3r0 opened this issue May 10, 2024 · 2 comments
Open

Email templates with <!--[if mso]> statements are broken #26396

SvbZ3r0 opened this issue May 10, 2024 · 2 comments
Labels

Comments

@SvbZ3r0
Copy link
Contributor

SvbZ3r0 commented May 10, 2024

Somewhere between creating an email template and using it, the template is processed in such a way that comments are url-encoded. This causes complex HTML templates to break.
For example,

<!--[if (mso 16)]>
    <style type="text/css">
    a {text-decoration: none;}
    </style>
    <![endif]--><!--[if gte mso 9]><style>sup { font-size: 100% !important; }</style><![endif]--><!--[if gte mso 9]>
<xml>
    <o:OfficeDocumentSettings>
    <o:AllowPNG></o:AllowPNG>
    <o:PixelsPerInch>96</o:PixelsPerInch>
    </o:OfficeDocumentSettings>
</xml>
<![endif]-->

is converted to

<!--[if (mso 16)]&gt;
    &lt;style type=&quot;text/css&quot;&gt;
    a {text-decoration: none;}
    &lt;/style&gt;
    &lt;![endif]--><!--[if gte mso 9]&gt;&lt;style&gt;sup { font-size: 100% !important; }&lt;/style&gt;&lt;![endif]--><!--[if gte mso 9]&gt;
&lt;xml&gt;
    &lt;o:OfficeDocumentSettings&gt;
    &lt;o:AllowPNG&gt;&lt;/o:AllowPNG&gt;
    &lt;o:PixelsPerInch&gt;96&lt;/o:PixelsPerInch&gt;
    &lt;/o:OfficeDocumentSettings&gt;
&lt;/xml&gt;
&lt;![endif]-->

Conditional statements like this are important to maintain cross-client compatibility for email templates.

In the end result, these emails are broken specifically when rendered on Outlook for Windows. Or maybe, my emails are broken in Outlook because the conditional statements here are specifically targetted towards Outlook. In either case, Outlook is still one of the leading email clients used in business settings.

@SvbZ3r0 SvbZ3r0 added the bug label May 10, 2024
@SvbZ3r0
Copy link
Contributor Author

SvbZ3r0 commented May 10, 2024

For context, the actual issue I have is that some emails are received empty when viewed in Outlook for Windows. I noticed this when still receiving blank test emails even after frappe/erpnext#41168 was fixed. I noticed by chance that the same email would render properly when viewed on my phone. I then found that the same template functions perfectly well even on Outlook for Windows when it was sent from outside the Frappe environment.
Clearly, something is causing the ancient renderer that Windows Outlook uses to discard the contents of these emails. After much testing, I found that any part after a conditional statement is discarded by Outlook.
Debugging this has been a nightmare. At the moment, my best guess as to why this happens is due to the conditional statements being encoded, but the issue might lie elsewhere.

@SvbZ3r0
Copy link
Contributor Author

SvbZ3r0 commented May 10, 2024

I've tracked the source of this issue all the way to here:

escaped_html = bleach.clean(
html,
tags=tags,
attributes=attributes,
css_sanitizer=css_sanitizer,
strip_comments=False,
protocols={"cid", "http", "https", "mailto"},
)

However, any changes in this function will affect all user input HTML in Frappe. It is also called in BaseDocument against every single field in every single doctype. I understand the need to sanitize HTML, but there's got to be a safe way to allow conditional html statements.

I've read a bit more on the subject and these conditional statements are only necessary for and executed by Windows IE and Outlook. Although Outlook only accounts for 4.06% of global market share of email clients, it still has an astounding 94.5% market share within businesses.

For the CRM module to be of any use for b2b users, full support for Outlook is absolutely necessary.

I'm in way over my head here. @ankush @shariquerik your inputs are valuable.

On a separate note, Bleach has been deprecated for over a year now.

@SvbZ3r0 SvbZ3r0 changed the title Email templates with conditional statements are broken Email templates with <!--[if mso]> statements are broken May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant