From 360f10cb1e00c0b58f34061327107e796c6f7fa5 Mon Sep 17 00:00:00 2001 From: Luis Carlos Bautista Date: Mon, 19 Apr 2021 14:02:22 +0200 Subject: [PATCH] new: blacklist recipients --- __terp__.py | 1 + poweremail_core.py | 21 ++++++++++++++++++++- poweremail_data.xml | 9 +++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 poweremail_data.xml diff --git a/__terp__.py b/__terp__.py index 76ef3fe..d1cd867 100644 --- a/__terp__.py +++ b/__terp__.py @@ -57,6 +57,7 @@ 'poweremail_template_view.xml', 'poweremail_send_wizard.xml', 'poweremail_mailbox_view.xml', + 'poweremail_data.xml', 'poweremail_serveraction_view.xml' ], "installable": True, diff --git a/poweremail_core.py b/poweremail_core.py index 18c2017..cf77c92 100644 --- a/poweremail_core.py +++ b/poweremail_core.py @@ -40,7 +40,7 @@ from tools import config import tools import six - +from ast import literal_eval as eval from qreu import Email from qreu.address import Address, parseaddr from qreu.sendcontext import Sender, SMTPSender @@ -532,6 +532,25 @@ def parse_sender(pem_account, pem_addresses): "when the addresses list is empty").format(ids) ) return error + varconf_o = self.pool.get('res.config') + blacklisted_recipients = set(eval( + varconf_o.get(cr, uid, 'poweremail_recipients_blacklist', '[]') + )) + recipients = set(addresses_list.get('To', []) + addresses_list.get('CC', []) + addresses_list.get('BCC', [])) + if len(blacklisted_recipients - recipients) != len(blacklisted_recipients): + error_mssg_blacklisted_recipients = _( + "ERROR: Trying to send an email to a blacklisted recipient:\n" + " - recipients: {}\n" + " - blacklisted recipients: {}" + ).format( + ", ".join(list(recipients)), + ", ".join(list(blacklisted_recipients)) + ) + logger.notifyChannel( + _("Power Email"), netsvc.LOG_ERROR, + error_mssg_blacklisted_recipients + ) + return Exception(error_mssg_blacklisted_recipients) # Get email Data subject = subject or context.get('subject', '') or '' body_html = parse_body_html( diff --git a/poweremail_data.xml b/poweremail_data.xml new file mode 100644 index 0000000..e4f082b --- /dev/null +++ b/poweremail_data.xml @@ -0,0 +1,9 @@ + + + + + poweremail_recipients_blacklist + [] + + +