Commit Graph
451 Commits
Author SHA1 Message Date
roen-odoo fef39f82ac [FIX] mail : Remove double signature on invoice email
Current behavior :
When sending an invoice by email there was 2 signature in the mail

Steps to reproduce :
Create an invoice
Send it by email
Check the mail, there are 2 signatures

opw-2703272

closes odoo/odoo#82347

X-original-commit: 00965df4be591b952b339038c324d7e92596e3d5
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2022-01-06 19:30:53 +00:00
Thibault Delavallée 14bbac3f35 [FIX] base: temporary files were not correctly attached 2021-12-23 12:50:14 +01:00
Olivier Dony ea0e9ec0aa [FIX] tools.mail: ignore original email during encapsulation
When the system broadcasts an email response to document followers,
if the config parameters `mail.force.smtp.from` or
`mail.dynamic.smtp.from` are defined, it will rewrite the `From`
address to avoid spoofing the sender's domain.
**NOTE**: As of 15.0, this is based on the `from_filter` setting on the
corresponding ir.mail_server, rather than the abovementioned config
parameters, but the rest of the discussion stands.

For example, if the `mail.catchall.domain` is set to `example.com` and
an email response comes from:

   "John D" <john@doe.com>

it will rewrite it to:

   "John D (john@doe.com)" <notifications@example.com>

This will make sure the system never sends outgoing email for an external
domain, as it has no authority for doing so, and that could
break mail filtering/authentication rules (SPF, DMARC, etc.)

During this "encapsulation rewrite step", both the original Sender name
and their email are preserved, and put into the quoted "name" field of
the rewritten address. It seems sensible to preserve as much information
as possible about the original sender.

Unfortunately, the inclusion of the Sender email in the final name makes
it appear to some inbox providers as if the message is trying to
deceptively impersonate another person (as many phishing schemes would).
As of November 2021 GMail at least does this, and will hide the name in
the UI when it happens. It will keep only the rewritten email, which is not
very useful in the case of a notification (even though it's more
technically correct, of course).

This patch removes the original email from the rewritten notification,
keeping only the name, considering that the email is not the most
important part, and it's better to have one of the two than none.

So after the patch, the rewritten address is now:

   "John D" <notifications@example.com>

When there is no name in the original address, we keep only the local
part of the email, to avoid the same display issue. The recipient will
have to identify the sender based on the context / past messages.

closes odoo/odoo#81807

X-original-commit: 3c65ec5a8191a392980ceb0a8c584767eae405f1
Signed-off-by: Olivier Dony <odo@odoo.com>
2021-12-22 15:45:53 +00:00
Rémy Voet (ryv) 034d369c10 [FIX] mail: batch _insert_followers in create of mail.thread
The `_insert_followers` wasn't batch in the `create` of `mail.thread`
for no reason, which call the create of a `mail.follower` one by one.
It is inefficient for the batch records creation (import or some
flows) of a model with `_inherit = [mail.thread, ...]`.

Then batch it, to miminize the cost of `_insert_followers`:
The creation of 100 `mail.follower` takes:
- 0.107 sec if you create one by one (before)
- 0.022 sec if you create in batch (now)

Also add two tests (on model with a chatter):
- One testing the behavior of follower and subtype in case of
multi-create
- One testing the number of queries done to create 5 records.
The old SQL request count was 23, now it is 19 (-1 by create
call).

task-2711448

closes odoo/odoo#80954

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-12-21 08:06:57 +00:00
Patrick Hoste a531a7d7e0 [IMP] mail: add lang default value for suggested reciptient
PURPOSE

Before this commit, when a partner was created through the
suggested recipient tool the langage wasn't considered...
The email was thus sent in the wrong langage most of the time
After this commit, the suggested recipient tool had the
langage correctly if present in the record.

LINKS

Task-2580065
PR : odoo/odoo#76812
2021-11-25 11:38:39 +00:00
Thibault Delavallée d348c5e880 [IMP] crm, test_mail: flush tracking in tests involving tracking
Tracking is generated using commit hooks, meaning they are really sent when
the commit ends. This is done to ease values aggregation and accumulation
through various record updates. In some tests we therefore have to manually
flush the tracking, otherwise it is not created and posted. Notably tests about
lead lost wizard were not flushing and therefore not generated the tracking
messages. Those tests will be improved in future commits, cleaning them is
therefore a necessary step.

We also specifically add some tracking flush in mail performance tests. This
is to be sure we measure impact of a write and tracking separately from
previous transactions. Seems everything is working as intended as warmup and
query counters already perform flushes. Here we simply flush at the end
of the setup to be sure all base is clean before starting tests.

Task-2671709

