diff --git a/mail_inline_css/README.rst b/mail_inline_css/README.rst new file mode 100644 index 00000000..409bd977 --- /dev/null +++ b/mail_inline_css/README.rst @@ -0,0 +1,99 @@ +=============== +Mail Inline CSS +=============== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:e3cd02099a2beb9db6980920f3d0547a5154e4a386f2f3e3bf189342a85a2110 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fmail-lightgray.png?logo=github + :target: https://github.com/OCA/mail/tree/18.0/mail_inline_css + :alt: OCA/mail +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/mail-18-0/mail-18-0-mail_inline_css + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/mail&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Convert styles to inline styles and make them play nice with emails. + +This module sole usage is to provide the same parsing functionality as +in the web editor but for the templates imported directly in database. + +**Table of contents** + +.. contents:: + :local: + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Akretion +* camptocamp + +Contributors +------------ + +- David BEAL + +- Akim Juillerat + +- Simone Orsi + +- Patrick Tombez + +- Phuc Tran Thanh + +- `Trobz `__: + + - Son Ho + - Khoi Vo + +Other credits +------------- + +The migration of this module from 16.0 to 18.0 was financially supported +by Camptocamp + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/mail `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mail_inline_css/__init__.py b/mail_inline_css/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/mail_inline_css/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/mail_inline_css/__manifest__.py b/mail_inline_css/__manifest__.py new file mode 100644 index 00000000..85914a80 --- /dev/null +++ b/mail_inline_css/__manifest__.py @@ -0,0 +1,17 @@ +# Copyright 2017 David BEAL @ Akretion +# Copyright 2019 Camptocamp SA + +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + "name": "Mail Inline CSS", + "summary": "Convert style tags in inline style in your mails", + "version": "18.0.1.0.0", + "author": "Akretion, camptocamp, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/mail", + "license": "AGPL-3", + "category": "Tools", + "installable": True, + "external_dependencies": {"python": ["premailer"]}, + "depends": ["mail"], + "demo": ["demo/demo_mail_template.xml"], +} diff --git a/mail_inline_css/demo/demo_mail_template.xml b/mail_inline_css/demo/demo_mail_template.xml new file mode 100644 index 00000000..a26086e5 --- /dev/null +++ b/mail_inline_css/demo/demo_mail_template.xml @@ -0,0 +1,102 @@ + + + + Inline styles demo + + Demo email inline styles + + + + + +
+
+ + + + + + + +
+ + + +
+
+
+
+

Hello .

+
+
+

This e-mail styles are inline rendered although its template defines styles as embedded CSS!

