From 6ea9a17f91f43a750c84ea0cfd48add6649d2c50 Mon Sep 17 00:00:00 2001 From: OCA-git-bot <oca-git-bot@odoo-community.org> Date: Mon, 20 Mar 2023 09:50:05 +0000 Subject: [PATCH] [ADD] mail_outbound_static: Forward port #1044 Signed-off-by hbrunn --- mail_outbound_static/README.rst | 6 ++++++ mail_outbound_static/__manifest__.py | 5 ++++- .../i18n/mail_outbound_static.pot | 12 +++++++++++ mail_outbound_static/models/ir_mail_server.py | 12 +++++++++++ mail_outbound_static/readme/CONTRIBUTORS.rst | 1 + mail_outbound_static/readme/DESCRIPTION.rst | 3 +++ mail_outbound_static/readme/USAGE.rst | 1 + .../static/description/index.html | 6 +++++- .../tests/test_ir_mail_server.py | 21 +++++++++++++++++++ .../views/ir_mail_server_view.xml | 4 ++++ 10 files changed, 69 insertions(+), 2 deletions(-) diff --git a/mail_outbound_static/README.rst b/mail_outbound_static/README.rst index e5287cf6a0..ad7711172d 100644 --- a/mail_outbound_static/README.rst +++ b/mail_outbound_static/README.rst @@ -53,6 +53,9 @@ being appended into the proper Sender header instead. To accomplish this we: smtp_from and smtp_whitelist_domain values will be used if there is not mail server configured in the system. +* If your server doesn't support catchall too, you can activate `Reply To The Same Address` + flag, so 'Reply-To' in your message will be the same as 'From'. + **Table of contents** .. contents:: @@ -64,6 +67,7 @@ Usage * Navigate to an Outbound Email Server * Set the `Email From` option to an email address * Set the `Domain Whitelist` option with the domain whitelist +* Set the `Reply to the same address` option to modify 'Reply-To' message field Bug Tracker =========== @@ -81,6 +85,7 @@ Credits Authors ~~~~~~~ +* Solvti sp. z o.o. * brain-tec AG * LasLabs * Adhoc SA @@ -97,6 +102,7 @@ Contributors * `Quartile <https://www.quartile.co>`__: * Yoshi Tashiro +* Sergei Ruzki <sergei.ruzki@gmail.com> Maintainers ~~~~~~~~~~~ diff --git a/mail_outbound_static/__manifest__.py b/mail_outbound_static/__manifest__.py index 5f7bbc7b3c..4db7ab0545 100644 --- a/mail_outbound_static/__manifest__.py +++ b/mail_outbound_static/__manifest__.py @@ -7,7 +7,10 @@ "version": "16.0.1.0.2", "category": "Discuss", "website": "https://github.com/OCA/social", - "author": "brain-tec AG, LasLabs, Adhoc SA, Odoo Community Association (OCA)", + "author": "Solvti sp. z o.o., " + "brain-tec AG, " + "LasLabs, Adhoc SA, " + "Odoo Community Association (OCA)", "license": "LGPL-3", "application": False, "installable": True, diff --git a/mail_outbound_static/i18n/mail_outbound_static.pot b/mail_outbound_static/i18n/mail_outbound_static.pot index da46df8422..f97ecd2b47 100644 --- a/mail_outbound_static/i18n/mail_outbound_static.pot +++ b/mail_outbound_static/i18n/mail_outbound_static.pot @@ -53,6 +53,18 @@ msgstr "" msgid "Not a valid Email From" msgstr "" +#. module: mail_outbound_static +#: model:ir.model.fields,field_description:mail_outbound_static.field_ir_mail_server__reply_to_the_same_address +msgid "Reply To The Same Address" +msgstr "" + +#. module: mail_outbound_static +#: model:ir.model.fields,help:mail_outbound_static.field_ir_mail_server__reply_to_the_same_address +msgid "" +"If you have no catchall support for this server and will activate " +"this option, Reply-To address will be the same as From address." +msgstr "" + #. module: mail_outbound_static #: model:ir.model.fields,help:mail_outbound_static.field_ir_mail_server__smtp_from msgid "" diff --git a/mail_outbound_static/models/ir_mail_server.py b/mail_outbound_static/models/ir_mail_server.py index 04559e120f..6512bc66ab 100644 --- a/mail_outbound_static/models/ir_mail_server.py +++ b/mail_outbound_static/models/ir_mail_server.py @@ -26,6 +26,11 @@ class IrMailServer(models.Model): " match with the domain whitelist." ) + reply_to_the_same_address = fields.Boolean( + help="If you have no catchall support for this server and will activate " + "this option, Reply-To address will be the same as From address." + ) + @api.constrains("domain_whitelist") def check_valid_domain_whitelist(self): if self.domain_whitelist: @@ -93,6 +98,13 @@ def _prepare_email_message(self, message, smtp_session): message.replace_header("Return-Path", email_from) else: message.add_header("Return-Path", email_from) + # If reply to the same address is True, + # Reply-To header field should have the same as sender address + if mail_server.reply_to_the_same_address: + message.replace_header("Reply-To", email_from) if message.get( + "Reply-To" + ) else message.add_header("Reply-To", email_from) + return smtp_from, smtp_to_list, message @api.model diff --git a/mail_outbound_static/readme/CONTRIBUTORS.rst b/mail_outbound_static/readme/CONTRIBUTORS.rst index 96f9e78569..93e743608c 100644 --- a/mail_outbound_static/readme/CONTRIBUTORS.rst +++ b/mail_outbound_static/readme/CONTRIBUTORS.rst @@ -7,3 +7,4 @@ * `Quartile <https://www.quartile.co>`__: * Yoshi Tashiro +* Sergei Ruzki <sergei.ruzki@gmail.com> diff --git a/mail_outbound_static/readme/DESCRIPTION.rst b/mail_outbound_static/readme/DESCRIPTION.rst index b4ffa0ac61..daedfae9ca 100644 --- a/mail_outbound_static/readme/DESCRIPTION.rst +++ b/mail_outbound_static/readme/DESCRIPTION.rst @@ -22,3 +22,6 @@ being appended into the proper Sender header instead. To accomplish this we: * Add compatibility to define the smtp information in Odoo config file. Both smtp_from and smtp_whitelist_domain values will be used if there is not mail server configured in the system. + +* If your server doesn't support catchall too, you can activate `Reply To The Same Address` + flag, so 'Reply-To' in your message will be the same as 'From'. diff --git a/mail_outbound_static/readme/USAGE.rst b/mail_outbound_static/readme/USAGE.rst index 195f5a9396..346098b231 100644 --- a/mail_outbound_static/readme/USAGE.rst +++ b/mail_outbound_static/readme/USAGE.rst @@ -1,3 +1,4 @@ * Navigate to an Outbound Email Server * Set the `Email From` option to an email address * Set the `Domain Whitelist` option with the domain whitelist +* Set the `Reply to the same address` option to modify 'Reply-To' message field diff --git a/mail_outbound_static/static/description/index.html b/mail_outbound_static/static/description/index.html index 3ce778c7c2..bf7416a06e 100644 --- a/mail_outbound_static/static/description/index.html +++ b/mail_outbound_static/static/description/index.html @@ -1,4 +1,3 @@ -<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> @@ -392,6 +391,8 @@ <h1 class="title">Mail Outbound Static</h1> <li>Add compatibility to define the smtp information in Odoo config file. Both smtp_from and smtp_whitelist_domain values will be used if there is not mail server configured in the system.</li> +<li>If your server doesn’t support catchall too, you can activate <cite>Reply To The Same Address</cite> +flag, so ‘Reply-To’ in your message will be the same as ‘From’.</li> </ul> <p><strong>Table of contents</strong></p> <div class="contents local topic" id="contents"> @@ -412,6 +413,7 @@ <h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1> <li>Navigate to an Outbound Email Server</li> <li>Set the <cite>Email From</cite> option to an email address</li> <li>Set the <cite>Domain Whitelist</cite> option with the domain whitelist</li> +<li>Set the <cite>Reply to the same address</cite> option to modify ‘Reply-To’ message field</li> </ul> </div> <div class="section" id="bug-tracker"> @@ -427,6 +429,7 @@ <h1><a class="toc-backref" href="#toc-entry-3">Credits</a></h1> <div class="section" id="authors"> <h2><a class="toc-backref" href="#toc-entry-4">Authors</a></h2> <ul class="simple"> +<li>Solvti sp. z o.o.</li> <li>brain-tec AG</li> <li>LasLabs</li> <li>Adhoc SA</li> @@ -445,6 +448,7 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2> <li>Yoshi Tashiro</li> </ul> </li> +<li>Sergei Ruzki <<a class="reference external" href="mailto:sergei.ruzki@gmail.com">sergei.ruzki@gmail.com</a>></li> </ul> </div> <div class="section" id="maintainers"> diff --git a/mail_outbound_static/tests/test_ir_mail_server.py b/mail_outbound_static/tests/test_ir_mail_server.py index c5f05b0d5d..ed8e7be5af 100644 --- a/mail_outbound_static/tests/test_ir_mail_server.py +++ b/mail_outbound_static/tests/test_ir_mail_server.py @@ -367,3 +367,24 @@ def test_10_not_valid_smtp_from(self): mail_server.smtp_from = "." mail_server.smtp_from = "notifications@test.com" + + def test_11_from_outgoing_server_with_catchall(self): + self._init_mail_server_domain_whilelist_based() + domain = "example.com" + email_from = "test@%s" % domain + + self.message.replace_header("From", email_from) + reply_to_address = self.message["Reply-To"] + message = self._send_mail(self.message) + self.assertEqual(message["Reply-To"], reply_to_address) + + def test_12_from_outgoing_server_no_catchall(self): + self._init_mail_server_domain_whilelist_based() + domain = "example.com" + email_from = "test@%s" % domain + expected_mail_server = self.mail_server_domainone + + self.message.replace_header("From", email_from) + expected_mail_server.reply_to_the_same_address = True + message = self._send_mail(self.message) + self.assertEqual(message["Reply-To"], expected_mail_server.smtp_from) diff --git a/mail_outbound_static/views/ir_mail_server_view.xml b/mail_outbound_static/views/ir_mail_server_view.xml index 5b533e96b4..fc158e20fa 100644 --- a/mail_outbound_static/views/ir_mail_server_view.xml +++ b/mail_outbound_static/views/ir_mail_server_view.xml @@ -13,6 +13,10 @@ <xpath expr="//field[@name='smtp_pass']" position="after"> <field name="domain_whitelist" /> <field name="smtp_from" widget="email" /> + <field + name="reply_to_the_same_address" + attrs="{'invisible': [('smtp_from', '=', False)]}" + /> </xpath> </field> </record>