Part-of: odoo/odoo#78648
2021-11-23 09:39:50 +00:00
Thibault Delavallée f9dbd38720 [IMP] mail, various: rename custom_layout / notif_layout context usage
RATIONALE

Currently we can specify email used for notification layouting through context
use in mail composer. It is then propagated to message_post, stored on
mail.message and used to encapsulate emails sent based on posted messages.

SPECIFICATIONS

On template model: rename ``notif_layout`` parameter of ``send_mail`` to
``email_layout_xmlid`` to be coherent with naming used in other parts of the
code. Moreover it better indicates we expect an xml id.

On rating model: rename ``notif_layout`` parameter of ``rating_send_request``
to ``email_layout_xmlid``, for the same reasons as above.

In various wizards: support ``email_layout_xmlid`` context key when no field
is available, notably because this is still done manually in some wizards
like survey invite. Keep a fallback on ``notif_layout`` but remove support of
``custom_layout`` deprecated since quite a long time.

Task-2621326 (Mail: add 'view' button in 'light notification template')
Task-2647302 (Mail: add layout field in composer)

Part-of: odoo/odoo#76418
2021-11-10 09:58:09 +00:00
Thibault Delavallée 88d66434a8 [REM] mail: remove unused notification template
RIP ``mail_notification_borders``. You were a joyful comrade.

Task-2621326 (Mail: add 'view' button in 'light notification template')
Related to odoo/upgrade#2829

Part-of: odoo/odoo#76418
2021-11-10 09:58:09 +00:00
Didier (did) 1afcc9c368 [IMP] bus, mail, *: improve longpolling bus notification format
* = auth_signup, calendar, im_livechat, snailmail_account, survey, test_mail,
    web_editor, website_crm_iap_reveal, website_livechat

The aim of this PR is to improve/fix various flaws and limitation of the current
API, to make it easier to use and more efficient.

Notification are now defined with 3 distinct parts:

- the channel determines which client(s) should receive it
- the type determines how it should be handled
- the payload determines any extra information helpful for handling it

Channel
=======

Business code
-------------

- Record channel is introduced for ease of subscribing to and sending
  notifications to specific partners, channels, documents, ...
- String channel is still supported (but it is converted internally to the tuple
  channel).
- Tuple channel is still supported without any change (but should be avoided
  whenever possible due to its complex syntax).

The channel is no longer sent to the client. When the channel was used for
business purpose, the information it contained has been moved into either the
new type, or the payload itself.

Technical note
--------------

All channels are now internally converted to the tuple (db, ...) channel, which
is necessary for the platform code (saas/sh).

Internally, the bus.bus table is not changed, type and payload are grouped
together into what was (and still is) called message.

Type
====

Type is introduced to uniformize the way notifications are sent and handled.
All existing notifications already had some kind of manually-built type in them.
This is now officially supported at the bus API.

In client code this will allow (to be done in future commits) to register one
handler per specific type, instead of having to iterate and to filter all
received notifications on every handler.

Payload
=======

Payload (ex message) did not change, it can still be anything depending on
business needs.

Few adaptations:
- When the type was included on the payload, the type has been moved to the new
  type parameter.
- When the channel was used in business code, its data has been copied into the
  payload.

task-1891151

closes odoo/odoo#79201

X-original-commit: 543af27c7d6836ffac9e80ff8490b6ddbd849221
Related: odoo/enterprise#21998
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
2021-10-29 16:05:23 +00:00
Thibault Delavallée 9146b68b3f [IMP] test_mail: add test for reply_to computation on records
Purpose is to assert current behavior as this may change in master. Two
kind of tests are added: performance and multi company.

Task-2661036 (Performance tests data cleanup)
Prepares Task-36879 (MultiCompany Aliases)

closes odoo/odoo#77845

Related: odoo/enterprise#21456
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-10-05 16:53:46 +00:00
Thibault Delavallée 201d6bf771 [FIX][IMP] test_mail: be sure performance test include mail gateway
Purpose of query counter tests is to try to match real life use cases. In
mail those generally involve a correctly configured mail gateway. This is
why we set those parameters in performance tests, leading to a small increase
in some counters.

Task-2661036 (Performance tests data cleanup)
Prepares Task-36879 (MultiCompany Aliases)

Part-of: odoo/odoo#77845
2021-10-05 16:53:46 +00:00
Thibault Delavallée f3a24527d2 [IMP] test_mail(_*): improve performance data preparation
Cleanup a bit ``BaseMailPerformance`` class: have more data available done
in setUpClass, then remove unnecessary code in sub classes. Overall purpose
is to lessen boilerplate in sub modules.

Task-2657021 (Performance tests cleanup)
Prepares Task-36879 (MultiCompany Aliases)