+
+
+ +
+ + +
+
+
diff --git a/mail_inline_css/i18n/de.po b/mail_inline_css/i18n/de.po new file mode 100644 index 00000000..dfb2ec63 --- /dev/null +++ b/mail_inline_css/i18n/de.po @@ -0,0 +1,51 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_inline_css +# +# Translators: +# Niki Waibel , 2018 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-01-16 03:47+0000\n" +"PO-Revision-Date: 2018-01-16 03:47+0000\n" +"Last-Translator: Niki Waibel , 2018\n" +"Language-Team: German (https://www.transifex.com/oca/teams/23907/de/)\n" +"Language: de\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: mail_inline_css +#: model:mail.template,subject:mail_inline_css.email_template_demo +msgid "Demo email inline styles" +msgstr "" + +#. module: mail_inline_css +#: model:ir.model,name:mail_inline_css.model_mail_template +msgid "Email Templates" +msgstr "E-Mail Vorlagen" + +#. module: mail_inline_css +#: model_terms:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "Hello" +msgstr "" + +#. module: mail_inline_css +#: model:mail.template,name:mail_inline_css.email_template_demo +msgid "Inline styles demo" +msgstr "" + +#. module: mail_inline_css +#: model_terms:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "" +"This e-mail styles are inline rendered although its template defines styles " +"as embedded CSS!" +msgstr "" + +#. module: mail_inline_css +#: model_terms:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "www.example.com" +msgstr "" diff --git a/mail_inline_css/i18n/es.po b/mail_inline_css/i18n/es.po new file mode 100644 index 00000000..d781ea29 --- /dev/null +++ b/mail_inline_css/i18n/es.po @@ -0,0 +1,46 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_inline_css +# +# Translators: +# Pedro M. Baeza , 2018 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-01-16 03:47+0000\n" +"PO-Revision-Date: 2018-01-16 03:47+0000\n" +"Last-Translator: Pedro M. Baeza , 2018\n" +"Language-Team: Spanish (https://www.transifex.com/oca/teams/23907/es/)\n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: mail_inline_css +#: model:mail.template,subject:mail_inline_css.email_template_demo +msgid "Demo email inline styles" +msgstr "" + +#. module: mail_inline_css +#: model:ir.model,name:mail_inline_css.model_mail_template +msgid "Email Templates" +msgstr "Plantillas de correo electrónico" + +#. module: mail_inline_css +#: model_terms:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "Hello" +msgstr "" + +#. module: mail_inline_css +#: model_terms:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "" +"This e-mail styles are inline rendered although its template defines styles " +"as embedded CSS!" +msgstr "" + +#. module: mail_inline_css +#: model_terms:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "www.example.com" +msgstr "" diff --git a/mail_inline_css/i18n/es_MX.po b/mail_inline_css/i18n/es_MX.po new file mode 100644 index 00000000..14a7466d --- /dev/null +++ b/mail_inline_css/i18n/es_MX.po @@ -0,0 +1,47 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_inline_css +# +# Translators: +# OCA Transbot , 2018 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-01-16 03:47+0000\n" +"PO-Revision-Date: 2018-01-16 03:47+0000\n" +"Last-Translator: OCA Transbot , 2018\n" +"Language-Team: Spanish (Mexico) (https://www.transifex.com/oca/teams/23907/" +"es_MX/)\n" +"Language: es_MX\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: mail_inline_css +#: model:mail.template,subject:mail_inline_css.email_template_demo +msgid "Demo email inline styles" +msgstr "" + +#. module: mail_inline_css +#: model:ir.model,name:mail_inline_css.model_mail_template +msgid "Email Templates" +msgstr "Plantillas de Correo Electrónico" + +#. module: mail_inline_css +#: model_terms:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "Hello" +msgstr "" + +#. module: mail_inline_css +#: model_terms:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "" +"This e-mail styles are inline rendered although its template defines styles " +"as embedded CSS!" +msgstr "" + +#. module: mail_inline_css +#: model_terms:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "www.example.com" +msgstr "" diff --git a/mail_inline_css/i18n/fr.po b/mail_inline_css/i18n/fr.po new file mode 100644 index 00000000..3a8135c8 --- /dev/null +++ b/mail_inline_css/i18n/fr.po @@ -0,0 +1,46 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_inline_css +# +# Translators: +# Quentin THEURET , 2018 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-01-16 03:47+0000\n" +"PO-Revision-Date: 2018-01-16 03:47+0000\n" +"Last-Translator: Quentin THEURET , 2018\n" +"Language-Team: French (https://www.transifex.com/oca/teams/23907/fr/)\n" +"Language: fr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" + +#. module: mail_inline_css +#: model:mail.template,subject:mail_inline_css.email_template_demo +msgid "Demo email inline styles" +msgstr "" + +#. module: mail_inline_css +#: model:ir.model,name:mail_inline_css.model_mail_template +msgid "Email Templates" +msgstr "Modèles de courriel" + +#. module: mail_inline_css +#: model_terms:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "Hello" +msgstr "" + +#. module: mail_inline_css +#: model_terms:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "" +"This e-mail styles are inline rendered although its template defines styles " +"as embedded CSS!" +msgstr "" + +#. module: mail_inline_css +#: model_terms:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "www.example.com" +msgstr "" diff --git a/mail_inline_css/i18n/hr.po b/mail_inline_css/i18n/hr.po new file mode 100644 index 00000000..ba019a69 --- /dev/null +++ b/mail_inline_css/i18n/hr.po @@ -0,0 +1,47 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_inline_css +# +# Translators: +# OCA Transbot , 2018 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-01-16 03:47+0000\n" +"PO-Revision-Date: 2018-01-16 03:47+0000\n" +"Last-Translator: OCA Transbot , 2018\n" +"Language-Team: Croatian (https://www.transifex.com/oca/teams/23907/hr/)\n" +"Language: hr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" +"%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2;\n" + +#. module: mail_inline_css +#: model:mail.template,subject:mail_inline_css.email_template_demo +msgid "Demo email inline styles" +msgstr "" + +#. module: mail_inline_css +#: model:ir.model,name:mail_inline_css.model_mail_template +msgid "Email Templates" +msgstr "Predlošci mailova" + +#. module: mail_inline_css +#: model_terms:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "Hello" +msgstr "" + +#. module: mail_inline_css +#: model_terms:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "" +"This e-mail styles are inline rendered although its template defines styles " +"as embedded CSS!" +msgstr "" + +#. module: mail_inline_css +#: model_terms:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "www.example.com" +msgstr "" diff --git a/mail_inline_css/i18n/it.po b/mail_inline_css/i18n/it.po new file mode 100644 index 00000000..8d05b4b8 --- /dev/null +++ b/mail_inline_css/i18n/it.po @@ -0,0 +1,49 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_inline_css +# +# Translators: +# Marius Marolla , 2018 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-01-16 03:47+0000\n" +"PO-Revision-Date: 2024-03-05 16:35+0000\n" +"Last-Translator: mymage \n" +"Language-Team: Italian (https://www.transifex.com/oca/teams/23907/it/)\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: mail_inline_css +#: model:mail.template,subject:mail_inline_css.email_template_demo +msgid "Demo email inline styles" +msgstr "Demo stili inline e-mail" + +#. module: mail_inline_css +#: model:ir.model,name:mail_inline_css.model_mail_template +msgid "Email Templates" +msgstr "Modelli Email" + +#. module: mail_inline_css +#: model_terms:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "Hello" +msgstr "Salve" + +#. module: mail_inline_css +#: model_terms:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "" +"This e-mail styles are inline rendered although its template defines styles " +"as embedded CSS!" +msgstr "" +"Questi stili e-mail sono resi inline anche se il loro modello definisce " +"stili come CSS incorporati!" + +#. module: mail_inline_css +#: model_terms:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "www.example.com" +msgstr "www.example.com" diff --git a/mail_inline_css/i18n/mail_inline_css.pot b/mail_inline_css/i18n/mail_inline_css.pot new file mode 100644 index 00000000..3830d2d2 --- /dev/null +++ b/mail_inline_css/i18n/mail_inline_css.pot @@ -0,0 +1,46 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_inline_css +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: mail_inline_css +#: model:mail.template,subject:mail_inline_css.email_template_demo +msgid "Demo email inline styles" +msgstr "" + +#. module: mail_inline_css +#: model:ir.model,name:mail_inline_css.model_mail_template +msgid "Email Templates" +msgstr "" + +#. module: mail_inline_css +#: model_terms:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "Hello" +msgstr "" + +#. module: mail_inline_css +#: model:mail.template,name:mail_inline_css.email_template_demo +msgid "Inline styles demo" +msgstr "" + +#. module: mail_inline_css +#: model_terms:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "" +"This e-mail styles are inline rendered although its template defines styles " +"as embedded CSS!" +msgstr "" + +#. module: mail_inline_css +#: model_terms:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "www.example.com" +msgstr "" diff --git a/mail_inline_css/i18n/nl_NL.po b/mail_inline_css/i18n/nl_NL.po new file mode 100644 index 00000000..502b990a --- /dev/null +++ b/mail_inline_css/i18n/nl_NL.po @@ -0,0 +1,47 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_inline_css +# +# Translators: +# Peter Hageman , 2018 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-01-16 03:47+0000\n" +"PO-Revision-Date: 2018-01-16 03:47+0000\n" +"Last-Translator: Peter Hageman , 2018\n" +"Language-Team: Dutch (Netherlands) (https://www.transifex.com/oca/" +"teams/23907/nl_NL/)\n" +"Language: nl_NL\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#. module: mail_inline_css +#: model:mail.template,subject:mail_inline_css.email_template_demo +msgid "Demo email inline styles" +msgstr "" + +#. module: mail_inline_css +#: model:ir.model,name:mail_inline_css.model_mail_template +msgid "Email Templates" +msgstr "E-mailsjablonen" + +#. module: mail_inline_css +#: model_terms:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "Hello" +msgstr "" + +#. module: mail_inline_css +#: model_terms:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "" +"This e-mail styles are inline rendered although its template defines styles " +"as embedded CSS!" +msgstr "" + +#. module: mail_inline_css +#: model_terms:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "www.example.com" +msgstr "" diff --git a/mail_inline_css/i18n/zh_CN.po b/mail_inline_css/i18n/zh_CN.po new file mode 100644 index 00000000..051bd42c --- /dev/null +++ b/mail_inline_css/i18n/zh_CN.po @@ -0,0 +1,47 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_inline_css +# +# Translators: +# OCA Transbot , 2018 +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 10.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-01-16 03:47+0000\n" +"PO-Revision-Date: 2018-01-16 03:47+0000\n" +"Last-Translator: OCA Transbot , 2018\n" +"Language-Team: Chinese (China) (https://www.transifex.com/oca/teams/23907/" +"zh_CN/)\n" +"Language: zh_CN\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=1; plural=0;\n" + +#. module: mail_inline_css +#: model:mail.template,subject:mail_inline_css.email_template_demo +msgid "Demo email inline styles" +msgstr "" + +#. module: mail_inline_css +#: model:ir.model,name:mail_inline_css.model_mail_template +msgid "Email Templates" +msgstr "Email 模板" + +#. module: mail_inline_css +#: model_terms:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "Hello" +msgstr "" + +#. module: mail_inline_css +#: model_terms:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "" +"This e-mail styles are inline rendered although its template defines styles " +"as embedded CSS!" +msgstr "" + +#. module: mail_inline_css +#: model_terms:ir.ui.view,arch_db:mail_inline_css.demo_email_hello +msgid "www.example.com" +msgstr "" diff --git a/mail_inline_css/models/__init__.py b/mail_inline_css/models/__init__.py new file mode 100644 index 00000000..44e83956 --- /dev/null +++ b/mail_inline_css/models/__init__.py @@ -0,0 +1 @@ +from . import mail_template diff --git a/mail_inline_css/models/mail_template.py b/mail_inline_css/models/mail_template.py new file mode 100644 index 00000000..ff1f9210 --- /dev/null +++ b/mail_inline_css/models/mail_template.py @@ -0,0 +1,27 @@ +# Copyright 2017 David BEAL @ Akretion +# Copyright 2019 Camptocamp SA + +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from premailer import Premailer + +from odoo import models + + +class MailTemplate(models.Model): + _inherit = "mail.template" + + def _render_template_postprocess(self, model, rendered): + rendered = super()._render_template_postprocess(model, rendered) + for res_id, html in rendered.items(): + rendered[res_id] = self._premailer_apply_transform(html) + return rendered + + def _premailer_apply_transform(self, html): + if not html.strip(): + return html + premailer = Premailer(html=html, **self._get_premailer_options()) + return premailer.transform() + + def _get_premailer_options(self): + return {} diff --git a/mail_inline_css/pyproject.toml b/mail_inline_css/pyproject.toml new file mode 100644 index 00000000..4231d0cc --- /dev/null +++ b/mail_inline_css/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/mail_inline_css/readme/CONTRIBUTORS.md b/mail_inline_css/readme/CONTRIBUTORS.md new file mode 100644 index 00000000..3a131d66 --- /dev/null +++ b/mail_inline_css/readme/CONTRIBUTORS.md @@ -0,0 +1,14 @@ +- David BEAL \<\> + +- Akim Juillerat \<\> + +- Simone Orsi \<\> + +- Patrick Tombez \<\> + +- Phuc Tran Thanh \<\> + +- [Trobz](https://trobz.com): + + > - Son Ho \<\> + > - Khoi Vo \<\> diff --git a/mail_inline_css/readme/CREDITS.md b/mail_inline_css/readme/CREDITS.md new file mode 100644 index 00000000..d514b5fb --- /dev/null +++ b/mail_inline_css/readme/CREDITS.md @@ -0,0 +1,2 @@ +The migration of this module from 16.0 to 18.0 was financially supported +by Camptocamp diff --git a/mail_inline_css/readme/DESCRIPTION.md b/mail_inline_css/readme/DESCRIPTION.md new file mode 100644 index 00000000..16543a80 --- /dev/null +++ b/mail_inline_css/readme/DESCRIPTION.md @@ -0,0 +1,4 @@ +Convert styles to inline styles and make them play nice with emails. + +This module sole usage is to provide the same parsing functionality as +in the web editor but for the templates imported directly in database. diff --git a/mail_inline_css/static/description/icon.png b/mail_inline_css/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/mail_inline_css/static/description/icon.png differ diff --git a/mail_inline_css/static/description/index.html b/mail_inline_css/static/description/index.html new file mode 100644 index 00000000..326db3c1 --- /dev/null +++ b/mail_inline_css/static/description/index.html @@ -0,0 +1,449 @@ + + + + + +Mail Inline CSS + + + +
+

