-
-
Notifications
You must be signed in to change notification settings - Fork 618
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by hbrunn
- Loading branch information
Showing
16 changed files
with
827 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
===================== | ||
Autogenerated headers | ||
===================== | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:c85cef2766e4f4e18f525f38d82ccee67b9e934eee4ca3cccd9ae68783d11a26 | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |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/17.0/mail_autogenerated_header | ||
:alt: OCA/social | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/social-17-0/social-17-0-mail_autogenerated_header | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png | ||
:target: https://runboat.odoo-community.org/builds?repo=OCA/social&target_branch=17.0 | ||
:alt: Try me on Runboat | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module was written to mark Odoo's emails as being autogenerated | ||
according to `RFC 3834 <https://tools.ietf.org/html/rfc3834>`__, section | ||
5. This allows receiving mail servers to act accordingly by for example | ||
not sending a vacation autoreply. | ||
|
||
On the receiving side, this module drops all notifications for | ||
autogenerated incoming e-mails. | ||
|
||
The combination of both avoids possible mail loops with misconfigured or | ||
broken email servers on the opposite side. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Usage | ||
===== | ||
|
||
There's nothing the user has to do. Developers can set the context flag | ||
``mail_autogenerated_header_disable`` in calls to ``send_email`` in | ||
order to suppress adding any headers at all, and override | ||
``_message_route_process_autoreply`` to fine tune dropping autogenerated | ||
mails per model. | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/social/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us to smash it by providing a detailed and welcomed | ||
`feedback <https://github.com/OCA/social/issues/new?body=module:%20mail_autogenerated_header%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
||
Do not contact contributors directly about support or help with technical issues. | ||
|
||
Credits | ||
======= | ||
|
||
Authors | ||
------- | ||
|
||
* Hunki Enterprises BV | ||
* Therp BV | ||
|
||
Contributors | ||
------------ | ||
|
||
- Holger Brunn <mail@hunki-enterprises.com> | ||
(https://hunki-enterprises.com) | ||
|
||
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 <https://github.com/OCA/social/tree/17.0/mail_autogenerated_header>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Copyright 2018 Therp BV <https://therp.nl> | ||
# Copyright 2022 Hunki Enterprises BV <https://hunki-enterprises.com> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Copyright 2018 Therp BV <https://therp.nl> | ||
# Copyright 2022 Hunki Enterprises BV <https://hunki-enterprises.com> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
{ | ||
"name": "Autogenerated headers", | ||
"version": "17.0.1.0.0", | ||
"author": "Hunki Enterprises BV, Therp BV,Odoo Community Association (OCA)", | ||
"website": "https://github.com/OCA/social", | ||
"license": "AGPL-3", | ||
"category": "Tools", | ||
"summary": "Add headers to Odoo's mails indicating they are autogenerated", | ||
"depends": [ | ||
"mail", | ||
], | ||
} |
30 changes: 30 additions & 0 deletions
30
mail_autogenerated_header/i18n/mail_autogenerated_header.pot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * mail_autogenerated_header | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 12.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_autogenerated_header | ||
#: model:ir.model,name:mail_autogenerated_header.model_res_partner | ||
msgid "Contact" | ||
msgstr "" | ||
|
||
#. module: mail_autogenerated_header | ||
#: model:ir.model,name:mail_autogenerated_header.model_mail_thread | ||
msgid "Email Thread" | ||
msgstr "" | ||
|
||
#. module: mail_autogenerated_header | ||
#: model:ir.model,name:mail_autogenerated_header.model_ir_mail_server | ||
msgid "Mail Server" | ||
msgstr "" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Copyright 2018 Therp BV <https://therp.nl> | ||
# Copyright 2022 Hunki Enterprises BV <https://hunki-enterprises.com> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
from . import ir_mail_server | ||
from . import mail_thread |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# Copyright 2018 Therp BV <https://therp.nl> | ||
# Copyright 2022 Hunki Enterprises BV <https://hunki-enterprises.com> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
from odoo import api, models | ||
|
||
|
||
class IrMailServer(models.Model): | ||
_inherit = "ir.mail_server" | ||
|
||
@api.model | ||
def send_email( | ||
self, | ||
message, | ||
mail_server_id=None, | ||
smtp_server=None, | ||
smtp_port=None, | ||
smtp_user=None, | ||
smtp_password=None, | ||
smtp_encryption=None, | ||
smtp_ssl_certificate=None, | ||
smtp_ssl_private_key=None, | ||
smtp_debug=False, | ||
smtp_session=None, | ||
): | ||
# Inject autogenerated header for autogoing mails | ||
|
||
if not self.env.context.get( | ||
"mail_autogenerated_header_disable" | ||
) and self._send_email_set_autogenerated( | ||
message, | ||
mail_server_id=mail_server_id, | ||
smtp_server=smtp_server, | ||
smtp_port=smtp_port, | ||
smtp_user=smtp_user, | ||
smtp_password=smtp_password, | ||
smtp_encryption=smtp_encryption, | ||
smtp_ssl_certificate=smtp_ssl_certificate, | ||
smtp_ssl_private_key=smtp_ssl_private_key, | ||
smtp_debug=smtp_debug, | ||
smtp_session=smtp_session, | ||
): | ||
# MS Exchange's broken version as of | ||
# http://blogs.technet.com/b/exchange/archive/2006/10/06/ | ||
# 3395024.aspx | ||
message["Precedence"] = "bulk" | ||
message["X-Auto-Response-Suppress"] = "OOF" | ||
# The right way to do it as of | ||
# https://tools.ietf.org/html/rfc3834 | ||
message["Auto-Submitted"] = "auto-generated" | ||
|
||
return super().send_email( | ||
message, | ||
mail_server_id=mail_server_id, | ||
smtp_server=smtp_server, | ||
smtp_port=smtp_port, | ||
smtp_user=smtp_user, | ||
smtp_password=smtp_password, | ||
smtp_encryption=smtp_encryption, | ||
smtp_ssl_certificate=smtp_ssl_certificate, | ||
smtp_ssl_private_key=smtp_ssl_private_key, | ||
smtp_debug=smtp_debug, | ||
smtp_session=smtp_session, | ||
) | ||
|
||
@api.model | ||
def _send_email_set_autogenerated( | ||
self, | ||
message, | ||
mail_server_id=None, | ||
smtp_server=None, | ||
smtp_port=None, | ||
smtp_user=None, | ||
smtp_password=None, | ||
smtp_encryption=None, | ||
smtp_ssl_certificate=None, | ||
smtp_ssl_private_key=None, | ||
smtp_debug=False, | ||
smtp_session=None, | ||
): | ||
"""Determine if some mail should have the autogenerated headers""" | ||
|
||
mail = self.env["mail.mail"].search( | ||
[ | ||
("message_id", "=", message["Message-Id"]), | ||
] | ||
) | ||
if not mail: | ||
return False | ||
return mail.subtype_id != self.env.ref("mail.mt_comment") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Copyright 2018 Therp BV <https://therp.nl> | ||
# Copyright 2022 Hunki Enterprises BV <https://hunki-enterprises.com> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). | ||
import logging | ||
|
||
from odoo import api, models | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
class MailThread(models.AbstractModel): | ||
_inherit = "mail.thread" | ||
|
||
@api.model | ||
def _message_route_process(self, message, message_dict, routes): | ||
# Set context key to suppress notification for autogenerated incoming mails | ||
if self._message_route_process_autoreply(message, message_dict, routes): | ||
_logger.info( | ||
"Ignoring email %s from %s because it seems to be an auto " "reply", | ||
message.get("Message-ID"), | ||
message.get("From"), | ||
) | ||
self = self.with_context(mail_autogenerated_header=message) | ||
return super()._message_route_process( | ||
message, | ||
message_dict, | ||
routes, | ||
) | ||
|
||
def _notify_thread(self, message, msg_vals=False, **kwargs): | ||
# Inhibit notifications if this is the notification for an incoming | ||
# autogenerated mail from another system | ||
if self.env.context.get("mail_autogenerated_header"): | ||
return False | ||
return super()._notify_thread(message, msg_vals=msg_vals, **kwargs) | ||
|
||
@api.model | ||
def _message_route_process_autoreply(self, message, message_dict, routes): | ||
"""Determine if some message is an autoreply""" | ||
return ( | ||
message["Auto-Submitted"] | ||
and message["Auto-Submitted"] != "no" | ||
or message["X-Auto-Response-Suppress"] | ||
and set(message["X-Auto-Response-Suppress"].split(", ")) | ||
& set(["AutoReply", "All"]) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[build-system] | ||
requires = ["whool"] | ||
build-backend = "whool.buildapi" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
- Holger Brunn \<<mail@hunki-enterprises.com>\> | ||
(<https://hunki-enterprises.com>) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
This module was written to mark Odoo's emails as being autogenerated | ||
according to [RFC 3834](https://tools.ietf.org/html/rfc3834), section 5. | ||
This allows receiving mail servers to act accordingly by for example not | ||
sending a vacation autoreply. | ||
|
||
On the receiving side, this module drops all notifications for | ||
autogenerated incoming e-mails. | ||
|
||
The combination of both avoids possible mail loops with misconfigured or | ||
broken email servers on the opposite side. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
There's nothing the user has to do. Developers can set the context flag | ||
`mail_autogenerated_header_disable` in calls to `send_email` in order to | ||
suppress adding any headers at all, and override | ||
`_message_route_process_autoreply` to fine tune dropping autogenerated | ||
mails per model. |
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.