Part-of: odoo/odoo#77845
2021-10-05 16:53:46 +00:00
Thibault Delavallée 974f073b11 [FIX] test_mail: improve multicompany activation
Let us use existing data for multi-company tests created when calling a specific
method available in mail tools. We may then remove TestMailMultiCompanyCommon
that is used in a single test, with an hardcoded currency_id (hem).

Task-2661036 (Performance tests data cleanup)
Prepares Task-36879 (MultiCompany Aliases)

Part-of: odoo/odoo#77845
2021-10-05 16:53:45 +00:00
Hubert Van de Walle (huvw) 7ea4eeae86 [FIX] mail: exception when sending an email with \n in the record_name
Step to follow:

  - Create an Asset Models
  - Set up the Fixed Asset Account:

  Automate Asset -> Create in draft or Create and validate
  Asset Model -> The one you have just created

  - Create a Vendor bill

  Account -> the Fixed Asset Account of the asset model created
  Label -> insert a newline
  Price -> (do not forget to set a price)

  - Validate
  - Go to the asset automatically created
  - @ mention a user in the chatter

Cause of the issue:

  The generated email subject comes from the record_name and it can
  contain newlines
  Email headers don't allow newlines and an exception is thrown here
  https://github.com/python/cpython/blob/60b93d9e4922eeae25052bc15909d1f4152babde/Lib/email/policy.py#L143

Solution

  Replace newlines by spaces in the email subject

opw-2522055

closes odoo/odoo#77712

X-original-commit: ed343998d39ff91a3f73cc8012be498d32c91b2f
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-10-04 14:12:30 +00:00
Nicolas Bayet 4813f42997 [IMP] mail,*: replace jinja with qweb
Jinja as a templating engine was problematic in differents respect:
- introduce external dependency to Odoo (less controll)
- add another templating mechanism in the stack
- specific feature in qweb cannot be reused
- difficulty in rendering easily editable templates
- more knowledge required with no betterment

By replacing jinja with qweb we can now build tools to edit a qweb
that will work with the previously jinja encoded document
(essentially `mail.template` records).

There is a catch however. Some email fields (eg. email_to) used jinja
syntax for rendering dynamic variables (ie. ${object.something} and
${object.something_that_should_not_be_escaped | safe}).

We still want user to use dynamic variables for some char fields (eg.
subject, from, to, ...). We made a new rendering engine called
"inline_template" that will render an expression enclosed by `{{` and
`}}`.

To be able to edit the templates from the backend interface, a
plugin to the Odoo editor has been made for seamlessly edit the
document.

This qweb plugin includes:
- make dynamic variables (eg. `<t t-out="variable"/>`) not editable
  (for preventing the user to shoot himself in the foot)
- group and hide related logical branching (ie. t-if, t-elif, and t-else)
  in order to see only one at once
- a floating select input to switch visibility of a particular logical
  branching

Task-27033

X-original-commit: odoo/odoo@68182baff4
Part-of: odoo/odoo#77377
2021-09-28 23:42:54 +00:00
Didier (did) 7ebde25cf7 [FIX] mail: avoid exception when creating channel
When a user without an email partner try to create a channel, an exception is
raised because he has no email.
This exception should not happen when creating a new channel.

task-2641660

closes odoo/odoo#77147

X-original-commit: 0970d8767ac27f9542bb3ad40a6f213f80f408d8
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
2021-09-24 14:00:30 +00:00
Thibault Delavallée c68f655782 [FIX] test_mail: fix activity tests
Fix some activity tests: use real test models, try to avoid date issues
by using freezegun.

Followup of odoo/odoo@a26e6e954c and odoo/odoo@06dee038dd .

Task-2654840

closes odoo/odoo#77120

X-original-commit: 2387c2ee6272a7c260386427c108208e747b819b
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-09-24 11:09:17 +00:00
Habib (ayh) 45ee18ce5b [IMP] mail: enable inheritance in the next activity values computation
values for next activities are currently prepared inside the `mail_activity._action_done()` method which makes inheritance very difficult. This commit delegates the value computation to a sub-method and thereby improves the extensibility of the module.

required to support changes to enterprise documents odoo/enterprise#20769
Task-2627837

closes odoo/odoo#77004

X-original-commit: a26e6e954c5e6c773f37e9239138a7b94ded821f
Related: odoo/enterprise#21079
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-09-22 20:38:59 +00:00
Jairo LlopisandThibault Delavallee 1efeffd297 [FW][IMP] test_mail: test models with type do not mess with attachment types
Purpose of this commit is to highlight an issue that may happens easily with
`crm` that is made generic here within `test_mail`.