Mail Inline CSS

+ + +

Beta License: AGPL-3 OCA/mail Translate me on Weblate Try me on Runboat

+

Convert styles to inline styles and make them play nice with emails.

+

This module sole usage is to provide the same parsing functionality as +in the web editor but for the templates imported directly in database.

+

Table of contents

+ +
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Akretion
  • +
  • camptocamp
  • +
+
+
+

Contributors

+ +
+
+

Other credits

+

The migration of this module from 16.0 to 18.0 was financially supported +by Camptocamp

+
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/mail project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/mail_inline_css/tests/__init__.py b/mail_inline_css/tests/__init__.py new file mode 100644 index 00000000..46429763 --- /dev/null +++ b/mail_inline_css/tests/__init__.py @@ -0,0 +1 @@ +from . import test_mail_inline_styles diff --git a/mail_inline_css/tests/test_mail_inline_styles.py b/mail_inline_css/tests/test_mail_inline_styles.py new file mode 100644 index 00000000..2b5a2183 --- /dev/null +++ b/mail_inline_css/tests/test_mail_inline_styles.py @@ -0,0 +1,59 @@ +# Copyright 2019 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from lxml import html + +from odoo.tests import TransactionCase + + +class TestMailInlineStyles(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.mail_template = cls.env.ref("mail_inline_css.email_template_demo") + cls.demo_user = cls.env.ref("base.user_demo") + + def to_xml_node(self, html_): + return html.fragments_fromstring(html_) + + def parse_node_style(self, node): + """Convert node CSS string to Python dict""" + res = {} + for style in node.attrib.get("style", "").split(";"): + rule = style.split(":") + res[rule[0].strip()] = rule[1].strip() + return res + + def find_by_id(self, node, html_id): + return node.xpath(f'//*[@id="{html_id}"]') + + def assertNodeStyle(self, node, expected): + self.assertIn("style", node.attrib) + self.assertEqual(self.parse_node_style(node), expected) + + def test_generate_mail(self): + res = self.mail_template._generate_template( + [self.demo_user.id], render_fields=["body_html"] + ) + body_html_string = res[self.demo_user.id].get("body_html") + html_node = self.to_xml_node(body_html_string)[0] + + expected = { + "main_logo": {"max-width": "300px"}, + "main_wrapper": { + "max-width": "620px", + "margin": "0 auto", + "border": "1px solid #ccc", + "font-size": "18px", + "font-family": "verdana", + "color": "#6B6E71", + }, + "main_footer": { + "padding-top": "0", + "font-size": "120%", + "padding": "30px 40px", + }, + } + + for html_id, expected_style in expected.items(): + node = self.find_by_id(html_node, html_id)[0] + self.assertNodeStyle(node, expected_style) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..4fb8946e --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +# generated from manifests external_dependencies +premailer