Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0] email_headers #341

Open
wants to merge 6 commits into
base: 14.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions email_headers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Robust Mails

This module is used to improve email deliverability and make sure that replies find
their way to the correct thread in Odoo.

Options:

- Force the `From` and `Reply-To` addresses of outgoing email
- Generate a thread-specific `Reply-To` address for outgoing emails so that losing the
headers used to identify the correct thread won't be a problem any more.

## Gotcha

To make the automatic bounce message work when using thread-specific `Reply-To`
addresses, you should define the actual catchall alias in a system parameter called
`mail.catchall.alias.custom` and change the `mail.catchall.alias` to something
completely random that will never be used, or alternatively remove it.

The reason is this: when Odoo is looking for a route for an incoming email that has lost
its headers, it won't check whether the email was sent to `[email protected]` but
instead it will see if the local part of that address contains the word `catchall`. And
this isn't a good thing when the address is something like
`[email protected]`. That's why we had to skip the default catchall
evaluation and redo it in a later phase.

## Database-specific Settings

| Setting | Purpose | Default value |
| --------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------- |
| email_headers.strip_mail_message_ids | Office 365 emails may add whitespaces before the Message-Id's. This feature removes them. | "True" |
| email_headers.prioritize_replyto_over_headers | When "True", Odoo will prioritize the (unique) Reply-To address of an incoming email and only then look at the `References` and `In-Reply-To` headers. | "True" |
| mail.catchall.alias | The default catchall alias. See "Gotcha" for more information. | "catchall" |
| mail.catchall.alias.custom | The new catchall alias setting. See "Gotcha" for more information. Will be set automatically upon module installation. | mail.catchall.alias value |

## Debugging

### Decode and decrypt a message id

```python
from odoo.addons.email_headers.models.mail import decode_msg_id
decode_msg_id(<encrypted and base32/64 encoded message database id>, self.env)
```

### Encrypt and encode a message id

```python
from odoo.addons.email_headers.models.mail import encode_msg_id
encode_msg_id(<message database id>, self.env)
```
32 changes: 32 additions & 0 deletions email_headers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
##############################################################################
#
# Author: Avoin.Systems
# Copyright 2017 Avoin.Systems
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
# noinspection PyUnresolvedReferences
from . import models
from odoo import SUPERUSER_ID, api


def set_catchall_alias(cr, registry):
env = api.Environment(cr, SUPERUSER_ID, {})
icp = env["ir.config_parameter"]
custom_alias = icp.get_param("mail.catchall.alias.custom")
if not custom_alias:
original_alias = icp.get_param("mail.catchall.alias", "catchall")
icp.set_param("mail.catchall.alias.custom", original_alias)
icp.set_param("mail.catchall.alias", "Use mail.catchall.alias.custom")
41 changes: 41 additions & 0 deletions email_headers/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
##############################################################################
#
# Author: Avoin.Systems
# Copyright 2017 Avoin.Systems
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

# noinspection PyStatementEffect
{
"name": "Robust Mails",
"version": "14.0.1.2.0",
"license": "AGPL-3",
"summary": """
Adds fields on outgoing email server that allows you to better control the
outgoing email headers and Reply-To addresses.
""",
"data": ["data/ir_config_parameter_data.xml", "views/ir_mail_server_views.xml"],
"author": "Avoin.Systems",
"website": "https://avoin.systems",
"category": "Email",
"depends": ["mail"],
"external_dependencies": {
"python": ["Crypto.Cipher.AES"], # pip3 install pycryptodome
"bin": [],
},
"installable": True,
"post_init_hook": "set_catchall_alias",
}
14 changes: 14 additions & 0 deletions email_headers/data/ir_config_parameter_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<record id="prioritize_replyto_over_headers" model="ir.config_parameter">
<field name="key">email_headers.prioritize_replyto_over_headers</field>
<field name="value">True</field>
</record>
<!-- The original field was called just strip_message_ids, but since
it's manually set in some production databases, it's risky to
define here. It might break a database upgrade. -->
<record id="strip_mail_message_ids" model="ir.config_parameter">
<field name="key">email_headers.strip_mail_message_ids</field>
<field name="value">True</field>
</record>
</odoo>
21 changes: 21 additions & 0 deletions email_headers/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
##############################################################################
#
# Author: Avoin.Systems
# Copyright 2018 Avoin.Systems
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
# noinspection PyUnresolvedReferences
from . import mail
Loading