`crm` alters the context when creating a new record adding in this case
`default_type` to it][1]. The returned record contains that altered context.
his results in other records created from it trying to assign that same default
value for `type`. This is a very common name for fields, and happens to exist
in `ir.attachment` too.

If you create an alias for incoming leads in your DB with default values
`{"type": "lead"}` (something very common) and then an email comes to that
alias that contains an inlined base64 image, the attachment creation process
would simply fail.

Obtained error is ``ValueError: Wrong value for ir.attachment.type: 'lead'`` .

[1]: https://github.com/odoo/odoo/blob/272602193f5647f7f2270ed6ec68777625a139dd/addons/crm/models/crm_lead.py#L310-L311

X-original-commit: 99434b2e8528c10fcc9cb6860765e0ddcaa364c8
Part-of: odoo/odoo#77005
Co-authored-by: Thibault Delavallee <tde@odoo.com>
2021-09-22 19:25:55 +00:00
Florent de LabarreandThibault Delavallee a8518ae75d [FIX] mail: handle parsing of void body in incoming emails
When body does not contain any tag or content parsing currently fails
with an ``lxml.etree.ParserError``. To avoid that we can improve condition
about void body: stripping void characters allows to avoid that traceback.

Task-2641572
PR odoo#76159
Closes odoo#75625

X-original-commit: 708fe3e74991c144a05c6bdcafa1931672e36ce9
Part-of: odoo/odoo#77005
Co-authored-by: Thibault Delavallee <tde@odoo.com>
2021-09-22 19:25:54 +00:00
Florent de LabarreandThibault Delavallee 1ca67905b4 [FIX] mail: handle wrong Final-Recipient header in incoming emails
Some emails are wrongly formatted mainly due to old servers. If Final-Recipient
header is void or wrongly encoded it currently crashes. This fix ensure there
is no crash, even if bounce detection could be incomplete.

Task-2641572
PR odoo/odoo#76159
Closes odoo/odoo#75618

X-original-commit: f437967a1fa4fca56c88e1cf79586805101ab712
Part-of: odoo/odoo#77005
Co-authored-by: Thibault Delavallee <tde@odoo.com>
2021-09-22 19:25:54 +00:00
Thibault Delavallée 2973ecd720 [IMP] test_mail: improve notification and post tests
Add tests for notification layouts. Purpose of this commit is to test rendering
of all current email notification layouts, ensuring they effectively render
well whatever changes done in mail thread mixin code about template preparation
or rendering. They should also correctly render on simple chatter models which
is currently not the case.

A test ensuring message_post returns an ID when called by RPC should be
called post install. That way we test overrides that frequently break
this method API, and not only the base one.

Task-2621326
PR odoo/odoo#76441

X-original-commit: d7343dc8917505914058b698c59e6520dbacffd5
Part-of: odoo/odoo#76459
2021-09-14 07:11:02 +00:00
Nicolas BayetandThibault Delavallee 60fce9f656 [FIX] mail: allow to preview a template in a specific lang
Followup of odoo/odoo@2d6df1fe7a : when forcing language in template preview
result is not returned according to the expected format.

Add tests.

Task-2643750

closes odoo/odoo#76458

X-original-commit: 80c6001f6f46cc548fb4e337ba71908bea768d86
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Co-authored-by: Thibault Delavallee <tde@odoo.com>
2021-09-14 07:10:57 +00:00
Thibault Delavallée bc7dbfea63 [IMP] test_mail: improve tests for template translations
Extract translations and preparation to setup of TestTemplate class. That
way those are usable in other tests.

Create a new model to test language computation. It holds both a string
and a partner field, allowing to test a bit jinja-based language computation.

Task-2643750

X-original-commit: 7896cbc4f2256122b5cf6c5506921398f2ebc931
Part-of: odoo/odoo#76458
2021-09-14 07:10:57 +00:00
Julien Giannone 63ff23c218 [IMP] mail, web: add message reactions with emojis
task-2361194

closes odoo/odoo#75630

Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
2021-09-07 18:08:11 +00:00
std-odoo cc012a0864 [IMP] mail, various: add email templates management levels
Purpose
=======

Purpose of this commit is to add a new group for the mail template designer.
Goal is to make roles clearer: managers edit templates, users use them. This
commit allow some designers / managers to make email template and to let
others users use those email templates.

Specifications
==============

When this feature is enabled in the Settings page, a new group is required to
modify email templates in a composer like wizard or to make dynamic content.
This allows to separate managers editing / composing templates from standard
users that use them.

If the current does not have this group, the email body will be in readonly
mode if he selected an email template. That way we force him to use the email
template that the manager made.

Technical
=========

New Group
---------

Only users in this group will be able to create / write email template or
to write Jinja code in the mail composer (including other fields like subject
in mailing).

