Hi Othmane,
For which model/module/form, you want to avoid?
You need to set context flag to that model's message_post() and this method create mail record so context pass to mail creation method and in that method you can check condition that context flag found than block email sending otherwise send email.
I am giving you hint.
1) Basically email send when you send message from chatter (bottom of any form), so in that model of that form, there is a method called message_post() thhis method send mail. So here you can add context flag.
2) So where to check context flag?:
There is a method in mail module (mail/models/res_partner(line no: 88-191)), the method _notify(), will prepare mail data and send mail.
So in that method go to line no: 149 (email = Mail.create(create_values))
and add condition here to block email sending.
You can add code like
if not self._context.get('CONTEXT_FLAG'):
# Line no: 149-164
email = Mail.create(create_values)
if email and recipient_ids:
notifications = self.env['mail.notification'].sudo().search([
('mail_message_id', '=', email.mail_message_id.id),
('res_partner_id', 'in', list(recipient_ids))
])
notifications.write({
'is_email': True,
'mail_id': email.id,
'is_read': True, # handle by email discards Inbox notification
'email_status': 'ready',
})
emails |= email
email_pids.update(recipient_ids)
I know it's innocent thing, but if you want to block for specific purpose then you need to custome code like this.
I hope it will helpful for you.
Thanks and regards
Haresh Kansara