summaryrefslogtreecommitdiff
path: root/odoo/tools/mail.py
AgeCommit message (Collapse)Author
2021-05-17[IMP] mail: allow to force the FROM headers of the outgoing mail serverstd-odoo
Purpose ======= We want to be able to force the FROM headers when we sent email in SMTP. So we can avoid the emails to be considered as spam. Specifications ============== This is done with 2 system parameters. If the system parameter `mail.force.smtp.from` is set we encapsulate all outgoing email from with the given value. If the previous system parameter is not set and if both `mail.dynamic.smtp.from` and `mail.catchall.domain` are set, we encapsulate the FROM only if the domain of the email is not the same as the domain of the catchall parameter. Otherwise we do not encapsulate the email (same behavior as before this commit). Task 2367946 See odoo/odoo/pull/61853 closes odoo/odoo#70854 X-original-commit: 044532aed6f796cd93e37556b4a8ce47d2c23a7c Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com> Signed-off-by: Olivier Dony (odo) <odo@openerp.com>
2021-04-28[FIX] mail.py: sanitize do not remove file iconNicolas Lempereur
Scenario: - add a file in mass mailing editor => an icon is added linking the file - save - edit => the icon is replaced by a generic icon - save - send mail => no icon is shown in email received The system is using eg. `data-mimetype="pdf"` to show the icon, before 12.0 this worked but in saas-12.3 the system uses mailing.mailing body_arch's field that is sanitizing attributes and remove it on save, so the icon is only working in received email if you save one and only one time after adding file inside the mass mailing. opw-2474053 (ticket for similar issue in 14.0) closes odoo/odoo#70046 X-original-commit: 7e14515b84d8081557517df7e9dc7d8c0d17f2be Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com>
2021-02-16[FIX] base: mail signature CSS inlined for icons etcNicolas Lempereur
The mail signature of an user did not inline the CSS like the body of a message, so for example icons seemed to work but would not be seen (unless the mail reader had the same font-awesome system). With this change we inline the signature too. On edition there was also an issue since the original icon was saved as data-class which was stripped: so eg. when editing a mail.message with working icon, the icons would disappear. opw-2453912 closes odoo/odoo#66264 X-original-commit: a723bcbebbbc3a526cf63f28b66f53b8be3fe76e Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com>
2020-12-28[FIX] odoo_tools/mail.py: Crash at html2plaintext if no treeAchraf (abz)
What are the steps to reproduce your issue ? 1. Install website_blog 2. Go to website and add a new blog post 3. Remove the block content 4. Save and go to Blog page What is currently happening ? Crash: Template fallback An error occured while rendering the template website_blog.post_teaser opw-241937 closes odoo/odoo#63840 X-original-commit: d9097c2b6244154ea64142b5e8fd31cfdd34e66e Signed-off-by: Achraf <abz-odoo@users.noreply.github.com>
2020-08-05[IMP] mass_mailing: add preview block for mailingsstd-odoo
PURPOSE When displaying an email in a list the mail client (gmail, outlook...) computes a preview based on the content. This preview is generally not well computed as it contains a lot of garbage and tags while it should contain only relevant text. SPECIFICATIONS To build this preview, all mail clients read the content of the email. The only way to be able to customize the preview is to add an invisible HTML element at the beginning of the email with the wanted preview text. We add at the end of the preview `&zwnj;` (zero-width non-joiner) to fill the end of the preview in order to not have the beginning of the mail at the end of the preview. It doesn't work with simple space as the mail clients trim each HTML element content. Task ID-2172125 PR #49886
2020-06-17[FIX] tools: fix tool method to check empty html contentDharmraj Jhala
Since a recent commit[1], we have a utility method in tools named 'is_html_empty' that checks whether the given html content is void(containing only formatting tags) or not. However, the re from this method does not consider the case of self closing tags, fox ex `<br/>`. In such cases, the method returns Falsy value even if the content is void. This commit fixes the issue by considering self-closing void tags in the regular expression. commit[1] - https://github.com/odoo/odoo/commit/974f512f5f5d3b9f80a8c3fcde290e4f55cf1230 Task - 2267689 closes odoo/odoo#53167 X-original-commit: 0fd6c9388dc959a9b6b7828850683175edb05b9d Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2020-06-12[IMP] mass_mailing: send a statistics email to the mailing responsiblestd-odoo
Purpose ======= Provide a follow-up/overview of the Mailing 24 hours after its been sent. Specifications ============== Send an email to the responsible of the mailing 24 hours the last email of the mass mailing. During the link trackers creation, extract the button label if exists (so we can display them in the statistics email). Technical remarks ================= The statistics email is sent to the responsible of each mailing in the CRON of mass mailing. Task-2227411 closes odoo/odoo#49836 Related: odoo/upgrade#1094 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2020-06-11[FIX] tools: add bdi tag as safe tagNicolas Lempereur
We already have BDO tag as allowed tag in sanitized HTML that is similar to BDI tag, so this commit also adds BDI in allowed tags. BDI* tags make sense in email since email client can have different orientation than Odoo (alternative is to use `<div dir="auto"></div>`). *: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/bdi opw-2256982 closes #52787 closes odoo/odoo#52801 X-original-commit: 68edebb0d862acb3dc14f839aaef744306c5e269 Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com>
2020-05-25[IMP] mail,tools: clean tags to kill list in HTML sanitizerStéphane Debauche
Some tags are not necessary in the HTML template and we can remove them to have a proper HTML output. Task 2171753 closes odoo/odoo#51757 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2020-05-14[IMP] tools: remove unnecessary lxml Cleaner overrideStéphane Debauche
Purpose ======= Currently a custom override of Cleaner.allow_element() exists in tools to allow object tags for SVG images. This was due to the first prototype of website builder and its first implementation of image and svg management. This is not necessary anymore as using the tag is sufficient. We can safely clean code in the cleaner, allowing to speedup its performances. As it is used in most html fields and email parsing each unnecessary code removed is time gainged. Task 2215228 closes odoo/odoo#51294 X-original-commit: 4a0b09fd3b0d3b63f2df00f002e4d6825cac4eef Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com> Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
2020-05-05[IMP] ir_mail_server: IDNA and SMTPUTF8 capabilitiesJulien Castiaux
It has been a recurrent request from customers to be able to send email messages to email addresses containing non-ascii characters. [IDNA] is a domain extension to allow unicode characters in domain names. [SMTPUTF8] is a SMTP extension to allow unicode in any header. IDNA defines the [punycode] encoding which translates unicode to an ascii representation. This encoding MUST be used to encode domains. SMTPUTF8 is an SMTP extension that allow utf-8 in all headers on the envelope. [IDNA] https://tools.ietf.org/html/rfc5890 [SMTPUTF8] https://tools.ietf.org/html/rfc6531 [punycode] https://tools.ietf.org/html/rfc3492 Task: 2116928 opw-2229906 opw-2248251 closes odoo/odoo#47709 Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2020-04-24[FIX] mail.py: escape plaintext emailNicolas Lempereur
A plaintext email is displayed in a `<pre/>` tag to conserve spacing. But since there is no escaping, if in this text there was XML tags or HTML entities, they would appear as HTML in browser which is not wanted. Do note that this was not a security issue since the content will still be subjected to the checks and foundling of HTML emails. Without the change, the added test would fail because character &,<,> were not escaped. opw-2242323 closes #50003 closes odoo/odoo#50123 X-original-commit: 932532b5b59e0b71c8e16dadfb2ff36c38764208 Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com> Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
2020-03-31[IMP] base, *: allow html fields not to sanitize formsfja-odoo
* = event, website_event_track, website_sale, website_hr_recruitment, website_livechat, website_sale, website_slides The option to sanitize or not the forms was not available, this will allow better flexibility on whether forms should be sanitized or not on an HTML field. Also we use this new param to allow forms to be added on some already existing html fields where forms where sanitized out. task-2209554 closes odoo/odoo#47318 Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
2020-03-24[MOV] link_tracker, various: more link shortening tools to mail.render.mixinThibault Delavallée
PURPOSE Move links shortening tools on mail.render.mixin to have rendering and post procesing tools available on that mixin. SPECIFICATIONS Move html and text links shortening methods on mail.render.mixin class. That way rendering and post processing is done in that mixin instead of being specific to link.tracker model. Indeed those methods are tools and not really business related methods. Future commits will improve the way mail and sms composer use the render mixin. This commit is therefore both a cleaning and preparing commit. LINKS Task ID 1963529 Community PR odoo/odoo#32397
2020-03-12[IMP] mail: ease bounce email content update based on alias securityRémy Voet (ryv)
PURPOSE When incoming emails bounce due to alias security bounce email is quite generic. Purpose of this task is to ease its customization and update. SPECIFICATIONS In order to improve the flexibility of alias, add a customizable html field on the alias model. This html content will be send as bounce email core content in case of bounced/unauthorized mail received for this alias, Obviously it has no effect on 'everyone' security setting as no email will bounce due to that issue. If it is not set a default generic mail will be send depending on security setting. It allows to keep void html fields when no specific bounce content is required In HR, an old template allowing some light customization for employee based security option is removed as it is completely replaced by the new feature. Also add references message-id of the mail received to the answer so that threads are correctly set. LINKS Task ID 2126509
2020-03-12[IMP] tools: add a tool method to find if an html content is emptyRémy Voet
In odoo empty html is not always completely empty. This tool method allow to consider html holding void tags as empty html. This happens notably when using the editor that may store <p><br><p> even if displayed content is void. Task ID 2126509 PR #41827
2020-02-26[FIX] sms: ensure chatter / SMS have the same contentDebauche Stéphane
When we send a SMS in the contact form view, exact body is sent by SMS and displayed in chatter. If some manual HTML is added chatter will display it as HTML while sms receive HTML tags. We want that the SMS content in the chatter is the same as the SMS sent and that HTML tags are removed to avoid being interpreted. To achieve that goal we call html2plaintext in ``_message_sms`` and in ``prepare_log_body_value`` that are two entry points to send SMS. We also update ``html2plaintext`` to strip result in order to avoid having unnecessary spaces left. Task ID 2126123 PR #40441 closes odoo/odoo#46362 X-original-commit: 4b7b14a5ea5e6ab521838c01813fa478154682fd Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2019-12-16[FIX] tools, mail: improve styling recognition in html fieldsDebauche Stéphane
Purpose of this commit is to better support custom styling used notably for mass mailing and outgoing emails. Indeed styling is whitelisted when storing html. Finding it in html requires some parsing. This commit improves the regex used to find it when semicolons are involved. It allows more use cases to be correctly supported. Task ID #2125856 PR #40433 closes odoo/odoo#41969 X-original-commit: 5235a49a5cd0f79f5590c96afa26dce25465fe06 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2019-11-12[IMP] tools: restore P2 formataddr default behaviorJulien Castiaux
Python 2 `email.tools.formataddr` doesn't encode not RFC-2822 compliant realname to base64 or quoted-printable. This is the wanted behavior to output formatted email addresses on screen. Python 3 `email.tools.formataddr` does encode the realname to be RFC-2822 compliant. This is the wanted behavior when connecting to a smtp server to send emails. That method has been deprecated by pep-594 as the new python email API is capable of automatically formatting email address in a RFC compliant way. As the method was still in use in a lot of modules as the preferred way to format email addresses, a refined P3-like implementation as been included in the tool suite. This commit changes the default behavior so it mimics P2 implementation with an easy way to use the P3 behavior. Task: 2003936
2019-11-12[FIX] tools: correctly format emails when having an encoding issueThibault Delavallée
It seems the emails &gt; &lt; are missing. By the way one manual formataddr is replaced by an email_formatted field. Result is the same but let us use fields doing it for us.
2019-10-09[MERGE] forward port branch 13.0 up to f4105eb9c70Christophe Simonis
2019-10-01[IMP] Prevent reverse tabnabbing in plaintext2html, linkify, _makeLinkSamuel Degueldre
These functions convert plain text links into clickable hyperlinks. These open in new tabs but did not have the "noreferrer noopener" rel attributes, which made them susceptible to reverse tabnabbing. A lot of attack vectors were available to unregistered, uninvited anonymous users and presented a significant phishing threat (such as posting links in the instant-chat, through a mail-alias, in a forum post or in a twitter post) and leading the operator to believe he had been disconnected from odoo in the original tab, prompting them to enter their credentials. while these three places will add the noreferrer and noopener attributes on the anchor tags generated by them, there are still many places that create hyperlinks without the use of these functions, although most of them are static links, they still represent a transitive security vulnerability to the linked sites. There are also a few modules and widgets that roll out their own links or open new tabs unsafely using window.open(), these will need to be patched separately. closes odoo/odoo#37591 Signed-off-by: Olivier Dony (odo) <odo@openerp.com>
2019-09-25[FIX] tools, crm : remove Flanker for email validationDavid Beguin
Since it appears that email validation feature from Flanker v0.9.0 is completelly broken (the lib explodes when calling address.validate_address('some@address.xxx')), Flanker is then removed and email validation will be done only using the email_normalize method. Task ID: 2044539 PR #37413
2019-09-13[MERGE] forward port branch saas-12.4 up to fe59754c520Christophe Simonis
closes odoo/odoo#36721 Signed-off-by: Christophe Simonis <chs@odoo.com>
2019-09-19[REF] base,mail,tools: use new python email APIJulien Castiaux
[PEP 594] is going to depreciate the legacy `email.message.Message` API and its related modules: `email.(charset|header|mime|utils)`. The new `email.message.EmailMessage` API exposes a much easier interface to create multiparted emails [1], is capable of doing all the necessary headers value conversion (RFCs [2045], [2047], [2049]) [2] and get/set different flavor of payload (text/bytes) in a straightforward way [3]. All headers are structured in a way to support python native types, i.e. the `Date` header supports `datetime.datetime` objects and automatically performs the required formatting. The same goes for multi-valued headers like the `To` header, one can directly set a python list of values, it will be automatically be formatted according to the RFCs. The dedicated encoding and decoding functions are no more needed thus has been removed has part of the refactor. FTR, [RFC2231] is an update of [RFC2047] and based on tests we've just conducted, both GMail and Thunderbird now support RFC2231 encoding just fine in all headers: attachments names, From, etc. [1]: http://docs.python.org/3/library/email.message.html [2]: http://docs.python.org/3/library/email.headerregistry.html [3]: http://docs.python.org/3/library/email.contentmanager.html [2045]: https://tools.ietf.org/html/rfc2045 [2047]: https://tools.ietf.org/html/rfc2047 [2049]: https://tools.ietf.org/html/rfc2049 [2231]: https://tools.ietf.org/html/rfc2231 closes odoo/odoo#35929 Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
2019-09-17[REF] mail: remove deprecated email formataddrJulien Castiaux
[PEP 594] is going to depreciate the legacy `email.message.Message` API and its related modules. Among them the `email.utils.formataddr` function, this function takes a `(name, email)` pair and returns a string value suitable for From, To and Cc headers. The stdlib function is capable of handling several character encoding and two binary-to-ascii encoding. Odoo only uses `utf-8` which is compatible with the base64 b2a encoding. The re-implementation of that function has been simplified to only support base64-ed utf-8 and ascii. [PEP 594]: https://www.python.org/dev/peps/pep-0594/\#email-lagacy-api
2019-09-11[MERGE] forward port branch saas-12.3 up to 50e571acf7cChristophe Simonis
closes odoo/odoo#36491 Signed-off-by: Christophe Simonis <chs@odoo.com>
2019-08-30[MERGE] forward port branch 12.0 up to 52f6e38cea8Christophe Simonis
2019-08-29[MERGE] forward port branch saas-11.3 up to ede253f1b2eChristophe Simonis
2019-08-27[MERGE] forward port branch 11.0 up to 1385b60004dChristophe Simonis
2019-08-27[MERGE] forward port branch saas-15 up to ea821b991aeChristophe Simonis
2019-08-27[MERGE] forward port branch 10.0 up to da474d0e872Christophe Simonis
2019-08-22[FIX] web_editor: parallax effect in sanitized fieldNicolas Lempereur
A sanitize fields by default remove all attributes outside of a whitelist (if sanitize_attributes on field is not set to false). This prevent to use parallax widget in Html sanitized field since attribute "data-scroll-background-ratio" define parallax effect speed but was not in whitelist. note: also keep data-interval for gallery widget opw-2053983 closes #35961 Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com>
2019-08-09[REF] mail: perform some code cleaning in mail gateway about parsing email ↵Thibault Delavallée
values PURPOSE Add some improvements in mail gateway: remove private discussion, improve bounce management, allow resetting bounce counters, improve automatic set or reset of blacklists and ease mass mailing inheritance. SPECIFICATIONS Parsing email values: make message_parse effectively prepare all required values for later processing * update message_parse to add some more data directly in parsed dictionary and avoid having to parse value again in later processing and computation. * notably recipients computation is now done directly in parsing. It includes email check and reconstruction using tools methods. That way routing just has to handle those values and not compute part of them; * from and cc are correctly managed with parsed and cleaned (sanitized) versions in dictionary; * remove all code decoding message header and replace them by fetching the parsed value instead; * filter parsed values before calling message_post to ensure right values are given to it instead of having to manage them in message_post. Indeed caller has to give the right input; * make parsing sub-methods (extract payload, post process payload) have a dictionary as input and output to always manage a dictionary of values through the parsing methods and update their namespace; Routing: remove deprecated code parts * remove use of email_references regex. Indeed emails are routed using their messageId and not the regex anymore since several versions [1]; * clean some unnecessary variables; * simplify variable type input, like message_parse accepts only valid email.message instances and to avoid several decode / encode. Tests are updated accordingly; Update docstrings of those methods. LINKS Related to task 1893155 Linked to PR #33340 [1] See df037e295971650e8843b2ee668501e7aa3e7df6 and 0028c42136f02fcb7a9a81ed5763396290ffdcb8
2019-06-11[IMP] tools : add email_validate optionaly using flankerDavid Beguin
As Flanker can be used to validate an email address and was originally used in website_crm_score module, the Flanker usage is now moved into tools. This commit prepares the next Predictive Lead Scoring (aka PLS) ones as PLS will use the email state as computation variable, it will need this flanker validation to compute first the email state. We use also the already implemented normalized email as a double validation. Flanker is not in the required dependencies of Odoo : So if flanker is installed, it will check if email is valid (checking DNS and other standard rules). If Flanker is not installed, email_validate will only normalize the email. Anyway, the email must at least be normalizable. Task ID : 1925439 PR #33589
2019-05-09[IMP] mail: improve "Pay Now" email notification layoutBarad Mahendra
In mail custom layout template display 'best regards' and signature in email only when user exists and is not odoobot. Border-bottom style is also now white-listed in sanitizer in order to ease customization of emails. Related to task ID 1873634 Linked to PR #28781
2019-03-28[IMP] mail, test_mail, *: add new email.cc.mixin on main modelsXavierDo
*: crm, project, maintenance, hr_recruitment When a record is created from an email, cc can be lost. This commit proposes a new mixin to keep cc on the record and allows to create partner for each of them when sending a message from the chatter. The mixin is added on the mail recors that can be created from mail.alias: document helpdesk.ticket mrp.eco quality.alert hr.applicant crm.lead project.task mail.channel maintenance.equipment Task: 1925001
2019-02-07[FIX] core: remove email escape logic from html_sanitize.XavierDo
Related to #30326 Before #30326, when calling html_sanitize, some content may be escaped when it shouldn't. A simple example was images with cid links containing @. (a first fix for another use case was made in 8aff53733b6ca1dd6f8074834ada1baaab3910d5) We suspect that this escaping (added in 71a92f46e4e223a3bad0e27ececa2ece3c09f5d1) was made to avoid loosing email with format '<email@domaine>' in html_sanitize to escape them if html_sanitize is called on plain text. Anyway, only html should be passed to html_sanitize, and therefore email of format <email@domain> should already be escaped. PR #30326 fixes the unwanted behaviour in 12.0 and this commit removes this logic in master. closes odoo/odoo#30815
2019-01-31[MERGE] forward port branch 12.0 up to cb8fefa8999Christophe Simonis
2019-01-17[FIX] base: avoid to escape image when src contains @XavierDo
The content id of an attachement can contains a @, therefore image contained in emails where sometimes escaped by html_sanitize as if they were emails adresses. Task: 1915251 closes odoo/odoo#30326
2018-11-29[REM] pycompat: remove python 2 shims and helpersAdrian Torres
Odoo no longer supports python 2, thus some of these helpers can and have been replaced by python 3 built-ins, therefore there is no need for them to stay defined. The removed helpers are: * izip, imap and ifilter * unichr, text_type * implements_to_string, implements_iterator * string_types, integer_types * to_native The python 2 shims have also been removed, and only the python 3 helpers have been kept, because they can still be usable (i.e. accepting both bytes and str for functions that can only accept one of the two) [REM] pyjsparser: remove PY3 shims They're no longer necessary as Odoo doesn't officially support python 2 anymore. closes odoo/odoo#28519
2018-11-29[REF] *: replace deprecated pycompat helpers for builtinsAdrian Torres
This commit replaces calls to pycompat helpers that were intended for python 2 <-> python 3 interoperability for python 3 builtins, as python 2 is no longer officially supported by Odoo. This includes: * calls to imap/izip/ifilter replaced by map/zip/filter * uses of text_type replaced by str * uses of unichr replaced by chr * calls to implements_to_string, implements_iterator removed * string_types and integer_types replaced by str, int respectively * calls to to_native replaced by calls to to_text This is done in preparation to the removal of these deprecated helpers in the following commit.
2018-11-20[IMP] tools, mail : adds email normalization method in mail toolsDavid Beguin
In order to normalize email independently from the mail.address.mixin model.
2018-08-21[MERGE] forward port branch saas-11.3 up to 6cc7d3f9451Christophe Simonis
2018-08-21[MERGE] forward port branch 11.0 up to fbfb91799eeChristophe Simonis
2018-08-17[FIX] tools: sanitize allow white-space styleLucas Perais (lpe)
OPW 1870847
2018-08-09[MERGE] forward port branch saas-11.3 up to af35aea6b0dChristophe Simonis
2018-08-07[MERGE] forward port branch saas-11.2 up to d7e2c767ce5Christophe Simonis
2018-08-06[FIX] base: inline buttons was breaking into multiple lines (outlook hack)Deep Patel
Because we converted buttons into tables so inline buttons was breaking into multiple lines so we need to add display inline and vertical align properties in tables. We allowed display property from mail sensitizer whitelist. Because in this commit https://github.com/odoo/odoo/commit/cf15030ed09f7479f5b2701ba101a5bed71f7409 we use display property for align items
2018-06-08[IMP] tools: allow more items in styling white list when sanitizingPratima Gupta
Some of the templates Odoo proposed do not display well on all email readers as too much styling attributes are sanitized. This commit adds some styling in the white list to allow having stylized templates while still having a coherent white list. This commit is related to task 51122 (and PR #24052).