By default, all internal users have this group. Mass mailing users also have
this group as writing mailings is about the same management level as writing
templates.

Mail Composer Mixin
-------------------

In comment mode, the template is rendered and then saved on the body field
so non-"Mail Template Editor" users can load email templates.

But in mass mode, the body of the template is saved and then rendered and
many things change the body (HTML sanitizer, web editor move inline CSS
properties, add / remove spaces...). So in this case, we can not know if
the user changed the body or not. That is why we put the body field in
readonly mode so, it is not modified by the web editor.

Jinja code detection
--------------------

To detect dynamic Jinja content, we compile the template, and we browse the
AST. If we do not have a single "Template Data" node, we assume that the
template is dynamic.

When we detect the template as static, we do not render it. That way we
avoid unnecessary rendering.

Code cleaning
-------------

Move Jinja import into tools so that it is outside of mail framework code.

Task-2187263

closes odoo/odoo#75840

Related: odoo/enterprise#20547
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-09-02 03:42:54 +00:00
Louis Wicket (wil) 80d74e7ee0 [IMP] mail, web, *: add support for guest users
* = crm_livechat, hr, hr_holidays, im_livechat, mail_bot, purchase, sms,
    snailmail, survey, test_discuss_full, test_mail, web_editor, website,
    website_livechat

 - Create new model `mail.guest` for guests.
 - Rewrite some RPCs to target routes rather than model methods so that
   guests are able to use them.
 - Patch JS and python models to support guests.
 - Create a stand-alone page and boot the channel in it.

task-2494829

closes odoo/odoo#75496

Related: odoo/enterprise#20417
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
2021-09-02 00:43:34 +00:00
Thibault Delavallée 5553ad50bf [MOV] mail: reorder model files
As mail grows and will continue to grow, ordering imports and having right
files naming as well as right content in them is important to understand
module organization and content.

Containing

  * reorder init file to give an overview of models;
  * move ResGroups override in its own file, outside of res_users file;
  * split file containing MailActivity model and MailActivityMixin so that
    mixin is contained in its own file, easing followup;
  * split Activity and ActivityType models into two files;

No functional change comes with this commit. This is only code move.

