diff --git a/mail_inline_css/README.rst b/mail_inline_css/README.rst new file mode 100644 index 000000000..bbcb0ad84 --- /dev/null +++ b/mail_inline_css/README.rst @@ -0,0 +1,89 @@ +=============== +Mail Inline CSS +=============== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fsocial-lightgray.png?logo=github + :target: https://github.com/OCA/social/tree/16.0/mail_inline_css + :alt: OCA/social +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/social-16-0/social-16-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/webui/builds.html?repo=OCA/social&target_branch=16.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 smashing 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 + +Other credits +~~~~~~~~~~~~~ + +The migration of this module from 15.0 to 16.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/social `_ 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 000000000..0650744f6 --- /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 000000000..1f94d47d0 --- /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": "16.0.0.1.0", + "author": "Akretion, camptocamp, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/social", + "license": "AGPL-3", + "category": "Tools", + "installable": True, + "external_dependencies": {"python": ["premailer"]}, + "depends": ["email_template_qweb"], + "demo": ["demo/demo_template.xml", "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 000000000..57211f977 --- /dev/null +++ b/mail_inline_css/demo/demo_mail_template.xml @@ -0,0 +1,10 @@ + + + + Inline styles demo + qweb_view + + + Demo email inline styles + + diff --git a/mail_inline_css/demo/demo_template.xml b/mail_inline_css/demo/demo_template.xml new file mode 100644 index 000000000..6171b77c7 --- /dev/null +++ b/mail_inline_css/demo/demo_template.xml @@ -0,0 +1,92 @@ + + + + diff --git a/mail_inline_css/i18n/de.po b/mail_inline_css/i18n/de.po new file mode 100644 index 000000000..d2f27f65e --- /dev/null +++ b/mail_inline_css/i18n/de.po @@ -0,0 +1,61 @@ +# 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.fields,field_description:mail_inline_css.field_mail_template__display_name +msgid "Display Name" +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:ir.model.fields,field_description:mail_inline_css.field_mail_template__id +msgid "ID" +msgstr "" + +#. module: mail_inline_css +#: model:ir.model.fields,field_description:mail_inline_css.field_mail_template____last_update +msgid "Last Modified on" +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 000000000..d781ea29e --- /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 000000000..14a7466d6 --- /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 000000000..3a8135c89 --- /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 000000000..ba019a69d --- /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 000000000..2d3c31194 --- /dev/null +++ b/mail_inline_css/i18n/it.po @@ -0,0 +1,46 @@ +# 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: 2018-01-16 03:47+0000\n" +"Last-Translator: Marius Marolla , 2018\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" + +#. 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 "Modelli 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/i18n/mail_inline_css.pot b/mail_inline_css/i18n/mail_inline_css.pot new file mode 100644 index 000000000..772a6f15f --- /dev/null +++ b/mail_inline_css/i18n/mail_inline_css.pot @@ -0,0 +1,56 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_inline_css +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.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.fields,field_description:mail_inline_css.field_mail_template__display_name +msgid "Display Name" +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:ir.model.fields,field_description:mail_inline_css.field_mail_template__id +msgid "ID" +msgstr "" + +#. module: mail_inline_css +#: model:ir.model.fields,field_description:mail_inline_css.field_mail_template____last_update +msgid "Last Modified on" +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 000000000..502b990ab --- /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 000000000..051bd42c9 --- /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 000000000..44e83956e --- /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 000000000..f31703a2f --- /dev/null +++ b/mail_inline_css/models/mail_template.py @@ -0,0 +1,33 @@ +# Copyright 2017 David BEAL @ Akretion +# Copyright 2019 Camptocamp SA + +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import models + +try: + from premailer import Premailer +except (ImportError, IOError) as err: # pragma: no cover + import logging + + _logger = logging.getLogger(__name__) + _logger.debug(err) + + +class MailTemplate(models.Model): + _inherit = "mail.template" + + def _render_template_postprocess(self, rendered): + rendered = super()._render_template_postprocess(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/readme/CONTRIBUTORS.rst b/mail_inline_css/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..761008460 --- /dev/null +++ b/mail_inline_css/readme/CONTRIBUTORS.rst @@ -0,0 +1,8 @@ +* David BEAL +* Akim Juillerat +* Simone Orsi +* Patrick Tombez +* Phuc Tran Thanh +* `Trobz `_: + + * Son Ho diff --git a/mail_inline_css/readme/CREDITS.rst b/mail_inline_css/readme/CREDITS.rst new file mode 100644 index 000000000..70bc307ad --- /dev/null +++ b/mail_inline_css/readme/CREDITS.rst @@ -0,0 +1 @@ +The migration of this module from 15.0 to 16.0 was financially supported by Camptocamp diff --git a/mail_inline_css/readme/DESCRIPTION.rst b/mail_inline_css/readme/DESCRIPTION.rst new file mode 100644 index 000000000..309573627 --- /dev/null +++ b/mail_inline_css/readme/DESCRIPTION.rst @@ -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 000000000..3a0328b51 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 000000000..60ebce14b --- /dev/null +++ b/mail_inline_css/static/description/index.html @@ -0,0 +1,443 @@ + + + + + + +Mail Inline CSS + + + +
+

Mail Inline CSS

+ + +

Beta License: AGPL-3 OCA/social 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 smashing 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 15.0 to 16.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/social 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 000000000..464297637 --- /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 000000000..e518d75d8 --- /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('//*[@id="{}"]'.format(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_email( + [self.demo_user.id], 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 index e4ecac191..2f1687e49 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ # generated from manifests external_dependencies cryptography<37 extract_msg +premailer diff --git a/setup/mail_inline_css/odoo/addons/mail_inline_css b/setup/mail_inline_css/odoo/addons/mail_inline_css new file mode 120000 index 000000000..b8e75268d --- /dev/null +++ b/setup/mail_inline_css/odoo/addons/mail_inline_css @@ -0,0 +1 @@ +../../../../mail_inline_css \ No newline at end of file diff --git a/setup/mail_inline_css/setup.py b/setup/mail_inline_css/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/mail_inline_css/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)