Task-2631873
PR odoo/odoo#75571
2021-08-25 13:12:11 +00:00
Martin Trigaux d9e3aab69b [FIX] mail: convert res_model_id to selection
Following the removal of read access on ir.model (odoo/odoo#69120),
the mail.activity.type model was not accessible to non-admin users due
to the res_model_id many2one field.

Before this commit, a project user could not access the Activity Type
menu.

Convert it to a selection field with the selection values being
computed in sudo.

closes odoo/odoo#74981

Related: odoo/enterprise#20214
Related: odoo/upgrade#2734
Signed-off-by: Martin Trigaux (mat) <mat@odoo.com>
2021-08-23 06:56:00 +00:00
Thibault Delavallée 19ce266dbf [REF] mail: rename notification of mail.mail to is_notification
RATIONALE

Prepare code cleaning and optimization in mail, mass_mailing and SMS by
cleaning models for readability and code complexity and footprint reduction.

SPECIFICATIONS

Purpose is to prepare future changes by easing its grep. Notification is too
much heavily used through the codebase and finding it was quite hard among
other noise.

Rename ``notification`` field to ``is_notification``.

LINKS

Task ID-2377974
Community PR odoo/odoo#61467
Enterprise PR odoo/enterprise#14633
Upgrade PR odoo/upgrade#1907
2021-08-18 13:38:17 +00:00
Thibault DelavalléeandRémy Voet 7e98beef84 [REF] mail: rename mail.notification mail_id to mail_mail_id
PURPOSE

Be aligned with mail_mail model naming as well as convention used in SMS
application (sms_sms_id, sms_sms_int) and mass mailing application (using
mail_mail_id on mailing.trace model).

LINKS

Task ID-2377974
Community PR odoo/odoo#61467
Enterprise PR odoo/enterprise#14633
Upgrade PR odoo/upgrade#1907

Co-Authored-By: Rémy Voet <ryv@odoo.com>
Co-Authored-By: Thibault Delavallée <tde@odoo.com>
2021-08-18 13:38:17 +00:00
Thibault Delavallée e9af609616 [IMP] mail, various: reorganize and lint composer action name
In this commit some reorganization is performed within mail compose message
code. Purpose is to reorder a bit methods by main usage: onchange, CRUD,
actions, values generation with rendering and template management.

Some renaming is performed on action methods, notably send_mail that has some
impact on sub-addons. Finally we also set onchange and sub-onchange methods
private.

No functional change should be implied by this commit.

LINKS

Task ID-2377974
Community PR odoo/odoo#61467
Enterprise PR odoo/enterprise#14633
2021-08-18 13:35:07 +00:00
Thibault Delavallée eebadb323b [MOV] (test_)mail: reorganize mail test tools files
Since a few time, test_mail holds tests linked to specific test models.
Generic testing of mail features are located in mail. Followup of fix done
in 12 and forward ported until odoo/odoo@b7af68590e

Also rename test_mass_mailing_server.py unit test file to test_mailing_server
to match current naming of files.

Task ID-2377974
Community PR odoo/odoo#61467
2021-08-18 13:33:25 +00:00
std-odoo 1b9dd118cb [IMP] base: do no spoof the mail from headers when sending emails
PURPOSE
=======
We want to increase the score of the emails sent by Odoo and we want to
avoid them to be marked as spam by the mail clients (gmail, outook...).

SPECIFICATIONS
===============
From filter
-----------
Add a new field on the "ir.mail_server" which is "from_filter". This
field defines the email address for which the outgoing email server can
be used.

The "from_filter" can either define an email address or a domain name.

Use the system parameter "mail.default.from" which allow us to define
a default email address which is used to encapsulate the emails
(default: notifications@<catch.all.domain>).

Mail server priorities
----------------------
When sending an email, we read the FROM header and,
- We first look for a mail server which match the entire mail FROM
  in that case, we do not change the email header (not needed)
- If not found, we search a mail server which matches the domain name of
  the mail from (do not need to change the headers in that case)
- If not found, find the mail server linked to the "notifications"
  email (defined in the system parameter). Then change the FROM header
  to the notification email, and put the old one in the name part of
  this header.
  E.g.
      Initial mail from: "Admin" < admin@example.com >
      Final mail from:   "Admin (admin@odoo.com)" < notifications@odoo.com >
- If no notification email is configured or if no mail server are
  found for the notification email, fallback to the old system and
  spoof the FROM header. In that case we do not have the choice if we
  want to send the email, he will probably be marked as spam.

Sending method priority
-----------------------
In the mail server models, we defined some priorities,
1. Forced SMTP session
2. Forced mail server
3. Try to find the best mail server (see "Mail server priorities")
4. If not found, read the odoo-bin arguments

Bounce
------
As there's no standard for bounce address, we put it in the envelope
(smtp_from). But in some case, it might be considered as spoofing. So,
we use the bounce address ONLY if the mail server is configured for the
entire domain name.

One behavior which might be broken is the following; we send an email as
"std@gmail.com" and the bounce address is on the domain "odoo.com".
Before we received the bounce notifications but we were spoofing the
local part and the domain.

Now
- if a mail server is configured for GMAIL, we do not use the bounce
  address (and we might not receive the bounce notification)
- if no mail server is configured for GMAIL, but one is configured for
  "odoo.com"
    - the FROM header will be "notifications@odoo.com"
    - the FROM envelope will be the bounce address
=> In this situation we are spoofing only the local part of the email
   but it's allowed as the mail server is configured for the entire
   domain name

LINKS
=====

Task-2367946
odoo/odoo#61853
odoo/upgrade#1903
2021-08-13 12:27:04 +00:00
Sébastien Theys 96d7102ee2 [IMP] mail, *: move init messaging in models and avoid self.env.user
* = im_livechat, test_mail

The goal of moving it in models and making it independent of current user is to
be able to test it easily in future commits.

Part of task-2622462
2021-08-12 10:11:42 +00:00
Martin Trigaux c7bac3dee0 [IMP] *: make ir.model.data helper private
No reason to interfact with them directly in RPC
2021-08-10 13:49:04 +02:00
Xavier-Do 288595f558 [FIX] *: add explicit license to all manifest
The license is missing in most enterprise manifest so
the decision was taken to make it explicit in all cases.
When not defined, a warning will be triggered starting from
14.0 when falling back on the default LGPL-3.

closes odoo/odoo#74245

Related: odoo/design-themes#48
Related: odoo/enterprise#19862
Signed-off-by: Xavier Dollé (xdo) <xdo@odoo.com>
2021-07-26 13:09:57 +00:00
Ivan YelizarievandNicolas Seinlet a88a912bd4 [FIX] mail: speed up read_progress_bar
This commit fixes the performance issue in getting statistics for
``activity_state`` (colored clock icon for overdue/today/planned) in
CRM.  The query has been tested for several years on a large database
(Odoo's own production database).

Performance test on 29 K crm.lead records (activity_state):

With a filter for 10 records:

```
| measurement        | before | after |
|--------------------+--------+-------|
| number of queries  |     25 |     5 |
| query time, ms     |     12 |    95 | (*)
| remaining time, ms |     32 |     7 |
```

All records:

```
| measurement        | before | after |
|--------------------+--------+-------|
| number of queries  |   1326 |     5 |
| query time, ms     |   1739 |   129 |
| remaining time, ms |  47934 |    17 |
```

As we can see in the last results, the time went from almost 50 seconds
(not responsive at all) to 150 milliseconds (responsive).  The time
increase in (*) may be caused by imperfect measurements, which are raw
and not averaged measures.

---

opw-2346901
task-1915411

X-original-commit: 1088e73c9a897902f9d2d70df980fe2a5ed23492
Co-authored-by: Nicolas Seinlet <nse@odoo.com>
2021-07-16 11:16:34 +00:00
Thibault Delavallée 38bf2c2de5 [REF] mail: remove plus addressing on bounce alias
Starting from this commit bounce addresses set in emails will not use any
plus addressing. They will always be ``bounce_alias#@alias_domain`` and
not ``bounce_alias+<mail_id>-<mail_model>-<mail_res_id>@alias_domain``.

Reasons are

  * this plus addressing adds information we do not use anymore since a long
    time as bounced messages are found using their message ID and not any
    information coming from this bounce address;
  * this generates unnecessary noise;
  * not all email providers really support plus addressing as a mean to
    generate "fake" additional email addresses;

This is the followup of odoo/odoo#71244 where a solution to avoid plus
addressing was done in table. We can now safely remove this feature in
master as a cleaning step.

Task ID-2577328

closes odoo/odoo#73363

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-07-07 10:36:36 +00:00
std-odoo 59d6bb23d7 [REM] mail: remove mail channel moderation
Rationale
=========

Currently, mail channels have 2 modes
- They can be used like Discuss channel (chat, livechat, group)
- They can be used like a Mailing List (with the "email_send" field)

The mix of both feature in the same model causes some code complexity.
Several fields are not used in both cases (moderation related field)
and the future "Discord like" Discuss will even push the mail channel
further than the usage of the mailing list.

Because of all those reasons, we want to split the 2 mains features of
the mail channels into 2 different modules and models.

Purpose
=======

This commit remove the moderation feature of the mail channel
(email_send=True). This will be re-implemented in a separate module
in the next commit.

Do not be able to check messages in Discuss anymore because this
feature is only used to moderate the message and this feature will be
spitted in a new module "mail_group".

Links
=====

Task-2510267
See odoo/odoo/pull/71599
See odoo/enterprise/pull/19296
See odoo/upgrade/pull/2600
2021-07-09 11:16:38 +00:00
Thibault Delavallée b7af68590e [IMP] test_mail: add tests for `_find_partner_from_emails`
See odoo/odoo#71047

closes odoo/odoo#73357

X-original-commit: b774cb09f8a44ce23213e80acc7138f96034c15e
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-07-07 09:39:06 +00:00
Thibault Delavallée 76616dc888 [IMP] mail: improve default bounce message
Current bounce message is not very user friendly. Purpose of this commit
is to improve it, by improving wording and overall phrasing used in it.

Form view is improved so that bounce message takes all available width in
form view.

Some tests are added, notably to detect pseudo-void content from editor.

Task ID-2532529
PR odoo/odoo#71793

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-07-07 06:29:01 +00:00
Thibault Delavallée 6bc1244c4f [FIX] test_mail: clean tests about alias mixin
Just move some tests in their own class (test of alias mixin) and quickly clean
them.

Followup of odoo/odoo@7ae1b46

Task ID-2532529
PR odoo/odoo#71793
2021-07-06 13:30:47 +00:00
Nasreddin (bon) ad434daf0f [FW][FIX] mail: display desired company logo in email + test
Steps to reproduce:

  - Install 'Accounting' module
  - Switch to "My Company (Chicago)"
  - Create an invoice
  - Set Invoice date to 1/1/21 and
  - Set Due date to 1/3/21
  - Add any product and 'Confirm' invoice
  - Go to customer profile
  - Click on 'Due' stat button
  - Click on 'Send by mail'

Issue

  In received email, logo displayed is of "My Company (San Francisco)".

Cause

  Env company not used.
  Instead, logo of customer.company_id is used if mail type have
   company_id field,
  else will fallback on user.company_id
  Also, if customer.company_id is null, it will fallback on '0':
  /logo.png?company=%s' % (company.id or 0)

Solution

  If mail record have NOT a company_id field or is not set,
  set company to self.env.company.
  Else, set company to record.company_id.

opw-2474114

closes odoo/odoo#73099

X-original-commit: 316b5956844d6f77f6fef1efeb5a8a8505e36e8e
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-07-01 16:23:46 +00:00
dht-odoo 84e3680d80 [FIX] test_mail: fix randomly failing activity test case
We have a test case 'test_my_activity_flow_employee' that checks user's
own activty for current day. However, the creation of the activities is
done with OdooBot, and 'date_deadline' is not being passed. For this
reason, the default deadline (default value = fields.Date.context_today)
is set based on the tz of OdooBot (which is Europe/Brussels) and so it
might happen that the deadline is set on the next day (when test case
is performed just before mid-night).

In such cases, when we search for today's activites for the employee
(with absolute current date in domain, which is still before midnight),
result can be misleading as we expect one activty for the employee but
none could be found (as deadlines are set for the next day).

This commit fixes the issue by using absolute current for the test case
(whlie setting 'date_dateline' and while searching records) and thus making
it more reliable.

Note: The test case was introduced with commit https://github.com/odoo/odoo/commit/6aa3dc609cb13a469492b1a39a8fd9810040f079

TaskID-2570963

closes odoo/odoo#73034

X-original-commit: 962153a062af3f611e38c0d588febfecd9755810
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-07-01 05:00:45 +00:00
bit-odoo e0df791441 [FIX] (test_)mail: update status of failure notification instantly
Before this commit:

Currently, failure notifications are sent to the author of the message that the
failure is concerning.

However, if another user than the author is resolving the failure, he is not
receiving any notification without refresh the page, so it appears as if nothing
happened even though the failure was indeed resolved
(either message resent, or failure ignored).

After this commit:

When another user than the author update the status of the failure notification
(message resent or failure ignored). the statues of the failure notification
update instantly, no refresh needed to show the updated status.

Task-2178257

closes odoo/odoo#68860

Related: odoo/enterprise#18748
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
2021-06-04 09:17:33 +00:00
Thibault Delavallée 49f95a9a00 [FW][FIX] mail: correctly avoid increasing bounced counter two times
When a bounce has to be managed on a record already inheriting from blacklist
mixin it shoudl not be counted two times: one for email-based bounce and one
for "all records using that email linked to blacklist mechanism should
bounce".

A mechanism exists to prevent that double increase but it was not correctly
done. Protection was reset in a loop.

Task ID-2547347
PR odoo/odoo#72347

closes odoo/odoo#72420

X-original-commit: 6e1bca5df19392d384d7c398b7aea66b62381938
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2021-06-21 10:57:12 +00:00
Jairo Llopis fd2ca5d8ec [FW][IMP] mail: allow to remove plus addressing from bounce return addresses
Since odoo/odoo@f4524f03c3 plus addressing is not used anymore
for handling bounces. Indeed it relies on references / in reply to to find
original message that bounced. It is therefore not necessary to enforce the
use of plus addressing.

As some provider do not support plus addressing as a way to contact left-part
of email with sub-informations people should have a way to deactivate plus
addressing used in bounce aliases.

To preserve backwards compatibility for stable versions old behavior is
retained unless a new `mail.bounce.alias.static` ICP is set with a truthy
value.

Fix https://github.com/odoo/odoo/issues/71242 by dropping requirement of plus addressing.

@Tecnativa TT29827
Closes #71242
Task ID-2547347
PR odoo/odoo#72347

X-original-commit: df2d955bf41b01556e1b84bb1204aac045c95a63
2021-06-21 10:57:11 +00:00
bit-odoo 800f9c499a [FW][FIX] mail, various: show only my activities shown through systray
Before this commit, suppose we have a scenario like below

  Task-A:
    Activity-1:
      name: Email ( Today )
      Assigned to: User-1
  Task-B:
    Activity-1:
      name: Email ( Today )
      assigned to: User-2
    Activity-2:
      name: Call ( Due in 3 Days )
      assigned to: User-1

When User-1 goes through the systray 'Today' filter shortcut he gets both
Task-A and Task-B in the list instead of only Task-A. Indeed currently
activities are not filtered based on current user with its deadlines.

However purpose of systray is to indicate activities current user has to
perform instead of global activities.

After this commit activities will be filtered based on deadlines as well as the
current user. In order to achieve this behavior we needed to pass a domain like
[
   ('activity_ids.date_deadline','=', fields.Date.today()),
   ('activity_ids.user_id','=', 1)
]

And for that purpose we introduced a non-stored compute field with a search
method.

Task ID-2438822
COM PR odoo/odoo#72219

X-original-commit: f4eaf4d8fb2f97240201104dcd4fc7e2674bce02
2021-06-21 07:51:00 +00:00
Aurélien Warnon 6ed53df401 [IMP] mail: add mailing.activity tests based on read_group operation
This commit adds some tests on mailing.activity to ensure read grouping is only
possible when the user has access to the underlying document.

Task-2272475
2021-06-02 07:18:06 +00:00